aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS7
-rw-r--r--Documentation/ABI/testing/sysfs-devices-system-cpu2
-rw-r--r--Documentation/IPMI.txt5
-rw-r--r--Documentation/acpi/enumeration.txt2
-rw-r--r--Documentation/acpi/gpio-properties.txt6
-rw-r--r--Documentation/devicetree/bindings/arm/omap/l3-noc.txt1
-rw-r--r--Documentation/devicetree/bindings/clock/silabs,si5351.txt4
-rw-r--r--Documentation/devicetree/bindings/dma/fsl-mxs-dma.txt2
-rw-r--r--Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt (renamed from Documentation/devicetree/bindings/mtd/m25p80.txt)6
-rw-r--r--Documentation/devicetree/bindings/net/cdns-emac.txt3
-rw-r--r--Documentation/devicetree/bindings/rtc/abracon,abx80x.txt30
-rw-r--r--Documentation/devicetree/bindings/sound/adi,adau1701.txt4
-rw-r--r--Documentation/devicetree/bindings/sound/bt-sco.txt13
-rw-r--r--Documentation/devicetree/bindings/sound/renesas,rsnd.txt1
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.txt1
-rw-r--r--Documentation/hwmon/tmp4012
-rw-r--r--Documentation/kasan.txt8
-rw-r--r--Documentation/kernel-parameters.txt2
-rw-r--r--Documentation/module-signing.txt6
-rw-r--r--Documentation/networking/mpls-sysctl.txt9
-rw-r--r--Documentation/networking/scaling.txt2
-rw-r--r--Documentation/powerpc/transactional_memory.txt32
-rw-r--r--Documentation/serial/tty.txt3
-rw-r--r--Documentation/target/tcmu-design.txt33
-rw-r--r--Documentation/virtual/kvm/mmu.txt18
-rw-r--r--MAINTAINERS98
-rw-r--r--Makefile2
-rw-r--r--arch/alpha/boot/Makefile16
-rw-r--r--arch/alpha/boot/main.c1
-rw-r--r--arch/alpha/boot/stdio.c306
-rw-r--r--arch/alpha/boot/tools/objstrip.c3
-rw-r--r--arch/alpha/include/asm/types.h1
-rw-r--r--arch/alpha/include/asm/unistd.h2
-rw-r--r--arch/alpha/include/uapi/asm/unistd.h3
-rw-r--r--arch/alpha/kernel/err_ev6.c1
-rw-r--r--arch/alpha/kernel/irq.c1
-rw-r--r--arch/alpha/kernel/osf_sys.c3
-rw-r--r--arch/alpha/kernel/process.c7
-rw-r--r--arch/alpha/kernel/smp.c8
-rw-r--r--arch/alpha/kernel/srmcons.c3
-rw-r--r--arch/alpha/kernel/sys_marvel.c2
-rw-r--r--arch/alpha/kernel/systbls.S3
-rw-r--r--arch/alpha/kernel/traps.c1
-rw-r--r--arch/alpha/oprofile/op_model_ev4.c1
-rw-r--r--arch/alpha/oprofile/op_model_ev5.c1
-rw-r--r--arch/alpha/oprofile/op_model_ev6.c1
-rw-r--r--arch/alpha/oprofile/op_model_ev67.c1
-rw-r--r--arch/arc/Kconfig.debug13
-rw-r--r--arch/arc/include/asm/atomic.h2
-rw-r--r--arch/arc/mm/cache_arc700.c4
-rw-r--r--arch/arm/boot/dts/Makefile2
-rw-r--r--arch/arm/boot/dts/am335x-boneblack.dts4
-rw-r--r--arch/arm/boot/dts/am335x-evmsk.dts2
-rw-r--r--arch/arm/boot/dts/am437x-sk-evm.dts4
-rw-r--r--arch/arm/boot/dts/am57xx-beagle-x15.dts11
-rw-r--r--arch/arm/boot/dts/armada-375.dtsi2
-rw-r--r--arch/arm/boot/dts/armada-38x.dtsi2
-rw-r--r--arch/arm/boot/dts/armada-39x.dtsi2
-rw-r--r--arch/arm/boot/dts/armada-xp-openblocks-ax3-4.dts4
-rw-r--r--arch/arm/boot/dts/dove-cubox.dts1
-rw-r--r--arch/arm/boot/dts/dra7.dtsi10
-rw-r--r--arch/arm/boot/dts/exynos4412-odroid-common.dtsi3
-rw-r--r--arch/arm/boot/dts/exynos4412-trats2.dts2
-rw-r--r--arch/arm/boot/dts/exynos5250-snow.dts1
-rw-r--r--arch/arm/boot/dts/exynos5420-peach-pit.dts1
-rw-r--r--arch/arm/boot/dts/exynos5420-trip-points.dtsi2
-rw-r--r--arch/arm/boot/dts/exynos5420.dtsi1
-rw-r--r--arch/arm/boot/dts/exynos5440-trip-points.dtsi2
-rw-r--r--arch/arm/boot/dts/exynos5800-peach-pi.dts1
-rw-r--r--arch/arm/boot/dts/imx23-olinuxino.dts4
-rw-r--r--arch/arm/boot/dts/imx25.dtsi1
-rw-r--r--arch/arm/boot/dts/imx27.dtsi2
-rw-r--r--arch/arm/boot/dts/imx28.dtsi2
-rw-r--r--arch/arm/boot/dts/imx6qdl-phytec-pfla02.dtsi2
-rw-r--r--arch/arm/boot/dts/imx6qdl-sabreauto.dtsi1
-rw-r--r--arch/arm/boot/dts/omap3-devkit8000.dts2
-rw-r--r--arch/arm/boot/dts/omap3-n900.dts4
-rw-r--r--arch/arm/boot/dts/omap3.dtsi2
-rw-r--r--arch/arm/boot/dts/omap5.dtsi2
-rw-r--r--arch/arm/boot/dts/r8a7791-koelsch.dts2
-rw-r--r--arch/arm/boot/dts/ste-dbx5x0.dtsi17
-rw-r--r--arch/arm/boot/dts/ste-href.dtsi15
-rw-r--r--arch/arm/boot/dts/ste-snowball.dts13
-rw-r--r--arch/arm/boot/dts/tegra124.dtsi8
-rw-r--r--arch/arm/boot/dts/vexpress-v2p-ca15_a7.dts1
-rw-r--r--arch/arm/boot/dts/vexpress-v2p-ca9.dts11
-rw-r--r--arch/arm/boot/dts/zynq-7000.dtsi4
-rw-r--r--arch/arm/configs/multi_v7_defconfig5
-rw-r--r--arch/arm/configs/omap2plus_defconfig2
-rw-r--r--arch/arm/include/asm/dma-iommu.h2
-rw-r--r--arch/arm/include/asm/xen/page.h1
-rw-r--r--arch/arm/kernel/entry-common.S4
-rw-r--r--arch/arm/kernel/perf_event_cpu.c12
-rw-r--r--arch/arm/mach-exynos/common.h2
-rw-r--r--arch/arm/mach-exynos/exynos.c27
-rw-r--r--arch/arm/mach-exynos/platsmp.c39
-rw-r--r--arch/arm/mach-exynos/pm_domains.c4
-rw-r--r--arch/arm/mach-exynos/suspend.c7
-rw-r--r--arch/arm/mach-gemini/common.h4
-rw-r--r--arch/arm/mach-gemini/reset.c4
-rw-r--r--arch/arm/mach-imx/devices/platform-sdhci-esdhc-imx.c2
-rw-r--r--arch/arm/mach-imx/gpc.c16
-rw-r--r--arch/arm/mach-omap2/omap_hwmod.c68
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_43xx_data.c70
-rw-r--r--arch/arm/mach-omap2/prcm43xx.h3
-rw-r--r--arch/arm/mach-omap2/prm-regbits-34xx.h1
-rw-r--r--arch/arm/mach-omap2/prm-regbits-44xx.h1
-rw-r--r--arch/arm/mach-omap2/prminst44xx.c20
-rw-r--r--arch/arm/mach-omap2/timer.c13
-rw-r--r--arch/arm/mach-omap2/vc.c12
-rw-r--r--arch/arm/mach-omap2/vc.h2
-rw-r--r--arch/arm/mach-omap2/vc3xxx_data.c1
-rw-r--r--arch/arm/mach-omap2/vc44xx_data.c1
-rw-r--r--arch/arm/mach-pxa/Kconfig9
-rw-r--r--arch/arm/mach-pxa/Makefile1
-rw-r--r--arch/arm/mach-pxa/include/mach/lubbock.h7
-rw-r--r--arch/arm/mach-pxa/include/mach/mainstone.h6
-rw-r--r--arch/arm/mach-pxa/lubbock.c108
-rw-r--r--arch/arm/mach-pxa/mainstone.c115
-rw-r--r--arch/arm/mach-pxa/pxa_cplds_irqs.c200
-rw-r--r--arch/arm/mach-rockchip/pm.c7
-rw-r--r--arch/arm/mach-rockchip/pm.h4
-rw-r--r--arch/arm/mach-rockchip/rockchip.c19
-rw-r--r--arch/arm/mm/dma-mapping.c13
-rw-r--r--arch/arm/mm/mmu.c20
-rw-r--r--arch/arm/mm/proc-arm1020.S2
-rw-r--r--arch/arm/mm/proc-arm1020e.S2
-rw-r--r--arch/arm/mm/proc-arm925.S3
-rw-r--r--arch/arm/mm/proc-feroceon.S1
-rw-r--r--arch/arm/net/bpf_jit_32.c42
-rw-r--r--arch/arm/xen/enlighten.c1
-rw-r--r--arch/arm/xen/mm.c15
-rw-r--r--arch/arm64/Kconfig1
-rw-r--r--arch/arm64/boot/dts/arm/juno-motherboard.dtsi31
-rw-r--r--arch/arm64/crypto/crc32-arm64.c22
-rw-r--r--arch/arm64/crypto/sha1-ce-glue.c3
-rw-r--r--arch/arm64/crypto/sha2-ce-glue.c3
-rw-r--r--arch/arm64/include/asm/barrier.h16
-rw-r--r--arch/arm64/kernel/alternative.c53
-rw-r--r--arch/arm64/kernel/perf_event.c9
-rw-r--r--arch/arm64/mm/dma-mapping.c9
-rw-r--r--arch/arm64/mm/dump.c2
-rw-r--r--arch/arm64/net/bpf_jit_comp.c2
-rw-r--r--arch/ia64/pci/pci.c13
-rw-r--r--arch/m32r/kernel/smp.c6
-rw-r--r--arch/mips/Makefile2
-rw-r--r--arch/mips/ath79/prom.c3
-rw-r--r--arch/mips/configs/fuloong2e_defconfig2
-rw-r--r--arch/mips/include/asm/elf.h4
-rw-r--r--arch/mips/include/asm/smp.h2
-rw-r--r--arch/mips/kernel/elf.c32
-rw-r--r--arch/mips/kernel/irq.c2
-rw-r--r--arch/mips/kernel/ptrace.c2
-rw-r--r--arch/mips/kernel/smp-bmips.c2
-rw-r--r--arch/mips/kernel/smp-cps.c2
-rw-r--r--arch/mips/kernel/smp.c6
-rw-r--r--arch/mips/kernel/traps.c1
-rw-r--r--arch/mips/kvm/emulate.c6
-rw-r--r--arch/mips/lib/strnlen_user.S15
-rw-r--r--arch/mips/math-emu/cp1emu.c4
-rw-r--r--arch/mips/mm/tlb-r4k.c2
-rw-r--r--arch/mips/sgi-ip32/ip32-platform.c4
-rw-r--r--arch/parisc/include/asm/elf.h4
-rw-r--r--arch/parisc/kernel/process.c10
-rw-r--r--arch/parisc/kernel/sys_parisc.c3
-rw-r--r--arch/powerpc/include/uapi/asm/tm.h2
-rw-r--r--arch/powerpc/kernel/eeh.c11
-rw-r--r--arch/powerpc/kernel/entry_64.S19
-rw-r--r--arch/powerpc/kernel/idle_power7.S2
-rw-r--r--arch/powerpc/kernel/mce.c4
-rw-r--r--arch/powerpc/kernel/vmlinux.lds.S1
-rw-r--r--arch/powerpc/kvm/book3s_hv.c5
-rw-r--r--arch/powerpc/kvm/book3s_xics.c2
-rw-r--r--arch/powerpc/mm/hugetlbpage.c25
-rw-r--r--arch/powerpc/mm/pgtable_64.c11
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c2
-rw-r--r--arch/powerpc/platforms/pseries/dlpar.c10
-rw-r--r--arch/s390/Kconfig2
-rw-r--r--arch/s390/crypto/crypt_s390.h122
-rw-r--r--arch/s390/crypto/ghash_s390.c25
-rw-r--r--arch/s390/crypto/prng.c850
-rw-r--r--arch/s390/include/asm/kexec.h3
-rw-r--r--arch/s390/include/asm/mmu.h4
-rw-r--r--arch/s390/include/asm/mmu_context.h3
-rw-r--r--arch/s390/include/asm/pgalloc.h1
-rw-r--r--arch/s390/include/asm/pgtable.h169
-rw-r--r--arch/s390/mm/hugetlbpage.c66
-rw-r--r--arch/s390/mm/pgtable.c142
-rw-r--r--arch/s390/net/bpf_jit_comp.c19
-rw-r--r--arch/tile/kernel/setup.c2
-rw-r--r--arch/x86/boot/compressed/eboot.c2
-rw-r--r--arch/x86/include/asm/hypervisor.h2
-rw-r--r--arch/x86/include/asm/kvm_host.h3
-rw-r--r--arch/x86/include/asm/pvclock.h1
-rw-r--r--arch/x86/include/asm/spinlock.h2
-rw-r--r--arch/x86/include/asm/xen/page.h5
-rw-r--r--arch/x86/include/uapi/asm/msr-index.h1
-rw-r--r--arch/x86/kernel/cpu/hypervisor.c4
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c7
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel.c73
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_rapl.c1
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c12
-rw-r--r--arch/x86/kernel/i387.c15
-rw-r--r--arch/x86/kernel/process.c14
-rw-r--r--arch/x86/kernel/pvclock.c44
-rw-r--r--arch/x86/kvm/cpuid.c4
-rw-r--r--arch/x86/kvm/cpuid.h8
-rw-r--r--arch/x86/kvm/mmu.c16
-rw-r--r--arch/x86/kvm/mmu.h4
-rw-r--r--arch/x86/kvm/paging_tmpl.h7
-rw-r--r--arch/x86/kvm/svm.c1
-rw-r--r--arch/x86/kvm/vmx.c1
-rw-r--r--arch/x86/kvm/x86.c59
-rw-r--r--arch/x86/mm/ioremap.c14
-rw-r--r--arch/x86/net/bpf_jit_comp.c35
-rw-r--r--arch/x86/pci/acpi.c37
-rw-r--r--arch/x86/vdso/Makefile2
-rw-r--r--arch/x86/vdso/vclock_gettime.c34
-rw-r--r--arch/x86/xen/enlighten.c27
-rw-r--r--arch/x86/xen/suspend.c10
-rw-r--r--arch/xtensa/include/asm/dma-mapping.h13
-rw-r--r--block/blk-core.c7
-rw-r--r--block/blk-mq.c60
-rw-r--r--block/blk-sysfs.c2
-rw-r--r--block/bounce.c2
-rw-r--r--block/elevator.c6
-rw-r--r--crypto/Kconfig9
-rw-r--r--crypto/algif_aead.c9
-rw-r--r--drivers/acpi/acpi_pnp.c2
-rw-r--r--drivers/acpi/acpica/utglobal.c13
-rw-r--r--drivers/acpi/osl.c6
-rw-r--r--drivers/acpi/resource.c2
-rw-r--r--drivers/acpi/sbs.c2
-rw-r--r--drivers/acpi/sbshc.c22
-rw-r--r--drivers/ata/Kconfig10
-rw-r--r--drivers/ata/Makefile1
-rw-r--r--drivers/ata/ahci.c103
-rw-r--r--drivers/ata/ahci_st.c49
-rw-r--r--drivers/ata/libahci.c3
-rw-r--r--drivers/ata/libata-core.c34
-rw-r--r--drivers/ata/libata-eh.c3
-rw-r--r--drivers/ata/pata_scc.c1110
-rw-r--r--drivers/block/loop.c2
-rw-r--r--drivers/block/nvme-scsi.c6
-rw-r--r--drivers/block/rbd.c5
-rw-r--r--drivers/block/xen-blkback/blkback.c35
-rw-r--r--drivers/block/zram/zram_drv.c23
-rw-r--r--drivers/bluetooth/ath3k.c4
-rw-r--r--drivers/bluetooth/bt3c_cs.c3
-rw-r--r--drivers/bluetooth/btbcm.c148
-rw-r--r--drivers/bluetooth/btbcm.h6
-rw-r--r--drivers/bluetooth/btusb.c406
-rw-r--r--drivers/bluetooth/hci_ath.c98
-rw-r--r--drivers/bus/arm-cci.c2
-rw-r--r--drivers/bus/mips_cdmm.c4
-rw-r--r--drivers/bus/omap_l3_noc.c5
-rw-r--r--drivers/bus/omap_l3_noc.h54
-rw-r--r--drivers/char/hw_random/bcm63xx-rng.c18
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c16
-rw-r--r--drivers/char/ipmi/ipmi_ssif.c213
-rw-r--r--drivers/clk/clk-si5351.c63
-rw-r--r--drivers/clk/clk.c8
-rw-r--r--drivers/clk/qcom/gcc-msm8916.c4
-rw-r--r--drivers/clk/samsung/Makefile2
-rw-r--r--drivers/clk/samsung/clk-exynos5420.c1
-rw-r--r--drivers/clk/samsung/clk-exynos5433.c12
-rw-r--r--drivers/cpuidle/cpuidle.c16
-rw-r--r--drivers/dma/Kconfig1
-rw-r--r--drivers/dma/dmaengine.c4
-rw-r--r--drivers/dma/sh/usb-dmac.c2
-rw-r--r--drivers/extcon/extcon-usb-gpio.c24
-rw-r--r--drivers/firmware/dmi_scan.c12
-rw-r--r--drivers/firmware/efi/runtime-map.c6
-rw-r--r--drivers/gpio/gpio-kempld.c2
-rw-r--r--drivers/gpio/gpio-omap.c48
-rw-r--r--drivers/gpio/gpiolib-acpi.c2
-rw-r--r--drivers/gpio/gpiolib-sysfs.c19
-rw-r--r--drivers/gpio/gpiolib.c10
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c7
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_topology.c4
-rw-r--r--drivers/gpu/drm/drm_irq.c9
-rw-r--r--drivers/gpu/drm/drm_plane_helper.c3
-rw-r--r--drivers/gpu/drm/exynos/exynos7_drm_decon.c4
-rw-r--r--drivers/gpu/drm/exynos/exynos_dp_core.c13
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_crtc.c10
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_crtc.h10
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.h20
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fb.c39
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fimd.c53
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fimd.h15
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_plane.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_vidi.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_mixer.c72
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c13
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h2
-rw-r--r--drivers/gpu/drm/i915/intel_display.c3
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c9
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c26
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c24
-rw-r--r--drivers/gpu/drm/i915/intel_uncore.c8
-rw-r--r--drivers/gpu/drm/msm/adreno/adreno_gpu.c2
-rw-r--r--drivers/gpu/drm/msm/dsi/dsi.c10
-rw-r--r--drivers/gpu/drm/msm/dsi/dsi_host.c21
-rw-r--r--drivers/gpu/drm/msm/dsi/dsi_manager.c6
-rw-r--r--drivers/gpu/drm/msm/edp/edp_aux.c4
-rw-r--r--drivers/gpu/drm/msm/edp/edp_connector.c2
-rw-r--r--drivers/gpu/drm/msm/edp/edp_ctrl.c3
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c34
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.h9
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c12
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c2
-rw-r--r--drivers/gpu/drm/msm/msm_drv.c24
-rw-r--r--drivers/gpu/drm/msm/msm_fb.c7
-rw-r--r--drivers/gpu/drm/msm/msm_gem.c2
-rw-r--r--drivers/gpu/drm/msm/msm_iommu.c4
-rw-r--r--drivers/gpu/drm/msm/msm_ringbuffer.c2
-rw-r--r--drivers/gpu/drm/nouveau/include/nvif/class.h2
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/engine/gr/gm204.c1
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c7
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm107.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm204.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvkm/subdev/devinit/nv50.h3
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c7
-rw-r--r--drivers/gpu/drm/radeon/atombios_dp.c20
-rw-r--r--drivers/gpu/drm/radeon/atombios_encoders.c6
-rw-r--r--drivers/gpu/drm/radeon/cik.c2
-rw-r--r--drivers/gpu/drm/radeon/dce6_afmt.c25
-rw-r--r--drivers/gpu/drm/radeon/evergreen_hdmi.c54
-rw-r--r--drivers/gpu/drm/radeon/ni.c3
-rw-r--r--drivers/gpu/drm/radeon/r600_hdmi.c9
-rw-r--r--drivers/gpu/drm/radeon/radeon.h1
-rw-r--r--drivers/gpu/drm/radeon/radeon_asic.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_asic.h4
-rw-r--r--drivers/gpu/drm/radeon/radeon_audio.c7
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_dp_auxch.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_dp_mst.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_mn.c13
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c8
-rw-r--r--drivers/gpu/drm/radeon/radeon_uvd.c144
-rw-r--r--drivers/gpu/drm/radeon/radeon_vce.c65
-rw-r--r--drivers/gpu/drm/radeon/radeon_vm.c36
-rw-r--r--drivers/gpu/drm/radeon/rv770d.h3
-rw-r--r--drivers/gpu/drm/radeon/si.c2
-rw-r--r--drivers/gpu/drm/radeon/si_dpm.c1
-rw-r--r--drivers/gpu/drm/radeon/uvd_v1_0.c14
-rw-r--r--drivers/gpu/drm/radeon/uvd_v2_2.c29
-rw-r--r--drivers/gpu/drm/rockchip/rockchip_drm_vop.c9
-rw-r--r--drivers/gpu/drm/tegra/drm.c1
-rw-r--r--drivers/gpu/drm/vgem/Makefile2
-rw-r--r--drivers/gpu/drm/vgem/vgem_dma_buf.c94
-rw-r--r--drivers/gpu/drm/vgem/vgem_drv.c11
-rw-r--r--drivers/gpu/drm/vgem/vgem_drv.h11
-rw-r--r--drivers/hid/hid-ids.h1
-rw-r--r--drivers/hid/hid-logitech-hidpp.c20
-rw-r--r--drivers/hid/hid-sensor-hub.c13
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c5
-rw-r--r--drivers/hid/usbhid/hid-quirks.c1
-rw-r--r--drivers/hid/wacom_wac.c3
-rw-r--r--drivers/hwmon/nct6683.c2
-rw-r--r--drivers/hwmon/nct6775.c2
-rw-r--r--drivers/hwmon/ntc_thermistor.c9
-rw-r--r--drivers/hwmon/tmp401.c2
-rw-r--r--drivers/ide/Kconfig9
-rw-r--r--drivers/ide/Makefile1
-rw-r--r--drivers/ide/scc_pata.c887
-rw-r--r--drivers/iio/accel/mma9551_core.c21
-rw-r--r--drivers/iio/accel/mma9553.c18
-rw-r--r--drivers/iio/accel/st_accel_core.c1
-rw-r--r--drivers/iio/adc/axp288_adc.c12
-rw-r--r--drivers/iio/adc/cc10001_adc.c60
-rw-r--r--drivers/iio/adc/mcp320x.c6
-rw-r--r--drivers/iio/adc/qcom-spmi-vadc.c7
-rw-r--r--drivers/iio/adc/xilinx-xadc-core.c5
-rw-r--r--drivers/iio/adc/xilinx-xadc.h6
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c2
-rw-r--r--drivers/iio/gyro/st_gyro_core.c1
-rw-r--r--drivers/iio/kfifo_buf.c3
-rw-r--r--drivers/iio/light/hid-sensor-prox.c12
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c1
-rw-r--r--drivers/iio/pressure/bmp280.c1
-rw-r--r--drivers/iio/pressure/hid-sensor-press.c2
-rw-r--r--drivers/iio/pressure/st_pressure_core.c1
-rw-r--r--drivers/infiniband/core/addr.c13
-rw-r--r--drivers/infiniband/core/cm.c25
-rw-r--r--drivers/infiniband/core/cm_msgs.h4
-rw-r--r--drivers/infiniband/core/cma.c59
-rw-r--r--drivers/infiniband/core/iwpm_msg.c75
-rw-r--r--drivers/infiniband/core/iwpm_util.c208
-rw-r--r--drivers/infiniband/core/iwpm_util.h15
-rw-r--r--drivers/infiniband/core/umem_odp.c14
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c87
-rw-r--r--drivers/infiniband/hw/cxgb4/cq.c22
-rw-r--r--drivers/infiniband/hw/cxgb4/device.c41
-rw-r--r--drivers/infiniband/hw/cxgb4/iw_cxgb4.h7
-rw-r--r--drivers/infiniband/hw/cxgb4/mem.c6
-rw-r--r--drivers/infiniband/hw/cxgb4/qp.c10
-rw-r--r--drivers/infiniband/hw/cxgb4/t4.h7
-rw-r--r--drivers/infiniband/hw/cxgb4/t4fw_ri_api.h4
-rw-r--r--drivers/infiniband/hw/ehca/ehca_mcast.c4
-rw-r--r--drivers/infiniband/hw/mlx4/main.c3
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c2
-rw-r--r--drivers/infiniband/hw/nes/nes.c1
-rw-r--r--drivers/infiniband/hw/nes/nes_cm.c65
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma.h4
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_ah.c12
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_hw.c83
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_sli.h9
-rw-r--r--drivers/infiniband/hw/ocrdma/ocrdma_verbs.c12
-rw-r--r--drivers/infiniband/hw/qib/qib.h3
-rw-r--r--drivers/infiniband/hw/qib/qib_file_ops.c3
-rw-r--r--drivers/infiniband/hw/qib/qib_iba6120.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7220.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c41
-rw-r--r--drivers/infiniband/hw/qib/qib_init.c26
-rw-r--r--drivers/infiniband/hw/qib/qib_wc_x86_64.c32
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c4
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c6
-rw-r--r--drivers/input/joydev.c61
-rw-r--r--drivers/input/mouse/Kconfig2
-rw-r--r--drivers/input/mouse/alps.c5
-rw-r--r--drivers/input/mouse/elantech.c2
-rw-r--r--drivers/input/touchscreen/stmpe-ts.c2
-rw-r--r--drivers/input/touchscreen/sx8654.c2
-rw-r--r--drivers/iommu/amd_iommu_v2.c1
-rw-r--r--drivers/iommu/arm-smmu.c30
-rw-r--r--drivers/iommu/rockchip-iommu.c4
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c9
-rw-r--r--drivers/irqchip/irq-gic.c71
-rw-r--r--drivers/irqchip/irq-tegra.c2
-rw-r--r--drivers/lguest/core.c2
-rw-r--r--drivers/md/bitmap.c7
-rw-r--r--drivers/md/dm-crypt.c12
-rw-r--r--drivers/md/dm-ioctl.c17
-rw-r--r--drivers/md/dm-mpath.c4
-rw-r--r--drivers/md/dm-table.c16
-rw-r--r--drivers/md/dm.c43
-rw-r--r--drivers/md/md.c18
-rw-r--r--drivers/md/raid0.c9
-rw-r--r--drivers/md/raid5.c269
-rw-r--r--drivers/md/raid5.h5
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c14
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.h8
-rw-r--r--drivers/media/platform/soc_camera/rcar_vin.c7
-rw-r--r--drivers/mfd/da9052-core.c8
-rw-r--r--drivers/mmc/card/block.c12
-rw-r--r--drivers/mmc/card/queue.c2
-rw-r--r--drivers/mmc/card/queue.h2
-rw-r--r--drivers/mmc/core/core.c1
-rw-r--r--drivers/mmc/host/atmel-mci.c9
-rw-r--r--drivers/mmc/host/dw_mmc.c7
-rw-r--r--drivers/mmc/host/sh_mmcif.c2
-rw-r--r--drivers/mtd/devices/m25p80.c6
-rw-r--r--drivers/mtd/tests/readtest.c6
-rw-r--r--drivers/mtd/ubi/block.c2
-rw-r--r--drivers/net/bonding/bond_main.c12
-rw-r--r--drivers/net/bonding/bond_options.c2
-rw-r--r--drivers/net/bonding/bond_procfs.c1
-rw-r--r--drivers/net/bonding/bonding_priv.h25
-rw-r--r--drivers/net/can/Kconfig2
-rw-r--r--drivers/net/can/usb/kvaser_usb.c2
-rw-r--r--drivers/net/can/xilinx_can.c7
-rw-r--r--drivers/net/dsa/mv88e6xxx.c3
-rw-r--r--drivers/net/ethernet/8390/etherh.c2
-rw-r--r--drivers/net/ethernet/altera/altera_msgdmahw.h5
-rw-r--r--drivers/net/ethernet/altera/altera_tse_main.c43
-rw-r--r--drivers/net/ethernet/amd/Kconfig3
-rw-r--r--drivers/net/ethernet/apm/xgene/Kconfig1
-rw-r--r--drivers/net/ethernet/arc/Kconfig5
-rw-r--r--drivers/net/ethernet/atheros/atl1e/atl1e_hw.h2
-rw-r--r--drivers/net/ethernet/broadcom/bcmsysport.h2
-rw-r--r--drivers/net/ethernet/broadcom/bgmac.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x.h4
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c116
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c17
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c22
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c2
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c4
-rw-r--r--drivers/net/ethernet/cadence/macb.c36
-rw-r--r--drivers/net/ethernet/cadence/macb.h1
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_hw.c2
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c11
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c5
-rw-r--r--drivers/net/ethernet/ibm/ehea/ehea_main.c6
-rw-r--r--drivers/net/ethernet/ibm/emac/core.c16
-rw-r--r--drivers/net/ethernet/ibm/emac/core.h7
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c4
-rw-r--r--drivers/net/ethernet/intel/e1000e/e1000.h1
-rw-r--r--drivers/net/ethernet/intel/fm10k/fm10k_main.c4
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_main.c7
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c4
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c4
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c2
-rw-r--r--drivers/net/ethernet/marvell/pxa168_eth.c16
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/cmd.c9
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_ethtool.c29
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c13
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_port.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_rx.c26
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_tx.c8
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/fw.c18
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4_en.h1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c22
-rw-r--r--drivers/net/ethernet/myricom/myri10ge/myri10ge.c38
-rw-r--r--drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c8
-rw-r--r--drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c6
-rw-r--r--drivers/net/ethernet/qualcomm/qca_spi.c4
-rw-r--r--drivers/net/ethernet/realtek/r8169.c4
-rw-r--r--drivers/net/ethernet/rocker/rocker.c13
-rw-r--r--drivers/net/ethernet/smsc/smc91x.c20
-rw-r--r--drivers/net/ethernet/smsc/smsc911x.c12
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac.h6
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c76
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c1
-rw-r--r--drivers/net/ethernet/ti/netcp_ethss.c8
-rw-r--r--drivers/net/ethernet/xilinx/ll_temac_main.c4
-rw-r--r--drivers/net/hyperv/hyperv_net.h13
-rw-r--r--drivers/net/hyperv/netvsc.c17
-rw-r--r--drivers/net/hyperv/netvsc_drv.c47
-rw-r--r--drivers/net/hyperv/rndis_filter.c3
-rw-r--r--drivers/net/ieee802154/at86rf230.c390
-rw-r--r--drivers/net/macvlan.c15
-rw-r--r--drivers/net/phy/Kconfig1
-rw-r--r--drivers/net/phy/amd-xgbe-phy.c45
-rw-r--r--drivers/net/phy/bcm7xxx.c2
-rw-r--r--drivers/net/phy/dp83640.c23
-rw-r--r--drivers/net/phy/mdio-gpio.c19
-rw-r--r--drivers/net/phy/mdio-mux-gpio.c60
-rw-r--r--drivers/net/phy/micrel.c3
-rw-r--r--drivers/net/phy/phy.c34
-rw-r--r--drivers/net/ppp/ppp_mppe.c36
-rw-r--r--drivers/net/ppp/pppoe.c4
-rw-r--r--drivers/net/usb/cdc_ncm.c2
-rw-r--r--drivers/net/usb/r8152.c1
-rw-r--r--drivers/net/usb/usbnet.c4
-rw-r--r--drivers/net/vxlan.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c52
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-7000.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fw-file.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-nvm-parse.c30
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans.h41
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/coex_legacy.c2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/d3.c24
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw-api-power.h34
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h44
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw-api.h13
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw.c54
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mac80211.c29
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mvm.h1
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/ops.c16
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/rs.c3
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/rx.c5
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c2
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c25
-rw-r--r--drivers/net/wireless/rtlwifi/usb.c2
-rw-r--r--drivers/net/xen-netback/xenbus.c1
-rw-r--r--drivers/net/xen-netfront.c15
-rw-r--r--drivers/parisc/superio.c2
-rw-r--r--drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c4
-rw-r--r--drivers/pinctrl/core.c10
-rw-r--r--drivers/pinctrl/core.h2
-rw-r--r--drivers/pinctrl/devicetree.c2
-rw-r--r--drivers/pinctrl/intel/pinctrl-cherryview.c44
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mtk-common.c2
-rw-r--r--drivers/pinctrl/meson/pinctrl-meson.c2
-rw-r--r--drivers/pinctrl/meson/pinctrl-meson8b.c4
-rw-r--r--drivers/pinctrl/mvebu/pinctrl-armada-370.c2
-rw-r--r--drivers/pinctrl/qcom/pinctrl-spmi-gpio.c14
-rw-r--r--drivers/pinctrl/qcom/pinctrl-spmi-mpp.c10
-rw-r--r--drivers/platform/x86/ideapad-laptop.c7
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c39
-rw-r--r--drivers/power/axp288_fuel_gauge.c1
-rw-r--r--drivers/power/bq27x00_battery.c8
-rw-r--r--drivers/power/collie_battery.c2
-rw-r--r--drivers/power/reset/Kconfig1
-rw-r--r--drivers/power/reset/at91-reset.c4
-rw-r--r--drivers/power/reset/ltc2952-poweroff.c18
-rw-r--r--drivers/pwm/pwm-img.c76
-rw-r--r--drivers/regulator/arizona-ldo1.c5
-rw-r--r--drivers/regulator/da9052-regulator.c5
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-abx80x.c307
-rw-r--r--drivers/rtc/rtc-armada38x.c26
-rw-r--r--drivers/s390/char/con3215.c2
-rw-r--r--drivers/s390/crypto/ap_bus.c20
-rw-r--r--drivers/scsi/3w-9xxx.c57
-rw-r--r--drivers/scsi/3w-9xxx.h5
-rw-r--r--drivers/scsi/3w-sas.c50
-rw-r--r--drivers/scsi/3w-sas.h4
-rw-r--r--drivers/scsi/3w-xxxx.c42
-rw-r--r--drivers/scsi/3w-xxxx.h5
-rw-r--r--drivers/scsi/aha1542.c23
-rw-r--r--drivers/scsi/be2iscsi/be.h6
-rw-r--r--drivers/scsi/be2iscsi/be_cmds.c6
-rw-r--r--drivers/scsi/be2iscsi/be_cmds.h6
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.c8
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.h8
-rw-r--r--drivers/scsi/be2iscsi/be_main.c12
-rw-r--r--drivers/scsi/be2iscsi/be_main.h10
-rw-r--r--drivers/scsi/be2iscsi/be_mgmt.c8
-rw-r--r--drivers/scsi/be2iscsi/be_mgmt.h8
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c41
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c6
-rw-r--r--drivers/scsi/scsi_devinfo.c1
-rw-r--r--drivers/scsi/scsi_scan.c6
-rw-r--r--drivers/scsi/sd.c19
-rw-r--r--drivers/scsi/storvsc_drv.c3
-rw-r--r--drivers/sh/pm_runtime.c7
-rw-r--r--drivers/spi/Kconfig3
-rw-r--r--drivers/spi/spi-bcm2835.c5
-rw-r--r--drivers/spi/spi-bitbang.c17
-rw-r--r--drivers/spi/spi-fsl-cpm.c40
-rw-r--r--drivers/spi/spi-fsl-espi.c45
-rw-r--r--drivers/spi/spi-omap2-mcspi.c16
-rw-r--r--drivers/spi/spi.c9
-rw-r--r--drivers/ssb/driver_pcicore.c7
-rw-r--r--drivers/staging/gdm724x/gdm_mux.c16
-rw-r--r--drivers/staging/media/omap4iss/Kconfig1
-rw-r--r--drivers/staging/media/omap4iss/iss.c11
-rw-r--r--drivers/staging/media/omap4iss/iss.h4
-rw-r--r--drivers/staging/media/omap4iss/iss_csiphy.c12
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c17
-rw-r--r--drivers/staging/sm750fb/sm750.c2
-rw-r--r--drivers/staging/vt6655/card.c10
-rw-r--r--drivers/staging/vt6655/card.h2
-rw-r--r--drivers/staging/vt6655/device_main.c42
-rw-r--r--drivers/staging/vt6656/rxtx.c14
-rw-r--r--drivers/target/iscsi/iscsi_target.c2
-rw-r--r--drivers/target/iscsi/iscsi_target_login.c1
-rw-r--r--drivers/target/iscsi/iscsi_target_tpg.c5
-rw-r--r--drivers/target/target_core_alua.c4
-rw-r--r--drivers/target/target_core_configfs.c40
-rw-r--r--drivers/target/target_core_device.c78
-rw-r--r--drivers/target/target_core_file.c1
-rw-r--r--drivers/target/target_core_iblock.c1
-rw-r--r--drivers/target/target_core_internal.h3
-rw-r--r--drivers/target/target_core_pr.c34
-rw-r--r--drivers/target/target_core_pscsi.c58
-rw-r--r--drivers/target/target_core_pscsi.h1
-rw-r--r--drivers/target/target_core_rd.c1
-rw-r--r--drivers/target/target_core_sbc.c2
-rw-r--r--drivers/target/target_core_transport.c13
-rw-r--r--drivers/target/target_core_user.c143
-rw-r--r--drivers/target/target_core_xcopy.c15
-rw-r--r--drivers/thermal/armada_thermal.c6
-rw-r--r--drivers/thermal/intel_powerclamp.c89
-rw-r--r--drivers/thermal/rockchip_thermal.c2
-rw-r--r--drivers/thermal/thermal_core.h2
-rw-r--r--drivers/thermal/ti-soc-thermal/dra752-thermal-data.c3
-rw-r--r--drivers/thermal/ti-soc-thermal/omap5-thermal-data.c3
-rw-r--r--drivers/thermal/ti-soc-thermal/ti-bandgap.c78
-rw-r--r--drivers/thermal/ti-soc-thermal/ti-bandgap.h6
-rw-r--r--drivers/tty/hvc/hvc_xen.c20
-rw-r--r--drivers/tty/mips_ejtag_fdc.c17
-rw-r--r--drivers/tty/n_gsm.c5
-rw-r--r--drivers/tty/n_hdlc.c4
-rw-r--r--drivers/tty/n_tty.c22
-rw-r--r--drivers/tty/pty.c5
-rw-r--r--drivers/tty/serial/8250/8250_pci.c25
-rw-r--r--drivers/tty/serial/amba-pl011.c5
-rw-r--r--drivers/tty/serial/atmel_serial.c2
-rw-r--r--drivers/tty/serial/earlycon.c9
-rw-r--r--drivers/tty/serial/of_serial.c1
-rw-r--r--drivers/tty/serial/omap-serial.c2
-rw-r--r--drivers/tty/serial/samsung.c5
-rw-r--r--drivers/tty/serial/serial_core.c2
-rw-r--r--drivers/tty/serial/uartlite.c11
-rw-r--r--drivers/tty/serial/xilinx_uartps.c12
-rw-r--r--drivers/tty/tty_buffer.c41
-rw-r--r--drivers/tty/tty_ioctl.c3
-rw-r--r--drivers/usb/chipidea/debug.c6
-rw-r--r--drivers/usb/chipidea/otg_fsm.c4
-rw-r--r--drivers/usb/class/cdc-acm.c7
-rw-r--r--drivers/usb/core/quirks.c3
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c94
-rw-r--r--drivers/usb/gadget/configfs.c1
-rw-r--r--drivers/usb/gadget/function/f_hid.c16
-rw-r--r--drivers/usb/gadget/function/u_serial.c5
-rw-r--r--drivers/usb/gadget/legacy/acm_ms.c10
-rw-r--r--drivers/usb/gadget/legacy/audio.c10
-rw-r--r--drivers/usb/gadget/legacy/cdc2.c10
-rw-r--r--drivers/usb/gadget/legacy/dbgp.c4
-rw-r--r--drivers/usb/gadget/legacy/ether.c12
-rw-r--r--drivers/usb/gadget/legacy/g_ffs.c2
-rw-r--r--drivers/usb/gadget/legacy/gmidi.c10
-rw-r--r--drivers/usb/gadget/legacy/hid.c12
-rw-r--r--drivers/usb/gadget/legacy/mass_storage.c6
-rw-r--r--drivers/usb/gadget/legacy/multi.c10
-rw-r--r--drivers/usb/gadget/legacy/ncm.c10
-rw-r--r--drivers/usb/gadget/legacy/nokia.c10
-rw-r--r--drivers/usb/gadget/legacy/printer.c8
-rw-r--r--drivers/usb/gadget/legacy/serial.c4
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.c2
-rw-r--r--drivers/usb/gadget/legacy/webcam.c8
-rw-r--r--drivers/usb/gadget/legacy/zero.c4
-rw-r--r--drivers/usb/gadget/udc/at91_udc.c4
-rw-r--r--drivers/usb/gadget/udc/atmel_usba_udc.c4
-rw-r--r--drivers/usb/gadget/udc/fsl_udc_core.c4
-rw-r--r--drivers/usb/gadget/udc/fusb300_udc.c4
-rw-r--r--drivers/usb/gadget/udc/m66592-udc.c4
-rw-r--r--drivers/usb/gadget/udc/r8a66597-udc.c4
-rw-r--r--drivers/usb/gadget/udc/udc-xilinx.c4
-rw-r--r--drivers/usb/host/ehci-msm.c13
-rw-r--r--drivers/usb/host/xhci-ring.c7
-rw-r--r--drivers/usb/host/xhci.h2
-rw-r--r--drivers/usb/phy/phy-isp1301-omap.c2
-rw-r--r--drivers/usb/serial/cp210x.c1
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/visor.c2
-rw-r--r--drivers/usb/storage/uas-detect.h11
-rw-r--r--drivers/usb/storage/uas.c16
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/usb/storage/usb.c8
-rw-r--r--drivers/vfio/pci/vfio_pci.c8
-rw-r--r--drivers/vfio/vfio.c21
-rw-r--r--drivers/vhost/scsi.c6
-rw-r--r--drivers/video/backlight/pwm_bl.c4
-rw-r--r--drivers/xen/events/events_2l.c10
-rw-r--r--drivers/xen/events/events_base.c19
-rw-r--r--drivers/xen/gntdev.c28
-rw-r--r--drivers/xen/grant-table.c28
-rw-r--r--drivers/xen/manage.c9
-rw-r--r--drivers/xen/swiotlb-xen.c2
-rw-r--r--drivers/xen/xen-pciback/conf_space.c6
-rw-r--r--drivers/xen/xen-pciback/conf_space.h2
-rw-r--r--drivers/xen/xen-pciback/conf_space_header.c2
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c29
-rw-r--r--fs/binfmt_elf.c2
-rw-r--r--fs/btrfs/backref.c17
-rw-r--r--fs/btrfs/delayed-inode.c2
-rw-r--r--fs/btrfs/extent-tree.c141
-rw-r--r--fs/btrfs/extent_io.c73
-rw-r--r--fs/btrfs/free-space-cache.c26
-rw-r--r--fs/btrfs/inode.c21
-rw-r--r--fs/btrfs/ioctl.c3
-rw-r--r--fs/btrfs/ordered-data.c14
-rw-r--r--fs/btrfs/volumes.c16
-rw-r--r--fs/cifs/cifs_dfs_ref.c3
-rw-r--r--fs/cifs/cifs_unicode.c182
-rw-r--r--fs/cifs/cifsfs.c2
-rw-r--r--fs/cifs/cifsproto.h4
-rw-r--r--fs/cifs/cifssmb.c23
-rw-r--r--fs/cifs/connect.c3
-rw-r--r--fs/cifs/dir.c3
-rw-r--r--fs/cifs/file.c7
-rw-r--r--fs/cifs/inode.c31
-rw-r--r--fs/cifs/link.c3
-rw-r--r--fs/cifs/readdir.c2
-rw-r--r--fs/cifs/smb1ops.c3
-rw-r--r--fs/cifs/smb2pdu.c2
-rw-r--r--fs/configfs/mount.c2
-rw-r--r--fs/dcache.c8
-rw-r--r--fs/efivarfs/super.c2
-rw-r--r--fs/exec.c3
-rw-r--r--fs/ext4/Kconfig9
-rw-r--r--fs/ext4/crypto_fname.c280
-rw-r--r--fs/ext4/crypto_key.c1
-rw-r--r--fs/ext4/crypto_policy.c14
-rw-r--r--fs/ext4/dir.c2
-rw-r--r--fs/ext4/ext4.h17
-rw-r--r--fs/ext4/ext4_crypto.h11
-rw-r--r--fs/ext4/ext4_jbd2.c6
-rw-r--r--fs/ext4/extents.c25
-rw-r--r--fs/ext4/extents_status.c8
-rw-r--r--fs/ext4/inode.c4
-rw-r--r--fs/ext4/namei.c72
-rw-r--r--fs/ext4/resize.c7
-rw-r--r--fs/ext4/super.c2
-rw-r--r--fs/ext4/symlink.c2
-rw-r--r--fs/f2fs/data.c7
-rw-r--r--fs/f2fs/f2fs.h1
-rw-r--r--fs/f2fs/namei.c8
-rw-r--r--fs/f2fs/super.c1
-rw-r--r--fs/hostfs/hostfs_kern.c2
-rw-r--r--fs/jbd2/recovery.c10
-rw-r--r--fs/jbd2/revoke.c18
-rw-r--r--fs/jbd2/transaction.c25
-rw-r--r--fs/kernfs/dir.c9
-rw-r--r--fs/namei.c22
-rw-r--r--fs/namespace.c6
-rw-r--r--fs/nfs/nfs4proc.c3
-rw-r--r--fs/nfs/write.c13
-rw-r--r--fs/nfsd/blocklayout.c11
-rw-r--r--fs/nfsd/nfs4callback.c119
-rw-r--r--fs/nfsd/nfs4state.c147
-rw-r--r--fs/nfsd/state.h19
-rw-r--r--fs/nfsd/xdr4.h1
-rw-r--r--fs/nilfs2/btree.c2
-rw-r--r--fs/ocfs2/dlm/dlmmaster.c13
-rw-r--r--fs/omfs/bitmap.c2
-rw-r--r--fs/omfs/inode.c10
-rw-r--r--fs/overlayfs/copy_up.c3
-rw-r--r--fs/overlayfs/dir.c33
-rw-r--r--fs/overlayfs/super.c10
-rw-r--r--fs/splice.c12
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.c8
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.h2
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c31
-rw-r--r--fs/xfs/libxfs/xfs_ialloc.c9
-rw-r--r--fs/xfs/xfs_attr_inactive.c83
-rw-r--r--fs/xfs/xfs_file.c2
-rw-r--r--fs/xfs/xfs_inode.c22
-rw-r--r--fs/xfs/xfs_mount.c34
-rw-r--r--include/acpi/actypes.h1
-rw-r--r--include/drm/drm_pciids.h1
-rw-r--r--include/dt-bindings/sound/audio-jack-events.h9
-rw-r--r--include/linux/blk_types.h2
-rw-r--r--include/linux/blkdev.h2
-rw-r--r--include/linux/brcmphy.h2
-rw-r--r--include/linux/compiler-gcc.h16
-rw-r--r--include/linux/compiler-intel.h3
-rw-r--r--include/linux/compiler.h4
-rw-r--r--include/linux/cpumask.h6
-rw-r--r--include/linux/ftrace_event.h2
-rw-r--r--include/linux/gfp.h2
-rw-r--r--include/linux/hid-sensor-hub.h4
-rw-r--r--include/linux/irqchip/arm-gic.h2
-rw-r--r--include/linux/kexec.h4
-rw-r--r--include/linux/ktime.h27
-rw-r--r--include/linux/libata.h10
-rw-r--r--include/linux/memcontrol.h4
-rw-r--r--include/linux/netdevice.h19
-rw-r--r--include/linux/netfilter_bridge.h16
-rw-r--r--include/linux/nilfs2_fs.h2
-rw-r--r--include/linux/pci_ids.h4
-rw-r--r--include/linux/percpu_counter.h13
-rw-r--r--include/linux/platform_data/si5351.h4
-rw-r--r--include/linux/rhashtable.h22
-rw-r--r--include/linux/rtnetlink.h2
-rw-r--r--include/linux/sched.h8
-rw-r--r--include/linux/sched/rt.h7
-rw-r--r--include/linux/skbuff.h2
-rw-r--r--include/linux/tcp.h10
-rw-r--r--include/linux/tty.h3
-rw-r--r--include/linux/uidgid.h4
-rw-r--r--include/linux/usb_usual.h2
-rw-r--r--include/linux/util_macros.h2
-rw-r--r--include/net/bonding.h7
-rw-r--r--include/net/cfg802154.h2
-rw-r--r--include/net/codel.h10
-rw-r--r--include/net/inet_connection_sock.h25
-rw-r--r--include/net/mac80211.h2
-rw-r--r--include/net/mac802154.h94
-rw-r--r--include/net/request_sock.h18
-rw-r--r--include/net/sctp/sctp.h7
-rw-r--r--include/net/tcp.h7
-rw-r--r--include/rdma/ib_addr.h3
-rw-r--r--include/rdma/ib_cm.h7
-rw-r--r--include/rdma/iw_portmap.h25
-rw-r--r--include/scsi/scsi_devinfo.h1
-rw-r--r--include/sound/designware_i2s.h2
-rw-r--r--include/sound/dmaengine_pcm.h5
-rw-r--r--include/sound/emu10k1.h14
-rw-r--r--include/sound/rt5645.h3
-rw-r--r--include/sound/soc-dapm.h48
-rw-r--r--include/sound/soc.h119
-rw-r--r--include/sound/spear_dma.h2
-rw-r--r--include/target/target_core_backend.h8
-rw-r--r--include/target/target_core_configfs.h2
-rw-r--r--include/target/target_core_fabric.h4
-rw-r--r--include/trace/events/kmem.h54
-rw-r--r--include/uapi/linux/inet_diag.h4
-rw-r--r--include/uapi/linux/mpls.h10
-rw-r--r--include/uapi/linux/netfilter/nf_conntrack_tcp.h3
-rw-r--r--include/uapi/linux/rtnetlink.h2
-rw-r--r--include/uapi/linux/tcp.h3
-rw-r--r--include/uapi/linux/virtio_ring.h2
-rw-r--r--include/uapi/rdma/rdma_netlink.h1
-rw-r--r--include/xen/events.h2
-rw-r--r--include/xen/grant_table.h1
-rw-r--r--include/xen/xen-ops.h1
-rw-r--r--init/do_mounts.c5
-rw-r--r--kernel/Makefile6
-rw-r--r--kernel/bpf/core.c12
-rw-r--r--kernel/events/core.c41
-rw-r--r--kernel/irq/dummychip.c1
-rw-r--r--kernel/kexec.c2
-rw-r--r--kernel/locking/rtmutex.c12
-rw-r--r--kernel/module.c3
-rw-r--r--kernel/rcu/tree.c16
-rw-r--r--kernel/sched/core.c74
-rw-r--r--kernel/sched/idle.c16
-rw-r--r--kernel/time/clockevents.c6
-rw-r--r--kernel/time/hrtimer.c14
-rw-r--r--kernel/trace/trace_output.c3
-rw-r--r--kernel/watchdog.c20
-rw-r--r--lib/Kconfig.debug1
-rw-r--r--lib/Kconfig.kasan8
-rw-r--r--lib/cpumask.c74
-rw-r--r--lib/find_last_bit.c41
-rw-r--r--lib/percpu_counter.c6
-rw-r--r--lib/rhashtable.c22
-rw-r--r--lib/string.c2
-rw-r--r--mm/hwpoison-inject.c13
-rw-r--r--mm/kmemleak.c3
-rw-r--r--mm/memory-failure.c16
-rw-r--r--mm/mempolicy.c2
-rw-r--r--mm/page-writeback.c6
-rw-r--r--mm/page_isolation.c3
-rw-r--r--net/8021q/vlan.c2
-rw-r--r--net/bluetooth/hci_core.c9
-rw-r--r--net/bridge/br_mdb.c2
-rw-r--r--net/bridge/br_multicast.c2
-rw-r--r--net/bridge/br_netfilter.c27
-rw-r--r--net/bridge/br_netlink.c4
-rw-r--r--net/bridge/br_private.h2
-rw-r--r--net/bridge/br_stp_timer.c2
-rw-r--r--net/bridge/netfilter/ebtables.c4
-rw-r--r--net/caif/caif_socket.c8
-rw-r--r--net/ceph/osd_client.c33
-rw-r--r--net/core/dev.c14
-rw-r--r--net/core/ethtool.c10
-rw-r--r--net/core/net_namespace.c2
-rw-r--r--net/core/rtnetlink.c15
-rw-r--r--net/core/skbuff.c30
-rw-r--r--net/core/sock.c2
-rw-r--r--net/dccp/ipv4.c3
-rw-r--r--net/dccp/ipv6.c3
-rw-r--r--net/dccp/minisocks.c3
-rw-r--r--net/dsa/dsa.c2
-rw-r--r--net/ieee802154/Makefile4
-rw-r--r--net/ieee802154/nl-phy.c5
-rw-r--r--net/ieee802154/nl802154.c2
-rw-r--r--net/ieee802154/rdev-ops.h85
-rw-r--r--net/ieee802154/trace.c7
-rw-r--r--net/ieee802154/trace.h247
-rw-r--r--net/ipv4/fib_trie.c3
-rw-r--r--net/ipv4/inet_connection_sock.c34
-rw-r--r--net/ipv4/inet_diag.c8
-rw-r--r--net/ipv4/netfilter/arp_tables.c6
-rw-r--r--net/ipv4/netfilter/ip_tables.c6
-rw-r--r--net/ipv4/ping.c1
-rw-r--r--net/ipv4/route.c9
-rw-r--r--net/ipv4/tcp.c31
-rw-r--r--net/ipv4/tcp_dctcp.c20
-rw-r--r--net/ipv4/tcp_fastopen.c5
-rw-r--r--net/ipv4/tcp_illinois.c21
-rw-r--r--net/ipv4/tcp_input.c55
-rw-r--r--net/ipv4/tcp_ipv4.c3
-rw-r--r--net/ipv4/tcp_minisocks.c9
-rw-r--r--net/ipv4/tcp_output.c64
-rw-r--r--net/ipv4/tcp_vegas.c19
-rw-r--r--net/ipv4/tcp_vegas.h3
-rw-r--r--net/ipv4/tcp_westwood.c15
-rw-r--r--net/ipv6/ip6_fib.c39
-rw-r--r--net/ipv6/ip6_gre.c9
-rw-r--r--net/ipv6/ip6_output.c43
-rw-r--r--net/ipv6/netfilter/ip6_tables.c6
-rw-r--r--net/ipv6/route.c19
-rw-r--r--net/ipv6/tcp_ipv6.c5
-rw-r--r--net/ipv6/udp.c4
-rw-r--r--net/mac80211/cfg.c59
-rw-r--r--net/mac80211/ieee80211_i.h9
-rw-r--r--net/mac80211/iface.c18
-rw-r--r--net/mac80211/key.c82
-rw-r--r--net/mac80211/key.h1
-rw-r--r--net/mac80211/rx.c5
-rw-r--r--net/mac80211/sta_info.c19
-rw-r--r--net/mac80211/util.c3
-rw-r--r--net/mac80211/wep.c6
-rw-r--r--net/mac802154/cfg.c9
-rw-r--r--net/mac802154/ieee802154_i.h3
-rw-r--r--net/mac802154/iface.c5
-rw-r--r--net/mac802154/llsec.c4
-rw-r--r--net/mac802154/main.c7
-rw-r--r--net/mpls/af_mpls.c141
-rw-r--r--net/mpls/internal.h16
-rw-r--r--net/netfilter/Kconfig2
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c3
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c35
-rw-r--r--net/netfilter/nf_tables_api.c7
-rw-r--r--net/netfilter/nfnetlink_log.c19
-rw-r--r--net/netfilter/nfnetlink_queue_core.c18
-rw-r--r--net/netfilter/nft_reject.c2
-rw-r--r--net/netfilter/nft_reject_inet.c2
-rw-r--r--net/netlink/af_netlink.c10
-rw-r--r--net/packet/af_packet.c9
-rw-r--r--net/rds/connection.c17
-rw-r--r--net/rds/ib_cm.c13
-rw-r--r--net/rds/tcp_connect.c1
-rw-r--r--net/rds/tcp_listen.c46
-rw-r--r--net/sched/act_connmark.c2
-rw-r--r--net/sched/cls_api.c12
-rw-r--r--net/sched/sch_api.c10
-rw-r--r--net/sched/sch_codel.c2
-rw-r--r--net/sched/sch_fq_codel.c2
-rw-r--r--net/sched/sch_gred.c4
-rw-r--r--net/sunrpc/auth_gss/gss_rpc_xdr.c23
-rw-r--r--net/switchdev/switchdev.c6
-rw-r--r--net/tipc/bearer.c17
-rw-r--r--net/tipc/link.c16
-rw-r--r--net/tipc/server.c9
-rw-r--r--net/tipc/socket.c3
-rw-r--r--net/unix/af_unix.c8
-rw-r--r--net/unix/garbage.c70
-rw-r--r--scripts/gdb/linux/modules.py9
-rw-r--r--sound/atmel/ac97c.c1
-rw-r--r--sound/core/pcm_lib.c2
-rw-r--r--sound/pci/emu10k1/emu10k1.c6
-rw-r--r--sound/pci/emu10k1/emu10k1_callback.c4
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c21
-rw-r--r--sound/pci/emu10k1/emupcm.c2
-rw-r--r--sound/pci/emu10k1/memory.c11
-rw-r--r--sound/pci/hda/hda_codec.c24
-rw-r--r--sound/pci/hda/hda_generic.c16
-rw-r--r--sound/pci/hda/hda_intel.c2
-rw-r--r--sound/pci/hda/patch_conexant.c12
-rw-r--r--sound/pci/hda/patch_realtek.c82
-rw-r--r--sound/pci/hda/patch_sigmatel.c4
-rw-r--r--sound/soc/atmel/Kconfig20
-rw-r--r--sound/soc/atmel/Makefile8
-rw-r--r--sound/soc/atmel/atmel-pcm-dma.c3
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c10
-rw-r--r--sound/soc/au1x/db1200.c2
-rw-r--r--sound/soc/cirrus/ep93xx-pcm.c1
-rw-r--r--sound/soc/codecs/88pm860x-codec.c19
-rw-r--r--sound/soc/codecs/Kconfig7
-rw-r--r--sound/soc/codecs/ab8500-codec.c20
-rw-r--r--sound/soc/codecs/ac97.c8
-rw-r--r--sound/soc/codecs/ad1836.c2
-rw-r--r--sound/soc/codecs/adau1373.c1
-rw-r--r--sound/soc/codecs/adau1701.c126
-rw-r--r--sound/soc/codecs/adau1761.c27
-rw-r--r--sound/soc/codecs/adau1781.c10
-rw-r--r--sound/soc/codecs/adau17x1.c20
-rw-r--r--sound/soc/codecs/adau1977.c14
-rw-r--r--sound/soc/codecs/adav80x.c11
-rw-r--r--sound/soc/codecs/ak4535.c1
-rw-r--r--sound/soc/codecs/ak4641.c3
-rw-r--r--sound/soc/codecs/ak4642.c1
-rw-r--r--sound/soc/codecs/ak4671.c1
-rw-r--r--sound/soc/codecs/alc5623.c3
-rw-r--r--sound/soc/codecs/alc5632.c1
-rw-r--r--sound/soc/codecs/arizona.c174
-rw-r--r--sound/soc/codecs/arizona.h17
-rw-r--r--sound/soc/codecs/bt-sco.c11
-rw-r--r--sound/soc/codecs/cq93vc.c1
-rw-r--r--sound/soc/codecs/cs35l32.c1
-rw-r--r--sound/soc/codecs/cs4265.c1
-rw-r--r--sound/soc/codecs/cs42l52.c5
-rw-r--r--sound/soc/codecs/cs42l56.c5
-rw-r--r--sound/soc/codecs/cs42l73.c3
-rw-r--r--sound/soc/codecs/cs42xx8.c2
-rw-r--r--sound/soc/codecs/cx20442.c6
-rw-r--r--sound/soc/codecs/da7213.c3
-rw-r--r--sound/soc/codecs/da732x.c4
-rw-r--r--sound/soc/codecs/da9055.c3
-rw-r--r--sound/soc/codecs/es8328.c3
-rw-r--r--sound/soc/codecs/isabelle.c2
-rw-r--r--sound/soc/codecs/jz4740.c4
-rw-r--r--sound/soc/codecs/lm4857.c2
-rw-r--r--sound/soc/codecs/lm49453.c4
-rw-r--r--sound/soc/codecs/max98088.c3
-rw-r--r--sound/soc/codecs/max98090.c21
-rw-r--r--sound/soc/codecs/max98095.c20
-rw-r--r--sound/soc/codecs/max9850.c3
-rw-r--r--sound/soc/codecs/max98925.c2
-rw-r--r--sound/soc/codecs/mc13783.c4
-rw-r--r--sound/soc/codecs/ml26124.c3
-rw-r--r--sound/soc/codecs/pcm512x.c8
-rw-r--r--sound/soc/codecs/rt286.c33
-rw-r--r--sound/soc/codecs/rt5631.c5
-rw-r--r--sound/soc/codecs/rt5640.c16
-rw-r--r--sound/soc/codecs/rt5645.c1100
-rw-r--r--sound/soc/codecs/rt5645.h30
-rw-r--r--sound/soc/codecs/rt5651.c5
-rw-r--r--sound/soc/codecs/rt5670.c26
-rw-r--r--sound/soc/codecs/rt5677.c19
-rw-r--r--sound/soc/codecs/sgtl5000.c3
-rw-r--r--sound/soc/codecs/sirf-audio-codec.c2
-rw-r--r--sound/soc/codecs/sn95031.c12
-rw-r--r--sound/soc/codecs/ssm2518.c7
-rw-r--r--sound/soc/codecs/ssm2602.c1
-rw-r--r--sound/soc/codecs/ssm4567.c7
-rw-r--r--sound/soc/codecs/sta32x.c5
-rw-r--r--sound/soc/codecs/sta350.c5
-rw-r--r--sound/soc/codecs/sta529.c8
-rw-r--r--sound/soc/codecs/stac9766.c3
-rw-r--r--sound/soc/codecs/tfa9879.c4
-rw-r--r--sound/soc/codecs/tlv320aic23.c1
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c11
-rw-r--r--sound/soc/codecs/tlv320aic32x4.c1
-rw-r--r--sound/soc/codecs/tlv320aic3x.c10
-rw-r--r--sound/soc/codecs/tlv320dac33.c5
-rw-r--r--sound/soc/codecs/twl4030.c3
-rw-r--r--sound/soc/codecs/twl6040.c6
-rw-r--r--sound/soc/codecs/uda134x.c4
-rw-r--r--sound/soc/codecs/uda1380.c8
-rw-r--r--sound/soc/codecs/wm0010.c6
-rw-r--r--sound/soc/codecs/wm1250-ev1.c2
-rw-r--r--sound/soc/codecs/wm5100.c6
-rw-r--r--sound/soc/codecs/wm5102.c62
-rw-r--r--sound/soc/codecs/wm5110.c11
-rw-r--r--sound/soc/codecs/wm8350.c3
-rw-r--r--sound/soc/codecs/wm8400.c3
-rw-r--r--sound/soc/codecs/wm8510.c3
-rw-r--r--sound/soc/codecs/wm8523.c3
-rw-r--r--sound/soc/codecs/wm8580.c3
-rw-r--r--sound/soc/codecs/wm8711.c3
-rw-r--r--sound/soc/codecs/wm8728.c3
-rw-r--r--sound/soc/codecs/wm8731.c8
-rw-r--r--sound/soc/codecs/wm8737.c11
-rw-r--r--sound/soc/codecs/wm8750.c3
-rw-r--r--sound/soc/codecs/wm8753.c3
-rw-r--r--sound/soc/codecs/wm8770.c3
-rw-r--r--sound/soc/codecs/wm8776.c3
-rw-r--r--sound/soc/codecs/wm8804.c2
-rw-r--r--sound/soc/codecs/wm8900.c13
-rw-r--r--sound/soc/codecs/wm8903.c4
-rw-r--r--sound/soc/codecs/wm8903.h2
-rw-r--r--sound/soc/codecs/wm8904.c5
-rw-r--r--sound/soc/codecs/wm8940.c6
-rw-r--r--sound/soc/codecs/wm8955.c7
-rw-r--r--sound/soc/codecs/wm8960.c18
-rw-r--r--sound/soc/codecs/wm8961.c6
-rw-r--r--sound/soc/codecs/wm8962.c21
-rw-r--r--sound/soc/codecs/wm8971.c3
-rw-r--r--sound/soc/codecs/wm8974.c3
-rw-r--r--sound/soc/codecs/wm8978.c7
-rw-r--r--sound/soc/codecs/wm8983.c3
-rw-r--r--sound/soc/codecs/wm8985.c3
-rw-r--r--sound/soc/codecs/wm8988.c3
-rw-r--r--sound/soc/codecs/wm8990.c5
-rw-r--r--sound/soc/codecs/wm8991.c3
-rw-r--r--sound/soc/codecs/wm8993.c12
-rw-r--r--sound/soc/codecs/wm8994.c64
-rw-r--r--sound/soc/codecs/wm8995.c6
-rw-r--r--sound/soc/codecs/wm8996.c17
-rw-r--r--sound/soc/codecs/wm8997.c18
-rw-r--r--sound/soc/codecs/wm9081.c4
-rw-r--r--sound/soc/codecs/wm9090.c6
-rw-r--r--sound/soc/codecs/wm9712.c3
-rw-r--r--sound/soc/codecs/wm9713.c7
-rw-r--r--sound/soc/codecs/wm_adsp.c1210
-rw-r--r--sound/soc/codecs/wm_adsp.h19
-rw-r--r--sound/soc/codecs/wm_hubs.c4
-rw-r--r--sound/soc/codecs/wmfw.h44
-rw-r--r--sound/soc/davinci/davinci-mcasp.c169
-rw-r--r--sound/soc/fsl/fsl_dma.c4
-rw-r--r--sound/soc/fsl/fsl_sai.c144
-rw-r--r--sound/soc/fsl/fsl_sai.h9
-rw-r--r--sound/soc/fsl/fsl_ssi.c9
-rw-r--r--sound/soc/fsl/imx-audmux.c2
-rw-r--r--sound/soc/fsl/imx-mc13783.c6
-rw-r--r--sound/soc/intel/Makefile2
-rw-r--r--sound/soc/intel/baytrail/sst-baytrail-ipc.c1
-rw-r--r--sound/soc/intel/boards/cht_bsw_rt5645.c2
-rw-r--r--sound/soc/intel/haswell/sst-haswell-ipc.c1
-rw-r--r--sound/soc/qcom/lpass-cpu.c2
-rw-r--r--sound/soc/samsung/s3c24xx-i2s.c4
-rw-r--r--sound/soc/sh/rcar/dma.c1
-rw-r--r--sound/soc/soc-core.c63
-rw-r--r--sound/soc/soc-dapm.c360
-rw-r--r--sound/soc/soc-generic-dmaengine-pcm.c25
-rw-r--r--sound/soc/soc-jack.c9
-rw-r--r--sound/soc/soc-pcm.c47
-rw-r--r--sound/soc/ux500/mop500_ab8500.c4
-rw-r--r--sound/soc/ux500/ux500_pcm.c1
-rw-r--r--sound/synth/emux/emux_oss.c11
-rw-r--r--sound/synth/emux/emux_seq.c29
-rw-r--r--sound/usb/quirks.c2
-rw-r--r--tools/lib/api/Makefile2
-rw-r--r--tools/lib/lockdep/Makefile3
-rw-r--r--tools/lib/lockdep/uinclude/linux/kernel.h3
-rw-r--r--tools/lib/traceevent/event-parse.c2
-rw-r--r--tools/net/bpf_jit_disasm.c2
-rw-r--r--tools/perf/Makefile2
-rw-r--r--tools/perf/bench/futex-requeue.c15
-rw-r--r--tools/perf/bench/numa.c12
-rw-r--r--tools/perf/builtin-kmem.c58
-rw-r--r--tools/perf/builtin-report.c2
-rw-r--r--tools/perf/builtin-top.c2
-rw-r--r--tools/perf/builtin-trace.c10
-rw-r--r--tools/perf/util/probe-event.c2
-rw-r--r--tools/perf/util/probe-finder.c4
-rw-r--r--tools/power/x86/turbostat/turbostat.c224
-rw-r--r--tools/testing/selftests/powerpc/pmu/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/tm/Makefile2
-rw-r--r--tools/testing/selftests/x86/Makefile53
-rwxr-xr-xtools/testing/selftests/x86/check_cc.sh16
-rw-r--r--tools/testing/selftests/x86/run_x86_tests.sh13
-rw-r--r--tools/testing/selftests/x86/trivial_32bit_program.c4
-rw-r--r--tools/testing/selftests/x86/trivial_64bit_program.c18
-rw-r--r--tools/thermal/tmon/Makefile8
-rw-r--r--tools/vm/Makefile2
1192 files changed, 15041 insertions, 9777 deletions
diff --git a/CREDITS b/CREDITS
index 40cc4bfb34db..ec7e6c7fdd1b 100644
--- a/CREDITS
+++ b/CREDITS
@@ -3709,6 +3709,13 @@ N: Dirk Verworner
3709D: Co-author of German book ``Linux-Kernel-Programmierung'' 3709D: Co-author of German book ``Linux-Kernel-Programmierung''
3710D: Co-founder of Berlin Linux User Group 3710D: Co-founder of Berlin Linux User Group
3711 3711
3712N: Andrew Victor
3713E: linux@maxim.org.za
3714W: http://maxim.org.za/at91_26.html
3715D: First maintainer of Atmel ARM-based SoC, aka AT91
3716D: Introduced support for at91rm9200, the first chip of AT91 family
3717S: South Africa
3718
3712N: Riku Voipio 3719N: Riku Voipio
3713E: riku.voipio@iki.fi 3720E: riku.voipio@iki.fi
3714D: Author of PCA9532 LED and Fintek f75375s hwmon driver 3721D: Author of PCA9532 LED and Fintek f75375s hwmon driver
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 99983e67c13c..da95513571ea 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -162,7 +162,7 @@ Description: Discover CPUs in the same CPU frequency coordination domain
162What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} 162What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1}
163Date: August 2008 163Date: August 2008
164KernelVersion: 2.6.27 164KernelVersion: 2.6.27
165Contact: discuss@x86-64.org 165Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
166Description: Disable L3 cache indices 166Description: Disable L3 cache indices
167 167
168 These files exist in every CPU's cache/index3 directory. Each 168 These files exist in every CPU's cache/index3 directory. Each
diff --git a/Documentation/IPMI.txt b/Documentation/IPMI.txt
index 653d5d739d7f..31d1d658827f 100644
--- a/Documentation/IPMI.txt
+++ b/Documentation/IPMI.txt
@@ -505,7 +505,10 @@ at module load time (for a module) with:
505 505
506The addresses are normal I2C addresses. The adapter is the string 506The addresses are normal I2C addresses. The adapter is the string
507name of the adapter, as shown in /sys/class/i2c-adapter/i2c-<n>/name. 507name of the adapter, as shown in /sys/class/i2c-adapter/i2c-<n>/name.
508It is *NOT* i2c-<n> itself. 508It is *NOT* i2c-<n> itself. Also, the comparison is done ignoring
509spaces, so if the name is "This is an I2C chip" you can say
510adapter_name=ThisisanI2cchip. This is because it's hard to pass in
511spaces in kernel parameters.
509 512
510The debug flags are bit flags for each BMC found, they are: 513The debug flags are bit flags for each BMC found, they are:
511IPMI messages: 1, driver state: 2, timing: 4, I2C probe: 8 514IPMI messages: 1, driver state: 2, timing: 4, I2C probe: 8
diff --git a/Documentation/acpi/enumeration.txt b/Documentation/acpi/enumeration.txt
index 750401f91341..15dfce708ebf 100644
--- a/Documentation/acpi/enumeration.txt
+++ b/Documentation/acpi/enumeration.txt
@@ -253,7 +253,7 @@ input driver:
253GPIO support 253GPIO support
254~~~~~~~~~~~~ 254~~~~~~~~~~~~
255ACPI 5 introduced two new resources to describe GPIO connections: GpioIo 255ACPI 5 introduced two new resources to describe GPIO connections: GpioIo
256and GpioInt. These resources are used be used to pass GPIO numbers used by 256and GpioInt. These resources can be used to pass GPIO numbers used by
257the device to the driver. ACPI 5.1 extended this with _DSD (Device 257the device to the driver. ACPI 5.1 extended this with _DSD (Device
258Specific Data) which made it possible to name the GPIOs among other things. 258Specific Data) which made it possible to name the GPIOs among other things.
259 259
diff --git a/Documentation/acpi/gpio-properties.txt b/Documentation/acpi/gpio-properties.txt
index ae36fcf86dc7..f35dad11f0de 100644
--- a/Documentation/acpi/gpio-properties.txt
+++ b/Documentation/acpi/gpio-properties.txt
@@ -1,9 +1,9 @@
1_DSD Device Properties Related to GPIO 1_DSD Device Properties Related to GPIO
2-------------------------------------- 2--------------------------------------
3 3
4With the release of ACPI 5.1 and the _DSD configuration objecte names 4With the release of ACPI 5.1, the _DSD configuration object finally
5can finally be given to GPIOs (and other things as well) returned by 5allows names to be given to GPIOs (and other things as well) returned
6_CRS. Previously, we were only able to use an integer index to find 6by _CRS. Previously, we were only able to use an integer index to find
7the corresponding GPIO, which is pretty error prone (it depends on 7the corresponding GPIO, which is pretty error prone (it depends on
8the _CRS output ordering, for example). 8the _CRS output ordering, for example).
9 9
diff --git a/Documentation/devicetree/bindings/arm/omap/l3-noc.txt b/Documentation/devicetree/bindings/arm/omap/l3-noc.txt
index 974624ea68f6..161448da959d 100644
--- a/Documentation/devicetree/bindings/arm/omap/l3-noc.txt
+++ b/Documentation/devicetree/bindings/arm/omap/l3-noc.txt
@@ -6,6 +6,7 @@ provided by Arteris.
6Required properties: 6Required properties:
7- compatible : Should be "ti,omap3-l3-smx" for OMAP3 family 7- compatible : Should be "ti,omap3-l3-smx" for OMAP3 family
8 Should be "ti,omap4-l3-noc" for OMAP4 family 8 Should be "ti,omap4-l3-noc" for OMAP4 family
9 Should be "ti,omap5-l3-noc" for OMAP5 family
9 Should be "ti,dra7-l3-noc" for DRA7 family 10 Should be "ti,dra7-l3-noc" for DRA7 family
10 Should be "ti,am4372-l3-noc" for AM43 family 11 Should be "ti,am4372-l3-noc" for AM43 family
11- reg: Contains L3 register address range for each noc domain. 12- reg: Contains L3 register address range for each noc domain.
diff --git a/Documentation/devicetree/bindings/clock/silabs,si5351.txt b/Documentation/devicetree/bindings/clock/silabs,si5351.txt
index c40711e8e8f7..28b28309f535 100644
--- a/Documentation/devicetree/bindings/clock/silabs,si5351.txt
+++ b/Documentation/devicetree/bindings/clock/silabs,si5351.txt
@@ -17,7 +17,8 @@ Required properties:
17- #clock-cells: from common clock binding; shall be set to 1. 17- #clock-cells: from common clock binding; shall be set to 1.
18- clocks: from common clock binding; list of parent clock 18- clocks: from common clock binding; list of parent clock
19 handles, shall be xtal reference clock or xtal and clkin for 19 handles, shall be xtal reference clock or xtal and clkin for
20 si5351c only. 20 si5351c only. Corresponding clock input names are "xtal" and
21 "clkin" respectively.
21- #address-cells: shall be set to 1. 22- #address-cells: shall be set to 1.
22- #size-cells: shall be set to 0. 23- #size-cells: shall be set to 0.
23 24
@@ -71,6 +72,7 @@ i2c-master-node {
71 72
72 /* connect xtal input to 25MHz reference */ 73 /* connect xtal input to 25MHz reference */
73 clocks = <&ref25>; 74 clocks = <&ref25>;
75 clock-names = "xtal";
74 76
75 /* connect xtal input as source of pll0 and pll1 */ 77 /* connect xtal input as source of pll0 and pll1 */
76 silabs,pll-source = <0 0>, <1 0>; 78 silabs,pll-source = <0 0>, <1 0>;
diff --git a/Documentation/devicetree/bindings/dma/fsl-mxs-dma.txt b/Documentation/devicetree/bindings/dma/fsl-mxs-dma.txt
index a4873e5e3e36..e30e184f50c7 100644
--- a/Documentation/devicetree/bindings/dma/fsl-mxs-dma.txt
+++ b/Documentation/devicetree/bindings/dma/fsl-mxs-dma.txt
@@ -38,7 +38,7 @@ dma_apbx: dma-apbx@80024000 {
38 80 81 68 69 38 80 81 68 69
39 70 71 72 73 39 70 71 72 73
40 74 75 76 77>; 40 74 75 76 77>;
41 interrupt-names = "auart4-rx", "aurat4-tx", "spdif-tx", "empty", 41 interrupt-names = "auart4-rx", "auart4-tx", "spdif-tx", "empty",
42 "saif0", "saif1", "i2c0", "i2c1", 42 "saif0", "saif1", "i2c0", "i2c1",
43 "auart0-rx", "auart0-tx", "auart1-rx", "auart1-tx", 43 "auart0-rx", "auart0-tx", "auart1-rx", "auart1-tx",
44 "auart2-rx", "auart2-tx", "auart3-rx", "auart3-tx"; 44 "auart2-rx", "auart2-tx", "auart3-rx", "auart3-tx";
diff --git a/Documentation/devicetree/bindings/mtd/m25p80.txt b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt
index f20b111b502a..2bee68103b01 100644
--- a/Documentation/devicetree/bindings/mtd/m25p80.txt
+++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt
@@ -8,8 +8,8 @@ Required properties:
8 is not Linux-only, but in case of Linux, see the "m25p_ids" 8 is not Linux-only, but in case of Linux, see the "m25p_ids"
9 table in drivers/mtd/devices/m25p80.c for the list of supported 9 table in drivers/mtd/devices/m25p80.c for the list of supported
10 chips. 10 chips.
11 Must also include "nor-jedec" for any SPI NOR flash that can be 11 Must also include "jedec,spi-nor" for any SPI NOR flash that can
12 identified by the JEDEC READ ID opcode (0x9F). 12 be identified by the JEDEC READ ID opcode (0x9F).
13- reg : Chip-Select number 13- reg : Chip-Select number
14- spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at 14- spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at
15 15
@@ -25,7 +25,7 @@ Example:
25 flash: m25p80@0 { 25 flash: m25p80@0 {
26 #address-cells = <1>; 26 #address-cells = <1>;
27 #size-cells = <1>; 27 #size-cells = <1>;
28 compatible = "spansion,m25p80", "nor-jedec"; 28 compatible = "spansion,m25p80", "jedec,spi-nor";
29 reg = <0>; 29 reg = <0>;
30 spi-max-frequency = <40000000>; 30 spi-max-frequency = <40000000>;
31 m25p,fast-read; 31 m25p,fast-read;
diff --git a/Documentation/devicetree/bindings/net/cdns-emac.txt b/Documentation/devicetree/bindings/net/cdns-emac.txt
index abd67c13d344..4451ee973223 100644
--- a/Documentation/devicetree/bindings/net/cdns-emac.txt
+++ b/Documentation/devicetree/bindings/net/cdns-emac.txt
@@ -3,7 +3,8 @@
3Required properties: 3Required properties:
4- compatible: Should be "cdns,[<chip>-]{emac}" 4- compatible: Should be "cdns,[<chip>-]{emac}"
5 Use "cdns,at91rm9200-emac" Atmel at91rm9200 SoC. 5 Use "cdns,at91rm9200-emac" Atmel at91rm9200 SoC.
6 or the generic form: "cdns,emac". 6 Use "cdns,zynq-gem" Xilinx Zynq-7xxx SoC.
7 Or the generic form: "cdns,emac".
7- reg: Address and length of the register set for the device 8- reg: Address and length of the register set for the device
8- interrupts: Should contain macb interrupt 9- interrupts: Should contain macb interrupt
9- phy-mode: see ethernet.txt file in the same directory. 10- phy-mode: see ethernet.txt file in the same directory.
diff --git a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
new file mode 100644
index 000000000000..be789685a1c2
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
@@ -0,0 +1,30 @@
1Abracon ABX80X I2C ultra low power RTC/Alarm chip
2
3The Abracon ABX80X family consist of the ab0801, ab0803, ab0804, ab0805, ab1801,
4ab1803, ab1804 and ab1805. The ab0805 is the superset of ab080x and the ab1805
5is the superset of ab180x.
6
7Required properties:
8
9 - "compatible": should one of:
10 "abracon,abx80x"
11 "abracon,ab0801"
12 "abracon,ab0803"
13 "abracon,ab0804"
14 "abracon,ab0805"
15 "abracon,ab1801"
16 "abracon,ab1803"
17 "abracon,ab1804"
18 "abracon,ab1805"
19 Using "abracon,abx80x" will enable chip autodetection.
20 - "reg": I2C bus address of the device
21
22Optional properties:
23
24The abx804 and abx805 have a trickle charger that is able to charge the
25connected battery or supercap. Both the following properties have to be defined
26and valid to enable charging:
27
28 - "abracon,tc-diode": should be "standard" (0.6V) or "schottky" (0.3V)
29 - "abracon,tc-resistor": should be <0>, <3>, <6> or <11>. 0 disables the output
30 resistor, the other values are in ohm.
diff --git a/Documentation/devicetree/bindings/sound/adi,adau1701.txt b/Documentation/devicetree/bindings/sound/adi,adau1701.txt
index 547a49b56a62..0d1128ce2ea7 100644
--- a/Documentation/devicetree/bindings/sound/adi,adau1701.txt
+++ b/Documentation/devicetree/bindings/sound/adi,adau1701.txt
@@ -20,6 +20,8 @@ Optional properties:
20 pin configurations as described in the datasheet, 20 pin configurations as described in the datasheet,
21 table 53. Note that the value of this property has 21 table 53. Note that the value of this property has
22 to be prefixed with '/bits/ 8'. 22 to be prefixed with '/bits/ 8'.
23 - avdd-supply: Power supply for AVDD, providing 3.3V
24 - dvdd-supply: Power supply for DVDD, providing 3.3V
23 25
24Examples: 26Examples:
25 27
@@ -28,6 +30,8 @@ Examples:
28 compatible = "adi,adau1701"; 30 compatible = "adi,adau1701";
29 reg = <0x34>; 31 reg = <0x34>;
30 reset-gpio = <&gpio 23 0>; 32 reset-gpio = <&gpio 23 0>;
33 avdd-supply = <&vdd_3v3_reg>;
34 dvdd-supply = <&vdd_3v3_reg>;
31 adi,pll-mode-gpios = <&gpio 24 0 &gpio 25 0>; 35 adi,pll-mode-gpios = <&gpio 24 0 &gpio 25 0>;
32 adi,pin-config = /bits/ 8 <0x4 0x7 0x5 0x5 0x4 0x4 36 adi,pin-config = /bits/ 8 <0x4 0x7 0x5 0x5 0x4 0x4
33 0x4 0x4 0x4 0x4 0x4 0x4>; 37 0x4 0x4 0x4 0x4 0x4 0x4>;
diff --git a/Documentation/devicetree/bindings/sound/bt-sco.txt b/Documentation/devicetree/bindings/sound/bt-sco.txt
new file mode 100644
index 000000000000..29b8e5d40203
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/bt-sco.txt
@@ -0,0 +1,13 @@
1Bluetooth-SCO audio CODEC
2
3This device support generic Bluetooth SCO link.
4
5Required properties:
6
7 - compatible : "delta,dfbmcs320"
8
9Example:
10
11codec: bt_sco {
12 compatible = "delta,dfbmcs320";
13};
diff --git a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
index f316ce1f214a..14f467345994 100644
--- a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
+++ b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
@@ -5,6 +5,7 @@ Required properties:
5 "renesas,rcar_sound-gen1" if generation1, and 5 "renesas,rcar_sound-gen1" if generation1, and
6 "renesas,rcar_sound-gen2" if generation2 6 "renesas,rcar_sound-gen2" if generation2
7 Examples with soctypes are: 7 Examples with soctypes are:
8 - "renesas,rcar_sound-r8a7778" (R-Car M1A)
8 - "renesas,rcar_sound-r8a7790" (R-Car H2) 9 - "renesas,rcar_sound-r8a7790" (R-Car H2)
9 - "renesas,rcar_sound-r8a7791" (R-Car M2-W) 10 - "renesas,rcar_sound-r8a7791" (R-Car M2-W)
10- reg : Should contain the register physical address. 11- reg : Should contain the register physical address.
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 80339192c93e..b6969e477bf3 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -54,6 +54,7 @@ cosmic Cosmic Circuits
54crystalfontz Crystalfontz America, Inc. 54crystalfontz Crystalfontz America, Inc.
55dallas Maxim Integrated Products (formerly Dallas Semiconductor) 55dallas Maxim Integrated Products (formerly Dallas Semiconductor)
56davicom DAVICOM Semiconductor, Inc. 56davicom DAVICOM Semiconductor, Inc.
57delta Delta Electronics, Inc.
57denx Denx Software Engineering 58denx Denx Software Engineering
58digi Digi International Inc. 59digi Digi International Inc.
59digilent Diglent, Inc. 60digilent Diglent, Inc.
diff --git a/Documentation/hwmon/tmp401 b/Documentation/hwmon/tmp401
index 8eb88e974055..711f75e189eb 100644
--- a/Documentation/hwmon/tmp401
+++ b/Documentation/hwmon/tmp401
@@ -20,7 +20,7 @@ Supported chips:
20 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp432.html 20 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp432.html
21 * Texas Instruments TMP435 21 * Texas Instruments TMP435
22 Prefix: 'tmp435' 22 Prefix: 'tmp435'
23 Addresses scanned: I2C 0x37, 0x48 - 0x4f 23 Addresses scanned: I2C 0x48 - 0x4f
24 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html 24 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html
25 25
26Authors: 26Authors:
diff --git a/Documentation/kasan.txt b/Documentation/kasan.txt
index 092fc10961fe..4692241789b1 100644
--- a/Documentation/kasan.txt
+++ b/Documentation/kasan.txt
@@ -9,7 +9,9 @@ a fast and comprehensive solution for finding use-after-free and out-of-bounds
9bugs. 9bugs.
10 10
11KASan uses compile-time instrumentation for checking every memory access, 11KASan uses compile-time instrumentation for checking every memory access,
12therefore you will need a certain version of GCC > 4.9.2 12therefore you will need a gcc version of 4.9.2 or later. KASan could detect out
13of bounds accesses to stack or global variables, but only if gcc 5.0 or later was
14used to built the kernel.
13 15
14Currently KASan is supported only for x86_64 architecture and requires that the 16Currently KASan is supported only for x86_64 architecture and requires that the
15kernel be built with the SLUB allocator. 17kernel be built with the SLUB allocator.
@@ -23,8 +25,8 @@ To enable KASAN configure kernel with:
23 25
24and choose between CONFIG_KASAN_OUTLINE and CONFIG_KASAN_INLINE. Outline/inline 26and choose between CONFIG_KASAN_OUTLINE and CONFIG_KASAN_INLINE. Outline/inline
25is compiler instrumentation types. The former produces smaller binary the 27is compiler instrumentation types. The former produces smaller binary the
26latter is 1.1 - 2 times faster. Inline instrumentation requires GCC 5.0 or 28latter is 1.1 - 2 times faster. Inline instrumentation requires a gcc version
27latter. 29of 5.0 or later.
28 30
29Currently KASAN works only with the SLUB memory allocator. 31Currently KASAN works only with the SLUB memory allocator.
30For better bug detection and nicer report, enable CONFIG_STACKTRACE and put 32For better bug detection and nicer report, enable CONFIG_STACKTRACE and put
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index f6befa9855c1..61ab1628a057 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3787,6 +3787,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
3787 READ_CAPACITY_16 command); 3787 READ_CAPACITY_16 command);
3788 f = NO_REPORT_OPCODES (don't use report opcodes 3788 f = NO_REPORT_OPCODES (don't use report opcodes
3789 command, uas only); 3789 command, uas only);
3790 g = MAX_SECTORS_240 (don't transfer more than
3791 240 sectors at a time, uas only);
3790 h = CAPACITY_HEURISTICS (decrease the 3792 h = CAPACITY_HEURISTICS (decrease the
3791 reported device capacity by one 3793 reported device capacity by one
3792 sector if the number is odd); 3794 sector if the number is odd);
diff --git a/Documentation/module-signing.txt b/Documentation/module-signing.txt
index 09c2382ad055..c72702ec1ded 100644
--- a/Documentation/module-signing.txt
+++ b/Documentation/module-signing.txt
@@ -119,9 +119,9 @@ Most notably, in the x509.genkey file, the req_distinguished_name section
119should be altered from the default: 119should be altered from the default:
120 120
121 [ req_distinguished_name ] 121 [ req_distinguished_name ]
122 O = Magrathea 122 #O = Unspecified company
123 CN = Glacier signing key 123 CN = Build time autogenerated kernel key
124 emailAddress = slartibartfast@magrathea.h2g2 124 #emailAddress = unspecified.user@unspecified.company
125 125
126The generated RSA key size can also be set with: 126The generated RSA key size can also be set with:
127 127
diff --git a/Documentation/networking/mpls-sysctl.txt b/Documentation/networking/mpls-sysctl.txt
index 639ddf0ece9b..9ed15f86c17c 100644
--- a/Documentation/networking/mpls-sysctl.txt
+++ b/Documentation/networking/mpls-sysctl.txt
@@ -18,3 +18,12 @@ platform_labels - INTEGER
18 18
19 Possible values: 0 - 1048575 19 Possible values: 0 - 1048575
20 Default: 0 20 Default: 0
21
22conf/<interface>/input - BOOL
23 Control whether packets can be input on this interface.
24
25 If disabled, packets will be discarded without further
26 processing.
27
28 0 - disabled (default)
29 not 0 - enabled
diff --git a/Documentation/networking/scaling.txt b/Documentation/networking/scaling.txt
index cbfac0949635..59f4db2a0c85 100644
--- a/Documentation/networking/scaling.txt
+++ b/Documentation/networking/scaling.txt
@@ -282,7 +282,7 @@ following is true:
282 282
283- The current CPU's queue head counter >= the recorded tail counter 283- The current CPU's queue head counter >= the recorded tail counter
284 value in rps_dev_flow[i] 284 value in rps_dev_flow[i]
285- The current CPU is unset (equal to RPS_NO_CPU) 285- The current CPU is unset (>= nr_cpu_ids)
286- The current CPU is offline 286- The current CPU is offline
287 287
288After this check, the packet is sent to the (possibly updated) current 288After this check, the packet is sent to the (possibly updated) current
diff --git a/Documentation/powerpc/transactional_memory.txt b/Documentation/powerpc/transactional_memory.txt
index ba0a2a4a54ba..ded69794a5c0 100644
--- a/Documentation/powerpc/transactional_memory.txt
+++ b/Documentation/powerpc/transactional_memory.txt
@@ -74,23 +74,22 @@ Causes of transaction aborts
74Syscalls 74Syscalls
75======== 75========
76 76
77Syscalls made from within an active transaction will not be performed and the 77Performing syscalls from within transaction is not recommended, and can lead
78transaction will be doomed by the kernel with the failure code TM_CAUSE_SYSCALL 78to unpredictable results.
79| TM_CAUSE_PERSISTENT.
80 79
81Syscalls made from within a suspended transaction are performed as normal and 80Syscalls do not by design abort transactions, but beware: The kernel code will
82the transaction is not explicitly doomed by the kernel. However, what the 81not be running in transactional state. The effect of syscalls will always
83kernel does to perform the syscall may result in the transaction being doomed 82remain visible, but depending on the call they may abort your transaction as a
84by the hardware. The syscall is performed in suspended mode so any side 83side-effect, read soon-to-be-aborted transactional data that should not remain
85effects will be persistent, independent of transaction success or failure. No 84invisible, etc. If you constantly retry a transaction that constantly aborts
86guarantees are provided by the kernel about which syscalls will affect 85itself by calling a syscall, you'll have a livelock & make no progress.
87transaction success.
88 86
89Care must be taken when relying on syscalls to abort during active transactions 87Simple syscalls (e.g. sigprocmask()) "could" be OK. Even things like write()
90if the calls are made via a library. Libraries may cache values (which may 88from, say, printf() should be OK as long as the kernel does not access any
91give the appearance of success) or perform operations that cause transaction 89memory that was accessed transactionally.
92failure before entering the kernel (which may produce different failure codes). 90
93Examples are glibc's getpid() and lazy symbol resolution. 91Consider any syscalls that happen to work as debug-only -- not recommended for
92production use. Best to queue them up till after the transaction is over.
94 93
95 94
96Signals 95Signals
@@ -177,7 +176,8 @@ kernel aborted a transaction:
177 TM_CAUSE_RESCHED Thread was rescheduled. 176 TM_CAUSE_RESCHED Thread was rescheduled.
178 TM_CAUSE_TLBI Software TLB invalid. 177 TM_CAUSE_TLBI Software TLB invalid.
179 TM_CAUSE_FAC_UNAV FP/VEC/VSX unavailable trap. 178 TM_CAUSE_FAC_UNAV FP/VEC/VSX unavailable trap.
180 TM_CAUSE_SYSCALL Syscall from active transaction. 179 TM_CAUSE_SYSCALL Currently unused; future syscalls that must abort
180 transactions for consistency will use this.
181 TM_CAUSE_SIGNAL Signal delivered. 181 TM_CAUSE_SIGNAL Signal delivered.
182 TM_CAUSE_MISC Currently unused. 182 TM_CAUSE_MISC Currently unused.
183 TM_CAUSE_ALIGNMENT Alignment fault. 183 TM_CAUSE_ALIGNMENT Alignment fault.
diff --git a/Documentation/serial/tty.txt b/Documentation/serial/tty.txt
index 1e52d67d0abf..dbe6623fed1c 100644
--- a/Documentation/serial/tty.txt
+++ b/Documentation/serial/tty.txt
@@ -198,6 +198,9 @@ TTY_IO_ERROR If set, causes all subsequent userspace read/write
198 198
199TTY_OTHER_CLOSED Device is a pty and the other side has closed. 199TTY_OTHER_CLOSED Device is a pty and the other side has closed.
200 200
201TTY_OTHER_DONE Device is a pty and the other side has closed and
202 all pending input processing has been completed.
203
201TTY_NO_WRITE_SPLIT Prevent driver from splitting up writes into 204TTY_NO_WRITE_SPLIT Prevent driver from splitting up writes into
202 smaller chunks. 205 smaller chunks.
203 206
diff --git a/Documentation/target/tcmu-design.txt b/Documentation/target/tcmu-design.txt
index 43e94ea6d2ca..263b907517ac 100644
--- a/Documentation/target/tcmu-design.txt
+++ b/Documentation/target/tcmu-design.txt
@@ -15,8 +15,7 @@ Contents:
15 a) Discovering and configuring TCMU uio devices 15 a) Discovering and configuring TCMU uio devices
16 b) Waiting for events on the device(s) 16 b) Waiting for events on the device(s)
17 c) Managing the command ring 17 c) Managing the command ring
183) Command filtering and pass_level 183) A final note
194) A final note
20 19
21 20
22TCM Userspace Design 21TCM Userspace Design
@@ -324,7 +323,7 @@ int handle_device_events(int fd, void *map)
324 /* Process events from cmd ring until we catch up with cmd_head */ 323 /* Process events from cmd ring until we catch up with cmd_head */
325 while (ent != (void *)mb + mb->cmdr_off + mb->cmd_head) { 324 while (ent != (void *)mb + mb->cmdr_off + mb->cmd_head) {
326 325
327 if (tcmu_hdr_get_op(&ent->hdr) == TCMU_OP_CMD) { 326 if (tcmu_hdr_get_op(ent->hdr.len_op) == TCMU_OP_CMD) {
328 uint8_t *cdb = (void *)mb + ent->req.cdb_off; 327 uint8_t *cdb = (void *)mb + ent->req.cdb_off;
329 bool success = true; 328 bool success = true;
330 329
@@ -339,8 +338,12 @@ int handle_device_events(int fd, void *map)
339 ent->rsp.scsi_status = SCSI_CHECK_CONDITION; 338 ent->rsp.scsi_status = SCSI_CHECK_CONDITION;
340 } 339 }
341 } 340 }
341 else if (tcmu_hdr_get_op(ent->hdr.len_op) != TCMU_OP_PAD) {
342 /* Tell the kernel we didn't handle unknown opcodes */
343 ent->hdr.uflags |= TCMU_UFLAG_UNKNOWN_OP;
344 }
342 else { 345 else {
343 /* Do nothing for PAD entries */ 346 /* Do nothing for PAD entries except update cmd_tail */
344 } 347 }
345 348
346 /* update cmd_tail */ 349 /* update cmd_tail */
@@ -360,28 +363,6 @@ int handle_device_events(int fd, void *map)
360} 363}
361 364
362 365
363Command filtering and pass_level
364--------------------------------
365
366TCMU supports a "pass_level" option with valid values of 0 or 1. When
367the value is 0 (the default), nearly all SCSI commands received for
368the device are passed through to the handler. This allows maximum
369flexibility but increases the amount of code required by the handler,
370to support all mandatory SCSI commands. If pass_level is set to 1,
371then only IO-related commands are presented, and the rest are handled
372by LIO's in-kernel command emulation. The commands presented at level
3731 include all versions of:
374
375READ
376WRITE
377WRITE_VERIFY
378XDWRITEREAD
379WRITE_SAME
380COMPARE_AND_WRITE
381SYNCHRONIZE_CACHE
382UNMAP
383
384
385A final note 366A final note
386------------ 367------------
387 368
diff --git a/Documentation/virtual/kvm/mmu.txt b/Documentation/virtual/kvm/mmu.txt
index 53838d9c6295..c59bd9bc41ef 100644
--- a/Documentation/virtual/kvm/mmu.txt
+++ b/Documentation/virtual/kvm/mmu.txt
@@ -169,6 +169,10 @@ Shadow pages contain the following information:
169 Contains the value of cr4.smep && !cr0.wp for which the page is valid 169 Contains the value of cr4.smep && !cr0.wp for which the page is valid
170 (pages for which this is true are different from other pages; see the 170 (pages for which this is true are different from other pages; see the
171 treatment of cr0.wp=0 below). 171 treatment of cr0.wp=0 below).
172 role.smap_andnot_wp:
173 Contains the value of cr4.smap && !cr0.wp for which the page is valid
174 (pages for which this is true are different from other pages; see the
175 treatment of cr0.wp=0 below).
172 gfn: 176 gfn:
173 Either the guest page table containing the translations shadowed by this 177 Either the guest page table containing the translations shadowed by this
174 page, or the base page frame for linear translations. See role.direct. 178 page, or the base page frame for linear translations. See role.direct.
@@ -344,10 +348,16 @@ on fault type:
344 348
345(user write faults generate a #PF) 349(user write faults generate a #PF)
346 350
347In the first case there is an additional complication if CR4.SMEP is 351In the first case there are two additional complications:
348enabled: since we've turned the page into a kernel page, the kernel may now 352- if CR4.SMEP is enabled: since we've turned the page into a kernel page,
349execute it. We handle this by also setting spte.nx. If we get a user 353 the kernel may now execute it. We handle this by also setting spte.nx.
350fetch or read fault, we'll change spte.u=1 and spte.nx=gpte.nx back. 354 If we get a user fetch or read fault, we'll change spte.u=1 and
355 spte.nx=gpte.nx back.
356- if CR4.SMAP is disabled: since the page has been changed to a kernel
357 page, it can not be reused when CR4.SMAP is enabled. We set
358 CR4.SMAP && !CR0.WP into shadow page's role to avoid this case. Note,
359 here we do not care the case that CR4.SMAP is enabled since KVM will
360 directly inject #PF to guest due to failed permission check.
351 361
352To prevent an spte that was converted into a kernel page with cr0.wp=0 362To prevent an spte that was converted into a kernel page with cr0.wp=0
353from being written by the kernel after cr0.wp has changed to 1, we make 363from being written by the kernel after cr0.wp has changed to 1, we make
diff --git a/MAINTAINERS b/MAINTAINERS
index 2e5bbc0d68b2..af802b357b6a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -892,11 +892,10 @@ S: Maintained
892F: arch/arm/mach-alpine/ 892F: arch/arm/mach-alpine/
893 893
894ARM/ATMEL AT91RM9200 AND AT91SAM ARM ARCHITECTURES 894ARM/ATMEL AT91RM9200 AND AT91SAM ARM ARCHITECTURES
895M: Andrew Victor <linux@maxim.org.za>
896M: Nicolas Ferre <nicolas.ferre@atmel.com> 895M: Nicolas Ferre <nicolas.ferre@atmel.com>
896M: Alexandre Belloni <alexandre.belloni@free-electrons.com>
897M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com> 897M: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
898L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 898L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
899W: http://maxim.org.za/at91_26.html
900W: http://www.linux4sam.org 899W: http://www.linux4sam.org
901S: Supported 900S: Supported
902F: arch/arm/mach-at91/ 901F: arch/arm/mach-at91/
@@ -975,7 +974,7 @@ S: Maintained
975ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE 974ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE
976M: Hans Ulli Kroll <ulli.kroll@googlemail.com> 975M: Hans Ulli Kroll <ulli.kroll@googlemail.com>
977L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 976L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
978T: git git://git.berlios.de/gemini-board 977T: git git://github.com/ulli-kroll/linux.git
979S: Maintained 978S: Maintained
980F: arch/arm/mach-gemini/ 979F: arch/arm/mach-gemini/
981 980
@@ -990,6 +989,12 @@ F: drivers/clocksource/timer-prima2.c
990F: drivers/clocksource/timer-atlas7.c 989F: drivers/clocksource/timer-atlas7.c
991N: [^a-z]sirf 990N: [^a-z]sirf
992 991
992ARM/CONEXANT DIGICOLOR MACHINE SUPPORT
993M: Baruch Siach <baruch@tkos.co.il>
994L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
995S: Maintained
996N: digicolor
997
993ARM/EBSA110 MACHINE SUPPORT 998ARM/EBSA110 MACHINE SUPPORT
994M: Russell King <linux@arm.linux.org.uk> 999M: Russell King <linux@arm.linux.org.uk>
995L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1000L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@ -1188,7 +1193,7 @@ ARM/MAGICIAN MACHINE SUPPORT
1188M: Philipp Zabel <philipp.zabel@gmail.com> 1193M: Philipp Zabel <philipp.zabel@gmail.com>
1189S: Maintained 1194S: Maintained
1190 1195
1191ARM/Marvell Armada 370 and Armada XP SOC support 1196ARM/Marvell Kirkwood and Armada 370, 375, 38x, XP SOC support
1192M: Jason Cooper <jason@lakedaemon.net> 1197M: Jason Cooper <jason@lakedaemon.net>
1193M: Andrew Lunn <andrew@lunn.ch> 1198M: Andrew Lunn <andrew@lunn.ch>
1194M: Gregory Clement <gregory.clement@free-electrons.com> 1199M: Gregory Clement <gregory.clement@free-electrons.com>
@@ -1197,12 +1202,17 @@ L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1197S: Maintained 1202S: Maintained
1198F: arch/arm/mach-mvebu/ 1203F: arch/arm/mach-mvebu/
1199F: drivers/rtc/rtc-armada38x.c 1204F: drivers/rtc/rtc-armada38x.c
1205F: arch/arm/boot/dts/armada*
1206F: arch/arm/boot/dts/kirkwood*
1207
1200 1208
1201ARM/Marvell Berlin SoC support 1209ARM/Marvell Berlin SoC support
1202M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 1210M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1203L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1211L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1204S: Maintained 1212S: Maintained
1205F: arch/arm/mach-berlin/ 1213F: arch/arm/mach-berlin/
1214F: arch/arm/boot/dts/berlin*
1215
1206 1216
1207ARM/Marvell Dove/MV78xx0/Orion SOC support 1217ARM/Marvell Dove/MV78xx0/Orion SOC support
1208M: Jason Cooper <jason@lakedaemon.net> 1218M: Jason Cooper <jason@lakedaemon.net>
@@ -1215,6 +1225,9 @@ F: arch/arm/mach-dove/
1215F: arch/arm/mach-mv78xx0/ 1225F: arch/arm/mach-mv78xx0/
1216F: arch/arm/mach-orion5x/ 1226F: arch/arm/mach-orion5x/
1217F: arch/arm/plat-orion/ 1227F: arch/arm/plat-orion/
1228F: arch/arm/boot/dts/dove*
1229F: arch/arm/boot/dts/orion5x*
1230
1218 1231
1219ARM/Orion SoC/Technologic Systems TS-78xx platform support 1232ARM/Orion SoC/Technologic Systems TS-78xx platform support
1220M: Alexander Clouter <alex@digriz.org.uk> 1233M: Alexander Clouter <alex@digriz.org.uk>
@@ -1366,6 +1379,7 @@ N: rockchip
1366 1379
1367ARM/SAMSUNG EXYNOS ARM ARCHITECTURES 1380ARM/SAMSUNG EXYNOS ARM ARCHITECTURES
1368M: Kukjin Kim <kgene@kernel.org> 1381M: Kukjin Kim <kgene@kernel.org>
1382M: Krzysztof Kozlowski <k.kozlowski@samsung.com>
1369L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1383L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1370L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 1384L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
1371S: Maintained 1385S: Maintained
@@ -1439,9 +1453,10 @@ ARM/SOCFPGA ARCHITECTURE
1439M: Dinh Nguyen <dinguyen@opensource.altera.com> 1453M: Dinh Nguyen <dinguyen@opensource.altera.com>
1440S: Maintained 1454S: Maintained
1441F: arch/arm/mach-socfpga/ 1455F: arch/arm/mach-socfpga/
1456F: arch/arm/boot/dts/socfpga*
1457F: arch/arm/configs/socfpga_defconfig
1442W: http://www.rocketboards.org 1458W: http://www.rocketboards.org
1443T: git://git.rocketboards.org/linux-socfpga.git 1459T: git git://git.kernel.org/pub/scm/linux/kernel/git/dinguyen/linux.git
1444T: git://git.rocketboards.org/linux-socfpga-next.git
1445 1460
1446ARM/SOCFPGA CLOCK FRAMEWORK SUPPORT 1461ARM/SOCFPGA CLOCK FRAMEWORK SUPPORT
1447M: Dinh Nguyen <dinguyen@opensource.altera.com> 1462M: Dinh Nguyen <dinguyen@opensource.altera.com>
@@ -1929,7 +1944,7 @@ S: Maintained
1929F: drivers/net/wireless/b43legacy/ 1944F: drivers/net/wireless/b43legacy/
1930 1945
1931BACKLIGHT CLASS/SUBSYSTEM 1946BACKLIGHT CLASS/SUBSYSTEM
1932M: Jingoo Han <jg1.han@samsung.com> 1947M: Jingoo Han <jingoohan1@gmail.com>
1933M: Lee Jones <lee.jones@linaro.org> 1948M: Lee Jones <lee.jones@linaro.org>
1934S: Maintained 1949S: Maintained
1935F: drivers/video/backlight/ 1950F: drivers/video/backlight/
@@ -2116,8 +2131,9 @@ S: Supported
2116F: drivers/net/ethernet/broadcom/bnx2x/ 2131F: drivers/net/ethernet/broadcom/bnx2x/
2117 2132
2118BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITECTURE 2133BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITECTURE
2119M: Christian Daudt <bcm@fixthebug.org>
2120M: Florian Fainelli <f.fainelli@gmail.com> 2134M: Florian Fainelli <f.fainelli@gmail.com>
2135M: Ray Jui <rjui@broadcom.com>
2136M: Scott Branden <sbranden@broadcom.com>
2121L: bcm-kernel-feedback-list@broadcom.com 2137L: bcm-kernel-feedback-list@broadcom.com
2122T: git git://github.com/broadcom/mach-bcm 2138T: git git://github.com/broadcom/mach-bcm
2123S: Maintained 2139S: Maintained
@@ -2168,7 +2184,6 @@ S: Maintained
2168F: drivers/usb/gadget/udc/bcm63xx_udc.* 2184F: drivers/usb/gadget/udc/bcm63xx_udc.*
2169 2185
2170BROADCOM BCM7XXX ARM ARCHITECTURE 2186BROADCOM BCM7XXX ARM ARCHITECTURE
2171M: Marc Carino <marc.ceeeee@gmail.com>
2172M: Brian Norris <computersforpeace@gmail.com> 2187M: Brian Norris <computersforpeace@gmail.com>
2173M: Gregory Fong <gregory.0xf0@gmail.com> 2188M: Gregory Fong <gregory.0xf0@gmail.com>
2174M: Florian Fainelli <f.fainelli@gmail.com> 2189M: Florian Fainelli <f.fainelli@gmail.com>
@@ -2412,7 +2427,6 @@ L: linux-security-module@vger.kernel.org
2412S: Supported 2427S: Supported
2413F: include/linux/capability.h 2428F: include/linux/capability.h
2414F: include/uapi/linux/capability.h 2429F: include/uapi/linux/capability.h
2415F: security/capability.c
2416F: security/commoncap.c 2430F: security/commoncap.c
2417F: kernel/capability.c 2431F: kernel/capability.c
2418 2432
@@ -3413,6 +3427,13 @@ F: drivers/gpu/drm/rcar-du/
3413F: drivers/gpu/drm/shmobile/ 3427F: drivers/gpu/drm/shmobile/
3414F: include/linux/platform_data/shmob_drm.h 3428F: include/linux/platform_data/shmob_drm.h
3415 3429
3430DRM DRIVERS FOR ROCKCHIP
3431M: Mark Yao <mark.yao@rock-chips.com>
3432L: dri-devel@lists.freedesktop.org
3433S: Maintained
3434F: drivers/gpu/drm/rockchip/
3435F: Documentation/devicetree/bindings/video/rockchip*
3436
3416DSBR100 USB FM RADIO DRIVER 3437DSBR100 USB FM RADIO DRIVER
3417M: Alexey Klimov <klimov.linux@gmail.com> 3438M: Alexey Klimov <klimov.linux@gmail.com>
3418L: linux-media@vger.kernel.org 3439L: linux-media@vger.kernel.org
@@ -3803,10 +3824,11 @@ M: David Woodhouse <dwmw2@infradead.org>
3803L: linux-embedded@vger.kernel.org 3824L: linux-embedded@vger.kernel.org
3804S: Maintained 3825S: Maintained
3805 3826
3806EMULEX LPFC FC SCSI DRIVER 3827EMULEX/AVAGO LPFC FC/FCOE SCSI DRIVER
3807M: James Smart <james.smart@emulex.com> 3828M: James Smart <james.smart@avagotech.com>
3829M: Dick Kennedy <dick.kennedy@avagotech.com>
3808L: linux-scsi@vger.kernel.org 3830L: linux-scsi@vger.kernel.org
3809W: http://sourceforge.net/projects/lpfcxxxx 3831W: http://www.avagotech.com
3810S: Supported 3832S: Supported
3811F: drivers/scsi/lpfc/ 3833F: drivers/scsi/lpfc/
3812 3834
@@ -3905,7 +3927,7 @@ F: drivers/extcon/
3905F: Documentation/extcon/ 3927F: Documentation/extcon/
3906 3928
3907EXYNOS DP DRIVER 3929EXYNOS DP DRIVER
3908M: Jingoo Han <jg1.han@samsung.com> 3930M: Jingoo Han <jingoohan1@gmail.com>
3909L: dri-devel@lists.freedesktop.org 3931L: dri-devel@lists.freedesktop.org
3910S: Maintained 3932S: Maintained
3911F: drivers/gpu/drm/exynos/exynos_dp* 3933F: drivers/gpu/drm/exynos/exynos_dp*
@@ -4364,11 +4386,10 @@ F: fs/gfs2/
4364F: include/uapi/linux/gfs2_ondisk.h 4386F: include/uapi/linux/gfs2_ondisk.h
4365 4387
4366GIGASET ISDN DRIVERS 4388GIGASET ISDN DRIVERS
4367M: Hansjoerg Lipp <hjlipp@web.de> 4389M: Paul Bolle <pebolle@tiscali.nl>
4368M: Tilman Schmidt <tilman@imap.cc>
4369L: gigaset307x-common@lists.sourceforge.net 4390L: gigaset307x-common@lists.sourceforge.net
4370W: http://gigaset307x.sourceforge.net/ 4391W: http://gigaset307x.sourceforge.net/
4371S: Maintained 4392S: Odd Fixes
4372F: Documentation/isdn/README.gigaset 4393F: Documentation/isdn/README.gigaset
4373F: drivers/isdn/gigaset/ 4394F: drivers/isdn/gigaset/
4374F: include/uapi/linux/gigaset_dev.h 4395F: include/uapi/linux/gigaset_dev.h
@@ -4515,7 +4536,7 @@ M: Jean Delvare <jdelvare@suse.de>
4515M: Guenter Roeck <linux@roeck-us.net> 4536M: Guenter Roeck <linux@roeck-us.net>
4516L: lm-sensors@lm-sensors.org 4537L: lm-sensors@lm-sensors.org
4517W: http://www.lm-sensors.org/ 4538W: http://www.lm-sensors.org/
4518T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/ 4539T: quilt http://jdelvare.nerim.net/devel/linux/jdelvare-hwmon/
4519T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git 4540T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
4520S: Maintained 4541S: Maintained
4521F: Documentation/hwmon/ 4542F: Documentation/hwmon/
@@ -5035,17 +5056,19 @@ S: Orphan
5035F: drivers/video/fbdev/imsttfb.c 5056F: drivers/video/fbdev/imsttfb.c
5036 5057
5037INFINIBAND SUBSYSTEM 5058INFINIBAND SUBSYSTEM
5038M: Roland Dreier <roland@kernel.org> 5059M: Doug Ledford <dledford@redhat.com>
5039M: Sean Hefty <sean.hefty@intel.com> 5060M: Sean Hefty <sean.hefty@intel.com>
5040M: Hal Rosenstock <hal.rosenstock@gmail.com> 5061M: Hal Rosenstock <hal.rosenstock@gmail.com>
5041L: linux-rdma@vger.kernel.org 5062L: linux-rdma@vger.kernel.org
5042W: http://www.openfabrics.org/ 5063W: http://www.openfabrics.org/
5043Q: http://patchwork.kernel.org/project/linux-rdma/list/ 5064Q: http://patchwork.kernel.org/project/linux-rdma/list/
5044T: git git://git.kernel.org/pub/scm/linux/kernel/git/roland/infiniband.git 5065T: git git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma.git
5045S: Supported 5066S: Supported
5046F: Documentation/infiniband/ 5067F: Documentation/infiniband/
5047F: drivers/infiniband/ 5068F: drivers/infiniband/
5048F: include/uapi/linux/if_infiniband.h 5069F: include/uapi/linux/if_infiniband.h
5070F: include/uapi/rdma/
5071F: include/rdma/
5049 5072
5050INOTIFY 5073INOTIFY
5051M: John McCutchan <john@johnmccutchan.com> 5074M: John McCutchan <john@johnmccutchan.com>
@@ -5798,6 +5821,7 @@ F: drivers/scsi/53c700*
5798LED SUBSYSTEM 5821LED SUBSYSTEM
5799M: Bryan Wu <cooloney@gmail.com> 5822M: Bryan Wu <cooloney@gmail.com>
5800M: Richard Purdie <rpurdie@rpsys.net> 5823M: Richard Purdie <rpurdie@rpsys.net>
5824M: Jacek Anaszewski <j.anaszewski@samsung.com>
5801L: linux-leds@vger.kernel.org 5825L: linux-leds@vger.kernel.org
5802T: git git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds.git 5826T: git git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds.git
5803S: Maintained 5827S: Maintained
@@ -6943,6 +6967,17 @@ T: git git://git.rocketboards.org/linux-socfpga-next.git
6943S: Maintained 6967S: Maintained
6944F: arch/nios2/ 6968F: arch/nios2/
6945 6969
6970NOKIA N900 POWER SUPPLY DRIVERS
6971M: Pali Rohár <pali.rohar@gmail.com>
6972S: Maintained
6973F: include/linux/power/bq2415x_charger.h
6974F: include/linux/power/bq27x00_battery.h
6975F: include/linux/power/isp1704_charger.h
6976F: drivers/power/bq2415x_charger.c
6977F: drivers/power/bq27x00_battery.c
6978F: drivers/power/isp1704_charger.c
6979F: drivers/power/rx51_battery.c
6980
6946NTB DRIVER 6981NTB DRIVER
6947M: Jon Mason <jdmason@kudzu.us> 6982M: Jon Mason <jdmason@kudzu.us>
6948M: Dave Jiang <dave.jiang@intel.com> 6983M: Dave Jiang <dave.jiang@intel.com>
@@ -7531,7 +7566,7 @@ S: Maintained
7531F: drivers/pci/host/*rcar* 7566F: drivers/pci/host/*rcar*
7532 7567
7533PCI DRIVER FOR SAMSUNG EXYNOS 7568PCI DRIVER FOR SAMSUNG EXYNOS
7534M: Jingoo Han <jg1.han@samsung.com> 7569M: Jingoo Han <jingoohan1@gmail.com>
7535L: linux-pci@vger.kernel.org 7570L: linux-pci@vger.kernel.org
7536L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7571L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
7537L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 7572L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
@@ -7539,7 +7574,7 @@ S: Maintained
7539F: drivers/pci/host/pci-exynos.c 7574F: drivers/pci/host/pci-exynos.c
7540 7575
7541PCI DRIVER FOR SYNOPSIS DESIGNWARE 7576PCI DRIVER FOR SYNOPSIS DESIGNWARE
7542M: Jingoo Han <jg1.han@samsung.com> 7577M: Jingoo Han <jingoohan1@gmail.com>
7543L: linux-pci@vger.kernel.org 7578L: linux-pci@vger.kernel.org
7544S: Maintained 7579S: Maintained
7545F: drivers/pci/host/*designware* 7580F: drivers/pci/host/*designware*
@@ -8495,7 +8530,7 @@ S: Supported
8495F: sound/soc/samsung/ 8530F: sound/soc/samsung/
8496 8531
8497SAMSUNG FRAMEBUFFER DRIVER 8532SAMSUNG FRAMEBUFFER DRIVER
8498M: Jingoo Han <jg1.han@samsung.com> 8533M: Jingoo Han <jingoohan1@gmail.com>
8499L: linux-fbdev@vger.kernel.org 8534L: linux-fbdev@vger.kernel.org
8500S: Maintained 8535S: Maintained
8501F: drivers/video/fbdev/s3c-fb.c 8536F: drivers/video/fbdev/s3c-fb.c
@@ -8794,16 +8829,19 @@ F: drivers/misc/phantom.c
8794F: include/uapi/linux/phantom.h 8829F: include/uapi/linux/phantom.h
8795 8830
8796SERVER ENGINES 10Gbps iSCSI - BladeEngine 2 DRIVER 8831SERVER ENGINES 10Gbps iSCSI - BladeEngine 2 DRIVER
8797M: Jayamohan Kallickal <jayamohan.kallickal@emulex.com> 8832M: Jayamohan Kallickal <jayamohan.kallickal@avagotech.com>
8833M: Minh Tran <minh.tran@avagotech.com>
8834M: John Soni Jose <sony.john-n@avagotech.com>
8798L: linux-scsi@vger.kernel.org 8835L: linux-scsi@vger.kernel.org
8799W: http://www.emulex.com 8836W: http://www.avagotech.com
8800S: Supported 8837S: Supported
8801F: drivers/scsi/be2iscsi/ 8838F: drivers/scsi/be2iscsi/
8802 8839
8803SERVER ENGINES 10Gbps NIC - BladeEngine 2 DRIVER 8840Emulex 10Gbps NIC BE2, BE3-R, Lancer, Skyhawk-R DRIVER
8804M: Sathya Perla <sathya.perla@emulex.com> 8841M: Sathya Perla <sathya.perla@avagotech.com>
8805M: Subbu Seetharaman <subbu.seetharaman@emulex.com> 8842M: Ajit Khaparde <ajit.khaparde@avagotech.com>
8806M: Ajit Khaparde <ajit.khaparde@emulex.com> 8843M: Padmanabh Ratnakar <padmanabh.ratnakar@avagotech.com>
8844M: Sriharsha Basavapatna <sriharsha.basavapatna@avagotech.com>
8807L: netdev@vger.kernel.org 8845L: netdev@vger.kernel.org
8808W: http://www.emulex.com 8846W: http://www.emulex.com
8809S: Supported 8847S: Supported
@@ -10523,7 +10561,6 @@ F: include/linux/virtio_console.h
10523F: include/uapi/linux/virtio_console.h 10561F: include/uapi/linux/virtio_console.h
10524 10562
10525VIRTIO CORE, NET AND BLOCK DRIVERS 10563VIRTIO CORE, NET AND BLOCK DRIVERS
10526M: Rusty Russell <rusty@rustcorp.com.au>
10527M: "Michael S. Tsirkin" <mst@redhat.com> 10564M: "Michael S. Tsirkin" <mst@redhat.com>
10528L: virtualization@lists.linux-foundation.org 10565L: virtualization@lists.linux-foundation.org
10529S: Maintained 10566S: Maintained
@@ -11031,6 +11068,7 @@ F: drivers/media/pci/zoran/
11031ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER 11068ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER
11032M: Minchan Kim <minchan@kernel.org> 11069M: Minchan Kim <minchan@kernel.org>
11033M: Nitin Gupta <ngupta@vflare.org> 11070M: Nitin Gupta <ngupta@vflare.org>
11071R: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
11034L: linux-kernel@vger.kernel.org 11072L: linux-kernel@vger.kernel.org
11035S: Maintained 11073S: Maintained
11036F: drivers/block/zram/ 11074F: drivers/block/zram/
diff --git a/Makefile b/Makefile
index 7ff1239f9cd2..aee7e5cb4c15 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 4 1VERSION = 4
2PATCHLEVEL = 1 2PATCHLEVEL = 1
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc1 4EXTRAVERSION = -rc6
5NAME = Hurr durr I'ma sheep 5NAME = Hurr durr I'ma sheep
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/alpha/boot/Makefile b/arch/alpha/boot/Makefile
index cd143887380a..8399bd0e68e8 100644
--- a/arch/alpha/boot/Makefile
+++ b/arch/alpha/boot/Makefile
@@ -14,6 +14,9 @@ targets := vmlinux.gz vmlinux \
14 tools/bootpzh bootloader bootpheader bootpzheader 14 tools/bootpzh bootloader bootpheader bootpzheader
15OBJSTRIP := $(obj)/tools/objstrip 15OBJSTRIP := $(obj)/tools/objstrip
16 16
17HOSTCFLAGS := -Wall -I$(objtree)/usr/include
18BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
19
17# SRM bootable image. Copy to offset 512 of a partition. 20# SRM bootable image. Copy to offset 512 of a partition.
18$(obj)/bootimage: $(addprefix $(obj)/tools/,mkbb lxboot bootlx) $(obj)/vmlinux.nh 21$(obj)/bootimage: $(addprefix $(obj)/tools/,mkbb lxboot bootlx) $(obj)/vmlinux.nh
19 ( cat $(obj)/tools/lxboot $(obj)/tools/bootlx $(obj)/vmlinux.nh ) > $@ 22 ( cat $(obj)/tools/lxboot $(obj)/tools/bootlx $(obj)/vmlinux.nh ) > $@
@@ -96,13 +99,14 @@ $(obj)/tools/bootph: $(obj)/bootpheader $(OBJSTRIP) FORCE
96$(obj)/tools/bootpzh: $(obj)/bootpzheader $(OBJSTRIP) FORCE 99$(obj)/tools/bootpzh: $(obj)/bootpzheader $(OBJSTRIP) FORCE
97 $(call if_changed,objstrip) 100 $(call if_changed,objstrip)
98 101
99LDFLAGS_bootloader := -static -uvsprintf -T #-N -relax 102LDFLAGS_bootloader := -static -T # -N -relax
100LDFLAGS_bootpheader := -static -uvsprintf -T #-N -relax 103LDFLAGS_bootloader := -static -T # -N -relax
101LDFLAGS_bootpzheader := -static -uvsprintf -T #-N -relax 104LDFLAGS_bootpheader := -static -T # -N -relax
105LDFLAGS_bootpzheader := -static -T # -N -relax
102 106
103OBJ_bootlx := $(obj)/head.o $(obj)/main.o 107OBJ_bootlx := $(obj)/head.o $(obj)/stdio.o $(obj)/main.o
104OBJ_bootph := $(obj)/head.o $(obj)/bootp.o 108OBJ_bootph := $(obj)/head.o $(obj)/stdio.o $(obj)/bootp.o
105OBJ_bootpzh := $(obj)/head.o $(obj)/bootpz.o $(obj)/misc.o 109OBJ_bootpzh := $(obj)/head.o $(obj)/stdio.o $(obj)/bootpz.o $(obj)/misc.o
106 110
107$(obj)/bootloader: $(obj)/bootloader.lds $(OBJ_bootlx) $(LIBS_Y) FORCE 111$(obj)/bootloader: $(obj)/bootloader.lds $(OBJ_bootlx) $(LIBS_Y) FORCE
108 $(call if_changed,ld) 112 $(call if_changed,ld)
diff --git a/arch/alpha/boot/main.c b/arch/alpha/boot/main.c
index 3baf2d1e908d..dd6eb4a33582 100644
--- a/arch/alpha/boot/main.c
+++ b/arch/alpha/boot/main.c
@@ -19,7 +19,6 @@
19 19
20#include "ksize.h" 20#include "ksize.h"
21 21
22extern int vsprintf(char *, const char *, va_list);
23extern unsigned long switch_to_osf_pal(unsigned long nr, 22extern unsigned long switch_to_osf_pal(unsigned long nr,
24 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa, 23 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
25 unsigned long *vptb); 24 unsigned long *vptb);
diff --git a/arch/alpha/boot/stdio.c b/arch/alpha/boot/stdio.c
new file mode 100644
index 000000000000..f844dae8a54a
--- /dev/null
+++ b/arch/alpha/boot/stdio.c
@@ -0,0 +1,306 @@
1/*
2 * Copyright (C) Paul Mackerras 1997.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9#include <stdarg.h>
10#include <stddef.h>
11
12size_t strnlen(const char * s, size_t count)
13{
14 const char *sc;
15
16 for (sc = s; count-- && *sc != '\0'; ++sc)
17 /* nothing */;
18 return sc - s;
19}
20
21# define do_div(n, base) ({ \
22 unsigned int __base = (base); \
23 unsigned int __rem; \
24 __rem = ((unsigned long long)(n)) % __base; \
25 (n) = ((unsigned long long)(n)) / __base; \
26 __rem; \
27})
28
29
30static int skip_atoi(const char **s)
31{
32 int i, c;
33
34 for (i = 0; '0' <= (c = **s) && c <= '9'; ++*s)
35 i = i*10 + c - '0';
36 return i;
37}
38
39#define ZEROPAD 1 /* pad with zero */
40#define SIGN 2 /* unsigned/signed long */
41#define PLUS 4 /* show plus */
42#define SPACE 8 /* space if plus */
43#define LEFT 16 /* left justified */
44#define SPECIAL 32 /* 0x */
45#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
46
47static char * number(char * str, unsigned long long num, int base, int size, int precision, int type)
48{
49 char c,sign,tmp[66];
50 const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
51 int i;
52
53 if (type & LARGE)
54 digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
55 if (type & LEFT)
56 type &= ~ZEROPAD;
57 if (base < 2 || base > 36)
58 return 0;
59 c = (type & ZEROPAD) ? '0' : ' ';
60 sign = 0;
61 if (type & SIGN) {
62 if ((signed long long)num < 0) {
63 sign = '-';
64 num = - (signed long long)num;
65 size--;
66 } else if (type & PLUS) {
67 sign = '+';
68 size--;
69 } else if (type & SPACE) {
70 sign = ' ';
71 size--;
72 }
73 }
74 if (type & SPECIAL) {
75 if (base == 16)
76 size -= 2;
77 else if (base == 8)
78 size--;
79 }
80 i = 0;
81 if (num == 0)
82 tmp[i++]='0';
83 else while (num != 0) {
84 tmp[i++] = digits[do_div(num, base)];
85 }
86 if (i > precision)
87 precision = i;
88 size -= precision;
89 if (!(type&(ZEROPAD+LEFT)))
90 while(size-->0)
91 *str++ = ' ';
92 if (sign)
93 *str++ = sign;
94 if (type & SPECIAL) {
95 if (base==8)
96 *str++ = '0';
97 else if (base==16) {
98 *str++ = '0';
99 *str++ = digits[33];
100 }
101 }
102 if (!(type & LEFT))
103 while (size-- > 0)
104 *str++ = c;
105 while (i < precision--)
106 *str++ = '0';
107 while (i-- > 0)
108 *str++ = tmp[i];
109 while (size-- > 0)
110 *str++ = ' ';
111 return str;
112}
113
114int vsprintf(char *buf, const char *fmt, va_list args)
115{
116 int len;
117 unsigned long long num;
118 int i, base;
119 char * str;
120 const char *s;
121
122 int flags; /* flags to number() */
123
124 int field_width; /* width of output field */
125 int precision; /* min. # of digits for integers; max
126 number of chars for from string */
127 int qualifier; /* 'h', 'l', or 'L' for integer fields */
128 /* 'z' support added 23/7/1999 S.H. */
129 /* 'z' changed to 'Z' --davidm 1/25/99 */
130
131
132 for (str=buf ; *fmt ; ++fmt) {
133 if (*fmt != '%') {
134 *str++ = *fmt;
135 continue;
136 }
137
138 /* process flags */
139 flags = 0;
140 repeat:
141 ++fmt; /* this also skips first '%' */
142 switch (*fmt) {
143 case '-': flags |= LEFT; goto repeat;
144 case '+': flags |= PLUS; goto repeat;
145 case ' ': flags |= SPACE; goto repeat;
146 case '#': flags |= SPECIAL; goto repeat;
147 case '0': flags |= ZEROPAD; goto repeat;
148 }
149
150 /* get field width */
151 field_width = -1;
152 if ('0' <= *fmt && *fmt <= '9')
153 field_width = skip_atoi(&fmt);
154 else if (*fmt == '*') {
155 ++fmt;
156 /* it's the next argument */
157 field_width = va_arg(args, int);
158 if (field_width < 0) {
159 field_width = -field_width;
160 flags |= LEFT;
161 }
162 }
163
164 /* get the precision */
165 precision = -1;
166 if (*fmt == '.') {
167 ++fmt;
168 if ('0' <= *fmt && *fmt <= '9')
169 precision = skip_atoi(&fmt);
170 else if (*fmt == '*') {
171 ++fmt;
172 /* it's the next argument */
173 precision = va_arg(args, int);
174 }
175 if (precision < 0)
176 precision = 0;
177 }
178
179 /* get the conversion qualifier */
180 qualifier = -1;
181 if (*fmt == 'l' && *(fmt + 1) == 'l') {
182 qualifier = 'q';
183 fmt += 2;
184 } else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L'
185 || *fmt == 'Z') {
186 qualifier = *fmt;
187 ++fmt;
188 }
189
190 /* default base */
191 base = 10;
192
193 switch (*fmt) {
194 case 'c':
195 if (!(flags & LEFT))
196 while (--field_width > 0)
197 *str++ = ' ';
198 *str++ = (unsigned char) va_arg(args, int);
199 while (--field_width > 0)
200 *str++ = ' ';
201 continue;
202
203 case 's':
204 s = va_arg(args, char *);
205 if (!s)
206 s = "<NULL>";
207
208 len = strnlen(s, precision);
209
210 if (!(flags & LEFT))
211 while (len < field_width--)
212 *str++ = ' ';
213 for (i = 0; i < len; ++i)
214 *str++ = *s++;
215 while (len < field_width--)
216 *str++ = ' ';
217 continue;
218
219 case 'p':
220 if (field_width == -1) {
221 field_width = 2*sizeof(void *);
222 flags |= ZEROPAD;
223 }
224 str = number(str,
225 (unsigned long) va_arg(args, void *), 16,
226 field_width, precision, flags);
227 continue;
228
229
230 case 'n':
231 if (qualifier == 'l') {
232 long * ip = va_arg(args, long *);
233 *ip = (str - buf);
234 } else if (qualifier == 'Z') {
235 size_t * ip = va_arg(args, size_t *);
236 *ip = (str - buf);
237 } else {
238 int * ip = va_arg(args, int *);
239 *ip = (str - buf);
240 }
241 continue;
242
243 case '%':
244 *str++ = '%';
245 continue;
246
247 /* integer number formats - set up the flags and "break" */
248 case 'o':
249 base = 8;
250 break;
251
252 case 'X':
253 flags |= LARGE;
254 case 'x':
255 base = 16;
256 break;
257
258 case 'd':
259 case 'i':
260 flags |= SIGN;
261 case 'u':
262 break;
263
264 default:
265 *str++ = '%';
266 if (*fmt)
267 *str++ = *fmt;
268 else
269 --fmt;
270 continue;
271 }
272 if (qualifier == 'l') {
273 num = va_arg(args, unsigned long);
274 if (flags & SIGN)
275 num = (signed long) num;
276 } else if (qualifier == 'q') {
277 num = va_arg(args, unsigned long long);
278 if (flags & SIGN)
279 num = (signed long long) num;
280 } else if (qualifier == 'Z') {
281 num = va_arg(args, size_t);
282 } else if (qualifier == 'h') {
283 num = (unsigned short) va_arg(args, int);
284 if (flags & SIGN)
285 num = (signed short) num;
286 } else {
287 num = va_arg(args, unsigned int);
288 if (flags & SIGN)
289 num = (signed int) num;
290 }
291 str = number(str, num, base, field_width, precision, flags);
292 }
293 *str = '\0';
294 return str-buf;
295}
296
297int sprintf(char * buf, const char *fmt, ...)
298{
299 va_list args;
300 int i;
301
302 va_start(args, fmt);
303 i=vsprintf(buf,fmt,args);
304 va_end(args);
305 return i;
306}
diff --git a/arch/alpha/boot/tools/objstrip.c b/arch/alpha/boot/tools/objstrip.c
index 367d53d031fc..dee82695f48b 100644
--- a/arch/alpha/boot/tools/objstrip.c
+++ b/arch/alpha/boot/tools/objstrip.c
@@ -27,6 +27,9 @@
27#include <linux/param.h> 27#include <linux/param.h>
28#ifdef __ELF__ 28#ifdef __ELF__
29# include <linux/elf.h> 29# include <linux/elf.h>
30# define elfhdr elf64_hdr
31# define elf_phdr elf64_phdr
32# define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)
30#endif 33#endif
31 34
32/* bootfile size must be multiple of BLOCK_SIZE: */ 35/* bootfile size must be multiple of BLOCK_SIZE: */
diff --git a/arch/alpha/include/asm/types.h b/arch/alpha/include/asm/types.h
index f61e1a56c378..4cb4b6d3452c 100644
--- a/arch/alpha/include/asm/types.h
+++ b/arch/alpha/include/asm/types.h
@@ -2,6 +2,5 @@
2#define _ALPHA_TYPES_H 2#define _ALPHA_TYPES_H
3 3
4#include <asm-generic/int-ll64.h> 4#include <asm-generic/int-ll64.h>
5#include <uapi/asm/types.h>
6 5
7#endif /* _ALPHA_TYPES_H */ 6#endif /* _ALPHA_TYPES_H */
diff --git a/arch/alpha/include/asm/unistd.h b/arch/alpha/include/asm/unistd.h
index c509d306db45..a56e608db2f9 100644
--- a/arch/alpha/include/asm/unistd.h
+++ b/arch/alpha/include/asm/unistd.h
@@ -3,7 +3,7 @@
3 3
4#include <uapi/asm/unistd.h> 4#include <uapi/asm/unistd.h>
5 5
6#define NR_SYSCALLS 511 6#define NR_SYSCALLS 514
7 7
8#define __ARCH_WANT_OLD_READDIR 8#define __ARCH_WANT_OLD_READDIR
9#define __ARCH_WANT_STAT64 9#define __ARCH_WANT_STAT64
diff --git a/arch/alpha/include/uapi/asm/unistd.h b/arch/alpha/include/uapi/asm/unistd.h
index d214a0358100..aa33bf5aacb6 100644
--- a/arch/alpha/include/uapi/asm/unistd.h
+++ b/arch/alpha/include/uapi/asm/unistd.h
@@ -472,5 +472,8 @@
472#define __NR_sched_setattr 508 472#define __NR_sched_setattr 508
473#define __NR_sched_getattr 509 473#define __NR_sched_getattr 509
474#define __NR_renameat2 510 474#define __NR_renameat2 510
475#define __NR_getrandom 511
476#define __NR_memfd_create 512
477#define __NR_execveat 513
475 478
476#endif /* _UAPI_ALPHA_UNISTD_H */ 479#endif /* _UAPI_ALPHA_UNISTD_H */
diff --git a/arch/alpha/kernel/err_ev6.c b/arch/alpha/kernel/err_ev6.c
index 253cf1a87481..51267ac5729b 100644
--- a/arch/alpha/kernel/err_ev6.c
+++ b/arch/alpha/kernel/err_ev6.c
@@ -6,7 +6,6 @@
6 * Error handling code supporting Alpha systems 6 * Error handling code supporting Alpha systems
7 */ 7 */
8 8
9#include <linux/init.h>
10#include <linux/sched.h> 9#include <linux/sched.h>
11 10
12#include <asm/io.h> 11#include <asm/io.h>
diff --git a/arch/alpha/kernel/irq.c b/arch/alpha/kernel/irq.c
index 7b2be251c30f..51f2c8654253 100644
--- a/arch/alpha/kernel/irq.c
+++ b/arch/alpha/kernel/irq.c
@@ -19,7 +19,6 @@
19#include <linux/ptrace.h> 19#include <linux/ptrace.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/random.h> 21#include <linux/random.h>
22#include <linux/init.h>
23#include <linux/irq.h> 22#include <linux/irq.h>
24#include <linux/proc_fs.h> 23#include <linux/proc_fs.h>
25#include <linux/seq_file.h> 24#include <linux/seq_file.h>
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index e51f578636a5..36dc91ace83a 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1019,14 +1019,13 @@ SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
1019 if (tv) { 1019 if (tv) {
1020 if (get_tv32((struct timeval *)&kts, tv)) 1020 if (get_tv32((struct timeval *)&kts, tv))
1021 return -EFAULT; 1021 return -EFAULT;
1022 kts.tv_nsec *= 1000;
1022 } 1023 }
1023 if (tz) { 1024 if (tz) {
1024 if (copy_from_user(&ktz, tz, sizeof(*tz))) 1025 if (copy_from_user(&ktz, tz, sizeof(*tz)))
1025 return -EFAULT; 1026 return -EFAULT;
1026 } 1027 }
1027 1028
1028 kts.tv_nsec *= 1000;
1029
1030 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); 1029 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
1031} 1030}
1032 1031
diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c
index 1941a07b5811..84d13263ce46 100644
--- a/arch/alpha/kernel/process.c
+++ b/arch/alpha/kernel/process.c
@@ -236,12 +236,11 @@ release_thread(struct task_struct *dead_task)
236} 236}
237 237
238/* 238/*
239 * Copy an alpha thread.. 239 * Copy architecture-specific thread state
240 */ 240 */
241
242int 241int
243copy_thread(unsigned long clone_flags, unsigned long usp, 242copy_thread(unsigned long clone_flags, unsigned long usp,
244 unsigned long arg, 243 unsigned long kthread_arg,
245 struct task_struct *p) 244 struct task_struct *p)
246{ 245{
247 extern void ret_from_fork(void); 246 extern void ret_from_fork(void);
@@ -262,7 +261,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
262 sizeof(struct switch_stack) + sizeof(struct pt_regs)); 261 sizeof(struct switch_stack) + sizeof(struct pt_regs));
263 childstack->r26 = (unsigned long) ret_from_kernel_thread; 262 childstack->r26 = (unsigned long) ret_from_kernel_thread;
264 childstack->r9 = usp; /* function */ 263 childstack->r9 = usp; /* function */
265 childstack->r10 = arg; 264 childstack->r10 = kthread_arg;
266 childregs->hae = alpha_mv.hae_cache, 265 childregs->hae = alpha_mv.hae_cache,
267 childti->pcb.usp = 0; 266 childti->pcb.usp = 0;
268 return 0; 267 return 0;
diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index 99ac36d5de4e..2f24447fef92 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -63,7 +63,6 @@ static struct {
63enum ipi_message_type { 63enum ipi_message_type {
64 IPI_RESCHEDULE, 64 IPI_RESCHEDULE,
65 IPI_CALL_FUNC, 65 IPI_CALL_FUNC,
66 IPI_CALL_FUNC_SINGLE,
67 IPI_CPU_STOP, 66 IPI_CPU_STOP,
68}; 67};
69 68
@@ -506,7 +505,6 @@ setup_profiling_timer(unsigned int multiplier)
506 return -EINVAL; 505 return -EINVAL;
507} 506}
508 507
509
510static void 508static void
511send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation) 509send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
512{ 510{
@@ -552,10 +550,6 @@ handle_ipi(struct pt_regs *regs)
552 generic_smp_call_function_interrupt(); 550 generic_smp_call_function_interrupt();
553 break; 551 break;
554 552
555 case IPI_CALL_FUNC_SINGLE:
556 generic_smp_call_function_single_interrupt();
557 break;
558
559 case IPI_CPU_STOP: 553 case IPI_CPU_STOP:
560 halt(); 554 halt();
561 555
@@ -606,7 +600,7 @@ void arch_send_call_function_ipi_mask(const struct cpumask *mask)
606 600
607void arch_send_call_function_single_ipi(int cpu) 601void arch_send_call_function_single_ipi(int cpu)
608{ 602{
609 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE); 603 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
610} 604}
611 605
612static void 606static void
diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index 6f01d9ad7b81..72b59511e59a 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -237,8 +237,7 @@ srmcons_init(void)
237 237
238 return -ENODEV; 238 return -ENODEV;
239} 239}
240 240device_initcall(srmcons_init);
241module_init(srmcons_init);
242 241
243 242
244/* 243/*
diff --git a/arch/alpha/kernel/sys_marvel.c b/arch/alpha/kernel/sys_marvel.c
index f21d61fab678..24e41bd7d3c9 100644
--- a/arch/alpha/kernel/sys_marvel.c
+++ b/arch/alpha/kernel/sys_marvel.c
@@ -331,7 +331,7 @@ marvel_map_irq(const struct pci_dev *cdev, u8 slot, u8 pin)
331 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline); 331 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
332 irq = intline; 332 irq = intline;
333 333
334 msi_loc = pci_find_capability(dev, PCI_CAP_ID_MSI); 334 msi_loc = dev->msi_cap;
335 msg_ctl = 0; 335 msg_ctl = 0;
336 if (msi_loc) 336 if (msi_loc)
337 pci_read_config_word(dev, msi_loc + PCI_MSI_FLAGS, &msg_ctl); 337 pci_read_config_word(dev, msi_loc + PCI_MSI_FLAGS, &msg_ctl);
diff --git a/arch/alpha/kernel/systbls.S b/arch/alpha/kernel/systbls.S
index 24789713f1ea..9b62e3fd4f03 100644
--- a/arch/alpha/kernel/systbls.S
+++ b/arch/alpha/kernel/systbls.S
@@ -529,6 +529,9 @@ sys_call_table:
529 .quad sys_sched_setattr 529 .quad sys_sched_setattr
530 .quad sys_sched_getattr 530 .quad sys_sched_getattr
531 .quad sys_renameat2 /* 510 */ 531 .quad sys_renameat2 /* 510 */
532 .quad sys_getrandom
533 .quad sys_memfd_create
534 .quad sys_execveat
532 535
533 .size sys_call_table, . - sys_call_table 536 .size sys_call_table, . - sys_call_table
534 .type sys_call_table, @object 537 .type sys_call_table, @object
diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 9c4c189eb22f..74aceead06e9 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -14,7 +14,6 @@
14#include <linux/tty.h> 14#include <linux/tty.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/kallsyms.h> 17#include <linux/kallsyms.h>
19#include <linux/ratelimit.h> 18#include <linux/ratelimit.h>
20 19
diff --git a/arch/alpha/oprofile/op_model_ev4.c b/arch/alpha/oprofile/op_model_ev4.c
index 18aa9b4f94f1..086a0d5445c5 100644
--- a/arch/alpha/oprofile/op_model_ev4.c
+++ b/arch/alpha/oprofile/op_model_ev4.c
@@ -8,7 +8,6 @@
8 */ 8 */
9 9
10#include <linux/oprofile.h> 10#include <linux/oprofile.h>
11#include <linux/init.h>
12#include <linux/smp.h> 11#include <linux/smp.h>
13#include <asm/ptrace.h> 12#include <asm/ptrace.h>
14 13
diff --git a/arch/alpha/oprofile/op_model_ev5.c b/arch/alpha/oprofile/op_model_ev5.c
index c32f8a0ad925..c300f5ef3482 100644
--- a/arch/alpha/oprofile/op_model_ev5.c
+++ b/arch/alpha/oprofile/op_model_ev5.c
@@ -8,7 +8,6 @@
8 */ 8 */
9 9
10#include <linux/oprofile.h> 10#include <linux/oprofile.h>
11#include <linux/init.h>
12#include <linux/smp.h> 11#include <linux/smp.h>
13#include <asm/ptrace.h> 12#include <asm/ptrace.h>
14 13
diff --git a/arch/alpha/oprofile/op_model_ev6.c b/arch/alpha/oprofile/op_model_ev6.c
index 1c84cc257fc7..02edf5971614 100644
--- a/arch/alpha/oprofile/op_model_ev6.c
+++ b/arch/alpha/oprofile/op_model_ev6.c
@@ -8,7 +8,6 @@
8 */ 8 */
9 9
10#include <linux/oprofile.h> 10#include <linux/oprofile.h>
11#include <linux/init.h>
12#include <linux/smp.h> 11#include <linux/smp.h>
13#include <asm/ptrace.h> 12#include <asm/ptrace.h>
14 13
diff --git a/arch/alpha/oprofile/op_model_ev67.c b/arch/alpha/oprofile/op_model_ev67.c
index 34a57a126553..adb1744d20f3 100644
--- a/arch/alpha/oprofile/op_model_ev67.c
+++ b/arch/alpha/oprofile/op_model_ev67.c
@@ -9,7 +9,6 @@
9 */ 9 */
10 10
11#include <linux/oprofile.h> 11#include <linux/oprofile.h>
12#include <linux/init.h>
13#include <linux/smp.h> 12#include <linux/smp.h>
14#include <asm/ptrace.h> 13#include <asm/ptrace.h>
15 14
diff --git a/arch/arc/Kconfig.debug b/arch/arc/Kconfig.debug
index a7fc0da25650..ff6a4b5ce927 100644
--- a/arch/arc/Kconfig.debug
+++ b/arch/arc/Kconfig.debug
@@ -2,19 +2,6 @@ menu "Kernel hacking"
2 2
3source "lib/Kconfig.debug" 3source "lib/Kconfig.debug"
4 4
5config EARLY_PRINTK
6 bool "Early printk" if EMBEDDED
7 default y
8 help
9 Write kernel log output directly into the VGA buffer or to a serial
10 port.
11
12 This is useful for kernel debugging when your machine crashes very
13 early before the console code is initialized. For normal operation
14 it is not recommended because it looks ugly and doesn't cooperate
15 with klogd/syslogd or the X server. You should normally N here,
16 unless you want to debug such a crash.
17
18config 16KSTACKS 5config 16KSTACKS
19 bool "Use 16Kb for kernel stacks instead of 8Kb" 6 bool "Use 16Kb for kernel stacks instead of 8Kb"
20 help 7 help
diff --git a/arch/arc/include/asm/atomic.h b/arch/arc/include/asm/atomic.h
index 067551b6920a..9917a45fc430 100644
--- a/arch/arc/include/asm/atomic.h
+++ b/arch/arc/include/asm/atomic.h
@@ -99,7 +99,7 @@ static inline void atomic_##op(int i, atomic_t *v) \
99 atomic_ops_unlock(flags); \ 99 atomic_ops_unlock(flags); \
100} 100}
101 101
102#define ATOMIC_OP_RETURN(op, c_op) \ 102#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
103static inline int atomic_##op##_return(int i, atomic_t *v) \ 103static inline int atomic_##op##_return(int i, atomic_t *v) \
104{ \ 104{ \
105 unsigned long flags; \ 105 unsigned long flags; \
diff --git a/arch/arc/mm/cache_arc700.c b/arch/arc/mm/cache_arc700.c
index 8c3a3e02ba92..12b2100db073 100644
--- a/arch/arc/mm/cache_arc700.c
+++ b/arch/arc/mm/cache_arc700.c
@@ -266,7 +266,7 @@ static inline void __cache_line_loop(unsigned long paddr, unsigned long vaddr,
266 * Machine specific helpers for Entire D-Cache or Per Line ops 266 * Machine specific helpers for Entire D-Cache or Per Line ops
267 */ 267 */
268 268
269static unsigned int __before_dc_op(const int op) 269static inline unsigned int __before_dc_op(const int op)
270{ 270{
271 unsigned int reg = reg; 271 unsigned int reg = reg;
272 272
@@ -284,7 +284,7 @@ static unsigned int __before_dc_op(const int op)
284 return reg; 284 return reg;
285} 285}
286 286
287static void __after_dc_op(const int op, unsigned int reg) 287static inline void __after_dc_op(const int op, unsigned int reg)
288{ 288{
289 if (op & OP_FLUSH) /* flush / flush-n-inv both wait */ 289 if (op & OP_FLUSH) /* flush / flush-n-inv both wait */
290 while (read_aux_reg(ARC_REG_DC_CTRL) & DC_CTRL_FLUSH_STATUS); 290 while (read_aux_reg(ARC_REG_DC_CTRL) & DC_CTRL_FLUSH_STATUS);
diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 86217db2937a..992736b5229b 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -223,7 +223,7 @@ dtb-$(CONFIG_SOC_IMX25) += \
223 imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dtb \ 223 imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dtb \
224 imx25-karo-tx25.dtb \ 224 imx25-karo-tx25.dtb \
225 imx25-pdk.dtb 225 imx25-pdk.dtb
226dtb-$(CONFIG_SOC_IMX31) += \ 226dtb-$(CONFIG_SOC_IMX27) += \
227 imx27-apf27.dtb \ 227 imx27-apf27.dtb \
228 imx27-apf27dev.dtb \ 228 imx27-apf27dev.dtb \
229 imx27-eukrea-mbimxsd27-baseboard.dtb \ 229 imx27-eukrea-mbimxsd27-baseboard.dtb \
diff --git a/arch/arm/boot/dts/am335x-boneblack.dts b/arch/arm/boot/dts/am335x-boneblack.dts
index 5c42d259fa68..901739fcb85a 100644
--- a/arch/arm/boot/dts/am335x-boneblack.dts
+++ b/arch/arm/boot/dts/am335x-boneblack.dts
@@ -80,7 +80,3 @@
80 status = "okay"; 80 status = "okay";
81 }; 81 };
82}; 82};
83
84&rtc {
85 system-power-controller;
86};
diff --git a/arch/arm/boot/dts/am335x-evmsk.dts b/arch/arm/boot/dts/am335x-evmsk.dts
index 87fc7a35e802..156d05efcb70 100644
--- a/arch/arm/boot/dts/am335x-evmsk.dts
+++ b/arch/arm/boot/dts/am335x-evmsk.dts
@@ -654,7 +654,7 @@
654 wlcore: wlcore@2 { 654 wlcore: wlcore@2 {
655 compatible = "ti,wl1271"; 655 compatible = "ti,wl1271";
656 reg = <2>; 656 reg = <2>;
657 interrupt-parent = <&gpio1>; 657 interrupt-parent = <&gpio0>;
658 interrupts = <31 IRQ_TYPE_LEVEL_HIGH>; /* gpio 31 */ 658 interrupts = <31 IRQ_TYPE_LEVEL_HIGH>; /* gpio 31 */
659 ref-clock-frequency = <38400000>; 659 ref-clock-frequency = <38400000>;
660 }; 660 };
diff --git a/arch/arm/boot/dts/am437x-sk-evm.dts b/arch/arm/boot/dts/am437x-sk-evm.dts
index 8ae29c955c11..c17097d2c167 100644
--- a/arch/arm/boot/dts/am437x-sk-evm.dts
+++ b/arch/arm/boot/dts/am437x-sk-evm.dts
@@ -49,7 +49,7 @@
49 pinctrl-0 = <&matrix_keypad_pins>; 49 pinctrl-0 = <&matrix_keypad_pins>;
50 50
51 debounce-delay-ms = <5>; 51 debounce-delay-ms = <5>;
52 col-scan-delay-us = <1500>; 52 col-scan-delay-us = <5>;
53 53
54 row-gpios = <&gpio5 5 GPIO_ACTIVE_HIGH /* Bank5, pin5 */ 54 row-gpios = <&gpio5 5 GPIO_ACTIVE_HIGH /* Bank5, pin5 */
55 &gpio5 6 GPIO_ACTIVE_HIGH>; /* Bank5, pin6 */ 55 &gpio5 6 GPIO_ACTIVE_HIGH>; /* Bank5, pin6 */
@@ -473,7 +473,7 @@
473 interrupt-parent = <&gpio0>; 473 interrupt-parent = <&gpio0>;
474 interrupts = <31 0>; 474 interrupts = <31 0>;
475 475
476 wake-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>; 476 reset-gpios = <&gpio1 28 GPIO_ACTIVE_LOW>;
477 477
478 touchscreen-size-x = <480>; 478 touchscreen-size-x = <480>;
479 touchscreen-size-y = <272>; 479 touchscreen-size-y = <272>;
diff --git a/arch/arm/boot/dts/am57xx-beagle-x15.dts b/arch/arm/boot/dts/am57xx-beagle-x15.dts
index 15f198e4864d..7128fad991ac 100644
--- a/arch/arm/boot/dts/am57xx-beagle-x15.dts
+++ b/arch/arm/boot/dts/am57xx-beagle-x15.dts
@@ -18,6 +18,7 @@
18 aliases { 18 aliases {
19 rtc0 = &mcp_rtc; 19 rtc0 = &mcp_rtc;
20 rtc1 = &tps659038_rtc; 20 rtc1 = &tps659038_rtc;
21 rtc2 = &rtc;
21 }; 22 };
22 23
23 memory { 24 memory {
@@ -83,7 +84,7 @@
83 gpio_fan: gpio_fan { 84 gpio_fan: gpio_fan {
84 /* Based on 5v 500mA AFB02505HHB */ 85 /* Based on 5v 500mA AFB02505HHB */
85 compatible = "gpio-fan"; 86 compatible = "gpio-fan";
86 gpios = <&tps659038_gpio 1 GPIO_ACTIVE_HIGH>; 87 gpios = <&tps659038_gpio 2 GPIO_ACTIVE_HIGH>;
87 gpio-fan,speed-map = <0 0>, 88 gpio-fan,speed-map = <0 0>,
88 <13000 1>; 89 <13000 1>;
89 #cooling-cells = <2>; 90 #cooling-cells = <2>;
@@ -130,8 +131,8 @@
130 131
131 uart3_pins_default: uart3_pins_default { 132 uart3_pins_default: uart3_pins_default {
132 pinctrl-single,pins = < 133 pinctrl-single,pins = <
133 0x248 (PIN_INPUT_SLEW | MUX_MODE0) /* uart3_rxd.rxd */ 134 0x3f8 (PIN_INPUT_SLEW | MUX_MODE2) /* uart2_ctsn.uart3_rxd */
134 0x24c (PIN_INPUT_SLEW | MUX_MODE0) /* uart3_txd.txd */ 135 0x3fc (PIN_INPUT_SLEW | MUX_MODE1) /* uart2_rtsn.uart3_txd */
135 >; 136 >;
136 }; 137 };
137 138
@@ -455,7 +456,7 @@
455 mcp_rtc: rtc@6f { 456 mcp_rtc: rtc@6f {
456 compatible = "microchip,mcp7941x"; 457 compatible = "microchip,mcp7941x";
457 reg = <0x6f>; 458 reg = <0x6f>;
458 interrupts = <GIC_SPI 2 IRQ_TYPE_LEVEL_LOW>; /* IRQ_SYS_1N */ 459 interrupts = <GIC_SPI 2 IRQ_TYPE_EDGE_RISING>; /* IRQ_SYS_1N */
459 460
460 pinctrl-names = "default"; 461 pinctrl-names = "default";
461 pinctrl-0 = <&mcp79410_pins_default>; 462 pinctrl-0 = <&mcp79410_pins_default>;
@@ -478,7 +479,7 @@
478&uart3 { 479&uart3 {
479 status = "okay"; 480 status = "okay";
480 interrupts-extended = <&crossbar_mpu GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>, 481 interrupts-extended = <&crossbar_mpu GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>,
481 <&dra7_pmx_core 0x248>; 482 <&dra7_pmx_core 0x3f8>;
482 483
483 pinctrl-names = "default"; 484 pinctrl-names = "default";
484 pinctrl-0 = <&uart3_pins_default>; 485 pinctrl-0 = <&uart3_pins_default>;
diff --git a/arch/arm/boot/dts/armada-375.dtsi b/arch/arm/boot/dts/armada-375.dtsi
index c675257f2377..f076ff856d8b 100644
--- a/arch/arm/boot/dts/armada-375.dtsi
+++ b/arch/arm/boot/dts/armada-375.dtsi
@@ -69,7 +69,7 @@
69 mainpll: mainpll { 69 mainpll: mainpll {
70 compatible = "fixed-clock"; 70 compatible = "fixed-clock";
71 #clock-cells = <0>; 71 #clock-cells = <0>;
72 clock-frequency = <2000000000>; 72 clock-frequency = <1000000000>;
73 }; 73 };
74 /* 25 MHz reference crystal */ 74 /* 25 MHz reference crystal */
75 refclk: oscillator { 75 refclk: oscillator {
diff --git a/arch/arm/boot/dts/armada-38x.dtsi b/arch/arm/boot/dts/armada-38x.dtsi
index ed2dd8ba4080..218a2acd36e5 100644
--- a/arch/arm/boot/dts/armada-38x.dtsi
+++ b/arch/arm/boot/dts/armada-38x.dtsi
@@ -585,7 +585,7 @@
585 mainpll: mainpll { 585 mainpll: mainpll {
586 compatible = "fixed-clock"; 586 compatible = "fixed-clock";
587 #clock-cells = <0>; 587 #clock-cells = <0>;
588 clock-frequency = <2000000000>; 588 clock-frequency = <1000000000>;
589 }; 589 };
590 590
591 /* 25 MHz reference crystal */ 591 /* 25 MHz reference crystal */
diff --git a/arch/arm/boot/dts/armada-39x.dtsi b/arch/arm/boot/dts/armada-39x.dtsi
index 0e85fc15ceda..ecd1318109ba 100644
--- a/arch/arm/boot/dts/armada-39x.dtsi
+++ b/arch/arm/boot/dts/armada-39x.dtsi
@@ -502,7 +502,7 @@
502 mainpll: mainpll { 502 mainpll: mainpll {
503 compatible = "fixed-clock"; 503 compatible = "fixed-clock";
504 #clock-cells = <0>; 504 #clock-cells = <0>;
505 clock-frequency = <2000000000>; 505 clock-frequency = <1000000000>;
506 }; 506 };
507 }; 507 };
508}; 508};
diff --git a/arch/arm/boot/dts/armada-xp-openblocks-ax3-4.dts b/arch/arm/boot/dts/armada-xp-openblocks-ax3-4.dts
index e3b08fb959e5..990e8a2100f0 100644
--- a/arch/arm/boot/dts/armada-xp-openblocks-ax3-4.dts
+++ b/arch/arm/boot/dts/armada-xp-openblocks-ax3-4.dts
@@ -105,6 +105,10 @@
105 }; 105 };
106 106
107 internal-regs { 107 internal-regs {
108 rtc@10300 {
109 /* No crystal connected to the internal RTC */
110 status = "disabled";
111 };
108 serial@12000 { 112 serial@12000 {
109 status = "okay"; 113 status = "okay";
110 }; 114 };
diff --git a/arch/arm/boot/dts/dove-cubox.dts b/arch/arm/boot/dts/dove-cubox.dts
index aae7efc09b0b..e6fa251e17b9 100644
--- a/arch/arm/boot/dts/dove-cubox.dts
+++ b/arch/arm/boot/dts/dove-cubox.dts
@@ -87,6 +87,7 @@
87 87
88 /* connect xtal input to 25MHz reference */ 88 /* connect xtal input to 25MHz reference */
89 clocks = <&ref25>; 89 clocks = <&ref25>;
90 clock-names = "xtal";
90 91
91 /* connect xtal input as source of pll0 and pll1 */ 92 /* connect xtal input as source of pll0 and pll1 */
92 silabs,pll-source = <0 0>, <1 0>; 93 silabs,pll-source = <0 0>, <1 0>;
diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
index 5332b57b4950..f03a091cd076 100644
--- a/arch/arm/boot/dts/dra7.dtsi
+++ b/arch/arm/boot/dts/dra7.dtsi
@@ -911,7 +911,7 @@
911 ti,clock-cycles = <16>; 911 ti,clock-cycles = <16>;
912 912
913 reg = <0x4ae07ddc 0x4>, <0x4ae07de0 0x4>, 913 reg = <0x4ae07ddc 0x4>, <0x4ae07de0 0x4>,
914 <0x4ae06014 0x4>, <0x4a003b20 0x8>, 914 <0x4ae06014 0x4>, <0x4a003b20 0xc>,
915 <0x4ae0c158 0x4>; 915 <0x4ae0c158 0x4>;
916 reg-names = "setup-address", "control-address", 916 reg-names = "setup-address", "control-address",
917 "int-address", "efuse-address", 917 "int-address", "efuse-address",
@@ -944,7 +944,7 @@
944 ti,clock-cycles = <16>; 944 ti,clock-cycles = <16>;
945 945
946 reg = <0x4ae07e34 0x4>, <0x4ae07e24 0x4>, 946 reg = <0x4ae07e34 0x4>, <0x4ae07e24 0x4>,
947 <0x4ae06010 0x4>, <0x4a0025cc 0x8>, 947 <0x4ae06010 0x4>, <0x4a0025cc 0xc>,
948 <0x4a002470 0x4>; 948 <0x4a002470 0x4>;
949 reg-names = "setup-address", "control-address", 949 reg-names = "setup-address", "control-address",
950 "int-address", "efuse-address", 950 "int-address", "efuse-address",
@@ -977,7 +977,7 @@
977 ti,clock-cycles = <16>; 977 ti,clock-cycles = <16>;
978 978
979 reg = <0x4ae07e30 0x4>, <0x4ae07e20 0x4>, 979 reg = <0x4ae07e30 0x4>, <0x4ae07e20 0x4>,
980 <0x4ae06010 0x4>, <0x4a0025e0 0x8>, 980 <0x4ae06010 0x4>, <0x4a0025e0 0xc>,
981 <0x4a00246c 0x4>; 981 <0x4a00246c 0x4>;
982 reg-names = "setup-address", "control-address", 982 reg-names = "setup-address", "control-address",
983 "int-address", "efuse-address", 983 "int-address", "efuse-address",
@@ -1010,7 +1010,7 @@
1010 ti,clock-cycles = <16>; 1010 ti,clock-cycles = <16>;
1011 1011
1012 reg = <0x4ae07de4 0x4>, <0x4ae07de8 0x4>, 1012 reg = <0x4ae07de4 0x4>, <0x4ae07de8 0x4>,
1013 <0x4ae06010 0x4>, <0x4a003b08 0x8>, 1013 <0x4ae06010 0x4>, <0x4a003b08 0xc>,
1014 <0x4ae0c154 0x4>; 1014 <0x4ae0c154 0x4>;
1015 reg-names = "setup-address", "control-address", 1015 reg-names = "setup-address", "control-address",
1016 "int-address", "efuse-address", 1016 "int-address", "efuse-address",
@@ -1203,7 +1203,7 @@
1203 status = "disabled"; 1203 status = "disabled";
1204 }; 1204 };
1205 1205
1206 rtc@48838000 { 1206 rtc: rtc@48838000 {
1207 compatible = "ti,am3352-rtc"; 1207 compatible = "ti,am3352-rtc";
1208 reg = <0x48838000 0x100>; 1208 reg = <0x48838000 0x100>;
1209 interrupts = <GIC_SPI 217 IRQ_TYPE_LEVEL_HIGH>, 1209 interrupts = <GIC_SPI 217 IRQ_TYPE_LEVEL_HIGH>,
diff --git a/arch/arm/boot/dts/exynos4412-odroid-common.dtsi b/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
index 8de12af7c276..d6b49e5b32e9 100644
--- a/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
+++ b/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
@@ -9,6 +9,7 @@
9 9
10#include <dt-bindings/sound/samsung-i2s.h> 10#include <dt-bindings/sound/samsung-i2s.h>
11#include <dt-bindings/input/input.h> 11#include <dt-bindings/input/input.h>
12#include <dt-bindings/clock/maxim,max77686.h>
12#include "exynos4412.dtsi" 13#include "exynos4412.dtsi"
13 14
14/ { 15/ {
@@ -105,6 +106,8 @@
105 106
106 rtc@10070000 { 107 rtc@10070000 {
107 status = "okay"; 108 status = "okay";
109 clocks = <&clock CLK_RTC>, <&max77686 MAX77686_CLK_AP>;
110 clock-names = "rtc", "rtc_src";
108 }; 111 };
109 112
110 g2d@10800000 { 113 g2d@10800000 {
diff --git a/arch/arm/boot/dts/exynos4412-trats2.dts b/arch/arm/boot/dts/exynos4412-trats2.dts
index 173ffa479ad3..792394dd0f2a 100644
--- a/arch/arm/boot/dts/exynos4412-trats2.dts
+++ b/arch/arm/boot/dts/exynos4412-trats2.dts
@@ -736,7 +736,7 @@
736 736
737 display-timings { 737 display-timings {
738 timing-0 { 738 timing-0 {
739 clock-frequency = <0>; 739 clock-frequency = <57153600>;
740 hactive = <720>; 740 hactive = <720>;
741 vactive = <1280>; 741 vactive = <1280>;
742 hfront-porch = <5>; 742 hfront-porch = <5>;
diff --git a/arch/arm/boot/dts/exynos5250-snow.dts b/arch/arm/boot/dts/exynos5250-snow.dts
index 2657e842e5a5..1eca97ee4bd6 100644
--- a/arch/arm/boot/dts/exynos5250-snow.dts
+++ b/arch/arm/boot/dts/exynos5250-snow.dts
@@ -567,6 +567,7 @@
567 num-slots = <1>; 567 num-slots = <1>;
568 broken-cd; 568 broken-cd;
569 cap-sdio-irq; 569 cap-sdio-irq;
570 keep-power-in-suspend;
570 card-detect-delay = <200>; 571 card-detect-delay = <200>;
571 samsung,dw-mshc-ciu-div = <3>; 572 samsung,dw-mshc-ciu-div = <3>;
572 samsung,dw-mshc-sdr-timing = <2 3>; 573 samsung,dw-mshc-sdr-timing = <2 3>;
diff --git a/arch/arm/boot/dts/exynos5420-peach-pit.dts b/arch/arm/boot/dts/exynos5420-peach-pit.dts
index 0788d08fb43e..146e71118a72 100644
--- a/arch/arm/boot/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/boot/dts/exynos5420-peach-pit.dts
@@ -711,6 +711,7 @@
711 num-slots = <1>; 711 num-slots = <1>;
712 broken-cd; 712 broken-cd;
713 cap-sdio-irq; 713 cap-sdio-irq;
714 keep-power-in-suspend;
714 card-detect-delay = <200>; 715 card-detect-delay = <200>;
715 clock-frequency = <400000000>; 716 clock-frequency = <400000000>;
716 samsung,dw-mshc-ciu-div = <1>; 717 samsung,dw-mshc-ciu-div = <1>;
diff --git a/arch/arm/boot/dts/exynos5420-trip-points.dtsi b/arch/arm/boot/dts/exynos5420-trip-points.dtsi
index 5d31fc140823..2180a0152c9b 100644
--- a/arch/arm/boot/dts/exynos5420-trip-points.dtsi
+++ b/arch/arm/boot/dts/exynos5420-trip-points.dtsi
@@ -28,7 +28,7 @@ trips {
28 type = "active"; 28 type = "active";
29 }; 29 };
30 cpu-crit-0 { 30 cpu-crit-0 {
31 temperature = <1200000>; /* millicelsius */ 31 temperature = <120000>; /* millicelsius */
32 hysteresis = <0>; /* millicelsius */ 32 hysteresis = <0>; /* millicelsius */
33 type = "critical"; 33 type = "critical";
34 }; 34 };
diff --git a/arch/arm/boot/dts/exynos5420.dtsi b/arch/arm/boot/dts/exynos5420.dtsi
index f67b23f303c3..45317538bbae 100644
--- a/arch/arm/boot/dts/exynos5420.dtsi
+++ b/arch/arm/boot/dts/exynos5420.dtsi
@@ -536,6 +536,7 @@
536 clock-names = "dp"; 536 clock-names = "dp";
537 phys = <&dp_phy>; 537 phys = <&dp_phy>;
538 phy-names = "dp"; 538 phy-names = "dp";
539 power-domains = <&disp_pd>;
539 }; 540 };
540 541
541 mipi_phy: video-phy@10040714 { 542 mipi_phy: video-phy@10040714 {
diff --git a/arch/arm/boot/dts/exynos5440-trip-points.dtsi b/arch/arm/boot/dts/exynos5440-trip-points.dtsi
index 48adfa8f4300..356e963edf11 100644
--- a/arch/arm/boot/dts/exynos5440-trip-points.dtsi
+++ b/arch/arm/boot/dts/exynos5440-trip-points.dtsi
@@ -18,7 +18,7 @@ trips {
18 type = "active"; 18 type = "active";
19 }; 19 };
20 cpu-crit-0 { 20 cpu-crit-0 {
21 temperature = <1050000>; /* millicelsius */ 21 temperature = <105000>; /* millicelsius */
22 hysteresis = <0>; /* millicelsius */ 22 hysteresis = <0>; /* millicelsius */
23 type = "critical"; 23 type = "critical";
24 }; 24 };
diff --git a/arch/arm/boot/dts/exynos5800-peach-pi.dts b/arch/arm/boot/dts/exynos5800-peach-pi.dts
index 412f41d62686..02eb8b15374f 100644
--- a/arch/arm/boot/dts/exynos5800-peach-pi.dts
+++ b/arch/arm/boot/dts/exynos5800-peach-pi.dts
@@ -674,6 +674,7 @@
674 num-slots = <1>; 674 num-slots = <1>;
675 broken-cd; 675 broken-cd;
676 cap-sdio-irq; 676 cap-sdio-irq;
677 keep-power-in-suspend;
677 card-detect-delay = <200>; 678 card-detect-delay = <200>;
678 clock-frequency = <400000000>; 679 clock-frequency = <400000000>;
679 samsung,dw-mshc-ciu-div = <1>; 680 samsung,dw-mshc-ciu-div = <1>;
diff --git a/arch/arm/boot/dts/imx23-olinuxino.dts b/arch/arm/boot/dts/imx23-olinuxino.dts
index 7e6eef2488e8..82045398bf1f 100644
--- a/arch/arm/boot/dts/imx23-olinuxino.dts
+++ b/arch/arm/boot/dts/imx23-olinuxino.dts
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14/dts-v1/; 14/dts-v1/;
15#include <dt-bindings/gpio/gpio.h>
15#include "imx23.dtsi" 16#include "imx23.dtsi"
16 17
17/ { 18/ {
@@ -93,6 +94,7 @@
93 94
94 ahb@80080000 { 95 ahb@80080000 {
95 usb0: usb@80080000 { 96 usb0: usb@80080000 {
97 dr_mode = "host";
96 vbus-supply = <&reg_usb0_vbus>; 98 vbus-supply = <&reg_usb0_vbus>;
97 status = "okay"; 99 status = "okay";
98 }; 100 };
@@ -122,7 +124,7 @@
122 124
123 user { 125 user {
124 label = "green"; 126 label = "green";
125 gpios = <&gpio2 1 1>; 127 gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>;
126 }; 128 };
127 }; 129 };
128}; 130};
diff --git a/arch/arm/boot/dts/imx25.dtsi b/arch/arm/boot/dts/imx25.dtsi
index e4d3aecc4ed2..677f81d9dcd5 100644
--- a/arch/arm/boot/dts/imx25.dtsi
+++ b/arch/arm/boot/dts/imx25.dtsi
@@ -428,6 +428,7 @@
428 428
429 pwm4: pwm@53fc8000 { 429 pwm4: pwm@53fc8000 {
430 compatible = "fsl,imx25-pwm", "fsl,imx27-pwm"; 430 compatible = "fsl,imx25-pwm", "fsl,imx27-pwm";
431 #pwm-cells = <2>;
431 reg = <0x53fc8000 0x4000>; 432 reg = <0x53fc8000 0x4000>;
432 clocks = <&clks 108>, <&clks 52>; 433 clocks = <&clks 108>, <&clks 52>;
433 clock-names = "ipg", "per"; 434 clock-names = "ipg", "per";
diff --git a/arch/arm/boot/dts/imx27.dtsi b/arch/arm/boot/dts/imx27.dtsi
index 6951b66d1ab7..bc215e4b75fd 100644
--- a/arch/arm/boot/dts/imx27.dtsi
+++ b/arch/arm/boot/dts/imx27.dtsi
@@ -533,7 +533,7 @@
533 533
534 fec: ethernet@1002b000 { 534 fec: ethernet@1002b000 {
535 compatible = "fsl,imx27-fec"; 535 compatible = "fsl,imx27-fec";
536 reg = <0x1002b000 0x4000>; 536 reg = <0x1002b000 0x1000>;
537 interrupts = <50>; 537 interrupts = <50>;
538 clocks = <&clks IMX27_CLK_FEC_IPG_GATE>, 538 clocks = <&clks IMX27_CLK_FEC_IPG_GATE>,
539 <&clks IMX27_CLK_FEC_AHB_GATE>; 539 <&clks IMX27_CLK_FEC_AHB_GATE>;
diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi
index 25e25f82fbae..4e073e854742 100644
--- a/arch/arm/boot/dts/imx28.dtsi
+++ b/arch/arm/boot/dts/imx28.dtsi
@@ -913,7 +913,7 @@
913 80 81 68 69 913 80 81 68 69
914 70 71 72 73 914 70 71 72 73
915 74 75 76 77>; 915 74 75 76 77>;
916 interrupt-names = "auart4-rx", "aurat4-tx", "spdif-tx", "empty", 916 interrupt-names = "auart4-rx", "auart4-tx", "spdif-tx", "empty",
917 "saif0", "saif1", "i2c0", "i2c1", 917 "saif0", "saif1", "i2c0", "i2c1",
918 "auart0-rx", "auart0-tx", "auart1-rx", "auart1-tx", 918 "auart0-rx", "auart0-tx", "auart1-rx", "auart1-tx",
919 "auart2-rx", "auart2-tx", "auart3-rx", "auart3-tx"; 919 "auart2-rx", "auart2-tx", "auart3-rx", "auart3-tx";
diff --git a/arch/arm/boot/dts/imx6qdl-phytec-pfla02.dtsi b/arch/arm/boot/dts/imx6qdl-phytec-pfla02.dtsi
index 19cc269a08d4..1ce6133b67f5 100644
--- a/arch/arm/boot/dts/imx6qdl-phytec-pfla02.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-phytec-pfla02.dtsi
@@ -31,6 +31,7 @@
31 regulator-min-microvolt = <5000000>; 31 regulator-min-microvolt = <5000000>;
32 regulator-max-microvolt = <5000000>; 32 regulator-max-microvolt = <5000000>;
33 gpio = <&gpio4 15 0>; 33 gpio = <&gpio4 15 0>;
34 enable-active-high;
34 }; 35 };
35 36
36 reg_usb_h1_vbus: regulator@1 { 37 reg_usb_h1_vbus: regulator@1 {
@@ -40,6 +41,7 @@
40 regulator-min-microvolt = <5000000>; 41 regulator-min-microvolt = <5000000>;
41 regulator-max-microvolt = <5000000>; 42 regulator-max-microvolt = <5000000>;
42 gpio = <&gpio1 0 0>; 43 gpio = <&gpio1 0 0>;
44 enable-active-high;
43 }; 45 };
44 }; 46 };
45 47
diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 46b2fed7c319..3b24b12651b2 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -185,7 +185,6 @@
185&i2c3 { 185&i2c3 {
186 pinctrl-names = "default"; 186 pinctrl-names = "default";
187 pinctrl-0 = <&pinctrl_i2c3>; 187 pinctrl-0 = <&pinctrl_i2c3>;
188 pinctrl-assert-gpios = <&gpio5 4 GPIO_ACTIVE_HIGH>;
189 status = "okay"; 188 status = "okay";
190 189
191 max7310_a: gpio@30 { 190 max7310_a: gpio@30 {
diff --git a/arch/arm/boot/dts/omap3-devkit8000.dts b/arch/arm/boot/dts/omap3-devkit8000.dts
index 134d3f27a8ec..921de6605f07 100644
--- a/arch/arm/boot/dts/omap3-devkit8000.dts
+++ b/arch/arm/boot/dts/omap3-devkit8000.dts
@@ -110,6 +110,8 @@
110 nand@0,0 { 110 nand@0,0 {
111 reg = <0 0 4>; /* CS0, offset 0, IO size 4 */ 111 reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
112 nand-bus-width = <16>; 112 nand-bus-width = <16>;
113 gpmc,device-width = <2>;
114 ti,nand-ecc-opt = "sw";
113 115
114 gpmc,sync-clk-ps = <0>; 116 gpmc,sync-clk-ps = <0>;
115 gpmc,cs-on-ns = <0>; 117 gpmc,cs-on-ns = <0>;
diff --git a/arch/arm/boot/dts/omap3-n900.dts b/arch/arm/boot/dts/omap3-n900.dts
index a29315833ecd..5c16145920ea 100644
--- a/arch/arm/boot/dts/omap3-n900.dts
+++ b/arch/arm/boot/dts/omap3-n900.dts
@@ -498,6 +498,8 @@
498 DRVDD-supply = <&vmmc2>; 498 DRVDD-supply = <&vmmc2>;
499 IOVDD-supply = <&vio>; 499 IOVDD-supply = <&vio>;
500 DVDD-supply = <&vio>; 500 DVDD-supply = <&vio>;
501
502 ai3x-micbias-vg = <1>;
501 }; 503 };
502 504
503 tlv320aic3x_aux: tlv320aic3x@19 { 505 tlv320aic3x_aux: tlv320aic3x@19 {
@@ -509,6 +511,8 @@
509 DRVDD-supply = <&vmmc2>; 511 DRVDD-supply = <&vmmc2>;
510 IOVDD-supply = <&vio>; 512 IOVDD-supply = <&vio>;
511 DVDD-supply = <&vio>; 513 DVDD-supply = <&vio>;
514
515 ai3x-micbias-vg = <2>;
512 }; 516 };
513 517
514 tsl2563: tsl2563@29 { 518 tsl2563: tsl2563@29 {
diff --git a/arch/arm/boot/dts/omap3.dtsi b/arch/arm/boot/dts/omap3.dtsi
index d18a90f5eca3..69a40cfc1f29 100644
--- a/arch/arm/boot/dts/omap3.dtsi
+++ b/arch/arm/boot/dts/omap3.dtsi
@@ -456,6 +456,7 @@
456 }; 456 };
457 457
458 mmu_isp: mmu@480bd400 { 458 mmu_isp: mmu@480bd400 {
459 #iommu-cells = <0>;
459 compatible = "ti,omap2-iommu"; 460 compatible = "ti,omap2-iommu";
460 reg = <0x480bd400 0x80>; 461 reg = <0x480bd400 0x80>;
461 interrupts = <24>; 462 interrupts = <24>;
@@ -464,6 +465,7 @@
464 }; 465 };
465 466
466 mmu_iva: mmu@5d000000 { 467 mmu_iva: mmu@5d000000 {
468 #iommu-cells = <0>;
467 compatible = "ti,omap2-iommu"; 469 compatible = "ti,omap2-iommu";
468 reg = <0x5d000000 0x80>; 470 reg = <0x5d000000 0x80>;
469 interrupts = <28>; 471 interrupts = <28>;
diff --git a/arch/arm/boot/dts/omap5.dtsi b/arch/arm/boot/dts/omap5.dtsi
index efe5f737f39b..7d24ae0306b5 100644
--- a/arch/arm/boot/dts/omap5.dtsi
+++ b/arch/arm/boot/dts/omap5.dtsi
@@ -128,7 +128,7 @@
128 * hierarchy. 128 * hierarchy.
129 */ 129 */
130 ocp { 130 ocp {
131 compatible = "ti,omap4-l3-noc", "simple-bus"; 131 compatible = "ti,omap5-l3-noc", "simple-bus";
132 #address-cells = <1>; 132 #address-cells = <1>;
133 #size-cells = <1>; 133 #size-cells = <1>;
134 ranges; 134 ranges;
diff --git a/arch/arm/boot/dts/r8a7791-koelsch.dts b/arch/arm/boot/dts/r8a7791-koelsch.dts
index 74c3212f1f11..824ddab9c3ad 100644
--- a/arch/arm/boot/dts/r8a7791-koelsch.dts
+++ b/arch/arm/boot/dts/r8a7791-koelsch.dts
@@ -545,7 +545,7 @@
545 compatible = "adi,adv7511w"; 545 compatible = "adi,adv7511w";
546 reg = <0x39>; 546 reg = <0x39>;
547 interrupt-parent = <&gpio3>; 547 interrupt-parent = <&gpio3>;
548 interrupts = <29 IRQ_TYPE_EDGE_FALLING>; 548 interrupts = <29 IRQ_TYPE_LEVEL_LOW>;
549 549
550 adi,input-depth = <8>; 550 adi,input-depth = <8>;
551 adi,input-colorspace = "rgb"; 551 adi,input-colorspace = "rgb";
diff --git a/arch/arm/boot/dts/ste-dbx5x0.dtsi b/arch/arm/boot/dts/ste-dbx5x0.dtsi
index bfd3f1c734b8..2201cd5da3bb 100644
--- a/arch/arm/boot/dts/ste-dbx5x0.dtsi
+++ b/arch/arm/boot/dts/ste-dbx5x0.dtsi
@@ -1017,23 +1017,6 @@
1017 status = "disabled"; 1017 status = "disabled";
1018 }; 1018 };
1019 1019
1020 vmmci: regulator-gpio {
1021 compatible = "regulator-gpio";
1022
1023 regulator-min-microvolt = <1800000>;
1024 regulator-max-microvolt = <2900000>;
1025 regulator-name = "mmci-reg";
1026 regulator-type = "voltage";
1027
1028 startup-delay-us = <100>;
1029 enable-active-high;
1030
1031 states = <1800000 0x1
1032 2900000 0x0>;
1033
1034 status = "disabled";
1035 };
1036
1037 mcde@a0350000 { 1020 mcde@a0350000 {
1038 compatible = "stericsson,mcde"; 1021 compatible = "stericsson,mcde";
1039 reg = <0xa0350000 0x1000>, /* MCDE */ 1022 reg = <0xa0350000 0x1000>, /* MCDE */
diff --git a/arch/arm/boot/dts/ste-href.dtsi b/arch/arm/boot/dts/ste-href.dtsi
index bf8f0eddc2c0..744c1e3a744d 100644
--- a/arch/arm/boot/dts/ste-href.dtsi
+++ b/arch/arm/boot/dts/ste-href.dtsi
@@ -111,6 +111,21 @@
111 pinctrl-1 = <&i2c3_sleep_mode>; 111 pinctrl-1 = <&i2c3_sleep_mode>;
112 }; 112 };
113 113
114 vmmci: regulator-gpio {
115 compatible = "regulator-gpio";
116
117 regulator-min-microvolt = <1800000>;
118 regulator-max-microvolt = <2900000>;
119 regulator-name = "mmci-reg";
120 regulator-type = "voltage";
121
122 startup-delay-us = <100>;
123 enable-active-high;
124
125 states = <1800000 0x1
126 2900000 0x0>;
127 };
128
114 // External Micro SD slot 129 // External Micro SD slot
115 sdi0_per1@80126000 { 130 sdi0_per1@80126000 {
116 arm,primecell-periphid = <0x10480180>; 131 arm,primecell-periphid = <0x10480180>;
diff --git a/arch/arm/boot/dts/ste-snowball.dts b/arch/arm/boot/dts/ste-snowball.dts
index 206826a855c0..1bc84ebdccaa 100644
--- a/arch/arm/boot/dts/ste-snowball.dts
+++ b/arch/arm/boot/dts/ste-snowball.dts
@@ -146,8 +146,21 @@
146 }; 146 };
147 147
148 vmmci: regulator-gpio { 148 vmmci: regulator-gpio {
149 compatible = "regulator-gpio";
150
149 gpios = <&gpio7 4 0x4>; 151 gpios = <&gpio7 4 0x4>;
150 enable-gpio = <&gpio6 25 0x4>; 152 enable-gpio = <&gpio6 25 0x4>;
153
154 regulator-min-microvolt = <1800000>;
155 regulator-max-microvolt = <2900000>;
156 regulator-name = "mmci-reg";
157 regulator-type = "voltage";
158
159 startup-delay-us = <100>;
160 enable-active-high;
161
162 states = <1800000 0x1
163 2900000 0x0>;
151 }; 164 };
152 165
153 // External Micro SD slot 166 // External Micro SD slot
diff --git a/arch/arm/boot/dts/tegra124.dtsi b/arch/arm/boot/dts/tegra124.dtsi
index cf01c818b8ea..13cc7ca5e031 100644
--- a/arch/arm/boot/dts/tegra124.dtsi
+++ b/arch/arm/boot/dts/tegra124.dtsi
@@ -826,7 +826,7 @@
826 <&tegra_car TEGRA124_CLK_PLL_U>, 826 <&tegra_car TEGRA124_CLK_PLL_U>,
827 <&tegra_car TEGRA124_CLK_USBD>; 827 <&tegra_car TEGRA124_CLK_USBD>;
828 clock-names = "reg", "pll_u", "utmi-pads"; 828 clock-names = "reg", "pll_u", "utmi-pads";
829 resets = <&tegra_car 59>, <&tegra_car 22>; 829 resets = <&tegra_car 22>, <&tegra_car 22>;
830 reset-names = "usb", "utmi-pads"; 830 reset-names = "usb", "utmi-pads";
831 nvidia,hssync-start-delay = <0>; 831 nvidia,hssync-start-delay = <0>;
832 nvidia,idle-wait-delay = <17>; 832 nvidia,idle-wait-delay = <17>;
@@ -838,6 +838,7 @@
838 nvidia,hssquelch-level = <2>; 838 nvidia,hssquelch-level = <2>;
839 nvidia,hsdiscon-level = <5>; 839 nvidia,hsdiscon-level = <5>;
840 nvidia,xcvr-hsslew = <12>; 840 nvidia,xcvr-hsslew = <12>;
841 nvidia,has-utmi-pad-registers;
841 status = "disabled"; 842 status = "disabled";
842 }; 843 };
843 844
@@ -862,7 +863,7 @@
862 <&tegra_car TEGRA124_CLK_PLL_U>, 863 <&tegra_car TEGRA124_CLK_PLL_U>,
863 <&tegra_car TEGRA124_CLK_USBD>; 864 <&tegra_car TEGRA124_CLK_USBD>;
864 clock-names = "reg", "pll_u", "utmi-pads"; 865 clock-names = "reg", "pll_u", "utmi-pads";
865 resets = <&tegra_car 22>, <&tegra_car 22>; 866 resets = <&tegra_car 58>, <&tegra_car 22>;
866 reset-names = "usb", "utmi-pads"; 867 reset-names = "usb", "utmi-pads";
867 nvidia,hssync-start-delay = <0>; 868 nvidia,hssync-start-delay = <0>;
868 nvidia,idle-wait-delay = <17>; 869 nvidia,idle-wait-delay = <17>;
@@ -874,7 +875,6 @@
874 nvidia,hssquelch-level = <2>; 875 nvidia,hssquelch-level = <2>;
875 nvidia,hsdiscon-level = <5>; 876 nvidia,hsdiscon-level = <5>;
876 nvidia,xcvr-hsslew = <12>; 877 nvidia,xcvr-hsslew = <12>;
877 nvidia,has-utmi-pad-registers;
878 status = "disabled"; 878 status = "disabled";
879 }; 879 };
880 880
@@ -899,7 +899,7 @@
899 <&tegra_car TEGRA124_CLK_PLL_U>, 899 <&tegra_car TEGRA124_CLK_PLL_U>,
900 <&tegra_car TEGRA124_CLK_USBD>; 900 <&tegra_car TEGRA124_CLK_USBD>;
901 clock-names = "reg", "pll_u", "utmi-pads"; 901 clock-names = "reg", "pll_u", "utmi-pads";
902 resets = <&tegra_car 58>, <&tegra_car 22>; 902 resets = <&tegra_car 59>, <&tegra_car 22>;
903 reset-names = "usb", "utmi-pads"; 903 reset-names = "usb", "utmi-pads";
904 nvidia,hssync-start-delay = <0>; 904 nvidia,hssync-start-delay = <0>;
905 nvidia,idle-wait-delay = <17>; 905 nvidia,idle-wait-delay = <17>;
diff --git a/arch/arm/boot/dts/vexpress-v2p-ca15_a7.dts b/arch/arm/boot/dts/vexpress-v2p-ca15_a7.dts
index 7a2aeacd62c0..107395c32d82 100644
--- a/arch/arm/boot/dts/vexpress-v2p-ca15_a7.dts
+++ b/arch/arm/boot/dts/vexpress-v2p-ca15_a7.dts
@@ -191,6 +191,7 @@
191 compatible = "arm,cortex-a15-pmu"; 191 compatible = "arm,cortex-a15-pmu";
192 interrupts = <0 68 4>, 192 interrupts = <0 68 4>,
193 <0 69 4>; 193 <0 69 4>;
194 interrupt-affinity = <&cpu0>, <&cpu1>;
194 }; 195 };
195 196
196 oscclk6a: oscclk6a { 197 oscclk6a: oscclk6a {
diff --git a/arch/arm/boot/dts/vexpress-v2p-ca9.dts b/arch/arm/boot/dts/vexpress-v2p-ca9.dts
index 23662b5a5e9d..d949facba376 100644
--- a/arch/arm/boot/dts/vexpress-v2p-ca9.dts
+++ b/arch/arm/boot/dts/vexpress-v2p-ca9.dts
@@ -33,28 +33,28 @@
33 #address-cells = <1>; 33 #address-cells = <1>;
34 #size-cells = <0>; 34 #size-cells = <0>;
35 35
36 cpu@0 { 36 A9_0: cpu@0 {
37 device_type = "cpu"; 37 device_type = "cpu";
38 compatible = "arm,cortex-a9"; 38 compatible = "arm,cortex-a9";
39 reg = <0>; 39 reg = <0>;
40 next-level-cache = <&L2>; 40 next-level-cache = <&L2>;
41 }; 41 };
42 42
43 cpu@1 { 43 A9_1: cpu@1 {
44 device_type = "cpu"; 44 device_type = "cpu";
45 compatible = "arm,cortex-a9"; 45 compatible = "arm,cortex-a9";
46 reg = <1>; 46 reg = <1>;
47 next-level-cache = <&L2>; 47 next-level-cache = <&L2>;
48 }; 48 };
49 49
50 cpu@2 { 50 A9_2: cpu@2 {
51 device_type = "cpu"; 51 device_type = "cpu";
52 compatible = "arm,cortex-a9"; 52 compatible = "arm,cortex-a9";
53 reg = <2>; 53 reg = <2>;
54 next-level-cache = <&L2>; 54 next-level-cache = <&L2>;
55 }; 55 };
56 56
57 cpu@3 { 57 A9_3: cpu@3 {
58 device_type = "cpu"; 58 device_type = "cpu";
59 compatible = "arm,cortex-a9"; 59 compatible = "arm,cortex-a9";
60 reg = <3>; 60 reg = <3>;
@@ -170,6 +170,7 @@
170 compatible = "arm,pl310-cache"; 170 compatible = "arm,pl310-cache";
171 reg = <0x1e00a000 0x1000>; 171 reg = <0x1e00a000 0x1000>;
172 interrupts = <0 43 4>; 172 interrupts = <0 43 4>;
173 cache-unified;
173 cache-level = <2>; 174 cache-level = <2>;
174 arm,data-latency = <1 1 1>; 175 arm,data-latency = <1 1 1>;
175 arm,tag-latency = <1 1 1>; 176 arm,tag-latency = <1 1 1>;
@@ -181,6 +182,8 @@
181 <0 61 4>, 182 <0 61 4>,
182 <0 62 4>, 183 <0 62 4>,
183 <0 63 4>; 184 <0 63 4>;
185 interrupt-affinity = <&A9_0>, <&A9_1>, <&A9_2>, <&A9_3>;
186
184 }; 187 };
185 188
186 dcc { 189 dcc {
diff --git a/arch/arm/boot/dts/zynq-7000.dtsi b/arch/arm/boot/dts/zynq-7000.dtsi
index a5cd2eda3edf..9ea54b3dba09 100644
--- a/arch/arm/boot/dts/zynq-7000.dtsi
+++ b/arch/arm/boot/dts/zynq-7000.dtsi
@@ -193,7 +193,7 @@
193 }; 193 };
194 194
195 gem0: ethernet@e000b000 { 195 gem0: ethernet@e000b000 {
196 compatible = "cdns,gem"; 196 compatible = "cdns,zynq-gem";
197 reg = <0xe000b000 0x1000>; 197 reg = <0xe000b000 0x1000>;
198 status = "disabled"; 198 status = "disabled";
199 interrupts = <0 22 4>; 199 interrupts = <0 22 4>;
@@ -204,7 +204,7 @@
204 }; 204 };
205 205
206 gem1: ethernet@e000c000 { 206 gem1: ethernet@e000c000 {
207 compatible = "cdns,gem"; 207 compatible = "cdns,zynq-gem";
208 reg = <0xe000c000 0x1000>; 208 reg = <0xe000c000 0x1000>;
209 status = "disabled"; 209 status = "disabled";
210 interrupts = <0 45 4>; 210 interrupts = <0 45 4>;
diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index ab86655c1f4b..fbbb1915c6a9 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -39,11 +39,14 @@ CONFIG_ARCH_HIP04=y
39CONFIG_ARCH_KEYSTONE=y 39CONFIG_ARCH_KEYSTONE=y
40CONFIG_ARCH_MESON=y 40CONFIG_ARCH_MESON=y
41CONFIG_ARCH_MXC=y 41CONFIG_ARCH_MXC=y
42CONFIG_SOC_IMX50=y
42CONFIG_SOC_IMX51=y 43CONFIG_SOC_IMX51=y
43CONFIG_SOC_IMX53=y 44CONFIG_SOC_IMX53=y
44CONFIG_SOC_IMX6Q=y 45CONFIG_SOC_IMX6Q=y
45CONFIG_SOC_IMX6SL=y 46CONFIG_SOC_IMX6SL=y
47CONFIG_SOC_IMX6SX=y
46CONFIG_SOC_VF610=y 48CONFIG_SOC_VF610=y
49CONFIG_SOC_LS1021A=y
47CONFIG_ARCH_OMAP3=y 50CONFIG_ARCH_OMAP3=y
48CONFIG_ARCH_OMAP4=y 51CONFIG_ARCH_OMAP4=y
49CONFIG_SOC_OMAP5=y 52CONFIG_SOC_OMAP5=y
@@ -426,7 +429,7 @@ CONFIG_USB_EHCI_EXYNOS=y
426CONFIG_USB_EHCI_TEGRA=y 429CONFIG_USB_EHCI_TEGRA=y
427CONFIG_USB_EHCI_HCD_STI=y 430CONFIG_USB_EHCI_HCD_STI=y
428CONFIG_USB_EHCI_HCD_PLATFORM=y 431CONFIG_USB_EHCI_HCD_PLATFORM=y
429CONFIG_USB_ISP1760_HCD=y 432CONFIG_USB_ISP1760=y
430CONFIG_USB_OHCI_HCD=y 433CONFIG_USB_OHCI_HCD=y
431CONFIG_USB_OHCI_HCD_STI=y 434CONFIG_USB_OHCI_HCD_STI=y
432CONFIG_USB_OHCI_HCD_PLATFORM=y 435CONFIG_USB_OHCI_HCD_PLATFORM=y
diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 9ff7b54b2a83..3743ca221d40 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -393,7 +393,7 @@ CONFIG_TI_EDMA=y
393CONFIG_DMA_OMAP=y 393CONFIG_DMA_OMAP=y
394# CONFIG_IOMMU_SUPPORT is not set 394# CONFIG_IOMMU_SUPPORT is not set
395CONFIG_EXTCON=m 395CONFIG_EXTCON=m
396CONFIG_EXTCON_GPIO=m 396CONFIG_EXTCON_USB_GPIO=m
397CONFIG_EXTCON_PALMAS=m 397CONFIG_EXTCON_PALMAS=m
398CONFIG_TI_EMIF=m 398CONFIG_TI_EMIF=m
399CONFIG_PWM=y 399CONFIG_PWM=y
diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h
index 8e3fcb924db6..2ef282f96651 100644
--- a/arch/arm/include/asm/dma-iommu.h
+++ b/arch/arm/include/asm/dma-iommu.h
@@ -25,7 +25,7 @@ struct dma_iommu_mapping {
25}; 25};
26 26
27struct dma_iommu_mapping * 27struct dma_iommu_mapping *
28arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size); 28arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size);
29 29
30void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping); 30void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping);
31 31
diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
index 2f7e6ff67d51..0b579b2f4e0e 100644
--- a/arch/arm/include/asm/xen/page.h
+++ b/arch/arm/include/asm/xen/page.h
@@ -110,5 +110,6 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
110bool xen_arch_need_swiotlb(struct device *dev, 110bool xen_arch_need_swiotlb(struct device *dev,
111 unsigned long pfn, 111 unsigned long pfn,
112 unsigned long mfn); 112 unsigned long mfn);
113unsigned long xen_get_swiotlb_free_pages(unsigned int order);
113 114
114#endif /* _ASM_ARM_XEN_PAGE_H */ 115#endif /* _ASM_ARM_XEN_PAGE_H */
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index f8ccc21fa032..4e7f40c577e6 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -33,7 +33,9 @@ ret_fast_syscall:
33 UNWIND(.fnstart ) 33 UNWIND(.fnstart )
34 UNWIND(.cantunwind ) 34 UNWIND(.cantunwind )
35 disable_irq @ disable interrupts 35 disable_irq @ disable interrupts
36 ldr r1, [tsk, #TI_FLAGS] 36 ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
37 tst r1, #_TIF_SYSCALL_WORK
38 bne __sys_trace_return
37 tst r1, #_TIF_WORK_MASK 39 tst r1, #_TIF_WORK_MASK
38 bne fast_work_pending 40 bne fast_work_pending
39 asm_trace_hardirqs_on 41 asm_trace_hardirqs_on
diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
index 91c7ba182dcd..3b8c2833c537 100644
--- a/arch/arm/kernel/perf_event_cpu.c
+++ b/arch/arm/kernel/perf_event_cpu.c
@@ -303,9 +303,15 @@ static int probe_current_pmu(struct arm_pmu *pmu)
303 303
304static int of_pmu_irq_cfg(struct platform_device *pdev) 304static int of_pmu_irq_cfg(struct platform_device *pdev)
305{ 305{
306 int i; 306 int i, irq;
307 int *irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL); 307 int *irqs;
308 308
309 /* Don't bother with PPIs; they're already affine */
310 irq = platform_get_irq(pdev, 0);
311 if (irq >= 0 && irq_is_percpu(irq))
312 return 0;
313
314 irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL);
309 if (!irqs) 315 if (!irqs)
310 return -ENOMEM; 316 return -ENOMEM;
311 317
@@ -317,7 +323,7 @@ static int of_pmu_irq_cfg(struct platform_device *pdev)
317 i); 323 i);
318 if (!dn) { 324 if (!dn) {
319 pr_warn("Failed to parse %s/interrupt-affinity[%d]\n", 325 pr_warn("Failed to parse %s/interrupt-affinity[%d]\n",
320 of_node_full_name(dn), i); 326 of_node_full_name(pdev->dev.of_node), i);
321 break; 327 break;
322 } 328 }
323 329
diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
index acd5b560b728..5f5cd562c593 100644
--- a/arch/arm/mach-exynos/common.h
+++ b/arch/arm/mach-exynos/common.h
@@ -159,6 +159,8 @@ extern void exynos_enter_aftr(void);
159 159
160extern struct cpuidle_exynos_data cpuidle_coupled_exynos_data; 160extern struct cpuidle_exynos_data cpuidle_coupled_exynos_data;
161 161
162extern void exynos_set_delayed_reset_assertion(bool enable);
163
162extern void s5p_init_cpu(void __iomem *cpuid_addr); 164extern void s5p_init_cpu(void __iomem *cpuid_addr);
163extern unsigned int samsung_rev(void); 165extern unsigned int samsung_rev(void);
164extern void __iomem *cpu_boot_reg_base(void); 166extern void __iomem *cpu_boot_reg_base(void);
diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
index bcde0dd668df..5917a30eee33 100644
--- a/arch/arm/mach-exynos/exynos.c
+++ b/arch/arm/mach-exynos/exynos.c
@@ -167,6 +167,33 @@ static void __init exynos_init_io(void)
167} 167}
168 168
169/* 169/*
170 * Set or clear the USE_DELAYED_RESET_ASSERTION option. Used by smp code
171 * and suspend.
172 *
173 * This is necessary only on Exynos4 SoCs. When system is running
174 * USE_DELAYED_RESET_ASSERTION should be set so the ARM CLK clock down
175 * feature could properly detect global idle state when secondary CPU is
176 * powered down.
177 *
178 * However this should not be set when such system is going into suspend.
179 */
180void exynos_set_delayed_reset_assertion(bool enable)
181{
182 if (of_machine_is_compatible("samsung,exynos4")) {
183 unsigned int tmp, core_id;
184
185 for (core_id = 0; core_id < num_possible_cpus(); core_id++) {
186 tmp = pmu_raw_readl(EXYNOS_ARM_CORE_OPTION(core_id));
187 if (enable)
188 tmp |= S5P_USE_DELAYED_RESET_ASSERTION;
189 else
190 tmp &= ~(S5P_USE_DELAYED_RESET_ASSERTION);
191 pmu_raw_writel(tmp, EXYNOS_ARM_CORE_OPTION(core_id));
192 }
193 }
194}
195
196/*
170 * Apparently, these SoCs are not able to wake-up from suspend using 197 * Apparently, these SoCs are not able to wake-up from suspend using
171 * the PMU. Too bad. Should they suddenly become capable of such a 198 * the PMU. Too bad. Should they suddenly become capable of such a
172 * feat, the matches below should be moved to suspend.c. 199 * feat, the matches below should be moved to suspend.c.
diff --git a/arch/arm/mach-exynos/platsmp.c b/arch/arm/mach-exynos/platsmp.c
index ebd135bb0995..a825bca2a2b6 100644
--- a/arch/arm/mach-exynos/platsmp.c
+++ b/arch/arm/mach-exynos/platsmp.c
@@ -34,30 +34,6 @@
34 34
35extern void exynos4_secondary_startup(void); 35extern void exynos4_secondary_startup(void);
36 36
37/*
38 * Set or clear the USE_DELAYED_RESET_ASSERTION option, set on Exynos4 SoCs
39 * during hot-(un)plugging CPUx.
40 *
41 * The feature can be cleared safely during first boot of secondary CPU.
42 *
43 * Exynos4 SoCs require setting USE_DELAYED_RESET_ASSERTION during powering
44 * down a CPU so the CPU idle clock down feature could properly detect global
45 * idle state when CPUx is off.
46 */
47static void exynos_set_delayed_reset_assertion(u32 core_id, bool enable)
48{
49 if (soc_is_exynos4()) {
50 unsigned int tmp;
51
52 tmp = pmu_raw_readl(EXYNOS_ARM_CORE_OPTION(core_id));
53 if (enable)
54 tmp |= S5P_USE_DELAYED_RESET_ASSERTION;
55 else
56 tmp &= ~(S5P_USE_DELAYED_RESET_ASSERTION);
57 pmu_raw_writel(tmp, EXYNOS_ARM_CORE_OPTION(core_id));
58 }
59}
60
61#ifdef CONFIG_HOTPLUG_CPU 37#ifdef CONFIG_HOTPLUG_CPU
62static inline void cpu_leave_lowpower(u32 core_id) 38static inline void cpu_leave_lowpower(u32 core_id)
63{ 39{
@@ -73,8 +49,6 @@ static inline void cpu_leave_lowpower(u32 core_id)
73 : "=&r" (v) 49 : "=&r" (v)
74 : "Ir" (CR_C), "Ir" (0x40) 50 : "Ir" (CR_C), "Ir" (0x40)
75 : "cc"); 51 : "cc");
76
77 exynos_set_delayed_reset_assertion(core_id, false);
78} 52}
79 53
80static inline void platform_do_lowpower(unsigned int cpu, int *spurious) 54static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
@@ -87,14 +61,6 @@ static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
87 /* Turn the CPU off on next WFI instruction. */ 61 /* Turn the CPU off on next WFI instruction. */
88 exynos_cpu_power_down(core_id); 62 exynos_cpu_power_down(core_id);
89 63
90 /*
91 * Exynos4 SoCs require setting
92 * USE_DELAYED_RESET_ASSERTION so the CPU idle
93 * clock down feature could properly detect
94 * global idle state when CPUx is off.
95 */
96 exynos_set_delayed_reset_assertion(core_id, true);
97
98 wfi(); 64 wfi();
99 65
100 if (pen_release == core_id) { 66 if (pen_release == core_id) {
@@ -371,9 +337,6 @@ static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
371 udelay(10); 337 udelay(10);
372 } 338 }
373 339
374 /* No harm if this is called during first boot of secondary CPU */
375 exynos_set_delayed_reset_assertion(core_id, false);
376
377 /* 340 /*
378 * now the secondary core is starting up let it run its 341 * now the secondary core is starting up let it run its
379 * calibrations, then wait for it to finish 342 * calibrations, then wait for it to finish
@@ -420,6 +383,8 @@ static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
420 383
421 exynos_sysram_init(); 384 exynos_sysram_init();
422 385
386 exynos_set_delayed_reset_assertion(true);
387
423 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) 388 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
424 scu_enable(scu_base_addr()); 389 scu_enable(scu_base_addr());
425 390
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index cbe56b35aea0..a9686535f9ed 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -188,7 +188,7 @@ no_clk:
188 args.np = np; 188 args.np = np;
189 args.args_count = 0; 189 args.args_count = 0;
190 child_domain = of_genpd_get_from_provider(&args); 190 child_domain = of_genpd_get_from_provider(&args);
191 if (!child_domain) 191 if (IS_ERR(child_domain))
192 continue; 192 continue;
193 193
194 if (of_parse_phandle_with_args(np, "power-domains", 194 if (of_parse_phandle_with_args(np, "power-domains",
@@ -196,7 +196,7 @@ no_clk:
196 continue; 196 continue;
197 197
198 parent_domain = of_genpd_get_from_provider(&args); 198 parent_domain = of_genpd_get_from_provider(&args);
199 if (!parent_domain) 199 if (IS_ERR(parent_domain))
200 continue; 200 continue;
201 201
202 if (pm_genpd_add_subdomain(parent_domain, child_domain)) 202 if (pm_genpd_add_subdomain(parent_domain, child_domain))
diff --git a/arch/arm/mach-exynos/suspend.c b/arch/arm/mach-exynos/suspend.c
index 3e6aea7f83af..c0b6dccbf7bd 100644
--- a/arch/arm/mach-exynos/suspend.c
+++ b/arch/arm/mach-exynos/suspend.c
@@ -342,6 +342,8 @@ static void exynos_pm_enter_sleep_mode(void)
342 342
343static void exynos_pm_prepare(void) 343static void exynos_pm_prepare(void)
344{ 344{
345 exynos_set_delayed_reset_assertion(false);
346
345 /* Set wake-up mask registers */ 347 /* Set wake-up mask registers */
346 exynos_pm_set_wakeup_mask(); 348 exynos_pm_set_wakeup_mask();
347 349
@@ -482,6 +484,7 @@ early_wakeup:
482 484
483 /* Clear SLEEP mode set in INFORM1 */ 485 /* Clear SLEEP mode set in INFORM1 */
484 pmu_raw_writel(0x0, S5P_INFORM1); 486 pmu_raw_writel(0x0, S5P_INFORM1);
487 exynos_set_delayed_reset_assertion(true);
485} 488}
486 489
487static void exynos3250_pm_resume(void) 490static void exynos3250_pm_resume(void)
@@ -723,8 +726,10 @@ void __init exynos_pm_init(void)
723 return; 726 return;
724 } 727 }
725 728
726 if (WARN_ON(!of_find_property(np, "interrupt-controller", NULL))) 729 if (WARN_ON(!of_find_property(np, "interrupt-controller", NULL))) {
727 pr_warn("Outdated DT detected, suspend/resume will NOT work\n"); 730 pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
731 return;
732 }
728 733
729 pm_data = (const struct exynos_pm_data *) match->data; 734 pm_data = (const struct exynos_pm_data *) match->data;
730 735
diff --git a/arch/arm/mach-gemini/common.h b/arch/arm/mach-gemini/common.h
index 38a45260a7c8..dd883698ff7e 100644
--- a/arch/arm/mach-gemini/common.h
+++ b/arch/arm/mach-gemini/common.h
@@ -12,6 +12,8 @@
12#ifndef __GEMINI_COMMON_H__ 12#ifndef __GEMINI_COMMON_H__
13#define __GEMINI_COMMON_H__ 13#define __GEMINI_COMMON_H__
14 14
15#include <linux/reboot.h>
16
15struct mtd_partition; 17struct mtd_partition;
16 18
17extern void gemini_map_io(void); 19extern void gemini_map_io(void);
@@ -26,6 +28,6 @@ extern int platform_register_pflash(unsigned int size,
26 struct mtd_partition *parts, 28 struct mtd_partition *parts,
27 unsigned int nr_parts); 29 unsigned int nr_parts);
28 30
29extern void gemini_restart(char mode, const char *cmd); 31extern void gemini_restart(enum reboot_mode mode, const char *cmd);
30 32
31#endif /* __GEMINI_COMMON_H__ */ 33#endif /* __GEMINI_COMMON_H__ */
diff --git a/arch/arm/mach-gemini/reset.c b/arch/arm/mach-gemini/reset.c
index b26659759e27..21a6d6d4f9c4 100644
--- a/arch/arm/mach-gemini/reset.c
+++ b/arch/arm/mach-gemini/reset.c
@@ -14,7 +14,9 @@
14#include <mach/hardware.h> 14#include <mach/hardware.h>
15#include <mach/global_reg.h> 15#include <mach/global_reg.h>
16 16
17void gemini_restart(char mode, const char *cmd) 17#include "common.h"
18
19void gemini_restart(enum reboot_mode mode, const char *cmd)
18{ 20{
19 __raw_writel(RESET_GLOBAL | RESET_CPU1, 21 __raw_writel(RESET_GLOBAL | RESET_CPU1,
20 IO_ADDRESS(GEMINI_GLOBAL_BASE) + GLOBAL_RESET); 22 IO_ADDRESS(GEMINI_GLOBAL_BASE) + GLOBAL_RESET);
diff --git a/arch/arm/mach-imx/devices/platform-sdhci-esdhc-imx.c b/arch/arm/mach-imx/devices/platform-sdhci-esdhc-imx.c
index fb8d4a2ad48c..a5edd7d60266 100644
--- a/arch/arm/mach-imx/devices/platform-sdhci-esdhc-imx.c
+++ b/arch/arm/mach-imx/devices/platform-sdhci-esdhc-imx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 Pengutronix, Wolfram Sang <w.sang@pengutronix.de> 2 * Copyright (C) 2010 Pengutronix, Wolfram Sang <kernel@pengutronix.de>
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it under 4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License version 2 as published by the 5 * the terms of the GNU General Public License version 2 as published by the
diff --git a/arch/arm/mach-imx/gpc.c b/arch/arm/mach-imx/gpc.c
index 4d60005e9277..6d0893a3828e 100644
--- a/arch/arm/mach-imx/gpc.c
+++ b/arch/arm/mach-imx/gpc.c
@@ -280,9 +280,15 @@ void __init imx_gpc_check_dt(void)
280 struct device_node *np; 280 struct device_node *np;
281 281
282 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc"); 282 np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
283 if (WARN_ON(!np || 283 if (WARN_ON(!np))
284 !of_find_property(np, "interrupt-controller", NULL))) 284 return;
285 pr_warn("Outdated DT detected, system is about to crash!!!\n"); 285
286 if (WARN_ON(!of_find_property(np, "interrupt-controller", NULL))) {
287 pr_warn("Outdated DT detected, suspend/resume will NOT work\n");
288
289 /* map GPC, so that at least CPUidle and WARs keep working */
290 gpc_base = of_iomap(np, 0);
291 }
286} 292}
287 293
288#ifdef CONFIG_PM_GENERIC_DOMAINS 294#ifdef CONFIG_PM_GENERIC_DOMAINS
@@ -443,6 +449,10 @@ static int imx_gpc_probe(struct platform_device *pdev)
443 struct regulator *pu_reg; 449 struct regulator *pu_reg;
444 int ret; 450 int ret;
445 451
452 /* bail out if DT too old and doesn't provide the necessary info */
453 if (!of_property_read_bool(pdev->dev.of_node, "#power-domain-cells"))
454 return 0;
455
446 pu_reg = devm_regulator_get_optional(&pdev->dev, "pu"); 456 pu_reg = devm_regulator_get_optional(&pdev->dev, "pu");
447 if (PTR_ERR(pu_reg) == -ENODEV) 457 if (PTR_ERR(pu_reg) == -ENODEV)
448 pu_reg = NULL; 458 pu_reg = NULL;
diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
index 355b08936871..752969ff9de0 100644
--- a/arch/arm/mach-omap2/omap_hwmod.c
+++ b/arch/arm/mach-omap2/omap_hwmod.c
@@ -171,6 +171,12 @@
171 */ 171 */
172#define LINKS_PER_OCP_IF 2 172#define LINKS_PER_OCP_IF 2
173 173
174/*
175 * Address offset (in bytes) between the reset control and the reset
176 * status registers: 4 bytes on OMAP4
177 */
178#define OMAP4_RST_CTRL_ST_OFFSET 4
179
174/** 180/**
175 * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations 181 * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
176 * @enable_module: function to enable a module (via MODULEMODE) 182 * @enable_module: function to enable a module (via MODULEMODE)
@@ -3016,10 +3022,12 @@ static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
3016 if (ohri->st_shift) 3022 if (ohri->st_shift)
3017 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n", 3023 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
3018 oh->name, ohri->name); 3024 oh->name, ohri->name);
3019 return omap_prm_deassert_hardreset(ohri->rst_shift, 0, 3025 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->rst_shift,
3020 oh->clkdm->pwrdm.ptr->prcm_partition, 3026 oh->clkdm->pwrdm.ptr->prcm_partition,
3021 oh->clkdm->pwrdm.ptr->prcm_offs, 3027 oh->clkdm->pwrdm.ptr->prcm_offs,
3022 oh->prcm.omap4.rstctrl_offs, 0); 3028 oh->prcm.omap4.rstctrl_offs,
3029 oh->prcm.omap4.rstctrl_offs +
3030 OMAP4_RST_CTRL_ST_OFFSET);
3023} 3031}
3024 3032
3025/** 3033/**
@@ -3048,27 +3056,6 @@ static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
3048} 3056}
3049 3057
3050/** 3058/**
3051 * _am33xx_assert_hardreset - call AM33XX PRM hardreset fn with hwmod args
3052 * @oh: struct omap_hwmod * to assert hardreset
3053 * @ohri: hardreset line data
3054 *
3055 * Call am33xx_prminst_assert_hardreset() with parameters extracted
3056 * from the hwmod @oh and the hardreset line data @ohri. Only
3057 * intended for use as an soc_ops function pointer. Passes along the
3058 * return value from am33xx_prminst_assert_hardreset(). XXX This
3059 * function is scheduled for removal when the PRM code is moved into
3060 * drivers/.
3061 */
3062static int _am33xx_assert_hardreset(struct omap_hwmod *oh,
3063 struct omap_hwmod_rst_info *ohri)
3064
3065{
3066 return omap_prm_assert_hardreset(ohri->rst_shift, 0,
3067 oh->clkdm->pwrdm.ptr->prcm_offs,
3068 oh->prcm.omap4.rstctrl_offs);
3069}
3070
3071/**
3072 * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args 3059 * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
3073 * @oh: struct omap_hwmod * to deassert hardreset 3060 * @oh: struct omap_hwmod * to deassert hardreset
3074 * @ohri: hardreset line data 3061 * @ohri: hardreset line data
@@ -3083,32 +3070,13 @@ static int _am33xx_assert_hardreset(struct omap_hwmod *oh,
3083static int _am33xx_deassert_hardreset(struct omap_hwmod *oh, 3070static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
3084 struct omap_hwmod_rst_info *ohri) 3071 struct omap_hwmod_rst_info *ohri)
3085{ 3072{
3086 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, 0, 3073 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift,
3074 oh->clkdm->pwrdm.ptr->prcm_partition,
3087 oh->clkdm->pwrdm.ptr->prcm_offs, 3075 oh->clkdm->pwrdm.ptr->prcm_offs,
3088 oh->prcm.omap4.rstctrl_offs, 3076 oh->prcm.omap4.rstctrl_offs,
3089 oh->prcm.omap4.rstst_offs); 3077 oh->prcm.omap4.rstst_offs);
3090} 3078}
3091 3079
3092/**
3093 * _am33xx_is_hardreset_asserted - call AM33XX PRM hardreset fn with hwmod args
3094 * @oh: struct omap_hwmod * to test hardreset
3095 * @ohri: hardreset line data
3096 *
3097 * Call am33xx_prminst_is_hardreset_asserted() with parameters
3098 * extracted from the hwmod @oh and the hardreset line data @ohri.
3099 * Only intended for use as an soc_ops function pointer. Passes along
3100 * the return value from am33xx_prminst_is_hardreset_asserted(). XXX
3101 * This function is scheduled for removal when the PRM code is moved
3102 * into drivers/.
3103 */
3104static int _am33xx_is_hardreset_asserted(struct omap_hwmod *oh,
3105 struct omap_hwmod_rst_info *ohri)
3106{
3107 return omap_prm_is_hardreset_asserted(ohri->rst_shift, 0,
3108 oh->clkdm->pwrdm.ptr->prcm_offs,
3109 oh->prcm.omap4.rstctrl_offs);
3110}
3111
3112/* Public functions */ 3080/* Public functions */
3113 3081
3114u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs) 3082u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
@@ -3908,21 +3876,13 @@ void __init omap_hwmod_init(void)
3908 soc_ops.init_clkdm = _init_clkdm; 3876 soc_ops.init_clkdm = _init_clkdm;
3909 soc_ops.update_context_lost = _omap4_update_context_lost; 3877 soc_ops.update_context_lost = _omap4_update_context_lost;
3910 soc_ops.get_context_lost = _omap4_get_context_lost; 3878 soc_ops.get_context_lost = _omap4_get_context_lost;
3911 } else if (soc_is_am43xx()) { 3879 } else if (cpu_is_ti816x() || soc_is_am33xx() || soc_is_am43xx()) {
3912 soc_ops.enable_module = _omap4_enable_module; 3880 soc_ops.enable_module = _omap4_enable_module;
3913 soc_ops.disable_module = _omap4_disable_module; 3881 soc_ops.disable_module = _omap4_disable_module;
3914 soc_ops.wait_target_ready = _omap4_wait_target_ready; 3882 soc_ops.wait_target_ready = _omap4_wait_target_ready;
3915 soc_ops.assert_hardreset = _omap4_assert_hardreset; 3883 soc_ops.assert_hardreset = _omap4_assert_hardreset;
3916 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
3917 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
3918 soc_ops.init_clkdm = _init_clkdm;
3919 } else if (cpu_is_ti816x() || soc_is_am33xx()) {
3920 soc_ops.enable_module = _omap4_enable_module;
3921 soc_ops.disable_module = _omap4_disable_module;
3922 soc_ops.wait_target_ready = _omap4_wait_target_ready;
3923 soc_ops.assert_hardreset = _am33xx_assert_hardreset;
3924 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset; 3884 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
3925 soc_ops.is_hardreset_asserted = _am33xx_is_hardreset_asserted; 3885 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
3926 soc_ops.init_clkdm = _init_clkdm; 3886 soc_ops.init_clkdm = _init_clkdm;
3927 } else { 3887 } else {
3928 WARN(1, "omap_hwmod: unknown SoC type\n"); 3888 WARN(1, "omap_hwmod: unknown SoC type\n");
diff --git a/arch/arm/mach-omap2/omap_hwmod_43xx_data.c b/arch/arm/mach-omap2/omap_hwmod_43xx_data.c
index e2223148ba4d..17e8004fc20f 100644
--- a/arch/arm/mach-omap2/omap_hwmod_43xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_43xx_data.c
@@ -544,6 +544,44 @@ static struct omap_hwmod am43xx_hdq1w_hwmod = {
544 }, 544 },
545}; 545};
546 546
547static struct omap_hwmod_class_sysconfig am43xx_vpfe_sysc = {
548 .rev_offs = 0x0,
549 .sysc_offs = 0x104,
550 .sysc_flags = SYSC_HAS_MIDLEMODE | SYSC_HAS_SIDLEMODE,
551 .idlemodes = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
552 MSTANDBY_FORCE | MSTANDBY_SMART | MSTANDBY_NO),
553 .sysc_fields = &omap_hwmod_sysc_type2,
554};
555
556static struct omap_hwmod_class am43xx_vpfe_hwmod_class = {
557 .name = "vpfe",
558 .sysc = &am43xx_vpfe_sysc,
559};
560
561static struct omap_hwmod am43xx_vpfe0_hwmod = {
562 .name = "vpfe0",
563 .class = &am43xx_vpfe_hwmod_class,
564 .clkdm_name = "l3s_clkdm",
565 .prcm = {
566 .omap4 = {
567 .modulemode = MODULEMODE_SWCTRL,
568 .clkctrl_offs = AM43XX_CM_PER_VPFE0_CLKCTRL_OFFSET,
569 },
570 },
571};
572
573static struct omap_hwmod am43xx_vpfe1_hwmod = {
574 .name = "vpfe1",
575 .class = &am43xx_vpfe_hwmod_class,
576 .clkdm_name = "l3s_clkdm",
577 .prcm = {
578 .omap4 = {
579 .modulemode = MODULEMODE_SWCTRL,
580 .clkctrl_offs = AM43XX_CM_PER_VPFE1_CLKCTRL_OFFSET,
581 },
582 },
583};
584
547/* Interfaces */ 585/* Interfaces */
548static struct omap_hwmod_ocp_if am43xx_l3_main__l4_hs = { 586static struct omap_hwmod_ocp_if am43xx_l3_main__l4_hs = {
549 .master = &am33xx_l3_main_hwmod, 587 .master = &am33xx_l3_main_hwmod,
@@ -825,6 +863,34 @@ static struct omap_hwmod_ocp_if am43xx_l4_ls__hdq1w = {
825 .user = OCP_USER_MPU | OCP_USER_SDMA, 863 .user = OCP_USER_MPU | OCP_USER_SDMA,
826}; 864};
827 865
866static struct omap_hwmod_ocp_if am43xx_l3__vpfe0 = {
867 .master = &am43xx_vpfe0_hwmod,
868 .slave = &am33xx_l3_main_hwmod,
869 .clk = "l3_gclk",
870 .user = OCP_USER_MPU | OCP_USER_SDMA,
871};
872
873static struct omap_hwmod_ocp_if am43xx_l3__vpfe1 = {
874 .master = &am43xx_vpfe1_hwmod,
875 .slave = &am33xx_l3_main_hwmod,
876 .clk = "l3_gclk",
877 .user = OCP_USER_MPU | OCP_USER_SDMA,
878};
879
880static struct omap_hwmod_ocp_if am43xx_l4_ls__vpfe0 = {
881 .master = &am33xx_l4_ls_hwmod,
882 .slave = &am43xx_vpfe0_hwmod,
883 .clk = "l4ls_gclk",
884 .user = OCP_USER_MPU | OCP_USER_SDMA,
885};
886
887static struct omap_hwmod_ocp_if am43xx_l4_ls__vpfe1 = {
888 .master = &am33xx_l4_ls_hwmod,
889 .slave = &am43xx_vpfe1_hwmod,
890 .clk = "l4ls_gclk",
891 .user = OCP_USER_MPU | OCP_USER_SDMA,
892};
893
828static struct omap_hwmod_ocp_if *am43xx_hwmod_ocp_ifs[] __initdata = { 894static struct omap_hwmod_ocp_if *am43xx_hwmod_ocp_ifs[] __initdata = {
829 &am33xx_l4_wkup__synctimer, 895 &am33xx_l4_wkup__synctimer,
830 &am43xx_l4_ls__timer8, 896 &am43xx_l4_ls__timer8,
@@ -925,6 +991,10 @@ static struct omap_hwmod_ocp_if *am43xx_hwmod_ocp_ifs[] __initdata = {
925 &am43xx_l4_ls__dss_dispc, 991 &am43xx_l4_ls__dss_dispc,
926 &am43xx_l4_ls__dss_rfbi, 992 &am43xx_l4_ls__dss_rfbi,
927 &am43xx_l4_ls__hdq1w, 993 &am43xx_l4_ls__hdq1w,
994 &am43xx_l3__vpfe0,
995 &am43xx_l3__vpfe1,
996 &am43xx_l4_ls__vpfe0,
997 &am43xx_l4_ls__vpfe1,
928 NULL, 998 NULL,
929}; 999};
930 1000
diff --git a/arch/arm/mach-omap2/prcm43xx.h b/arch/arm/mach-omap2/prcm43xx.h
index 48df3b55057e..d0261996db6d 100644
--- a/arch/arm/mach-omap2/prcm43xx.h
+++ b/arch/arm/mach-omap2/prcm43xx.h
@@ -144,5 +144,6 @@
144#define AM43XX_CM_PER_USBPHYOCP2SCP1_CLKCTRL_OFFSET 0x05C0 144#define AM43XX_CM_PER_USBPHYOCP2SCP1_CLKCTRL_OFFSET 0x05C0
145#define AM43XX_CM_PER_DSS_CLKCTRL_OFFSET 0x0a20 145#define AM43XX_CM_PER_DSS_CLKCTRL_OFFSET 0x0a20
146#define AM43XX_CM_PER_HDQ1W_CLKCTRL_OFFSET 0x04a0 146#define AM43XX_CM_PER_HDQ1W_CLKCTRL_OFFSET 0x04a0
147 147#define AM43XX_CM_PER_VPFE0_CLKCTRL_OFFSET 0x0068
148#define AM43XX_CM_PER_VPFE1_CLKCTRL_OFFSET 0x0070
148#endif 149#endif
diff --git a/arch/arm/mach-omap2/prm-regbits-34xx.h b/arch/arm/mach-omap2/prm-regbits-34xx.h
index cbefbd7cfdb5..661d753df584 100644
--- a/arch/arm/mach-omap2/prm-regbits-34xx.h
+++ b/arch/arm/mach-omap2/prm-regbits-34xx.h
@@ -112,6 +112,7 @@
112#define OMAP3430_VC_CMD_ONLP_SHIFT 16 112#define OMAP3430_VC_CMD_ONLP_SHIFT 16
113#define OMAP3430_VC_CMD_RET_SHIFT 8 113#define OMAP3430_VC_CMD_RET_SHIFT 8
114#define OMAP3430_VC_CMD_OFF_SHIFT 0 114#define OMAP3430_VC_CMD_OFF_SHIFT 0
115#define OMAP3430_SREN_MASK (1 << 4)
115#define OMAP3430_HSEN_MASK (1 << 3) 116#define OMAP3430_HSEN_MASK (1 << 3)
116#define OMAP3430_MCODE_MASK (0x7 << 0) 117#define OMAP3430_MCODE_MASK (0x7 << 0)
117#define OMAP3430_VALID_MASK (1 << 24) 118#define OMAP3430_VALID_MASK (1 << 24)
diff --git a/arch/arm/mach-omap2/prm-regbits-44xx.h b/arch/arm/mach-omap2/prm-regbits-44xx.h
index b1c7a33e00e7..e794828dee55 100644
--- a/arch/arm/mach-omap2/prm-regbits-44xx.h
+++ b/arch/arm/mach-omap2/prm-regbits-44xx.h
@@ -35,6 +35,7 @@
35#define OMAP4430_GLOBAL_WARM_SW_RST_SHIFT 1 35#define OMAP4430_GLOBAL_WARM_SW_RST_SHIFT 1
36#define OMAP4430_GLOBAL_WUEN_MASK (1 << 16) 36#define OMAP4430_GLOBAL_WUEN_MASK (1 << 16)
37#define OMAP4430_HSMCODE_MASK (0x7 << 0) 37#define OMAP4430_HSMCODE_MASK (0x7 << 0)
38#define OMAP4430_SRMODEEN_MASK (1 << 4)
38#define OMAP4430_HSMODEEN_MASK (1 << 3) 39#define OMAP4430_HSMODEEN_MASK (1 << 3)
39#define OMAP4430_HSSCLL_SHIFT 24 40#define OMAP4430_HSSCLL_SHIFT 24
40#define OMAP4430_ICEPICK_RST_SHIFT 9 41#define OMAP4430_ICEPICK_RST_SHIFT 9
diff --git a/arch/arm/mach-omap2/prminst44xx.c b/arch/arm/mach-omap2/prminst44xx.c
index c4859c4d3646..d0b15dbafa2e 100644
--- a/arch/arm/mach-omap2/prminst44xx.c
+++ b/arch/arm/mach-omap2/prminst44xx.c
@@ -87,12 +87,6 @@ u32 omap4_prminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
87 return v; 87 return v;
88} 88}
89 89
90/*
91 * Address offset (in bytes) between the reset control and the reset
92 * status registers: 4 bytes on OMAP4
93 */
94#define OMAP4_RST_CTRL_ST_OFFSET 4
95
96/** 90/**
97 * omap4_prminst_is_hardreset_asserted - read the HW reset line state of 91 * omap4_prminst_is_hardreset_asserted - read the HW reset line state of
98 * submodules contained in the hwmod module 92 * submodules contained in the hwmod module
@@ -141,11 +135,11 @@ int omap4_prminst_assert_hardreset(u8 shift, u8 part, s16 inst,
141 * omap4_prminst_deassert_hardreset - deassert a submodule hardreset line and 135 * omap4_prminst_deassert_hardreset - deassert a submodule hardreset line and
142 * wait 136 * wait
143 * @shift: register bit shift corresponding to the reset line to deassert 137 * @shift: register bit shift corresponding to the reset line to deassert
144 * @st_shift: status bit offset, not used for OMAP4+ 138 * @st_shift: status bit offset corresponding to the reset line
145 * @part: PRM partition 139 * @part: PRM partition
146 * @inst: PRM instance offset 140 * @inst: PRM instance offset
147 * @rstctrl_offs: reset register offset 141 * @rstctrl_offs: reset register offset
148 * @st_offs: reset status register offset, not used for OMAP4+ 142 * @rstst_offs: reset status register offset
149 * 143 *
150 * Some IPs like dsp, ipu or iva contain processors that require an HW 144 * Some IPs like dsp, ipu or iva contain processors that require an HW
151 * reset line to be asserted / deasserted in order to fully enable the 145 * reset line to be asserted / deasserted in order to fully enable the
@@ -157,11 +151,11 @@ int omap4_prminst_assert_hardreset(u8 shift, u8 part, s16 inst,
157 * of reset, or -EBUSY if the submodule did not exit reset promptly. 151 * of reset, or -EBUSY if the submodule did not exit reset promptly.
158 */ 152 */
159int omap4_prminst_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 inst, 153int omap4_prminst_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 inst,
160 u16 rstctrl_offs, u16 st_offs) 154 u16 rstctrl_offs, u16 rstst_offs)
161{ 155{
162 int c; 156 int c;
163 u32 mask = 1 << shift; 157 u32 mask = 1 << shift;
164 u16 rstst_offs = rstctrl_offs + OMAP4_RST_CTRL_ST_OFFSET; 158 u32 st_mask = 1 << st_shift;
165 159
166 /* Check the current status to avoid de-asserting the line twice */ 160 /* Check the current status to avoid de-asserting the line twice */
167 if (omap4_prminst_is_hardreset_asserted(shift, part, inst, 161 if (omap4_prminst_is_hardreset_asserted(shift, part, inst,
@@ -169,13 +163,13 @@ int omap4_prminst_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 inst,
169 return -EEXIST; 163 return -EEXIST;
170 164
171 /* Clear the reset status by writing 1 to the status bit */ 165 /* Clear the reset status by writing 1 to the status bit */
172 omap4_prminst_rmw_inst_reg_bits(0xffffffff, mask, part, inst, 166 omap4_prminst_rmw_inst_reg_bits(0xffffffff, st_mask, part, inst,
173 rstst_offs); 167 rstst_offs);
174 /* de-assert the reset control line */ 168 /* de-assert the reset control line */
175 omap4_prminst_rmw_inst_reg_bits(mask, 0, part, inst, rstctrl_offs); 169 omap4_prminst_rmw_inst_reg_bits(mask, 0, part, inst, rstctrl_offs);
176 /* wait the status to be set */ 170 /* wait the status to be set */
177 omap_test_timeout(omap4_prminst_is_hardreset_asserted(shift, part, inst, 171 omap_test_timeout(omap4_prminst_is_hardreset_asserted(st_shift, part,
178 rstst_offs), 172 inst, rstst_offs),
179 MAX_MODULE_HARDRESET_WAIT, c); 173 MAX_MODULE_HARDRESET_WAIT, c);
180 174
181 return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0; 175 return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c
index cef67af9e9b8..cac46d852da1 100644
--- a/arch/arm/mach-omap2/timer.c
+++ b/arch/arm/mach-omap2/timer.c
@@ -298,14 +298,11 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
298 if (IS_ERR(src)) 298 if (IS_ERR(src))
299 return PTR_ERR(src); 299 return PTR_ERR(src);
300 300
301 if (clk_get_parent(timer->fclk) != src) { 301 r = clk_set_parent(timer->fclk, src);
302 r = clk_set_parent(timer->fclk, src); 302 if (r < 0) {
303 if (r < 0) { 303 pr_warn("%s: %s cannot set source\n", __func__, oh->name);
304 pr_warn("%s: %s cannot set source\n", __func__, 304 clk_put(src);
305 oh->name); 305 return r;
306 clk_put(src);
307 return r;
308 }
309 } 306 }
310 307
311 clk_put(src); 308 clk_put(src);
diff --git a/arch/arm/mach-omap2/vc.c b/arch/arm/mach-omap2/vc.c
index be9ef834fa81..076fd20d7e5a 100644
--- a/arch/arm/mach-omap2/vc.c
+++ b/arch/arm/mach-omap2/vc.c
@@ -316,7 +316,8 @@ static void __init omap3_vc_init_pmic_signaling(struct voltagedomain *voltdm)
316 * idle. And we can also scale voltages to zero for off-idle. 316 * idle. And we can also scale voltages to zero for off-idle.
317 * Note that no actual voltage scaling during off-idle will 317 * Note that no actual voltage scaling during off-idle will
318 * happen unless the board specific twl4030 PMIC scripts are 318 * happen unless the board specific twl4030 PMIC scripts are
319 * loaded. 319 * loaded. See also omap_vc_i2c_init for comments regarding
320 * erratum i531.
320 */ 321 */
321 val = voltdm->read(OMAP3_PRM_VOLTCTRL_OFFSET); 322 val = voltdm->read(OMAP3_PRM_VOLTCTRL_OFFSET);
322 if (!(val & OMAP3430_PRM_VOLTCTRL_SEL_OFF)) { 323 if (!(val & OMAP3430_PRM_VOLTCTRL_SEL_OFF)) {
@@ -704,9 +705,16 @@ static void __init omap_vc_i2c_init(struct voltagedomain *voltdm)
704 return; 705 return;
705 } 706 }
706 707
708 /*
709 * Note that for omap3 OMAP3430_SREN_MASK clears SREN to work around
710 * erratum i531 "Extra Power Consumed When Repeated Start Operation
711 * Mode Is Enabled on I2C Interface Dedicated for Smart Reflex (I2C4)".
712 * Otherwise I2C4 eventually leads into about 23mW extra power being
713 * consumed even during off idle using VMODE.
714 */
707 i2c_high_speed = voltdm->pmic->i2c_high_speed; 715 i2c_high_speed = voltdm->pmic->i2c_high_speed;
708 if (i2c_high_speed) 716 if (i2c_high_speed)
709 voltdm->rmw(vc->common->i2c_cfg_hsen_mask, 717 voltdm->rmw(vc->common->i2c_cfg_clear_mask,
710 vc->common->i2c_cfg_hsen_mask, 718 vc->common->i2c_cfg_hsen_mask,
711 vc->common->i2c_cfg_reg); 719 vc->common->i2c_cfg_reg);
712 720
diff --git a/arch/arm/mach-omap2/vc.h b/arch/arm/mach-omap2/vc.h
index cdbdd78e755e..89b83b7ff3ec 100644
--- a/arch/arm/mach-omap2/vc.h
+++ b/arch/arm/mach-omap2/vc.h
@@ -34,6 +34,7 @@ struct voltagedomain;
34 * @cmd_ret_shift: RET field shift in PRM_VC_CMD_VAL_* register 34 * @cmd_ret_shift: RET field shift in PRM_VC_CMD_VAL_* register
35 * @cmd_off_shift: OFF field shift in PRM_VC_CMD_VAL_* register 35 * @cmd_off_shift: OFF field shift in PRM_VC_CMD_VAL_* register
36 * @i2c_cfg_reg: I2C configuration register offset 36 * @i2c_cfg_reg: I2C configuration register offset
37 * @i2c_cfg_clear_mask: high-speed mode bit clear mask in I2C config register
37 * @i2c_cfg_hsen_mask: high-speed mode bit field mask in I2C config register 38 * @i2c_cfg_hsen_mask: high-speed mode bit field mask in I2C config register
38 * @i2c_mcode_mask: MCODE field mask for I2C config register 39 * @i2c_mcode_mask: MCODE field mask for I2C config register
39 * 40 *
@@ -52,6 +53,7 @@ struct omap_vc_common {
52 u8 cmd_ret_shift; 53 u8 cmd_ret_shift;
53 u8 cmd_off_shift; 54 u8 cmd_off_shift;
54 u8 i2c_cfg_reg; 55 u8 i2c_cfg_reg;
56 u8 i2c_cfg_clear_mask;
55 u8 i2c_cfg_hsen_mask; 57 u8 i2c_cfg_hsen_mask;
56 u8 i2c_mcode_mask; 58 u8 i2c_mcode_mask;
57}; 59};
diff --git a/arch/arm/mach-omap2/vc3xxx_data.c b/arch/arm/mach-omap2/vc3xxx_data.c
index 75bc4aa22b3a..71d74c9172c1 100644
--- a/arch/arm/mach-omap2/vc3xxx_data.c
+++ b/arch/arm/mach-omap2/vc3xxx_data.c
@@ -40,6 +40,7 @@ static struct omap_vc_common omap3_vc_common = {
40 .cmd_onlp_shift = OMAP3430_VC_CMD_ONLP_SHIFT, 40 .cmd_onlp_shift = OMAP3430_VC_CMD_ONLP_SHIFT,
41 .cmd_ret_shift = OMAP3430_VC_CMD_RET_SHIFT, 41 .cmd_ret_shift = OMAP3430_VC_CMD_RET_SHIFT,
42 .cmd_off_shift = OMAP3430_VC_CMD_OFF_SHIFT, 42 .cmd_off_shift = OMAP3430_VC_CMD_OFF_SHIFT,
43 .i2c_cfg_clear_mask = OMAP3430_SREN_MASK | OMAP3430_HSEN_MASK,
43 .i2c_cfg_hsen_mask = OMAP3430_HSEN_MASK, 44 .i2c_cfg_hsen_mask = OMAP3430_HSEN_MASK,
44 .i2c_cfg_reg = OMAP3_PRM_VC_I2C_CFG_OFFSET, 45 .i2c_cfg_reg = OMAP3_PRM_VC_I2C_CFG_OFFSET,
45 .i2c_mcode_mask = OMAP3430_MCODE_MASK, 46 .i2c_mcode_mask = OMAP3430_MCODE_MASK,
diff --git a/arch/arm/mach-omap2/vc44xx_data.c b/arch/arm/mach-omap2/vc44xx_data.c
index 085e5d6a04fd..2abd5fa8a697 100644
--- a/arch/arm/mach-omap2/vc44xx_data.c
+++ b/arch/arm/mach-omap2/vc44xx_data.c
@@ -42,6 +42,7 @@ static const struct omap_vc_common omap4_vc_common = {
42 .cmd_ret_shift = OMAP4430_RET_SHIFT, 42 .cmd_ret_shift = OMAP4430_RET_SHIFT,
43 .cmd_off_shift = OMAP4430_OFF_SHIFT, 43 .cmd_off_shift = OMAP4430_OFF_SHIFT,
44 .i2c_cfg_reg = OMAP4_PRM_VC_CFG_I2C_MODE_OFFSET, 44 .i2c_cfg_reg = OMAP4_PRM_VC_CFG_I2C_MODE_OFFSET,
45 .i2c_cfg_clear_mask = OMAP4430_SRMODEEN_MASK | OMAP4430_HSMODEEN_MASK,
45 .i2c_cfg_hsen_mask = OMAP4430_HSMODEEN_MASK, 46 .i2c_cfg_hsen_mask = OMAP4430_HSMODEEN_MASK,
46 .i2c_mcode_mask = OMAP4430_HSMCODE_MASK, 47 .i2c_mcode_mask = OMAP4430_HSMCODE_MASK,
47}; 48};
diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index 8896e71586f5..f09683687963 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -691,4 +691,13 @@ config SHARPSL_PM_MAX1111
691config PXA310_ULPI 691config PXA310_ULPI
692 bool 692 bool
693 693
694config PXA_SYSTEMS_CPLDS
695 tristate "Motherboard cplds"
696 default ARCH_LUBBOCK || MACH_MAINSTONE
697 help
698 This driver supports the Lubbock and Mainstone multifunction chip
699 found on the pxa25x development platform system (Lubbock) and pxa27x
700 development platform system (Mainstone). This IO board supports the
701 interrupts handling, ethernet controller, flash chips, etc ...
702
694endif 703endif
diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile
index eb0bf7678a99..4087d334ecdf 100644
--- a/arch/arm/mach-pxa/Makefile
+++ b/arch/arm/mach-pxa/Makefile
@@ -90,4 +90,5 @@ obj-$(CONFIG_MACH_RAUMFELD_CONNECTOR) += raumfeld.o
90obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o 90obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o
91obj-$(CONFIG_MACH_ZIPIT2) += z2.o 91obj-$(CONFIG_MACH_ZIPIT2) += z2.o
92 92
93obj-$(CONFIG_PXA_SYSTEMS_CPLDS) += pxa_cplds_irqs.o
93obj-$(CONFIG_TOSA_BT) += tosa-bt.o 94obj-$(CONFIG_TOSA_BT) += tosa-bt.o
diff --git a/arch/arm/mach-pxa/include/mach/lubbock.h b/arch/arm/mach-pxa/include/mach/lubbock.h
index 958cd6af9384..1eecf794acd2 100644
--- a/arch/arm/mach-pxa/include/mach/lubbock.h
+++ b/arch/arm/mach-pxa/include/mach/lubbock.h
@@ -37,7 +37,9 @@
37#define LUB_GP __LUB_REG(LUBBOCK_FPGA_PHYS + 0x100) 37#define LUB_GP __LUB_REG(LUBBOCK_FPGA_PHYS + 0x100)
38 38
39/* Board specific IRQs */ 39/* Board specific IRQs */
40#define LUBBOCK_IRQ(x) (IRQ_BOARD_START + (x)) 40#define LUBBOCK_NR_IRQS IRQ_BOARD_START
41
42#define LUBBOCK_IRQ(x) (LUBBOCK_NR_IRQS + (x))
41#define LUBBOCK_SD_IRQ LUBBOCK_IRQ(0) 43#define LUBBOCK_SD_IRQ LUBBOCK_IRQ(0)
42#define LUBBOCK_SA1111_IRQ LUBBOCK_IRQ(1) 44#define LUBBOCK_SA1111_IRQ LUBBOCK_IRQ(1)
43#define LUBBOCK_USB_IRQ LUBBOCK_IRQ(2) /* usb connect */ 45#define LUBBOCK_USB_IRQ LUBBOCK_IRQ(2) /* usb connect */
@@ -47,8 +49,7 @@
47#define LUBBOCK_USB_DISC_IRQ LUBBOCK_IRQ(6) /* usb disconnect */ 49#define LUBBOCK_USB_DISC_IRQ LUBBOCK_IRQ(6) /* usb disconnect */
48#define LUBBOCK_LAST_IRQ LUBBOCK_IRQ(6) 50#define LUBBOCK_LAST_IRQ LUBBOCK_IRQ(6)
49 51
50#define LUBBOCK_SA1111_IRQ_BASE (IRQ_BOARD_START + 16) 52#define LUBBOCK_SA1111_IRQ_BASE (LUBBOCK_NR_IRQS + 32)
51#define LUBBOCK_NR_IRQS (IRQ_BOARD_START + 16 + 55)
52 53
53#ifndef __ASSEMBLY__ 54#ifndef __ASSEMBLY__
54extern void lubbock_set_misc_wr(unsigned int mask, unsigned int set); 55extern void lubbock_set_misc_wr(unsigned int mask, unsigned int set);
diff --git a/arch/arm/mach-pxa/include/mach/mainstone.h b/arch/arm/mach-pxa/include/mach/mainstone.h
index 1bfc4e822a41..e82a7d31104e 100644
--- a/arch/arm/mach-pxa/include/mach/mainstone.h
+++ b/arch/arm/mach-pxa/include/mach/mainstone.h
@@ -120,7 +120,9 @@
120#define MST_PCMCIA_PWR_VCC_50 0x4 /* voltage VCC = 5.0V */ 120#define MST_PCMCIA_PWR_VCC_50 0x4 /* voltage VCC = 5.0V */
121 121
122/* board specific IRQs */ 122/* board specific IRQs */
123#define MAINSTONE_IRQ(x) (IRQ_BOARD_START + (x)) 123#define MAINSTONE_NR_IRQS IRQ_BOARD_START
124
125#define MAINSTONE_IRQ(x) (MAINSTONE_NR_IRQS + (x))
124#define MAINSTONE_MMC_IRQ MAINSTONE_IRQ(0) 126#define MAINSTONE_MMC_IRQ MAINSTONE_IRQ(0)
125#define MAINSTONE_USIM_IRQ MAINSTONE_IRQ(1) 127#define MAINSTONE_USIM_IRQ MAINSTONE_IRQ(1)
126#define MAINSTONE_USBC_IRQ MAINSTONE_IRQ(2) 128#define MAINSTONE_USBC_IRQ MAINSTONE_IRQ(2)
@@ -136,6 +138,4 @@
136#define MAINSTONE_S1_STSCHG_IRQ MAINSTONE_IRQ(14) 138#define MAINSTONE_S1_STSCHG_IRQ MAINSTONE_IRQ(14)
137#define MAINSTONE_S1_IRQ MAINSTONE_IRQ(15) 139#define MAINSTONE_S1_IRQ MAINSTONE_IRQ(15)
138 140
139#define MAINSTONE_NR_IRQS (IRQ_BOARD_START + 16)
140
141#endif 141#endif
diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
index d8a1be619f21..4ac9ab80d24b 100644
--- a/arch/arm/mach-pxa/lubbock.c
+++ b/arch/arm/mach-pxa/lubbock.c
@@ -12,6 +12,7 @@
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13 */ 13 */
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/gpio/machine.h>
15#include <linux/module.h> 16#include <linux/module.h>
16#include <linux/kernel.h> 17#include <linux/kernel.h>
17#include <linux/init.h> 18#include <linux/init.h>
@@ -123,84 +124,6 @@ void lubbock_set_misc_wr(unsigned int mask, unsigned int set)
123} 124}
124EXPORT_SYMBOL(lubbock_set_misc_wr); 125EXPORT_SYMBOL(lubbock_set_misc_wr);
125 126
126static unsigned long lubbock_irq_enabled;
127
128static void lubbock_mask_irq(struct irq_data *d)
129{
130 int lubbock_irq = (d->irq - LUBBOCK_IRQ(0));
131 LUB_IRQ_MASK_EN = (lubbock_irq_enabled &= ~(1 << lubbock_irq));
132}
133
134static void lubbock_unmask_irq(struct irq_data *d)
135{
136 int lubbock_irq = (d->irq - LUBBOCK_IRQ(0));
137 /* the irq can be acknowledged only if deasserted, so it's done here */
138 LUB_IRQ_SET_CLR &= ~(1 << lubbock_irq);
139 LUB_IRQ_MASK_EN = (lubbock_irq_enabled |= (1 << lubbock_irq));
140}
141
142static struct irq_chip lubbock_irq_chip = {
143 .name = "FPGA",
144 .irq_ack = lubbock_mask_irq,
145 .irq_mask = lubbock_mask_irq,
146 .irq_unmask = lubbock_unmask_irq,
147};
148
149static void lubbock_irq_handler(unsigned int irq, struct irq_desc *desc)
150{
151 unsigned long pending = LUB_IRQ_SET_CLR & lubbock_irq_enabled;
152 do {
153 /* clear our parent irq */
154 desc->irq_data.chip->irq_ack(&desc->irq_data);
155 if (likely(pending)) {
156 irq = LUBBOCK_IRQ(0) + __ffs(pending);
157 generic_handle_irq(irq);
158 }
159 pending = LUB_IRQ_SET_CLR & lubbock_irq_enabled;
160 } while (pending);
161}
162
163static void __init lubbock_init_irq(void)
164{
165 int irq;
166
167 pxa25x_init_irq();
168
169 /* setup extra lubbock irqs */
170 for (irq = LUBBOCK_IRQ(0); irq <= LUBBOCK_LAST_IRQ; irq++) {
171 irq_set_chip_and_handler(irq, &lubbock_irq_chip,
172 handle_level_irq);
173 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
174 }
175
176 irq_set_chained_handler(PXA_GPIO_TO_IRQ(0), lubbock_irq_handler);
177 irq_set_irq_type(PXA_GPIO_TO_IRQ(0), IRQ_TYPE_EDGE_FALLING);
178}
179
180#ifdef CONFIG_PM
181
182static void lubbock_irq_resume(void)
183{
184 LUB_IRQ_MASK_EN = lubbock_irq_enabled;
185}
186
187static struct syscore_ops lubbock_irq_syscore_ops = {
188 .resume = lubbock_irq_resume,
189};
190
191static int __init lubbock_irq_device_init(void)
192{
193 if (machine_is_lubbock()) {
194 register_syscore_ops(&lubbock_irq_syscore_ops);
195 return 0;
196 }
197 return -ENODEV;
198}
199
200device_initcall(lubbock_irq_device_init);
201
202#endif
203
204static int lubbock_udc_is_connected(void) 127static int lubbock_udc_is_connected(void)
205{ 128{
206 return (LUB_MISC_RD & (1 << 9)) == 0; 129 return (LUB_MISC_RD & (1 << 9)) == 0;
@@ -383,11 +306,38 @@ static struct platform_device lubbock_flash_device[2] = {
383 }, 306 },
384}; 307};
385 308
309static struct resource lubbock_cplds_resources[] = {
310 [0] = {
311 .start = LUBBOCK_FPGA_PHYS + 0xc0,
312 .end = LUBBOCK_FPGA_PHYS + 0xe0 - 1,
313 .flags = IORESOURCE_MEM,
314 },
315 [1] = {
316 .start = PXA_GPIO_TO_IRQ(0),
317 .end = PXA_GPIO_TO_IRQ(0),
318 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
319 },
320 [2] = {
321 .start = LUBBOCK_IRQ(0),
322 .end = LUBBOCK_IRQ(6),
323 .flags = IORESOURCE_IRQ,
324 },
325};
326
327static struct platform_device lubbock_cplds_device = {
328 .name = "pxa_cplds_irqs",
329 .id = -1,
330 .resource = &lubbock_cplds_resources[0],
331 .num_resources = 3,
332};
333
334
386static struct platform_device *devices[] __initdata = { 335static struct platform_device *devices[] __initdata = {
387 &sa1111_device, 336 &sa1111_device,
388 &smc91x_device, 337 &smc91x_device,
389 &lubbock_flash_device[0], 338 &lubbock_flash_device[0],
390 &lubbock_flash_device[1], 339 &lubbock_flash_device[1],
340 &lubbock_cplds_device,
391}; 341};
392 342
393static struct pxafb_mode_info sharp_lm8v31_mode = { 343static struct pxafb_mode_info sharp_lm8v31_mode = {
@@ -648,7 +598,7 @@ MACHINE_START(LUBBOCK, "Intel DBPXA250 Development Platform (aka Lubbock)")
648 /* Maintainer: MontaVista Software Inc. */ 598 /* Maintainer: MontaVista Software Inc. */
649 .map_io = lubbock_map_io, 599 .map_io = lubbock_map_io,
650 .nr_irqs = LUBBOCK_NR_IRQS, 600 .nr_irqs = LUBBOCK_NR_IRQS,
651 .init_irq = lubbock_init_irq, 601 .init_irq = pxa25x_init_irq,
652 .handle_irq = pxa25x_handle_irq, 602 .handle_irq = pxa25x_handle_irq,
653 .init_time = pxa_timer_init, 603 .init_time = pxa_timer_init,
654 .init_machine = lubbock_init, 604 .init_machine = lubbock_init,
diff --git a/arch/arm/mach-pxa/mainstone.c b/arch/arm/mach-pxa/mainstone.c
index 78b84c0dfc79..2c0658cf6be2 100644
--- a/arch/arm/mach-pxa/mainstone.c
+++ b/arch/arm/mach-pxa/mainstone.c
@@ -13,6 +13,7 @@
13 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
14 */ 14 */
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/gpio/machine.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/platform_device.h> 18#include <linux/platform_device.h>
18#include <linux/syscore_ops.h> 19#include <linux/syscore_ops.h>
@@ -122,92 +123,6 @@ static unsigned long mainstone_pin_config[] = {
122 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH, 123 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
123}; 124};
124 125
125static unsigned long mainstone_irq_enabled;
126
127static void mainstone_mask_irq(struct irq_data *d)
128{
129 int mainstone_irq = (d->irq - MAINSTONE_IRQ(0));
130 MST_INTMSKENA = (mainstone_irq_enabled &= ~(1 << mainstone_irq));
131}
132
133static void mainstone_unmask_irq(struct irq_data *d)
134{
135 int mainstone_irq = (d->irq - MAINSTONE_IRQ(0));
136 /* the irq can be acknowledged only if deasserted, so it's done here */
137 MST_INTSETCLR &= ~(1 << mainstone_irq);
138 MST_INTMSKENA = (mainstone_irq_enabled |= (1 << mainstone_irq));
139}
140
141static struct irq_chip mainstone_irq_chip = {
142 .name = "FPGA",
143 .irq_ack = mainstone_mask_irq,
144 .irq_mask = mainstone_mask_irq,
145 .irq_unmask = mainstone_unmask_irq,
146};
147
148static void mainstone_irq_handler(unsigned int irq, struct irq_desc *desc)
149{
150 unsigned long pending = MST_INTSETCLR & mainstone_irq_enabled;
151 do {
152 /* clear useless edge notification */
153 desc->irq_data.chip->irq_ack(&desc->irq_data);
154 if (likely(pending)) {
155 irq = MAINSTONE_IRQ(0) + __ffs(pending);
156 generic_handle_irq(irq);
157 }
158 pending = MST_INTSETCLR & mainstone_irq_enabled;
159 } while (pending);
160}
161
162static void __init mainstone_init_irq(void)
163{
164 int irq;
165
166 pxa27x_init_irq();
167
168 /* setup extra Mainstone irqs */
169 for(irq = MAINSTONE_IRQ(0); irq <= MAINSTONE_IRQ(15); irq++) {
170 irq_set_chip_and_handler(irq, &mainstone_irq_chip,
171 handle_level_irq);
172 if (irq == MAINSTONE_IRQ(10) || irq == MAINSTONE_IRQ(14))
173 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_NOAUTOEN);
174 else
175 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
176 }
177 set_irq_flags(MAINSTONE_IRQ(8), 0);
178 set_irq_flags(MAINSTONE_IRQ(12), 0);
179
180 MST_INTMSKENA = 0;
181 MST_INTSETCLR = 0;
182
183 irq_set_chained_handler(PXA_GPIO_TO_IRQ(0), mainstone_irq_handler);
184 irq_set_irq_type(PXA_GPIO_TO_IRQ(0), IRQ_TYPE_EDGE_FALLING);
185}
186
187#ifdef CONFIG_PM
188
189static void mainstone_irq_resume(void)
190{
191 MST_INTMSKENA = mainstone_irq_enabled;
192}
193
194static struct syscore_ops mainstone_irq_syscore_ops = {
195 .resume = mainstone_irq_resume,
196};
197
198static int __init mainstone_irq_device_init(void)
199{
200 if (machine_is_mainstone())
201 register_syscore_ops(&mainstone_irq_syscore_ops);
202
203 return 0;
204}
205
206device_initcall(mainstone_irq_device_init);
207
208#endif
209
210
211static struct resource smc91x_resources[] = { 126static struct resource smc91x_resources[] = {
212 [0] = { 127 [0] = {
213 .start = (MST_ETH_PHYS + 0x300), 128 .start = (MST_ETH_PHYS + 0x300),
@@ -487,11 +402,37 @@ static struct platform_device mst_gpio_keys_device = {
487 }, 402 },
488}; 403};
489 404
405static struct resource mst_cplds_resources[] = {
406 [0] = {
407 .start = MST_FPGA_PHYS + 0xc0,
408 .end = MST_FPGA_PHYS + 0xe0 - 1,
409 .flags = IORESOURCE_MEM,
410 },
411 [1] = {
412 .start = PXA_GPIO_TO_IRQ(0),
413 .end = PXA_GPIO_TO_IRQ(0),
414 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
415 },
416 [2] = {
417 .start = MAINSTONE_IRQ(0),
418 .end = MAINSTONE_IRQ(15),
419 .flags = IORESOURCE_IRQ,
420 },
421};
422
423static struct platform_device mst_cplds_device = {
424 .name = "pxa_cplds_irqs",
425 .id = -1,
426 .resource = &mst_cplds_resources[0],
427 .num_resources = 3,
428};
429
490static struct platform_device *platform_devices[] __initdata = { 430static struct platform_device *platform_devices[] __initdata = {
491 &smc91x_device, 431 &smc91x_device,
492 &mst_flash_device[0], 432 &mst_flash_device[0],
493 &mst_flash_device[1], 433 &mst_flash_device[1],
494 &mst_gpio_keys_device, 434 &mst_gpio_keys_device,
435 &mst_cplds_device,
495}; 436};
496 437
497static struct pxaohci_platform_data mainstone_ohci_platform_data = { 438static struct pxaohci_platform_data mainstone_ohci_platform_data = {
@@ -718,7 +659,7 @@ MACHINE_START(MAINSTONE, "Intel HCDDBBVA0 Development Platform (aka Mainstone)")
718 .atag_offset = 0x100, /* BLOB boot parameter setting */ 659 .atag_offset = 0x100, /* BLOB boot parameter setting */
719 .map_io = mainstone_map_io, 660 .map_io = mainstone_map_io,
720 .nr_irqs = MAINSTONE_NR_IRQS, 661 .nr_irqs = MAINSTONE_NR_IRQS,
721 .init_irq = mainstone_init_irq, 662 .init_irq = pxa27x_init_irq,
722 .handle_irq = pxa27x_handle_irq, 663 .handle_irq = pxa27x_handle_irq,
723 .init_time = pxa_timer_init, 664 .init_time = pxa_timer_init,
724 .init_machine = mainstone_init, 665 .init_machine = mainstone_init,
diff --git a/arch/arm/mach-pxa/pxa_cplds_irqs.c b/arch/arm/mach-pxa/pxa_cplds_irqs.c
new file mode 100644
index 000000000000..2385052b0ce1
--- /dev/null
+++ b/arch/arm/mach-pxa/pxa_cplds_irqs.c
@@ -0,0 +1,200 @@
1/*
2 * Intel Reference Systems cplds
3 *
4 * Copyright (C) 2014 Robert Jarzmik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Cplds motherboard driver, supporting lubbock and mainstone SoC board.
12 */
13
14#include <linux/bitops.h>
15#include <linux/gpio.h>
16#include <linux/gpio/consumer.h>
17#include <linux/interrupt.h>
18#include <linux/io.h>
19#include <linux/irq.h>
20#include <linux/irqdomain.h>
21#include <linux/mfd/core.h>
22#include <linux/module.h>
23#include <linux/of_platform.h>
24
25#define FPGA_IRQ_MASK_EN 0x0
26#define FPGA_IRQ_SET_CLR 0x10
27
28#define CPLDS_NB_IRQ 32
29
30struct cplds {
31 void __iomem *base;
32 int irq;
33 unsigned int irq_mask;
34 struct gpio_desc *gpio0;
35 struct irq_domain *irqdomain;
36};
37
38static irqreturn_t cplds_irq_handler(int in_irq, void *d)
39{
40 struct cplds *fpga = d;
41 unsigned long pending;
42 unsigned int bit;
43
44 pending = readl(fpga->base + FPGA_IRQ_SET_CLR) & fpga->irq_mask;
45 for_each_set_bit(bit, &pending, CPLDS_NB_IRQ)
46 generic_handle_irq(irq_find_mapping(fpga->irqdomain, bit));
47
48 return IRQ_HANDLED;
49}
50
51static void cplds_irq_mask_ack(struct irq_data *d)
52{
53 struct cplds *fpga = irq_data_get_irq_chip_data(d);
54 unsigned int cplds_irq = irqd_to_hwirq(d);
55 unsigned int set, bit = BIT(cplds_irq);
56
57 fpga->irq_mask &= ~bit;
58 writel(fpga->irq_mask, fpga->base + FPGA_IRQ_MASK_EN);
59 set = readl(fpga->base + FPGA_IRQ_SET_CLR);
60 writel(set & ~bit, fpga->base + FPGA_IRQ_SET_CLR);
61}
62
63static void cplds_irq_unmask(struct irq_data *d)
64{
65 struct cplds *fpga = irq_data_get_irq_chip_data(d);
66 unsigned int cplds_irq = irqd_to_hwirq(d);
67 unsigned int bit = BIT(cplds_irq);
68
69 fpga->irq_mask |= bit;
70 writel(fpga->irq_mask, fpga->base + FPGA_IRQ_MASK_EN);
71}
72
73static struct irq_chip cplds_irq_chip = {
74 .name = "pxa_cplds",
75 .irq_mask_ack = cplds_irq_mask_ack,
76 .irq_unmask = cplds_irq_unmask,
77 .flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SKIP_SET_WAKE,
78};
79
80static int cplds_irq_domain_map(struct irq_domain *d, unsigned int irq,
81 irq_hw_number_t hwirq)
82{
83 struct cplds *fpga = d->host_data;
84
85 irq_set_chip_and_handler(irq, &cplds_irq_chip, handle_level_irq);
86 irq_set_chip_data(irq, fpga);
87
88 return 0;
89}
90
91static const struct irq_domain_ops cplds_irq_domain_ops = {
92 .xlate = irq_domain_xlate_twocell,
93 .map = cplds_irq_domain_map,
94};
95
96static int cplds_resume(struct platform_device *pdev)
97{
98 struct cplds *fpga = platform_get_drvdata(pdev);
99
100 writel(fpga->irq_mask, fpga->base + FPGA_IRQ_MASK_EN);
101
102 return 0;
103}
104
105static int cplds_probe(struct platform_device *pdev)
106{
107 struct resource *res;
108 struct cplds *fpga;
109 int ret;
110 int base_irq;
111 unsigned long irqflags = 0;
112
113 fpga = devm_kzalloc(&pdev->dev, sizeof(*fpga), GFP_KERNEL);
114 if (!fpga)
115 return -ENOMEM;
116
117 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
118 if (res) {
119 fpga->irq = (unsigned int)res->start;
120 irqflags = res->flags;
121 }
122 if (!fpga->irq)
123 return -ENODEV;
124
125 base_irq = platform_get_irq(pdev, 1);
126 if (base_irq < 0)
127 base_irq = 0;
128
129 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
130 fpga->base = devm_ioremap_resource(&pdev->dev, res);
131 if (IS_ERR(fpga->base))
132 return PTR_ERR(fpga->base);
133
134 platform_set_drvdata(pdev, fpga);
135
136 writel(fpga->irq_mask, fpga->base + FPGA_IRQ_MASK_EN);
137 writel(0, fpga->base + FPGA_IRQ_SET_CLR);
138
139 ret = devm_request_irq(&pdev->dev, fpga->irq, cplds_irq_handler,
140 irqflags, dev_name(&pdev->dev), fpga);
141 if (ret == -ENOSYS)
142 return -EPROBE_DEFER;
143
144 if (ret) {
145 dev_err(&pdev->dev, "couldn't request main irq%d: %d\n",
146 fpga->irq, ret);
147 return ret;
148 }
149
150 irq_set_irq_wake(fpga->irq, 1);
151 fpga->irqdomain = irq_domain_add_linear(pdev->dev.of_node,
152 CPLDS_NB_IRQ,
153 &cplds_irq_domain_ops, fpga);
154 if (!fpga->irqdomain)
155 return -ENODEV;
156
157 if (base_irq) {
158 ret = irq_create_strict_mappings(fpga->irqdomain, base_irq, 0,
159 CPLDS_NB_IRQ);
160 if (ret) {
161 dev_err(&pdev->dev, "couldn't create the irq mapping %d..%d\n",
162 base_irq, base_irq + CPLDS_NB_IRQ);
163 return ret;
164 }
165 }
166
167 return 0;
168}
169
170static int cplds_remove(struct platform_device *pdev)
171{
172 struct cplds *fpga = platform_get_drvdata(pdev);
173
174 irq_set_chip_and_handler(fpga->irq, NULL, NULL);
175
176 return 0;
177}
178
179static const struct of_device_id cplds_id_table[] = {
180 { .compatible = "intel,lubbock-cplds-irqs", },
181 { .compatible = "intel,mainstone-cplds-irqs", },
182 { }
183};
184MODULE_DEVICE_TABLE(of, cplds_id_table);
185
186static struct platform_driver cplds_driver = {
187 .driver = {
188 .name = "pxa_cplds_irqs",
189 .of_match_table = of_match_ptr(cplds_id_table),
190 },
191 .probe = cplds_probe,
192 .remove = cplds_remove,
193 .resume = cplds_resume,
194};
195
196module_platform_driver(cplds_driver);
197
198MODULE_DESCRIPTION("PXA Cplds interrupts driver");
199MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
200MODULE_LICENSE("GPL");
diff --git a/arch/arm/mach-rockchip/pm.c b/arch/arm/mach-rockchip/pm.c
index b07d88602073..b0dcbe28f78c 100644
--- a/arch/arm/mach-rockchip/pm.c
+++ b/arch/arm/mach-rockchip/pm.c
@@ -83,6 +83,13 @@ static void rk3288_slp_mode_set(int level)
83 SGRF_PCLK_WDT_GATE | SGRF_FAST_BOOT_EN 83 SGRF_PCLK_WDT_GATE | SGRF_FAST_BOOT_EN
84 | SGRF_PCLK_WDT_GATE_WRITE | SGRF_FAST_BOOT_EN_WRITE); 84 | SGRF_PCLK_WDT_GATE_WRITE | SGRF_FAST_BOOT_EN_WRITE);
85 85
86 /*
87 * The dapswjdp can not auto reset before resume, that cause it may
88 * access some illegal address during resume. Let's disable it before
89 * suspend, and the MASKROM will enable it back.
90 */
91 regmap_write(sgrf_regmap, RK3288_SGRF_CPU_CON0, SGRF_DAPDEVICEEN_WRITE);
92
86 /* booting address of resuming system is from this register value */ 93 /* booting address of resuming system is from this register value */
87 regmap_write(sgrf_regmap, RK3288_SGRF_FAST_BOOT_ADDR, 94 regmap_write(sgrf_regmap, RK3288_SGRF_FAST_BOOT_ADDR,
88 rk3288_bootram_phy); 95 rk3288_bootram_phy);
diff --git a/arch/arm/mach-rockchip/pm.h b/arch/arm/mach-rockchip/pm.h
index 03ff31d8282d..3e8d39c0c3d5 100644
--- a/arch/arm/mach-rockchip/pm.h
+++ b/arch/arm/mach-rockchip/pm.h
@@ -55,6 +55,10 @@ static inline void rockchip_suspend_init(void)
55#define SGRF_FAST_BOOT_EN BIT(8) 55#define SGRF_FAST_BOOT_EN BIT(8)
56#define SGRF_FAST_BOOT_EN_WRITE BIT(24) 56#define SGRF_FAST_BOOT_EN_WRITE BIT(24)
57 57
58#define RK3288_SGRF_CPU_CON0 (0x40)
59#define SGRF_DAPDEVICEEN BIT(0)
60#define SGRF_DAPDEVICEEN_WRITE BIT(16)
61
58#define RK3288_CRU_MODE_CON 0x50 62#define RK3288_CRU_MODE_CON 0x50
59#define RK3288_CRU_SEL0_CON 0x60 63#define RK3288_CRU_SEL0_CON 0x60
60#define RK3288_CRU_SEL1_CON 0x64 64#define RK3288_CRU_SEL1_CON 0x64
diff --git a/arch/arm/mach-rockchip/rockchip.c b/arch/arm/mach-rockchip/rockchip.c
index d360ec044b66..b6cf3b449428 100644
--- a/arch/arm/mach-rockchip/rockchip.c
+++ b/arch/arm/mach-rockchip/rockchip.c
@@ -30,11 +30,30 @@
30#include "pm.h" 30#include "pm.h"
31 31
32#define RK3288_GRF_SOC_CON0 0x244 32#define RK3288_GRF_SOC_CON0 0x244
33#define RK3288_TIMER6_7_PHYS 0xff810000
33 34
34static void __init rockchip_timer_init(void) 35static void __init rockchip_timer_init(void)
35{ 36{
36 if (of_machine_is_compatible("rockchip,rk3288")) { 37 if (of_machine_is_compatible("rockchip,rk3288")) {
37 struct regmap *grf; 38 struct regmap *grf;
39 void __iomem *reg_base;
40
41 /*
42 * Most/all uboot versions for rk3288 don't enable timer7
43 * which is needed for the architected timer to work.
44 * So make sure it is running during early boot.
45 */
46 reg_base = ioremap(RK3288_TIMER6_7_PHYS, SZ_16K);
47 if (reg_base) {
48 writel(0, reg_base + 0x30);
49 writel(0xffffffff, reg_base + 0x20);
50 writel(0xffffffff, reg_base + 0x24);
51 writel(1, reg_base + 0x30);
52 dsb();
53 iounmap(reg_base);
54 } else {
55 pr_err("rockchip: could not map timer7 registers\n");
56 }
38 57
39 /* 58 /*
40 * Disable auto jtag/sdmmc switching that causes issues 59 * Disable auto jtag/sdmmc switching that causes issues
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 09c5fe3d30c2..7e7583ddd607 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1878,7 +1878,7 @@ struct dma_map_ops iommu_coherent_ops = {
1878 * arm_iommu_attach_device function. 1878 * arm_iommu_attach_device function.
1879 */ 1879 */
1880struct dma_iommu_mapping * 1880struct dma_iommu_mapping *
1881arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) 1881arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size)
1882{ 1882{
1883 unsigned int bits = size >> PAGE_SHIFT; 1883 unsigned int bits = size >> PAGE_SHIFT;
1884 unsigned int bitmap_size = BITS_TO_LONGS(bits) * sizeof(long); 1884 unsigned int bitmap_size = BITS_TO_LONGS(bits) * sizeof(long);
@@ -1886,6 +1886,10 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size)
1886 int extensions = 1; 1886 int extensions = 1;
1887 int err = -ENOMEM; 1887 int err = -ENOMEM;
1888 1888
1889 /* currently only 32-bit DMA address space is supported */
1890 if (size > DMA_BIT_MASK(32) + 1)
1891 return ERR_PTR(-ERANGE);
1892
1889 if (!bitmap_size) 1893 if (!bitmap_size)
1890 return ERR_PTR(-EINVAL); 1894 return ERR_PTR(-EINVAL);
1891 1895
@@ -2057,13 +2061,6 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
2057 if (!iommu) 2061 if (!iommu)
2058 return false; 2062 return false;
2059 2063
2060 /*
2061 * currently arm_iommu_create_mapping() takes a max of size_t
2062 * for size param. So check this limit for now.
2063 */
2064 if (size > SIZE_MAX)
2065 return false;
2066
2067 mapping = arm_iommu_create_mapping(dev->bus, dma_base, size); 2064 mapping = arm_iommu_create_mapping(dev->bus, dma_base, size);
2068 if (IS_ERR(mapping)) { 2065 if (IS_ERR(mapping)) {
2069 pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n", 2066 pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n",
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 4e6ef896c619..7186382672b5 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1112,22 +1112,22 @@ void __init sanity_check_meminfo(void)
1112 } 1112 }
1113 1113
1114 /* 1114 /*
1115 * Find the first non-section-aligned page, and point 1115 * Find the first non-pmd-aligned page, and point
1116 * memblock_limit at it. This relies on rounding the 1116 * memblock_limit at it. This relies on rounding the
1117 * limit down to be section-aligned, which happens at 1117 * limit down to be pmd-aligned, which happens at the
1118 * the end of this function. 1118 * end of this function.
1119 * 1119 *
1120 * With this algorithm, the start or end of almost any 1120 * With this algorithm, the start or end of almost any
1121 * bank can be non-section-aligned. The only exception 1121 * bank can be non-pmd-aligned. The only exception is
1122 * is that the start of the bank 0 must be section- 1122 * that the start of the bank 0 must be section-
1123 * aligned, since otherwise memory would need to be 1123 * aligned, since otherwise memory would need to be
1124 * allocated when mapping the start of bank 0, which 1124 * allocated when mapping the start of bank 0, which
1125 * occurs before any free memory is mapped. 1125 * occurs before any free memory is mapped.
1126 */ 1126 */
1127 if (!memblock_limit) { 1127 if (!memblock_limit) {
1128 if (!IS_ALIGNED(block_start, SECTION_SIZE)) 1128 if (!IS_ALIGNED(block_start, PMD_SIZE))
1129 memblock_limit = block_start; 1129 memblock_limit = block_start;
1130 else if (!IS_ALIGNED(block_end, SECTION_SIZE)) 1130 else if (!IS_ALIGNED(block_end, PMD_SIZE))
1131 memblock_limit = arm_lowmem_limit; 1131 memblock_limit = arm_lowmem_limit;
1132 } 1132 }
1133 1133
@@ -1137,12 +1137,12 @@ void __init sanity_check_meminfo(void)
1137 high_memory = __va(arm_lowmem_limit - 1) + 1; 1137 high_memory = __va(arm_lowmem_limit - 1) + 1;
1138 1138
1139 /* 1139 /*
1140 * Round the memblock limit down to a section size. This 1140 * Round the memblock limit down to a pmd size. This
1141 * helps to ensure that we will allocate memory from the 1141 * helps to ensure that we will allocate memory from the
1142 * last full section, which should be mapped. 1142 * last full pmd, which should be mapped.
1143 */ 1143 */
1144 if (memblock_limit) 1144 if (memblock_limit)
1145 memblock_limit = round_down(memblock_limit, SECTION_SIZE); 1145 memblock_limit = round_down(memblock_limit, PMD_SIZE);
1146 if (!memblock_limit) 1146 if (!memblock_limit)
1147 memblock_limit = arm_lowmem_limit; 1147 memblock_limit = arm_lowmem_limit;
1148 1148
diff --git a/arch/arm/mm/proc-arm1020.S b/arch/arm/mm/proc-arm1020.S
index aa0519eed698..774ef1323554 100644
--- a/arch/arm/mm/proc-arm1020.S
+++ b/arch/arm/mm/proc-arm1020.S
@@ -22,8 +22,6 @@
22 * 22 *
23 * These are the low level assembler for performing cache and TLB 23 * These are the low level assembler for performing cache and TLB
24 * functions on the arm1020. 24 * functions on the arm1020.
25 *
26 * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
27 */ 25 */
28#include <linux/linkage.h> 26#include <linux/linkage.h>
29#include <linux/init.h> 27#include <linux/init.h>
diff --git a/arch/arm/mm/proc-arm1020e.S b/arch/arm/mm/proc-arm1020e.S
index bff4c7f70fd6..ae3c27b71594 100644
--- a/arch/arm/mm/proc-arm1020e.S
+++ b/arch/arm/mm/proc-arm1020e.S
@@ -22,8 +22,6 @@
22 * 22 *
23 * These are the low level assembler for performing cache and TLB 23 * These are the low level assembler for performing cache and TLB
24 * functions on the arm1020e. 24 * functions on the arm1020e.
25 *
26 * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
27 */ 25 */
28#include <linux/linkage.h> 26#include <linux/linkage.h>
29#include <linux/init.h> 27#include <linux/init.h>
diff --git a/arch/arm/mm/proc-arm925.S b/arch/arm/mm/proc-arm925.S
index ede8c54ab4aa..32a47cc19076 100644
--- a/arch/arm/mm/proc-arm925.S
+++ b/arch/arm/mm/proc-arm925.S
@@ -441,9 +441,6 @@ ENTRY(cpu_arm925_set_pte_ext)
441 .type __arm925_setup, #function 441 .type __arm925_setup, #function
442__arm925_setup: 442__arm925_setup:
443 mov r0, #0 443 mov r0, #0
444#if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
445 orr r0,r0,#1 << 7
446#endif
447 444
448 /* Transparent on, D-cache clean & flush mode. See NOTE2 above */ 445 /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
449 orr r0,r0,#1 << 1 @ transparent mode on 446 orr r0,r0,#1 << 1 @ transparent mode on
diff --git a/arch/arm/mm/proc-feroceon.S b/arch/arm/mm/proc-feroceon.S
index e494d6d6acbe..92e08bf37aad 100644
--- a/arch/arm/mm/proc-feroceon.S
+++ b/arch/arm/mm/proc-feroceon.S
@@ -602,7 +602,6 @@ __\name\()_proc_info:
602 PMD_SECT_AP_WRITE | \ 602 PMD_SECT_AP_WRITE | \
603 PMD_SECT_AP_READ 603 PMD_SECT_AP_READ
604 initfn __feroceon_setup, __\name\()_proc_info 604 initfn __feroceon_setup, __\name\()_proc_info
605 .long __feroceon_setup
606 .long cpu_arch_name 605 .long cpu_arch_name
607 .long cpu_elf_name 606 .long cpu_elf_name
608 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP 607 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index e1268f905026..e0e23582c8b4 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -54,6 +54,7 @@
54#define SEEN_DATA (1 << (BPF_MEMWORDS + 3)) 54#define SEEN_DATA (1 << (BPF_MEMWORDS + 3))
55 55
56#define FLAG_NEED_X_RESET (1 << 0) 56#define FLAG_NEED_X_RESET (1 << 0)
57#define FLAG_IMM_OVERFLOW (1 << 1)
57 58
58struct jit_ctx { 59struct jit_ctx {
59 const struct bpf_prog *skf; 60 const struct bpf_prog *skf;
@@ -293,6 +294,15 @@ static u16 imm_offset(u32 k, struct jit_ctx *ctx)
293 /* PC in ARM mode == address of the instruction + 8 */ 294 /* PC in ARM mode == address of the instruction + 8 */
294 imm = offset - (8 + ctx->idx * 4); 295 imm = offset - (8 + ctx->idx * 4);
295 296
297 if (imm & ~0xfff) {
298 /*
299 * literal pool is too far, signal it into flags. we
300 * can only detect it on the second pass unfortunately.
301 */
302 ctx->flags |= FLAG_IMM_OVERFLOW;
303 return 0;
304 }
305
296 return imm; 306 return imm;
297} 307}
298 308
@@ -449,10 +459,21 @@ static inline void emit_udiv(u8 rd, u8 rm, u8 rn, struct jit_ctx *ctx)
449 return; 459 return;
450 } 460 }
451#endif 461#endif
452 if (rm != ARM_R0) 462
453 emit(ARM_MOV_R(ARM_R0, rm), ctx); 463 /*
464 * For BPF_ALU | BPF_DIV | BPF_K instructions, rm is ARM_R4
465 * (r_A) and rn is ARM_R0 (r_scratch) so load rn first into
466 * ARM_R1 to avoid accidentally overwriting ARM_R0 with rm
467 * before using it as a source for ARM_R1.
468 *
469 * For BPF_ALU | BPF_DIV | BPF_X rm is ARM_R4 (r_A) and rn is
470 * ARM_R5 (r_X) so there is no particular register overlap
471 * issues.
472 */
454 if (rn != ARM_R1) 473 if (rn != ARM_R1)
455 emit(ARM_MOV_R(ARM_R1, rn), ctx); 474 emit(ARM_MOV_R(ARM_R1, rn), ctx);
475 if (rm != ARM_R0)
476 emit(ARM_MOV_R(ARM_R0, rm), ctx);
456 477
457 ctx->seen |= SEEN_CALL; 478 ctx->seen |= SEEN_CALL;
458 emit_mov_i(ARM_R3, (u32)jit_udiv, ctx); 479 emit_mov_i(ARM_R3, (u32)jit_udiv, ctx);
@@ -855,6 +876,14 @@ b_epilogue:
855 default: 876 default:
856 return -1; 877 return -1;
857 } 878 }
879
880 if (ctx->flags & FLAG_IMM_OVERFLOW)
881 /*
882 * this instruction generated an overflow when
883 * trying to access the literal pool, so
884 * delegate this filter to the kernel interpreter.
885 */
886 return -1;
858 } 887 }
859 888
860 /* compute offsets only during the first pass */ 889 /* compute offsets only during the first pass */
@@ -917,7 +946,14 @@ void bpf_jit_compile(struct bpf_prog *fp)
917 ctx.idx = 0; 946 ctx.idx = 0;
918 947
919 build_prologue(&ctx); 948 build_prologue(&ctx);
920 build_body(&ctx); 949 if (build_body(&ctx) < 0) {
950#if __LINUX_ARM_ARCH__ < 7
951 if (ctx.imm_count)
952 kfree(ctx.imms);
953#endif
954 bpf_jit_binary_free(header);
955 goto out;
956 }
921 build_epilogue(&ctx); 957 build_epilogue(&ctx);
922 958
923 flush_icache_range((u32)ctx.target, (u32)(ctx.target + ctx.idx)); 959 flush_icache_range((u32)ctx.target, (u32)(ctx.target + ctx.idx));
diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
index 224081ccc92f..7d0f07020c80 100644
--- a/arch/arm/xen/enlighten.c
+++ b/arch/arm/xen/enlighten.c
@@ -272,6 +272,7 @@ void xen_arch_pre_suspend(void) { }
272void xen_arch_post_suspend(int suspend_cancelled) { } 272void xen_arch_post_suspend(int suspend_cancelled) { }
273void xen_timer_resume(void) { } 273void xen_timer_resume(void) { }
274void xen_arch_resume(void) { } 274void xen_arch_resume(void) { }
275void xen_arch_suspend(void) { }
275 276
276 277
277/* In the hypervisor.S file. */ 278/* In the hypervisor.S file. */
diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c
index 793551d15f1d..498325074a06 100644
--- a/arch/arm/xen/mm.c
+++ b/arch/arm/xen/mm.c
@@ -4,6 +4,7 @@
4#include <linux/gfp.h> 4#include <linux/gfp.h>
5#include <linux/highmem.h> 5#include <linux/highmem.h>
6#include <linux/export.h> 6#include <linux/export.h>
7#include <linux/memblock.h>
7#include <linux/of_address.h> 8#include <linux/of_address.h>
8#include <linux/slab.h> 9#include <linux/slab.h>
9#include <linux/types.h> 10#include <linux/types.h>
@@ -21,6 +22,20 @@
21#include <asm/xen/hypercall.h> 22#include <asm/xen/hypercall.h>
22#include <asm/xen/interface.h> 23#include <asm/xen/interface.h>
23 24
25unsigned long xen_get_swiotlb_free_pages(unsigned int order)
26{
27 struct memblock_region *reg;
28 gfp_t flags = __GFP_NOWARN;
29
30 for_each_memblock(memory, reg) {
31 if (reg->base < (phys_addr_t)0xffffffff) {
32 flags |= __GFP_DMA;
33 break;
34 }
35 }
36 return __get_free_pages(flags, order);
37}
38
24enum dma_cache_op { 39enum dma_cache_op {
25 DMA_UNMAP, 40 DMA_UNMAP,
26 DMA_MAP, 41 DMA_MAP,
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 4269dba63cf1..7796af4b1d6f 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -31,6 +31,7 @@ config ARM64
31 select GENERIC_EARLY_IOREMAP 31 select GENERIC_EARLY_IOREMAP
32 select GENERIC_IRQ_PROBE 32 select GENERIC_IRQ_PROBE
33 select GENERIC_IRQ_SHOW 33 select GENERIC_IRQ_SHOW
34 select GENERIC_IRQ_SHOW_LEVEL
34 select GENERIC_PCI_IOMAP 35 select GENERIC_PCI_IOMAP
35 select GENERIC_SCHED_CLOCK 36 select GENERIC_SCHED_CLOCK
36 select GENERIC_SMP_IDLE_THREAD 37 select GENERIC_SMP_IDLE_THREAD
diff --git a/arch/arm64/boot/dts/arm/juno-motherboard.dtsi b/arch/arm64/boot/dts/arm/juno-motherboard.dtsi
index c138b95a8356..351c95bda89e 100644
--- a/arch/arm64/boot/dts/arm/juno-motherboard.dtsi
+++ b/arch/arm64/boot/dts/arm/juno-motherboard.dtsi
@@ -21,6 +21,20 @@
21 clock-output-names = "juno_mb:clk25mhz"; 21 clock-output-names = "juno_mb:clk25mhz";
22 }; 22 };
23 23
24 v2m_refclk1mhz: refclk1mhz {
25 compatible = "fixed-clock";
26 #clock-cells = <0>;
27 clock-frequency = <1000000>;
28 clock-output-names = "juno_mb:refclk1mhz";
29 };
30
31 v2m_refclk32khz: refclk32khz {
32 compatible = "fixed-clock";
33 #clock-cells = <0>;
34 clock-frequency = <32768>;
35 clock-output-names = "juno_mb:refclk32khz";
36 };
37
24 motherboard { 38 motherboard {
25 compatible = "arm,vexpress,v2p-p1", "simple-bus"; 39 compatible = "arm,vexpress,v2p-p1", "simple-bus";
26 #address-cells = <2>; /* SMB chipselect number and offset */ 40 #address-cells = <2>; /* SMB chipselect number and offset */
@@ -66,6 +80,15 @@
66 #size-cells = <1>; 80 #size-cells = <1>;
67 ranges = <0 3 0 0x200000>; 81 ranges = <0 3 0 0x200000>;
68 82
83 v2m_sysctl: sysctl@020000 {
84 compatible = "arm,sp810", "arm,primecell";
85 reg = <0x020000 0x1000>;
86 clocks = <&v2m_refclk32khz>, <&v2m_refclk1mhz>, <&mb_clk24mhz>;
87 clock-names = "refclk", "timclk", "apb_pclk";
88 #clock-cells = <1>;
89 clock-output-names = "timerclken0", "timerclken1", "timerclken2", "timerclken3";
90 };
91
69 mmci@050000 { 92 mmci@050000 {
70 compatible = "arm,pl180", "arm,primecell"; 93 compatible = "arm,pl180", "arm,primecell";
71 reg = <0x050000 0x1000>; 94 reg = <0x050000 0x1000>;
@@ -106,16 +129,16 @@
106 compatible = "arm,sp804", "arm,primecell"; 129 compatible = "arm,sp804", "arm,primecell";
107 reg = <0x110000 0x10000>; 130 reg = <0x110000 0x10000>;
108 interrupts = <9>; 131 interrupts = <9>;
109 clocks = <&mb_clk24mhz>, <&soc_smc50mhz>; 132 clocks = <&v2m_sysctl 0>, <&v2m_sysctl 1>, <&mb_clk24mhz>;
110 clock-names = "timclken1", "apb_pclk"; 133 clock-names = "timclken1", "timclken2", "apb_pclk";
111 }; 134 };
112 135
113 v2m_timer23: timer@120000 { 136 v2m_timer23: timer@120000 {
114 compatible = "arm,sp804", "arm,primecell"; 137 compatible = "arm,sp804", "arm,primecell";
115 reg = <0x120000 0x10000>; 138 reg = <0x120000 0x10000>;
116 interrupts = <9>; 139 interrupts = <9>;
117 clocks = <&mb_clk24mhz>, <&soc_smc50mhz>; 140 clocks = <&v2m_sysctl 2>, <&v2m_sysctl 3>, <&mb_clk24mhz>;
118 clock-names = "timclken1", "apb_pclk"; 141 clock-names = "timclken1", "timclken2", "apb_pclk";
119 }; 142 };
120 143
121 rtc@170000 { 144 rtc@170000 {
diff --git a/arch/arm64/crypto/crc32-arm64.c b/arch/arm64/crypto/crc32-arm64.c
index 9499199924ae..6a37c3c6b11d 100644
--- a/arch/arm64/crypto/crc32-arm64.c
+++ b/arch/arm64/crypto/crc32-arm64.c
@@ -147,13 +147,21 @@ static int chksum_final(struct shash_desc *desc, u8 *out)
147{ 147{
148 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc); 148 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
149 149
150 put_unaligned_le32(ctx->crc, out);
151 return 0;
152}
153
154static int chksumc_final(struct shash_desc *desc, u8 *out)
155{
156 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
157
150 put_unaligned_le32(~ctx->crc, out); 158 put_unaligned_le32(~ctx->crc, out);
151 return 0; 159 return 0;
152} 160}
153 161
154static int __chksum_finup(u32 crc, const u8 *data, unsigned int len, u8 *out) 162static int __chksum_finup(u32 crc, const u8 *data, unsigned int len, u8 *out)
155{ 163{
156 put_unaligned_le32(~crc32_arm64_le_hw(crc, data, len), out); 164 put_unaligned_le32(crc32_arm64_le_hw(crc, data, len), out);
157 return 0; 165 return 0;
158} 166}
159 167
@@ -199,6 +207,14 @@ static int crc32_cra_init(struct crypto_tfm *tfm)
199{ 207{
200 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm); 208 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
201 209
210 mctx->key = 0;
211 return 0;
212}
213
214static int crc32c_cra_init(struct crypto_tfm *tfm)
215{
216 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
217
202 mctx->key = ~0; 218 mctx->key = ~0;
203 return 0; 219 return 0;
204} 220}
@@ -229,7 +245,7 @@ static struct shash_alg crc32c_alg = {
229 .setkey = chksum_setkey, 245 .setkey = chksum_setkey,
230 .init = chksum_init, 246 .init = chksum_init,
231 .update = chksumc_update, 247 .update = chksumc_update,
232 .final = chksum_final, 248 .final = chksumc_final,
233 .finup = chksumc_finup, 249 .finup = chksumc_finup,
234 .digest = chksumc_digest, 250 .digest = chksumc_digest,
235 .descsize = sizeof(struct chksum_desc_ctx), 251 .descsize = sizeof(struct chksum_desc_ctx),
@@ -241,7 +257,7 @@ static struct shash_alg crc32c_alg = {
241 .cra_alignmask = 0, 257 .cra_alignmask = 0,
242 .cra_ctxsize = sizeof(struct chksum_ctx), 258 .cra_ctxsize = sizeof(struct chksum_ctx),
243 .cra_module = THIS_MODULE, 259 .cra_module = THIS_MODULE,
244 .cra_init = crc32_cra_init, 260 .cra_init = crc32c_cra_init,
245 } 261 }
246}; 262};
247 263
diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
index 114e7cc5de8c..aefda9868627 100644
--- a/arch/arm64/crypto/sha1-ce-glue.c
+++ b/arch/arm64/crypto/sha1-ce-glue.c
@@ -74,6 +74,9 @@ static int sha1_ce_finup(struct shash_desc *desc, const u8 *data,
74 74
75static int sha1_ce_final(struct shash_desc *desc, u8 *out) 75static int sha1_ce_final(struct shash_desc *desc, u8 *out)
76{ 76{
77 struct sha1_ce_state *sctx = shash_desc_ctx(desc);
78
79 sctx->finalize = 0;
77 kernel_neon_begin_partial(16); 80 kernel_neon_begin_partial(16);
78 sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_ce_transform); 81 sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_ce_transform);
79 kernel_neon_end(); 82 kernel_neon_end();
diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c
index 1340e44c048b..7cd587564a41 100644
--- a/arch/arm64/crypto/sha2-ce-glue.c
+++ b/arch/arm64/crypto/sha2-ce-glue.c
@@ -75,6 +75,9 @@ static int sha256_ce_finup(struct shash_desc *desc, const u8 *data,
75 75
76static int sha256_ce_final(struct shash_desc *desc, u8 *out) 76static int sha256_ce_final(struct shash_desc *desc, u8 *out)
77{ 77{
78 struct sha256_ce_state *sctx = shash_desc_ctx(desc);
79
80 sctx->finalize = 0;
78 kernel_neon_begin_partial(28); 81 kernel_neon_begin_partial(28);
79 sha256_base_do_finalize(desc, (sha256_block_fn *)sha2_ce_transform); 82 sha256_base_do_finalize(desc, (sha256_block_fn *)sha2_ce_transform);
80 kernel_neon_end(); 83 kernel_neon_end();
diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
index a5abb0062d6e..71f19c4dc0de 100644
--- a/arch/arm64/include/asm/barrier.h
+++ b/arch/arm64/include/asm/barrier.h
@@ -65,6 +65,14 @@ do { \
65do { \ 65do { \
66 compiletime_assert_atomic_type(*p); \ 66 compiletime_assert_atomic_type(*p); \
67 switch (sizeof(*p)) { \ 67 switch (sizeof(*p)) { \
68 case 1: \
69 asm volatile ("stlrb %w1, %0" \
70 : "=Q" (*p) : "r" (v) : "memory"); \
71 break; \
72 case 2: \
73 asm volatile ("stlrh %w1, %0" \
74 : "=Q" (*p) : "r" (v) : "memory"); \
75 break; \
68 case 4: \ 76 case 4: \
69 asm volatile ("stlr %w1, %0" \ 77 asm volatile ("stlr %w1, %0" \
70 : "=Q" (*p) : "r" (v) : "memory"); \ 78 : "=Q" (*p) : "r" (v) : "memory"); \
@@ -81,6 +89,14 @@ do { \
81 typeof(*p) ___p1; \ 89 typeof(*p) ___p1; \
82 compiletime_assert_atomic_type(*p); \ 90 compiletime_assert_atomic_type(*p); \
83 switch (sizeof(*p)) { \ 91 switch (sizeof(*p)) { \
92 case 1: \
93 asm volatile ("ldarb %w0, %1" \
94 : "=r" (___p1) : "Q" (*p) : "memory"); \
95 break; \
96 case 2: \
97 asm volatile ("ldarh %w0, %1" \
98 : "=r" (___p1) : "Q" (*p) : "memory"); \
99 break; \
84 case 4: \ 100 case 4: \
85 asm volatile ("ldar %w0, %1" \ 101 asm volatile ("ldar %w0, %1" \
86 : "=r" (___p1) : "Q" (*p) : "memory"); \ 102 : "=r" (___p1) : "Q" (*p) : "memory"); \
diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
index 21033bba9390..28f8365edc4c 100644
--- a/arch/arm64/kernel/alternative.c
+++ b/arch/arm64/kernel/alternative.c
@@ -24,7 +24,6 @@
24#include <asm/cacheflush.h> 24#include <asm/cacheflush.h>
25#include <asm/alternative.h> 25#include <asm/alternative.h>
26#include <asm/cpufeature.h> 26#include <asm/cpufeature.h>
27#include <asm/insn.h>
28#include <linux/stop_machine.h> 27#include <linux/stop_machine.h>
29 28
30extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; 29extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
@@ -34,48 +33,6 @@ struct alt_region {
34 struct alt_instr *end; 33 struct alt_instr *end;
35}; 34};
36 35
37/*
38 * Decode the imm field of a b/bl instruction, and return the byte
39 * offset as a signed value (so it can be used when computing a new
40 * branch target).
41 */
42static s32 get_branch_offset(u32 insn)
43{
44 s32 imm = aarch64_insn_decode_immediate(AARCH64_INSN_IMM_26, insn);
45
46 /* sign-extend the immediate before turning it into a byte offset */
47 return (imm << 6) >> 4;
48}
49
50static u32 get_alt_insn(u8 *insnptr, u8 *altinsnptr)
51{
52 u32 insn;
53
54 aarch64_insn_read(altinsnptr, &insn);
55
56 /* Stop the world on instructions we don't support... */
57 BUG_ON(aarch64_insn_is_cbz(insn));
58 BUG_ON(aarch64_insn_is_cbnz(insn));
59 BUG_ON(aarch64_insn_is_bcond(insn));
60 /* ... and there is probably more. */
61
62 if (aarch64_insn_is_b(insn) || aarch64_insn_is_bl(insn)) {
63 enum aarch64_insn_branch_type type;
64 unsigned long target;
65
66 if (aarch64_insn_is_b(insn))
67 type = AARCH64_INSN_BRANCH_NOLINK;
68 else
69 type = AARCH64_INSN_BRANCH_LINK;
70
71 target = (unsigned long)altinsnptr + get_branch_offset(insn);
72 insn = aarch64_insn_gen_branch_imm((unsigned long)insnptr,
73 target, type);
74 }
75
76 return insn;
77}
78
79static int __apply_alternatives(void *alt_region) 36static int __apply_alternatives(void *alt_region)
80{ 37{
81 struct alt_instr *alt; 38 struct alt_instr *alt;
@@ -83,9 +40,6 @@ static int __apply_alternatives(void *alt_region)
83 u8 *origptr, *replptr; 40 u8 *origptr, *replptr;
84 41
85 for (alt = region->begin; alt < region->end; alt++) { 42 for (alt = region->begin; alt < region->end; alt++) {
86 u32 insn;
87 int i;
88
89 if (!cpus_have_cap(alt->cpufeature)) 43 if (!cpus_have_cap(alt->cpufeature))
90 continue; 44 continue;
91 45
@@ -95,12 +49,7 @@ static int __apply_alternatives(void *alt_region)
95 49
96 origptr = (u8 *)&alt->orig_offset + alt->orig_offset; 50 origptr = (u8 *)&alt->orig_offset + alt->orig_offset;
97 replptr = (u8 *)&alt->alt_offset + alt->alt_offset; 51 replptr = (u8 *)&alt->alt_offset + alt->alt_offset;
98 52 memcpy(origptr, replptr, alt->alt_len);
99 for (i = 0; i < alt->alt_len; i += sizeof(insn)) {
100 insn = get_alt_insn(origptr + i, replptr + i);
101 aarch64_insn_write(origptr + i, insn);
102 }
103
104 flush_icache_range((uintptr_t)origptr, 53 flush_icache_range((uintptr_t)origptr,
105 (uintptr_t)(origptr + alt->alt_len)); 54 (uintptr_t)(origptr + alt->alt_len));
106 } 55 }
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 195991dadc37..cce18c85d2e8 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -1310,11 +1310,16 @@ static const struct of_device_id armpmu_of_device_ids[] = {
1310 1310
1311static int armpmu_device_probe(struct platform_device *pdev) 1311static int armpmu_device_probe(struct platform_device *pdev)
1312{ 1312{
1313 int i, *irqs; 1313 int i, irq, *irqs;
1314 1314
1315 if (!cpu_pmu) 1315 if (!cpu_pmu)
1316 return -ENODEV; 1316 return -ENODEV;
1317 1317
1318 /* Don't bother with PPIs; they're already affine */
1319 irq = platform_get_irq(pdev, 0);
1320 if (irq >= 0 && irq_is_percpu(irq))
1321 return 0;
1322
1318 irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL); 1323 irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL);
1319 if (!irqs) 1324 if (!irqs)
1320 return -ENOMEM; 1325 return -ENOMEM;
@@ -1327,7 +1332,7 @@ static int armpmu_device_probe(struct platform_device *pdev)
1327 i); 1332 i);
1328 if (!dn) { 1333 if (!dn) {
1329 pr_warn("Failed to parse %s/interrupt-affinity[%d]\n", 1334 pr_warn("Failed to parse %s/interrupt-affinity[%d]\n",
1330 of_node_full_name(dn), i); 1335 of_node_full_name(pdev->dev.of_node), i);
1331 break; 1336 break;
1332 } 1337 }
1333 1338
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index ef7d112f5ce0..b0bd4e5fd5cf 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -67,8 +67,7 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags)
67 67
68 *ret_page = phys_to_page(phys); 68 *ret_page = phys_to_page(phys);
69 ptr = (void *)val; 69 ptr = (void *)val;
70 if (flags & __GFP_ZERO) 70 memset(ptr, 0, size);
71 memset(ptr, 0, size);
72 } 71 }
73 72
74 return ptr; 73 return ptr;
@@ -105,7 +104,6 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size,
105 struct page *page; 104 struct page *page;
106 void *addr; 105 void *addr;
107 106
108 size = PAGE_ALIGN(size);
109 page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, 107 page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT,
110 get_order(size)); 108 get_order(size));
111 if (!page) 109 if (!page)
@@ -113,8 +111,7 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size,
113 111
114 *dma_handle = phys_to_dma(dev, page_to_phys(page)); 112 *dma_handle = phys_to_dma(dev, page_to_phys(page));
115 addr = page_address(page); 113 addr = page_address(page);
116 if (flags & __GFP_ZERO) 114 memset(addr, 0, size);
117 memset(addr, 0, size);
118 return addr; 115 return addr;
119 } else { 116 } else {
120 return swiotlb_alloc_coherent(dev, size, dma_handle, flags); 117 return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
@@ -195,6 +192,8 @@ static void __dma_free(struct device *dev, size_t size,
195{ 192{
196 void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle)); 193 void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle));
197 194
195 size = PAGE_ALIGN(size);
196
198 if (!is_device_dma_coherent(dev)) { 197 if (!is_device_dma_coherent(dev)) {
199 if (__free_from_pool(vaddr, size)) 198 if (__free_from_pool(vaddr, size))
200 return; 199 return;
diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c
index 74c256744b25..f3d6221cd5bd 100644
--- a/arch/arm64/mm/dump.c
+++ b/arch/arm64/mm/dump.c
@@ -328,10 +328,12 @@ static int ptdump_init(void)
328 for (j = 0; j < pg_level[i].num; j++) 328 for (j = 0; j < pg_level[i].num; j++)
329 pg_level[i].mask |= pg_level[i].bits[j].mask; 329 pg_level[i].mask |= pg_level[i].bits[j].mask;
330 330
331#ifdef CONFIG_SPARSEMEM_VMEMMAP
331 address_markers[VMEMMAP_START_NR].start_address = 332 address_markers[VMEMMAP_START_NR].start_address =
332 (unsigned long)virt_to_page(PAGE_OFFSET); 333 (unsigned long)virt_to_page(PAGE_OFFSET);
333 address_markers[VMEMMAP_END_NR].start_address = 334 address_markers[VMEMMAP_END_NR].start_address =
334 (unsigned long)virt_to_page(high_memory); 335 (unsigned long)virt_to_page(high_memory);
336#endif
335 337
336 pe = debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, 338 pe = debugfs_create_file("kernel_page_tables", 0400, NULL, NULL,
337 &ptdump_fops); 339 &ptdump_fops);
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index edba042b2325..dc6a4842683a 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -487,7 +487,7 @@ emit_cond_jmp:
487 return -EINVAL; 487 return -EINVAL;
488 } 488 }
489 489
490 imm64 = (u64)insn1.imm << 32 | imm; 490 imm64 = (u64)insn1.imm << 32 | (u32)imm;
491 emit_a64_mov_i64(dst, imm64, ctx); 491 emit_a64_mov_i64(dst, imm64, ctx);
492 492
493 return 1; 493 return 1;
diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c
index d4e162d35b34..7cc3be9fa7c6 100644
--- a/arch/ia64/pci/pci.c
+++ b/arch/ia64/pci/pci.c
@@ -478,9 +478,16 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
478 478
479int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) 479int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
480{ 480{
481 struct pci_controller *controller = bridge->bus->sysdata; 481 /*
482 482 * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL
483 ACPI_COMPANION_SET(&bridge->dev, controller->companion); 483 * here, pci_create_root_bus() has been called by someone else and
484 * sysdata is likely to be different from what we expect. Let it go in
485 * that case.
486 */
487 if (!bridge->dev.parent) {
488 struct pci_controller *controller = bridge->bus->sysdata;
489 ACPI_COMPANION_SET(&bridge->dev, controller->companion);
490 }
484 return 0; 491 return 0;
485} 492}
486 493
diff --git a/arch/m32r/kernel/smp.c b/arch/m32r/kernel/smp.c
index ce7aea34fdf4..c18ddc74ef9a 100644
--- a/arch/m32r/kernel/smp.c
+++ b/arch/m32r/kernel/smp.c
@@ -45,7 +45,7 @@ static volatile unsigned long flushcache_cpumask = 0;
45/* 45/*
46 * For flush_tlb_others() 46 * For flush_tlb_others()
47 */ 47 */
48static volatile cpumask_t flush_cpumask; 48static cpumask_t flush_cpumask;
49static struct mm_struct *flush_mm; 49static struct mm_struct *flush_mm;
50static struct vm_area_struct *flush_vma; 50static struct vm_area_struct *flush_vma;
51static volatile unsigned long flush_va; 51static volatile unsigned long flush_va;
@@ -415,7 +415,7 @@ static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
415 */ 415 */
416 send_IPI_mask(&cpumask, INVALIDATE_TLB_IPI, 0); 416 send_IPI_mask(&cpumask, INVALIDATE_TLB_IPI, 0);
417 417
418 while (!cpumask_empty((cpumask_t*)&flush_cpumask)) { 418 while (!cpumask_empty(&flush_cpumask)) {
419 /* nothing. lockup detection does not belong here */ 419 /* nothing. lockup detection does not belong here */
420 mb(); 420 mb();
421 } 421 }
@@ -468,7 +468,7 @@ void smp_invalidate_interrupt(void)
468 __flush_tlb_page(va); 468 __flush_tlb_page(va);
469 } 469 }
470 } 470 }
471 cpumask_clear_cpu(cpu_id, (cpumask_t*)&flush_cpumask); 471 cpumask_clear_cpu(cpu_id, &flush_cpumask);
472} 472}
473 473
474/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 474/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 5200f649dd4e..ae2dd59050f7 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -277,7 +277,7 @@ LDFLAGS += -m $(ld-emul)
277ifdef CONFIG_MIPS 277ifdef CONFIG_MIPS
278CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ 278CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
279 egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_)_' | \ 279 egrep -vw '__GNUC_(|MINOR_|PATCHLEVEL_)_' | \
280 sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/") 280 sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
281ifdef CONFIG_64BIT 281ifdef CONFIG_64BIT
282CHECKFLAGS += -m64 282CHECKFLAGS += -m64
283endif 283endif
diff --git a/arch/mips/ath79/prom.c b/arch/mips/ath79/prom.c
index e1fe63051136..597899ad5438 100644
--- a/arch/mips/ath79/prom.c
+++ b/arch/mips/ath79/prom.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Atheros AR71XX/AR724X/AR913X specific prom routines 2 * Atheros AR71XX/AR724X/AR913X specific prom routines
3 * 3 *
4 * Copyright (C) 2015 Laurent Fasnacht <l@libres.ch>
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org> 5 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> 6 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 * 7 *
@@ -25,12 +26,14 @@ void __init prom_init(void)
25{ 26{
26 fw_init_cmdline(); 27 fw_init_cmdline();
27 28
29#ifdef CONFIG_BLK_DEV_INITRD
28 /* Read the initrd address from the firmware environment */ 30 /* Read the initrd address from the firmware environment */
29 initrd_start = fw_getenvl("initrd_start"); 31 initrd_start = fw_getenvl("initrd_start");
30 if (initrd_start) { 32 if (initrd_start) {
31 initrd_start = KSEG0ADDR(initrd_start); 33 initrd_start = KSEG0ADDR(initrd_start);
32 initrd_end = initrd_start + fw_getenvl("initrd_size"); 34 initrd_end = initrd_start + fw_getenvl("initrd_size");
33 } 35 }
36#endif
34} 37}
35 38
36void __init prom_free_prom_memory(void) 39void __init prom_free_prom_memory(void)
diff --git a/arch/mips/configs/fuloong2e_defconfig b/arch/mips/configs/fuloong2e_defconfig
index 002680648dcb..b2a577ebce0b 100644
--- a/arch/mips/configs/fuloong2e_defconfig
+++ b/arch/mips/configs/fuloong2e_defconfig
@@ -194,7 +194,7 @@ CONFIG_USB_WUSB_CBAF=m
194CONFIG_USB_C67X00_HCD=m 194CONFIG_USB_C67X00_HCD=m
195CONFIG_USB_EHCI_HCD=y 195CONFIG_USB_EHCI_HCD=y
196CONFIG_USB_EHCI_ROOT_HUB_TT=y 196CONFIG_USB_EHCI_ROOT_HUB_TT=y
197CONFIG_USB_ISP1760_HCD=m 197CONFIG_USB_ISP1760=m
198CONFIG_USB_OHCI_HCD=y 198CONFIG_USB_OHCI_HCD=y
199CONFIG_USB_UHCI_HCD=m 199CONFIG_USB_UHCI_HCD=m
200CONFIG_USB_R8A66597_HCD=m 200CONFIG_USB_R8A66597_HCD=m
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index a594d8ed9698..f19e890b99d2 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -304,7 +304,7 @@ do { \
304 \ 304 \
305 current->thread.abi = &mips_abi; \ 305 current->thread.abi = &mips_abi; \
306 \ 306 \
307 current->thread.fpu.fcr31 = current_cpu_data.fpu_csr31; \ 307 current->thread.fpu.fcr31 = boot_cpu_data.fpu_csr31; \
308} while (0) 308} while (0)
309 309
310#endif /* CONFIG_32BIT */ 310#endif /* CONFIG_32BIT */
@@ -366,7 +366,7 @@ do { \
366 else \ 366 else \
367 current->thread.abi = &mips_abi; \ 367 current->thread.abi = &mips_abi; \
368 \ 368 \
369 current->thread.fpu.fcr31 = current_cpu_data.fpu_csr31; \ 369 current->thread.fpu.fcr31 = boot_cpu_data.fpu_csr31; \
370 \ 370 \
371 p = personality(current->personality); \ 371 p = personality(current->personality); \
372 if (p != PER_LINUX32 && p != PER_LINUX) \ 372 if (p != PER_LINUX32 && p != PER_LINUX) \
diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index bb02fac9b4fa..2b25d1ba1ea0 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -45,7 +45,7 @@ extern int __cpu_logical_map[NR_CPUS];
45#define SMP_DUMP 0x8 45#define SMP_DUMP 0x8
46#define SMP_ASK_C0COUNT 0x10 46#define SMP_ASK_C0COUNT 0x10
47 47
48extern volatile cpumask_t cpu_callin_map; 48extern cpumask_t cpu_callin_map;
49 49
50/* Mask of CPUs which are currently definitely operating coherently */ 50/* Mask of CPUs which are currently definitely operating coherently */
51extern cpumask_t cpu_coherent_mask; 51extern cpumask_t cpu_coherent_mask;
diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c
index be4899f3c393..4a4d9e067c89 100644
--- a/arch/mips/kernel/elf.c
+++ b/arch/mips/kernel/elf.c
@@ -76,14 +76,6 @@ int arch_elf_pt_proc(void *_ehdr, void *_phdr, struct file *elf,
76 76
77 /* Lets see if this is an O32 ELF */ 77 /* Lets see if this is an O32 ELF */
78 if (ehdr32->e_ident[EI_CLASS] == ELFCLASS32) { 78 if (ehdr32->e_ident[EI_CLASS] == ELFCLASS32) {
79 /* FR = 1 for N32 */
80 if (ehdr32->e_flags & EF_MIPS_ABI2)
81 state->overall_fp_mode = FP_FR1;
82 else
83 /* Set a good default FPU mode for O32 */
84 state->overall_fp_mode = cpu_has_mips_r6 ?
85 FP_FRE : FP_FR0;
86
87 if (ehdr32->e_flags & EF_MIPS_FP64) { 79 if (ehdr32->e_flags & EF_MIPS_FP64) {
88 /* 80 /*
89 * Set MIPS_ABI_FP_OLD_64 for EF_MIPS_FP64. We will override it 81 * Set MIPS_ABI_FP_OLD_64 for EF_MIPS_FP64. We will override it
@@ -104,9 +96,6 @@ int arch_elf_pt_proc(void *_ehdr, void *_phdr, struct file *elf,
104 (char *)&abiflags, 96 (char *)&abiflags,
105 sizeof(abiflags)); 97 sizeof(abiflags));
106 } else { 98 } else {
107 /* FR=1 is really the only option for 64-bit */
108 state->overall_fp_mode = FP_FR1;
109
110 if (phdr64->p_type != PT_MIPS_ABIFLAGS) 99 if (phdr64->p_type != PT_MIPS_ABIFLAGS)
111 return 0; 100 return 0;
112 if (phdr64->p_filesz < sizeof(abiflags)) 101 if (phdr64->p_filesz < sizeof(abiflags))
@@ -137,6 +126,7 @@ int arch_check_elf(void *_ehdr, bool has_interpreter,
137 struct elf32_hdr *ehdr = _ehdr; 126 struct elf32_hdr *ehdr = _ehdr;
138 struct mode_req prog_req, interp_req; 127 struct mode_req prog_req, interp_req;
139 int fp_abi, interp_fp_abi, abi0, abi1, max_abi; 128 int fp_abi, interp_fp_abi, abi0, abi1, max_abi;
129 bool is_mips64;
140 130
141 if (!config_enabled(CONFIG_MIPS_O32_FP64_SUPPORT)) 131 if (!config_enabled(CONFIG_MIPS_O32_FP64_SUPPORT))
142 return 0; 132 return 0;
@@ -152,10 +142,22 @@ int arch_check_elf(void *_ehdr, bool has_interpreter,
152 abi0 = abi1 = fp_abi; 142 abi0 = abi1 = fp_abi;
153 } 143 }
154 144
155 /* ABI limits. O32 = FP_64A, N32/N64 = FP_SOFT */ 145 is_mips64 = (ehdr->e_ident[EI_CLASS] == ELFCLASS64) ||
156 max_abi = ((ehdr->e_ident[EI_CLASS] == ELFCLASS32) && 146 (ehdr->e_flags & EF_MIPS_ABI2);
157 (!(ehdr->e_flags & EF_MIPS_ABI2))) ? 147
158 MIPS_ABI_FP_64A : MIPS_ABI_FP_SOFT; 148 if (is_mips64) {
149 /* MIPS64 code always uses FR=1, thus the default is easy */
150 state->overall_fp_mode = FP_FR1;
151
152 /* Disallow access to the various FPXX & FP64 ABIs */
153 max_abi = MIPS_ABI_FP_SOFT;
154 } else {
155 /* Default to a mode capable of running code expecting FR=0 */
156 state->overall_fp_mode = cpu_has_mips_r6 ? FP_FRE : FP_FR0;
157
158 /* Allow all ABIs we know about */
159 max_abi = MIPS_ABI_FP_64A;
160 }
159 161
160 if ((abi0 > max_abi && abi0 != MIPS_ABI_FP_UNKNOWN) || 162 if ((abi0 > max_abi && abi0 != MIPS_ABI_FP_UNKNOWN) ||
161 (abi1 > max_abi && abi1 != MIPS_ABI_FP_UNKNOWN)) 163 (abi1 > max_abi && abi1 != MIPS_ABI_FP_UNKNOWN))
diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
index d2bfbc2e8995..51f57d841662 100644
--- a/arch/mips/kernel/irq.c
+++ b/arch/mips/kernel/irq.c
@@ -29,7 +29,7 @@
29int kgdb_early_setup; 29int kgdb_early_setup;
30#endif 30#endif
31 31
32static unsigned long irq_map[NR_IRQS / BITS_PER_LONG]; 32static DECLARE_BITMAP(irq_map, NR_IRQS);
33 33
34int allocate_irqno(void) 34int allocate_irqno(void)
35{ 35{
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index d544e774eea6..e933a309f2ea 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -176,7 +176,7 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
176 176
177 __get_user(value, data + 64); 177 __get_user(value, data + 64);
178 fcr31 = child->thread.fpu.fcr31; 178 fcr31 = child->thread.fpu.fcr31;
179 mask = current_cpu_data.fpu_msk31; 179 mask = boot_cpu_data.fpu_msk31;
180 child->thread.fpu.fcr31 = (value & ~mask) | (fcr31 & mask); 180 child->thread.fpu.fcr31 = (value & ~mask) | (fcr31 & mask);
181 181
182 /* FIR may not be written. */ 182 /* FIR may not be written. */
diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
index fd528d7ea278..336708ae5c5b 100644
--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -444,7 +444,7 @@ struct plat_smp_ops bmips5000_smp_ops = {
444static void bmips_wr_vec(unsigned long dst, char *start, char *end) 444static void bmips_wr_vec(unsigned long dst, char *start, char *end)
445{ 445{
446 memcpy((void *)dst, start, end - start); 446 memcpy((void *)dst, start, end - start);
447 dma_cache_wback((unsigned long)start, end - start); 447 dma_cache_wback(dst, end - start);
448 local_flush_icache_range(dst, dst + (end - start)); 448 local_flush_icache_range(dst, dst + (end - start));
449 instruction_hazard(); 449 instruction_hazard();
450} 450}
diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index 7e011f95bb8e..4251d390b5b6 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -92,7 +92,7 @@ static void __init cps_smp_setup(void)
92#ifdef CONFIG_MIPS_MT_FPAFF 92#ifdef CONFIG_MIPS_MT_FPAFF
93 /* If we have an FPU, enroll ourselves in the FPU-full mask */ 93 /* If we have an FPU, enroll ourselves in the FPU-full mask */
94 if (cpu_has_fpu) 94 if (cpu_has_fpu)
95 cpu_set(0, mt_fpu_cpumask); 95 cpumask_set_cpu(0, &mt_fpu_cpumask);
96#endif /* CONFIG_MIPS_MT_FPAFF */ 96#endif /* CONFIG_MIPS_MT_FPAFF */
97} 97}
98 98
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index 193ace7955fb..faa46ebd9dda 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -43,7 +43,7 @@
43#include <asm/time.h> 43#include <asm/time.h>
44#include <asm/setup.h> 44#include <asm/setup.h>
45 45
46volatile cpumask_t cpu_callin_map; /* Bitmask of started secondaries */ 46cpumask_t cpu_callin_map; /* Bitmask of started secondaries */
47 47
48int __cpu_number_map[NR_CPUS]; /* Map physical to logical */ 48int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
49EXPORT_SYMBOL(__cpu_number_map); 49EXPORT_SYMBOL(__cpu_number_map);
@@ -218,8 +218,10 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
218 /* 218 /*
219 * Trust is futile. We should really have timeouts ... 219 * Trust is futile. We should really have timeouts ...
220 */ 220 */
221 while (!cpumask_test_cpu(cpu, &cpu_callin_map)) 221 while (!cpumask_test_cpu(cpu, &cpu_callin_map)) {
222 udelay(100); 222 udelay(100);
223 schedule();
224 }
223 225
224 synchronise_count_master(cpu); 226 synchronise_count_master(cpu);
225 return 0; 227 return 0;
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index ba32e48d4697..d2d1c1933bc9 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -269,7 +269,6 @@ static void __show_regs(const struct pt_regs *regs)
269 */ 269 */
270 printk("epc : %0*lx %pS\n", field, regs->cp0_epc, 270 printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
271 (void *) regs->cp0_epc); 271 (void *) regs->cp0_epc);
272 printk(" %s\n", print_tainted());
273 printk("ra : %0*lx %pS\n", field, regs->regs[31], 272 printk("ra : %0*lx %pS\n", field, regs->regs[31],
274 (void *) regs->regs[31]); 273 (void *) regs->regs[31]);
275 274
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 6230f376a44e..4b50c5787e25 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -2389,7 +2389,6 @@ enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
2389{ 2389{
2390 unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr]; 2390 unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr];
2391 enum emulation_result er = EMULATE_DONE; 2391 enum emulation_result er = EMULATE_DONE;
2392 unsigned long curr_pc;
2393 2392
2394 if (run->mmio.len > sizeof(*gpr)) { 2393 if (run->mmio.len > sizeof(*gpr)) {
2395 kvm_err("Bad MMIO length: %d", run->mmio.len); 2394 kvm_err("Bad MMIO length: %d", run->mmio.len);
@@ -2397,11 +2396,6 @@ enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
2397 goto done; 2396 goto done;
2398 } 2397 }
2399 2398
2400 /*
2401 * Update PC and hold onto current PC in case there is
2402 * an error and we want to rollback the PC
2403 */
2404 curr_pc = vcpu->arch.pc;
2405 er = update_pc(vcpu, vcpu->arch.pending_load_cause); 2399 er = update_pc(vcpu, vcpu->arch.pending_load_cause);
2406 if (er == EMULATE_FAIL) 2400 if (er == EMULATE_FAIL)
2407 return er; 2401 return er;
diff --git a/arch/mips/lib/strnlen_user.S b/arch/mips/lib/strnlen_user.S
index 7d12c0dded3d..77e64942f004 100644
--- a/arch/mips/lib/strnlen_user.S
+++ b/arch/mips/lib/strnlen_user.S
@@ -34,7 +34,12 @@ LEAF(__strnlen_\func\()_asm)
34FEXPORT(__strnlen_\func\()_nocheck_asm) 34FEXPORT(__strnlen_\func\()_nocheck_asm)
35 move v0, a0 35 move v0, a0
36 PTR_ADDU a1, a0 # stop pointer 36 PTR_ADDU a1, a0 # stop pointer
371: beq v0, a1, 1f # limit reached? 371:
38#ifdef CONFIG_CPU_DADDI_WORKAROUNDS
39 .set noat
40 li AT, 1
41#endif
42 beq v0, a1, 1f # limit reached?
38.ifeqs "\func", "kernel" 43.ifeqs "\func", "kernel"
39 EX(lb, t0, (v0), .Lfault\@) 44 EX(lb, t0, (v0), .Lfault\@)
40.else 45.else
@@ -42,7 +47,13 @@ FEXPORT(__strnlen_\func\()_nocheck_asm)
42.endif 47.endif
43 .set noreorder 48 .set noreorder
44 bnez t0, 1b 49 bnez t0, 1b
451: PTR_ADDIU v0, 1 501:
51#ifndef CONFIG_CPU_DADDI_WORKAROUNDS
52 PTR_ADDIU v0, 1
53#else
54 PTR_ADDU v0, AT
55 .set at
56#endif
46 .set reorder 57 .set reorder
47 PTR_SUBU v0, a0 58 PTR_SUBU v0, a0
48 jr ra 59 jr ra
diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
index d31c537ace1d..22b9b2cb9219 100644
--- a/arch/mips/math-emu/cp1emu.c
+++ b/arch/mips/math-emu/cp1emu.c
@@ -889,7 +889,7 @@ static inline void cop1_cfc(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
889 break; 889 break;
890 890
891 case FPCREG_RID: 891 case FPCREG_RID:
892 value = current_cpu_data.fpu_id; 892 value = boot_cpu_data.fpu_id;
893 break; 893 break;
894 894
895 default: 895 default:
@@ -921,7 +921,7 @@ static inline void cop1_ctc(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
921 (void *)xcp->cp0_epc, MIPSInst_RT(ir), value); 921 (void *)xcp->cp0_epc, MIPSInst_RT(ir), value);
922 922
923 /* Preserve read-only bits. */ 923 /* Preserve read-only bits. */
924 mask = current_cpu_data.fpu_msk31; 924 mask = boot_cpu_data.fpu_msk31;
925 fcr31 = (value & ~mask) | (fcr31 & mask); 925 fcr31 = (value & ~mask) | (fcr31 & mask);
926 break; 926 break;
927 927
diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c
index a27a088e6f9f..08318ecb803a 100644
--- a/arch/mips/mm/tlb-r4k.c
+++ b/arch/mips/mm/tlb-r4k.c
@@ -495,7 +495,7 @@ static void r4k_tlb_configure(void)
495 495
496 if (cpu_has_rixi) { 496 if (cpu_has_rixi) {
497 /* 497 /*
498 * Enable the no read, no exec bits, and enable large virtual 498 * Enable the no read, no exec bits, and enable large physical
499 * address. 499 * address.
500 */ 500 */
501#ifdef CONFIG_64BIT 501#ifdef CONFIG_64BIT
diff --git a/arch/mips/sgi-ip32/ip32-platform.c b/arch/mips/sgi-ip32/ip32-platform.c
index 0134db2ad0a8..5a2a82148d8d 100644
--- a/arch/mips/sgi-ip32/ip32-platform.c
+++ b/arch/mips/sgi-ip32/ip32-platform.c
@@ -130,9 +130,9 @@ struct platform_device ip32_rtc_device = {
130 .resource = ip32_rtc_resources, 130 .resource = ip32_rtc_resources,
131}; 131};
132 132
133+static int __init sgio2_rtc_devinit(void) 133static __init int sgio2_rtc_devinit(void)
134{ 134{
135 return platform_device_register(&ip32_rtc_device); 135 return platform_device_register(&ip32_rtc_device);
136} 136}
137 137
138device_initcall(sgio2_cmos_devinit); 138device_initcall(sgio2_rtc_devinit);
diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
index 3391d061eccc..78c9fd32c554 100644
--- a/arch/parisc/include/asm/elf.h
+++ b/arch/parisc/include/asm/elf.h
@@ -348,6 +348,10 @@ struct pt_regs; /* forward declaration... */
348 348
349#define ELF_HWCAP 0 349#define ELF_HWCAP 0
350 350
351#define STACK_RND_MASK (is_32bit_task() ? \
352 0x7ff >> (PAGE_SHIFT - 12) : \
353 0x3ffff >> (PAGE_SHIFT - 12))
354
351struct mm_struct; 355struct mm_struct;
352extern unsigned long arch_randomize_brk(struct mm_struct *); 356extern unsigned long arch_randomize_brk(struct mm_struct *);
353#define arch_randomize_brk arch_randomize_brk 357#define arch_randomize_brk arch_randomize_brk
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 8a488c22a99f..809905a811ed 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -181,9 +181,12 @@ int dump_task_fpu (struct task_struct *tsk, elf_fpregset_t *r)
181 return 1; 181 return 1;
182} 182}
183 183
184/*
185 * Copy architecture-specific thread state
186 */
184int 187int
185copy_thread(unsigned long clone_flags, unsigned long usp, 188copy_thread(unsigned long clone_flags, unsigned long usp,
186 unsigned long arg, struct task_struct *p) 189 unsigned long kthread_arg, struct task_struct *p)
187{ 190{
188 struct pt_regs *cregs = &(p->thread.regs); 191 struct pt_regs *cregs = &(p->thread.regs);
189 void *stack = task_stack_page(p); 192 void *stack = task_stack_page(p);
@@ -195,11 +198,10 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
195 extern void * const child_return; 198 extern void * const child_return;
196 199
197 if (unlikely(p->flags & PF_KTHREAD)) { 200 if (unlikely(p->flags & PF_KTHREAD)) {
201 /* kernel thread */
198 memset(cregs, 0, sizeof(struct pt_regs)); 202 memset(cregs, 0, sizeof(struct pt_regs));
199 if (!usp) /* idle thread */ 203 if (!usp) /* idle thread */
200 return 0; 204 return 0;
201
202 /* kernel thread */
203 /* Must exit via ret_from_kernel_thread in order 205 /* Must exit via ret_from_kernel_thread in order
204 * to call schedule_tail() 206 * to call schedule_tail()
205 */ 207 */
@@ -215,7 +217,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
215#else 217#else
216 cregs->gr[26] = usp; 218 cregs->gr[26] = usp;
217#endif 219#endif
218 cregs->gr[25] = arg; 220 cregs->gr[25] = kthread_arg;
219 } else { 221 } else {
220 /* user thread */ 222 /* user thread */
221 /* usp must be word aligned. This also prevents users from 223 /* usp must be word aligned. This also prevents users from
diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
index e1ffea2f9a0b..5aba01ac457f 100644
--- a/arch/parisc/kernel/sys_parisc.c
+++ b/arch/parisc/kernel/sys_parisc.c
@@ -77,6 +77,9 @@ static unsigned long mmap_upper_limit(void)
77 if (stack_base > STACK_SIZE_MAX) 77 if (stack_base > STACK_SIZE_MAX)
78 stack_base = STACK_SIZE_MAX; 78 stack_base = STACK_SIZE_MAX;
79 79
80 /* Add space for stack randomization. */
81 stack_base += (STACK_RND_MASK << PAGE_SHIFT);
82
80 return PAGE_ALIGN(STACK_TOP - stack_base); 83 return PAGE_ALIGN(STACK_TOP - stack_base);
81} 84}
82 85
diff --git a/arch/powerpc/include/uapi/asm/tm.h b/arch/powerpc/include/uapi/asm/tm.h
index 5047659815a5..5d836b7c1176 100644
--- a/arch/powerpc/include/uapi/asm/tm.h
+++ b/arch/powerpc/include/uapi/asm/tm.h
@@ -11,7 +11,7 @@
11#define TM_CAUSE_RESCHED 0xde 11#define TM_CAUSE_RESCHED 0xde
12#define TM_CAUSE_TLBI 0xdc 12#define TM_CAUSE_TLBI 0xdc
13#define TM_CAUSE_FAC_UNAV 0xda 13#define TM_CAUSE_FAC_UNAV 0xda
14#define TM_CAUSE_SYSCALL 0xd8 14#define TM_CAUSE_SYSCALL 0xd8 /* future use */
15#define TM_CAUSE_MISC 0xd6 /* future use */ 15#define TM_CAUSE_MISC 0xd6 /* future use */
16#define TM_CAUSE_SIGNAL 0xd4 16#define TM_CAUSE_SIGNAL 0xd4
17#define TM_CAUSE_ALIGNMENT 0xd2 17#define TM_CAUSE_ALIGNMENT 0xd2
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index 44b480e3a5af..9ee61d15653d 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c
@@ -749,21 +749,24 @@ int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state stat
749 eeh_unfreeze_pe(pe, false); 749 eeh_unfreeze_pe(pe, false);
750 eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED); 750 eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED);
751 eeh_pe_dev_traverse(pe, eeh_restore_dev_state, dev); 751 eeh_pe_dev_traverse(pe, eeh_restore_dev_state, dev);
752 eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
752 break; 753 break;
753 case pcie_hot_reset: 754 case pcie_hot_reset:
755 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
754 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE); 756 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
755 eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev); 757 eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev);
756 eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED); 758 eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
757 eeh_ops->reset(pe, EEH_RESET_HOT); 759 eeh_ops->reset(pe, EEH_RESET_HOT);
758 break; 760 break;
759 case pcie_warm_reset: 761 case pcie_warm_reset:
762 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
760 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE); 763 eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
761 eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev); 764 eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev);
762 eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED); 765 eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
763 eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL); 766 eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
764 break; 767 break;
765 default: 768 default:
766 eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED); 769 eeh_pe_state_clear(pe, EEH_PE_ISOLATED | EEH_PE_CFG_BLOCKED);
767 return -EINVAL; 770 return -EINVAL;
768 }; 771 };
769 772
@@ -1058,6 +1061,9 @@ void eeh_add_device_early(struct pci_dn *pdn)
1058 if (!edev || !eeh_enabled()) 1061 if (!edev || !eeh_enabled())
1059 return; 1062 return;
1060 1063
1064 if (!eeh_has_flag(EEH_PROBE_MODE_DEVTREE))
1065 return;
1066
1061 /* USB Bus children of PCI devices will not have BUID's */ 1067 /* USB Bus children of PCI devices will not have BUID's */
1062 phb = edev->phb; 1068 phb = edev->phb;
1063 if (NULL == phb || 1069 if (NULL == phb ||
@@ -1112,6 +1118,9 @@ void eeh_add_device_late(struct pci_dev *dev)
1112 return; 1118 return;
1113 } 1119 }
1114 1120
1121 if (eeh_has_flag(EEH_PROBE_MODE_DEV))
1122 eeh_ops->probe(pdn, NULL);
1123
1115 /* 1124 /*
1116 * The EEH cache might not be removed correctly because of 1125 * The EEH cache might not be removed correctly because of
1117 * unbalanced kref to the device during unplug time, which 1126 * unbalanced kref to the device during unplug time, which
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 8ca9434c40e6..afbc20019c2e 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -34,7 +34,6 @@
34#include <asm/ftrace.h> 34#include <asm/ftrace.h>
35#include <asm/hw_irq.h> 35#include <asm/hw_irq.h>
36#include <asm/context_tracking.h> 36#include <asm/context_tracking.h>
37#include <asm/tm.h>
38 37
39/* 38/*
40 * System calls. 39 * System calls.
@@ -146,24 +145,6 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
146 andi. r11,r10,_TIF_SYSCALL_DOTRACE 145 andi. r11,r10,_TIF_SYSCALL_DOTRACE
147 bne syscall_dotrace 146 bne syscall_dotrace
148.Lsyscall_dotrace_cont: 147.Lsyscall_dotrace_cont:
149#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
150BEGIN_FTR_SECTION
151 b 1f
152END_FTR_SECTION_IFCLR(CPU_FTR_TM)
153 extrdi. r11, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */
154 beq+ 1f
155
156 /* Doom the transaction and don't perform the syscall: */
157 mfmsr r11
158 li r12, 1
159 rldimi r11, r12, MSR_TM_LG, 63-MSR_TM_LG
160 mtmsrd r11, 0
161 li r11, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
162 TABORT(R11)
163
164 b .Lsyscall_exit
1651:
166#endif
167 cmpldi 0,r0,NR_syscalls 148 cmpldi 0,r0,NR_syscalls
168 bge- syscall_enosys 149 bge- syscall_enosys
169 150
diff --git a/arch/powerpc/kernel/idle_power7.S b/arch/powerpc/kernel/idle_power7.S
index eeaa0d5f69d5..ccde8f084ce4 100644
--- a/arch/powerpc/kernel/idle_power7.S
+++ b/arch/powerpc/kernel/idle_power7.S
@@ -501,9 +501,11 @@ BEGIN_FTR_SECTION
501 CHECK_HMI_INTERRUPT 501 CHECK_HMI_INTERRUPT
502END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) 502END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
503 ld r1,PACAR1(r13) 503 ld r1,PACAR1(r13)
504 ld r6,_CCR(r1)
504 ld r4,_MSR(r1) 505 ld r4,_MSR(r1)
505 ld r5,_NIP(r1) 506 ld r5,_NIP(r1)
506 addi r1,r1,INT_FRAME_SIZE 507 addi r1,r1,INT_FRAME_SIZE
508 mtcr r6
507 mtspr SPRN_SRR1,r4 509 mtspr SPRN_SRR1,r4
508 mtspr SPRN_SRR0,r5 510 mtspr SPRN_SRR0,r5
509 rfid 511 rfid
diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index 15c99b649b04..b2eb4686bd8f 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -73,7 +73,7 @@ void save_mce_event(struct pt_regs *regs, long handled,
73 uint64_t nip, uint64_t addr) 73 uint64_t nip, uint64_t addr)
74{ 74{
75 uint64_t srr1; 75 uint64_t srr1;
76 int index = __this_cpu_inc_return(mce_nest_count); 76 int index = __this_cpu_inc_return(mce_nest_count) - 1;
77 struct machine_check_event *mce = this_cpu_ptr(&mce_event[index]); 77 struct machine_check_event *mce = this_cpu_ptr(&mce_event[index]);
78 78
79 /* 79 /*
@@ -184,7 +184,7 @@ void machine_check_queue_event(void)
184 if (!get_mce_event(&evt, MCE_EVENT_RELEASE)) 184 if (!get_mce_event(&evt, MCE_EVENT_RELEASE))
185 return; 185 return;
186 186
187 index = __this_cpu_inc_return(mce_queue_count); 187 index = __this_cpu_inc_return(mce_queue_count) - 1;
188 /* If queue is full, just return for now. */ 188 /* If queue is full, just return for now. */
189 if (index >= MAX_MC_EVT) { 189 if (index >= MAX_MC_EVT) {
190 __this_cpu_dec(mce_queue_count); 190 __this_cpu_dec(mce_queue_count);
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index f096e72262f4..1db685104ffc 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -213,6 +213,7 @@ SECTIONS
213 *(.opd) 213 *(.opd)
214 } 214 }
215 215
216 . = ALIGN(256);
216 .got : AT(ADDR(.got) - LOAD_OFFSET) { 217 .got : AT(ADDR(.got) - LOAD_OFFSET) {
217 __toc_start = .; 218 __toc_start = .;
218#ifndef CONFIG_RELOCATABLE 219#ifndef CONFIG_RELOCATABLE
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 48d3c5d2ecc9..df81caab7383 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1952,7 +1952,7 @@ static void post_guest_process(struct kvmppc_vcore *vc)
1952 */ 1952 */
1953static noinline void kvmppc_run_core(struct kvmppc_vcore *vc) 1953static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
1954{ 1954{
1955 struct kvm_vcpu *vcpu; 1955 struct kvm_vcpu *vcpu, *vnext;
1956 int i; 1956 int i;
1957 int srcu_idx; 1957 int srcu_idx;
1958 1958
@@ -1982,7 +1982,8 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
1982 */ 1982 */
1983 if ((threads_per_core > 1) && 1983 if ((threads_per_core > 1) &&
1984 ((vc->num_threads > threads_per_subcore) || !on_primary_thread())) { 1984 ((vc->num_threads > threads_per_subcore) || !on_primary_thread())) {
1985 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { 1985 list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads,
1986 arch.run_list) {
1986 vcpu->arch.ret = -EBUSY; 1987 vcpu->arch.ret = -EBUSY;
1987 kvmppc_remove_runnable(vc, vcpu); 1988 kvmppc_remove_runnable(vc, vcpu);
1988 wake_up(&vcpu->arch.cpu_run); 1989 wake_up(&vcpu->arch.cpu_run);
diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 8f3e6cc54d95..c6ca7db64673 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -12,6 +12,7 @@
12#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/gfp.h> 13#include <linux/gfp.h>
14#include <linux/anon_inodes.h> 14#include <linux/anon_inodes.h>
15#include <linux/spinlock.h>
15 16
16#include <asm/uaccess.h> 17#include <asm/uaccess.h>
17#include <asm/kvm_book3s.h> 18#include <asm/kvm_book3s.h>
@@ -20,7 +21,6 @@
20#include <asm/xics.h> 21#include <asm/xics.h>
21#include <asm/debug.h> 22#include <asm/debug.h>
22#include <asm/time.h> 23#include <asm/time.h>
23#include <asm/spinlock.h>
24 24
25#include <linux/debugfs.h> 25#include <linux/debugfs.h>
26#include <linux/seq_file.h> 26#include <linux/seq_file.h>
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 0ce968b00b7c..3385e3d0506e 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -689,27 +689,34 @@ void hugetlb_free_pgd_range(struct mmu_gather *tlb,
689struct page * 689struct page *
690follow_huge_addr(struct mm_struct *mm, unsigned long address, int write) 690follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
691{ 691{
692 pte_t *ptep; 692 pte_t *ptep, pte;
693 struct page *page;
694 unsigned shift; 693 unsigned shift;
695 unsigned long mask, flags; 694 unsigned long mask, flags;
695 struct page *page = ERR_PTR(-EINVAL);
696
697 local_irq_save(flags);
698 ptep = find_linux_pte_or_hugepte(mm->pgd, address, &shift);
699 if (!ptep)
700 goto no_page;
701 pte = READ_ONCE(*ptep);
696 /* 702 /*
703 * Verify it is a huge page else bail.
697 * Transparent hugepages are handled by generic code. We can skip them 704 * Transparent hugepages are handled by generic code. We can skip them
698 * here. 705 * here.
699 */ 706 */
700 local_irq_save(flags); 707 if (!shift || pmd_trans_huge(__pmd(pte_val(pte))))
701 ptep = find_linux_pte_or_hugepte(mm->pgd, address, &shift); 708 goto no_page;
702 709
703 /* Verify it is a huge page else bail. */ 710 if (!pte_present(pte)) {
704 if (!ptep || !shift || pmd_trans_huge(*(pmd_t *)ptep)) { 711 page = NULL;
705 local_irq_restore(flags); 712 goto no_page;
706 return ERR_PTR(-EINVAL);
707 } 713 }
708 mask = (1UL << shift) - 1; 714 mask = (1UL << shift) - 1;
709 page = pte_page(*ptep); 715 page = pte_page(pte);
710 if (page) 716 if (page)
711 page += (address & mask) / PAGE_SIZE; 717 page += (address & mask) / PAGE_SIZE;
712 718
719no_page:
713 local_irq_restore(flags); 720 local_irq_restore(flags);
714 return page; 721 return page;
715} 722}
diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c
index 59daa5eeec25..6bfadf1aa5cb 100644
--- a/arch/powerpc/mm/pgtable_64.c
+++ b/arch/powerpc/mm/pgtable_64.c
@@ -839,6 +839,17 @@ pmd_t pmdp_get_and_clear(struct mm_struct *mm,
839 * hash fault look at them. 839 * hash fault look at them.
840 */ 840 */
841 memset(pgtable, 0, PTE_FRAG_SIZE); 841 memset(pgtable, 0, PTE_FRAG_SIZE);
842 /*
843 * Serialize against find_linux_pte_or_hugepte which does lock-less
844 * lookup in page tables with local interrupts disabled. For huge pages
845 * it casts pmd_t to pte_t. Since format of pte_t is different from
846 * pmd_t we want to prevent transit from pmd pointing to page table
847 * to pmd pointing to huge page (and back) while interrupts are disabled.
848 * We clear pmd to possibly replace it with page table pointer in
849 * different code paths. So make sure we wait for the parallel
850 * find_linux_pte_or_hugepage to finish.
851 */
852 kick_all_cpus_sync();
842 return old_pmd; 853 return old_pmd;
843} 854}
844 855
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 920c252d1f49..f8bc950efcae 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2693,7 +2693,6 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
2693 hose->last_busno = 0xff; 2693 hose->last_busno = 0xff;
2694 } 2694 }
2695 hose->private_data = phb; 2695 hose->private_data = phb;
2696 hose->controller_ops = pnv_pci_controller_ops;
2697 phb->hub_id = hub_id; 2696 phb->hub_id = hub_id;
2698 phb->opal_id = phb_id; 2697 phb->opal_id = phb_id;
2699 phb->type = ioda_type; 2698 phb->type = ioda_type;
@@ -2812,6 +2811,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
2812 pnv_pci_controller_ops.enable_device_hook = pnv_pci_enable_device_hook; 2811 pnv_pci_controller_ops.enable_device_hook = pnv_pci_enable_device_hook;
2813 pnv_pci_controller_ops.window_alignment = pnv_pci_window_alignment; 2812 pnv_pci_controller_ops.window_alignment = pnv_pci_window_alignment;
2814 pnv_pci_controller_ops.reset_secondary_bus = pnv_pci_reset_secondary_bus; 2813 pnv_pci_controller_ops.reset_secondary_bus = pnv_pci_reset_secondary_bus;
2814 hose->controller_ops = pnv_pci_controller_ops;
2815 2815
2816#ifdef CONFIG_PCI_IOV 2816#ifdef CONFIG_PCI_IOV
2817 ppc_md.pcibios_fixup_sriov = pnv_pci_ioda_fixup_iov_resources; 2817 ppc_md.pcibios_fixup_sriov = pnv_pci_ioda_fixup_iov_resources;
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index b4b11096ea8b..019d34aaf054 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -412,6 +412,10 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
412 if (rc) 412 if (rc)
413 return -EINVAL; 413 return -EINVAL;
414 414
415 rc = dlpar_acquire_drc(drc_index);
416 if (rc)
417 return -EINVAL;
418
415 parent = of_find_node_by_path("/cpus"); 419 parent = of_find_node_by_path("/cpus");
416 if (!parent) 420 if (!parent)
417 return -ENODEV; 421 return -ENODEV;
@@ -422,12 +426,6 @@ static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
422 426
423 of_node_put(parent); 427 of_node_put(parent);
424 428
425 rc = dlpar_acquire_drc(drc_index);
426 if (rc) {
427 dlpar_free_cc_nodes(dn);
428 return -EINVAL;
429 }
430
431 rc = dlpar_attach_node(dn); 429 rc = dlpar_attach_node(dn);
432 if (rc) { 430 if (rc) {
433 dlpar_release_drc(drc_index); 431 dlpar_release_drc(drc_index);
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 8e58c614c37d..b06dc3839268 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -115,7 +115,7 @@ config S390
115 select HAVE_ARCH_SECCOMP_FILTER 115 select HAVE_ARCH_SECCOMP_FILTER
116 select HAVE_ARCH_TRACEHOOK 116 select HAVE_ARCH_TRACEHOOK
117 select HAVE_ARCH_TRANSPARENT_HUGEPAGE 117 select HAVE_ARCH_TRANSPARENT_HUGEPAGE
118 select HAVE_BPF_JIT if PACK_STACK && HAVE_MARCH_Z9_109_FEATURES 118 select HAVE_BPF_JIT if PACK_STACK && HAVE_MARCH_Z196_FEATURES
119 select HAVE_CMPXCHG_DOUBLE 119 select HAVE_CMPXCHG_DOUBLE
120 select HAVE_CMPXCHG_LOCAL 120 select HAVE_CMPXCHG_LOCAL
121 select HAVE_DEBUG_KMEMLEAK 121 select HAVE_DEBUG_KMEMLEAK
diff --git a/arch/s390/crypto/crypt_s390.h b/arch/s390/crypto/crypt_s390.h
index ba3b2aefddf5..d9c4c313fbc6 100644
--- a/arch/s390/crypto/crypt_s390.h
+++ b/arch/s390/crypto/crypt_s390.h
@@ -3,9 +3,10 @@
3 * 3 *
4 * Support for s390 cryptographic instructions. 4 * Support for s390 cryptographic instructions.
5 * 5 *
6 * Copyright IBM Corp. 2003, 2007 6 * Copyright IBM Corp. 2003, 2015
7 * Author(s): Thomas Spatzier 7 * Author(s): Thomas Spatzier
8 * Jan Glauber (jan.glauber@de.ibm.com) 8 * Jan Glauber (jan.glauber@de.ibm.com)
9 * Harald Freudenberger (freude@de.ibm.com)
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify it 11 * 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 * under the terms of the GNU General Public License as published by the Free
@@ -28,15 +29,17 @@
28#define CRYPT_S390_MSA 0x1 29#define CRYPT_S390_MSA 0x1
29#define CRYPT_S390_MSA3 0x2 30#define CRYPT_S390_MSA3 0x2
30#define CRYPT_S390_MSA4 0x4 31#define CRYPT_S390_MSA4 0x4
32#define CRYPT_S390_MSA5 0x8
31 33
32/* s390 cryptographic operations */ 34/* s390 cryptographic operations */
33enum crypt_s390_operations { 35enum crypt_s390_operations {
34 CRYPT_S390_KM = 0x0100, 36 CRYPT_S390_KM = 0x0100,
35 CRYPT_S390_KMC = 0x0200, 37 CRYPT_S390_KMC = 0x0200,
36 CRYPT_S390_KIMD = 0x0300, 38 CRYPT_S390_KIMD = 0x0300,
37 CRYPT_S390_KLMD = 0x0400, 39 CRYPT_S390_KLMD = 0x0400,
38 CRYPT_S390_KMAC = 0x0500, 40 CRYPT_S390_KMAC = 0x0500,
39 CRYPT_S390_KMCTR = 0x0600 41 CRYPT_S390_KMCTR = 0x0600,
42 CRYPT_S390_PPNO = 0x0700
40}; 43};
41 44
42/* 45/*
@@ -138,6 +141,16 @@ enum crypt_s390_kmac_func {
138 KMAC_TDEA_192 = CRYPT_S390_KMAC | 3 141 KMAC_TDEA_192 = CRYPT_S390_KMAC | 3
139}; 142};
140 143
144/*
145 * function codes for PPNO (PERFORM PSEUDORANDOM NUMBER
146 * OPERATION) instruction
147 */
148enum crypt_s390_ppno_func {
149 PPNO_QUERY = CRYPT_S390_PPNO | 0,
150 PPNO_SHA512_DRNG_GEN = CRYPT_S390_PPNO | 3,
151 PPNO_SHA512_DRNG_SEED = CRYPT_S390_PPNO | 0x83
152};
153
141/** 154/**
142 * crypt_s390_km: 155 * crypt_s390_km:
143 * @func: the function code passed to KM; see crypt_s390_km_func 156 * @func: the function code passed to KM; see crypt_s390_km_func
@@ -162,11 +175,11 @@ static inline int crypt_s390_km(long func, void *param,
162 int ret; 175 int ret;
163 176
164 asm volatile( 177 asm volatile(
165 "0: .insn rre,0xb92e0000,%3,%1 \n" /* KM opcode */ 178 "0: .insn rre,0xb92e0000,%3,%1\n" /* KM opcode */
166 "1: brc 1,0b \n" /* handle partial completion */ 179 "1: brc 1,0b\n" /* handle partial completion */
167 " la %0,0\n" 180 " la %0,0\n"
168 "2:\n" 181 "2:\n"
169 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 182 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
170 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest) 183 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
171 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 184 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
172 if (ret < 0) 185 if (ret < 0)
@@ -198,11 +211,11 @@ static inline int crypt_s390_kmc(long func, void *param,
198 int ret; 211 int ret;
199 212
200 asm volatile( 213 asm volatile(
201 "0: .insn rre,0xb92f0000,%3,%1 \n" /* KMC opcode */ 214 "0: .insn rre,0xb92f0000,%3,%1\n" /* KMC opcode */
202 "1: brc 1,0b \n" /* handle partial completion */ 215 "1: brc 1,0b\n" /* handle partial completion */
203 " la %0,0\n" 216 " la %0,0\n"
204 "2:\n" 217 "2:\n"
205 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 218 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
206 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest) 219 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
207 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 220 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
208 if (ret < 0) 221 if (ret < 0)
@@ -233,11 +246,11 @@ static inline int crypt_s390_kimd(long func, void *param,
233 int ret; 246 int ret;
234 247
235 asm volatile( 248 asm volatile(
236 "0: .insn rre,0xb93e0000,%1,%1 \n" /* KIMD opcode */ 249 "0: .insn rre,0xb93e0000,%1,%1\n" /* KIMD opcode */
237 "1: brc 1,0b \n" /* handle partial completion */ 250 "1: brc 1,0b\n" /* handle partial completion */
238 " la %0,0\n" 251 " la %0,0\n"
239 "2:\n" 252 "2:\n"
240 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 253 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
241 : "=d" (ret), "+a" (__src), "+d" (__src_len) 254 : "=d" (ret), "+a" (__src), "+d" (__src_len)
242 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 255 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
243 if (ret < 0) 256 if (ret < 0)
@@ -267,11 +280,11 @@ static inline int crypt_s390_klmd(long func, void *param,
267 int ret; 280 int ret;
268 281
269 asm volatile( 282 asm volatile(
270 "0: .insn rre,0xb93f0000,%1,%1 \n" /* KLMD opcode */ 283 "0: .insn rre,0xb93f0000,%1,%1\n" /* KLMD opcode */
271 "1: brc 1,0b \n" /* handle partial completion */ 284 "1: brc 1,0b\n" /* handle partial completion */
272 " la %0,0\n" 285 " la %0,0\n"
273 "2:\n" 286 "2:\n"
274 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 287 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
275 : "=d" (ret), "+a" (__src), "+d" (__src_len) 288 : "=d" (ret), "+a" (__src), "+d" (__src_len)
276 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 289 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
277 if (ret < 0) 290 if (ret < 0)
@@ -302,11 +315,11 @@ static inline int crypt_s390_kmac(long func, void *param,
302 int ret; 315 int ret;
303 316
304 asm volatile( 317 asm volatile(
305 "0: .insn rre,0xb91e0000,%1,%1 \n" /* KLAC opcode */ 318 "0: .insn rre,0xb91e0000,%1,%1\n" /* KLAC opcode */
306 "1: brc 1,0b \n" /* handle partial completion */ 319 "1: brc 1,0b\n" /* handle partial completion */
307 " la %0,0\n" 320 " la %0,0\n"
308 "2:\n" 321 "2:\n"
309 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 322 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
310 : "=d" (ret), "+a" (__src), "+d" (__src_len) 323 : "=d" (ret), "+a" (__src), "+d" (__src_len)
311 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 324 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
312 if (ret < 0) 325 if (ret < 0)
@@ -340,11 +353,11 @@ static inline int crypt_s390_kmctr(long func, void *param, u8 *dest,
340 int ret = -1; 353 int ret = -1;
341 354
342 asm volatile( 355 asm volatile(
343 "0: .insn rrf,0xb92d0000,%3,%1,%4,0 \n" /* KMCTR opcode */ 356 "0: .insn rrf,0xb92d0000,%3,%1,%4,0\n" /* KMCTR opcode */
344 "1: brc 1,0b \n" /* handle partial completion */ 357 "1: brc 1,0b\n" /* handle partial completion */
345 " la %0,0\n" 358 " la %0,0\n"
346 "2:\n" 359 "2:\n"
347 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 360 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
348 : "+d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest), 361 : "+d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest),
349 "+a" (__ctr) 362 "+a" (__ctr)
350 : "d" (__func), "a" (__param) : "cc", "memory"); 363 : "d" (__func), "a" (__param) : "cc", "memory");
@@ -354,6 +367,47 @@ static inline int crypt_s390_kmctr(long func, void *param, u8 *dest,
354} 367}
355 368
356/** 369/**
370 * crypt_s390_ppno:
371 * @func: the function code passed to PPNO; see crypt_s390_ppno_func
372 * @param: address of parameter block; see POP for details on each func
373 * @dest: address of destination memory area
374 * @dest_len: size of destination memory area in bytes
375 * @seed: address of seed data
376 * @seed_len: size of seed data in bytes
377 *
378 * Executes the PPNO (PERFORM PSEUDORANDOM NUMBER OPERATION)
379 * operation of the CPU.
380 *
381 * Returns -1 for failure, 0 for the query func, number of random
382 * bytes stored in dest buffer for generate function
383 */
384static inline int crypt_s390_ppno(long func, void *param,
385 u8 *dest, long dest_len,
386 const u8 *seed, long seed_len)
387{
388 register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
389 register void *__param asm("1") = param; /* param block (240 bytes) */
390 register u8 *__dest asm("2") = dest; /* buf for recv random bytes */
391 register long __dest_len asm("3") = dest_len; /* requested random bytes */
392 register const u8 *__seed asm("4") = seed; /* buf with seed data */
393 register long __seed_len asm("5") = seed_len; /* bytes in seed buf */
394 int ret = -1;
395
396 asm volatile (
397 "0: .insn rre,0xb93c0000,%1,%5\n" /* PPNO opcode */
398 "1: brc 1,0b\n" /* handle partial completion */
399 " la %0,0\n"
400 "2:\n"
401 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
402 : "+d" (ret), "+a"(__dest), "+d"(__dest_len)
403 : "d"(__func), "a"(__param), "a"(__seed), "d"(__seed_len)
404 : "cc", "memory");
405 if (ret < 0)
406 return ret;
407 return (func & CRYPT_S390_FUNC_MASK) ? dest_len - __dest_len : 0;
408}
409
410/**
357 * crypt_s390_func_available: 411 * crypt_s390_func_available:
358 * @func: the function code of the specific function; 0 if op in general 412 * @func: the function code of the specific function; 0 if op in general
359 * 413 *
@@ -373,6 +427,9 @@ static inline int crypt_s390_func_available(int func,
373 return 0; 427 return 0;
374 if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77)) 428 if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77))
375 return 0; 429 return 0;
430 if (facility_mask & CRYPT_S390_MSA5 && !test_facility(57))
431 return 0;
432
376 switch (func & CRYPT_S390_OP_MASK) { 433 switch (func & CRYPT_S390_OP_MASK) {
377 case CRYPT_S390_KM: 434 case CRYPT_S390_KM:
378 ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0); 435 ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0);
@@ -390,8 +447,12 @@ static inline int crypt_s390_func_available(int func,
390 ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0); 447 ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0);
391 break; 448 break;
392 case CRYPT_S390_KMCTR: 449 case CRYPT_S390_KMCTR:
393 ret = crypt_s390_kmctr(KMCTR_QUERY, &status, NULL, NULL, 0, 450 ret = crypt_s390_kmctr(KMCTR_QUERY, &status,
394 NULL); 451 NULL, NULL, 0, NULL);
452 break;
453 case CRYPT_S390_PPNO:
454 ret = crypt_s390_ppno(PPNO_QUERY, &status,
455 NULL, 0, NULL, 0);
395 break; 456 break;
396 default: 457 default:
397 return 0; 458 return 0;
@@ -419,15 +480,14 @@ static inline int crypt_s390_pcc(long func, void *param)
419 int ret = -1; 480 int ret = -1;
420 481
421 asm volatile( 482 asm volatile(
422 "0: .insn rre,0xb92c0000,0,0 \n" /* PCC opcode */ 483 "0: .insn rre,0xb92c0000,0,0\n" /* PCC opcode */
423 "1: brc 1,0b \n" /* handle partial completion */ 484 "1: brc 1,0b\n" /* handle partial completion */
424 " la %0,0\n" 485 " la %0,0\n"
425 "2:\n" 486 "2:\n"
426 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 487 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
427 : "+d" (ret) 488 : "+d" (ret)
428 : "d" (__func), "a" (__param) : "cc", "memory"); 489 : "d" (__func), "a" (__param) : "cc", "memory");
429 return ret; 490 return ret;
430} 491}
431 492
432
433#endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */ 493#endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */
diff --git a/arch/s390/crypto/ghash_s390.c b/arch/s390/crypto/ghash_s390.c
index 7940dc90e80b..b258110da952 100644
--- a/arch/s390/crypto/ghash_s390.c
+++ b/arch/s390/crypto/ghash_s390.c
@@ -16,11 +16,12 @@
16#define GHASH_DIGEST_SIZE 16 16#define GHASH_DIGEST_SIZE 16
17 17
18struct ghash_ctx { 18struct ghash_ctx {
19 u8 icv[16]; 19 u8 key[GHASH_BLOCK_SIZE];
20 u8 key[16];
21}; 20};
22 21
23struct ghash_desc_ctx { 22struct ghash_desc_ctx {
23 u8 icv[GHASH_BLOCK_SIZE];
24 u8 key[GHASH_BLOCK_SIZE];
24 u8 buffer[GHASH_BLOCK_SIZE]; 25 u8 buffer[GHASH_BLOCK_SIZE];
25 u32 bytes; 26 u32 bytes;
26}; 27};
@@ -28,8 +29,10 @@ struct ghash_desc_ctx {
28static int ghash_init(struct shash_desc *desc) 29static int ghash_init(struct shash_desc *desc)
29{ 30{
30 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); 31 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc);
32 struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm);
31 33
32 memset(dctx, 0, sizeof(*dctx)); 34 memset(dctx, 0, sizeof(*dctx));
35 memcpy(dctx->key, ctx->key, GHASH_BLOCK_SIZE);
33 36
34 return 0; 37 return 0;
35} 38}
@@ -45,7 +48,6 @@ static int ghash_setkey(struct crypto_shash *tfm,
45 } 48 }
46 49
47 memcpy(ctx->key, key, GHASH_BLOCK_SIZE); 50 memcpy(ctx->key, key, GHASH_BLOCK_SIZE);
48 memset(ctx->icv, 0, GHASH_BLOCK_SIZE);
49 51
50 return 0; 52 return 0;
51} 53}
@@ -54,7 +56,6 @@ static int ghash_update(struct shash_desc *desc,
54 const u8 *src, unsigned int srclen) 56 const u8 *src, unsigned int srclen)
55{ 57{
56 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); 58 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc);
57 struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm);
58 unsigned int n; 59 unsigned int n;
59 u8 *buf = dctx->buffer; 60 u8 *buf = dctx->buffer;
60 int ret; 61 int ret;
@@ -70,7 +71,7 @@ static int ghash_update(struct shash_desc *desc,
70 src += n; 71 src += n;
71 72
72 if (!dctx->bytes) { 73 if (!dctx->bytes) {
73 ret = crypt_s390_kimd(KIMD_GHASH, ctx, buf, 74 ret = crypt_s390_kimd(KIMD_GHASH, dctx, buf,
74 GHASH_BLOCK_SIZE); 75 GHASH_BLOCK_SIZE);
75 if (ret != GHASH_BLOCK_SIZE) 76 if (ret != GHASH_BLOCK_SIZE)
76 return -EIO; 77 return -EIO;
@@ -79,7 +80,7 @@ static int ghash_update(struct shash_desc *desc,
79 80
80 n = srclen & ~(GHASH_BLOCK_SIZE - 1); 81 n = srclen & ~(GHASH_BLOCK_SIZE - 1);
81 if (n) { 82 if (n) {
82 ret = crypt_s390_kimd(KIMD_GHASH, ctx, src, n); 83 ret = crypt_s390_kimd(KIMD_GHASH, dctx, src, n);
83 if (ret != n) 84 if (ret != n)
84 return -EIO; 85 return -EIO;
85 src += n; 86 src += n;
@@ -94,7 +95,7 @@ static int ghash_update(struct shash_desc *desc,
94 return 0; 95 return 0;
95} 96}
96 97
97static int ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx) 98static int ghash_flush(struct ghash_desc_ctx *dctx)
98{ 99{
99 u8 *buf = dctx->buffer; 100 u8 *buf = dctx->buffer;
100 int ret; 101 int ret;
@@ -104,24 +105,24 @@ static int ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx)
104 105
105 memset(pos, 0, dctx->bytes); 106 memset(pos, 0, dctx->bytes);
106 107
107 ret = crypt_s390_kimd(KIMD_GHASH, ctx, buf, GHASH_BLOCK_SIZE); 108 ret = crypt_s390_kimd(KIMD_GHASH, dctx, buf, GHASH_BLOCK_SIZE);
108 if (ret != GHASH_BLOCK_SIZE) 109 if (ret != GHASH_BLOCK_SIZE)
109 return -EIO; 110 return -EIO;
111
112 dctx->bytes = 0;
110 } 113 }
111 114
112 dctx->bytes = 0;
113 return 0; 115 return 0;
114} 116}
115 117
116static int ghash_final(struct shash_desc *desc, u8 *dst) 118static int ghash_final(struct shash_desc *desc, u8 *dst)
117{ 119{
118 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); 120 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc);
119 struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm);
120 int ret; 121 int ret;
121 122
122 ret = ghash_flush(ctx, dctx); 123 ret = ghash_flush(dctx);
123 if (!ret) 124 if (!ret)
124 memcpy(dst, ctx->icv, GHASH_BLOCK_SIZE); 125 memcpy(dst, dctx->icv, GHASH_BLOCK_SIZE);
125 return ret; 126 return ret;
126} 127}
127 128
diff --git a/arch/s390/crypto/prng.c b/arch/s390/crypto/prng.c
index 94a35a4c1b48..9d5192c94963 100644
--- a/arch/s390/crypto/prng.c
+++ b/arch/s390/crypto/prng.c
@@ -1,106 +1,529 @@
1/* 1/*
2 * Copyright IBM Corp. 2006, 2007 2 * Copyright IBM Corp. 2006, 2015
3 * Author(s): Jan Glauber <jan.glauber@de.ibm.com> 3 * Author(s): Jan Glauber <jan.glauber@de.ibm.com>
4 * Harald Freudenberger <freude@de.ibm.com>
4 * Driver for the s390 pseudo random number generator 5 * Driver for the s390 pseudo random number generator
5 */ 6 */
7
8#define KMSG_COMPONENT "prng"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10
6#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/fips.h>
7#include <linux/init.h> 13#include <linux/init.h>
8#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/device.h>
9#include <linux/miscdevice.h> 16#include <linux/miscdevice.h>
10#include <linux/module.h> 17#include <linux/module.h>
11#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/mutex.h>
12#include <linux/random.h> 20#include <linux/random.h>
13#include <linux/slab.h> 21#include <linux/slab.h>
14#include <asm/debug.h> 22#include <asm/debug.h>
15#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/timex.h>
16 25
17#include "crypt_s390.h" 26#include "crypt_s390.h"
18 27
19MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Jan Glauber <jan.glauber@de.ibm.com>"); 29MODULE_AUTHOR("IBM Corporation");
21MODULE_DESCRIPTION("s390 PRNG interface"); 30MODULE_DESCRIPTION("s390 PRNG interface");
22 31
23static int prng_chunk_size = 256; 32
24module_param(prng_chunk_size, int, S_IRUSR | S_IRGRP | S_IROTH); 33#define PRNG_MODE_AUTO 0
34#define PRNG_MODE_TDES 1
35#define PRNG_MODE_SHA512 2
36
37static unsigned int prng_mode = PRNG_MODE_AUTO;
38module_param_named(mode, prng_mode, int, 0);
39MODULE_PARM_DESC(prng_mode, "PRNG mode: 0 - auto, 1 - TDES, 2 - SHA512");
40
41
42#define PRNG_CHUNKSIZE_TDES_MIN 8
43#define PRNG_CHUNKSIZE_TDES_MAX (64*1024)
44#define PRNG_CHUNKSIZE_SHA512_MIN 64
45#define PRNG_CHUNKSIZE_SHA512_MAX (64*1024)
46
47static unsigned int prng_chunk_size = 256;
48module_param_named(chunksize, prng_chunk_size, int, 0);
25MODULE_PARM_DESC(prng_chunk_size, "PRNG read chunk size in bytes"); 49MODULE_PARM_DESC(prng_chunk_size, "PRNG read chunk size in bytes");
26 50
27static int prng_entropy_limit = 4096; 51
28module_param(prng_entropy_limit, int, S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR); 52#define PRNG_RESEED_LIMIT_TDES 4096
29MODULE_PARM_DESC(prng_entropy_limit, 53#define PRNG_RESEED_LIMIT_TDES_LOWER 4096
30 "PRNG add entropy after that much bytes were produced"); 54#define PRNG_RESEED_LIMIT_SHA512 100000
55#define PRNG_RESEED_LIMIT_SHA512_LOWER 10000
56
57static unsigned int prng_reseed_limit;
58module_param_named(reseed_limit, prng_reseed_limit, int, 0);
59MODULE_PARM_DESC(prng_reseed_limit, "PRNG reseed limit");
60
31 61
32/* 62/*
33 * Any one who considers arithmetical methods of producing random digits is, 63 * Any one who considers arithmetical methods of producing random digits is,
34 * of course, in a state of sin. -- John von Neumann 64 * of course, in a state of sin. -- John von Neumann
35 */ 65 */
36 66
37struct s390_prng_data { 67static int prng_errorflag;
38 unsigned long count; /* how many bytes were produced */ 68
39 char *buf; 69#define PRNG_GEN_ENTROPY_FAILED 1
70#define PRNG_SELFTEST_FAILED 2
71#define PRNG_INSTANTIATE_FAILED 3
72#define PRNG_SEED_FAILED 4
73#define PRNG_RESEED_FAILED 5
74#define PRNG_GEN_FAILED 6
75
76struct prng_ws_s {
77 u8 parm_block[32];
78 u32 reseed_counter;
79 u64 byte_counter;
40}; 80};
41 81
42static struct s390_prng_data *p; 82struct ppno_ws_s {
83 u32 res;
84 u32 reseed_counter;
85 u64 stream_bytes;
86 u8 V[112];
87 u8 C[112];
88};
43 89
44/* copied from libica, use a non-zero initial parameter block */ 90struct prng_data_s {
45static unsigned char parm_block[32] = { 91 struct mutex mutex;
460x0F,0x2B,0x8E,0x63,0x8C,0x8E,0xD2,0x52,0x64,0xB7,0xA0,0x7B,0x75,0x28,0xB8,0xF4, 92 union {
470x75,0x5F,0xD2,0xA6,0x8D,0x97,0x11,0xFF,0x49,0xD8,0x23,0xF3,0x7E,0x21,0xEC,0xA0, 93 struct prng_ws_s prngws;
94 struct ppno_ws_s ppnows;
95 };
96 u8 *buf;
97 u32 rest;
98 u8 *prev;
48}; 99};
49 100
50static int prng_open(struct inode *inode, struct file *file) 101static struct prng_data_s *prng_data;
102
103/* initial parameter block for tdes mode, copied from libica */
104static const u8 initial_parm_block[32] __initconst = {
105 0x0F, 0x2B, 0x8E, 0x63, 0x8C, 0x8E, 0xD2, 0x52,
106 0x64, 0xB7, 0xA0, 0x7B, 0x75, 0x28, 0xB8, 0xF4,
107 0x75, 0x5F, 0xD2, 0xA6, 0x8D, 0x97, 0x11, 0xFF,
108 0x49, 0xD8, 0x23, 0xF3, 0x7E, 0x21, 0xEC, 0xA0 };
109
110
111/*** helper functions ***/
112
113static int generate_entropy(u8 *ebuf, size_t nbytes)
51{ 114{
52 return nonseekable_open(inode, file); 115 int n, ret = 0;
116 u8 *pg, *h, hash[32];
117
118 pg = (u8 *) __get_free_page(GFP_KERNEL);
119 if (!pg) {
120 prng_errorflag = PRNG_GEN_ENTROPY_FAILED;
121 return -ENOMEM;
122 }
123
124 while (nbytes) {
125 /* fill page with urandom bytes */
126 get_random_bytes(pg, PAGE_SIZE);
127 /* exor page with stckf values */
128 for (n = 0; n < PAGE_SIZE / sizeof(u64); n++) {
129 u64 *p = ((u64 *)pg) + n;
130 *p ^= get_tod_clock_fast();
131 }
132 n = (nbytes < sizeof(hash)) ? nbytes : sizeof(hash);
133 if (n < sizeof(hash))
134 h = hash;
135 else
136 h = ebuf;
137 /* generate sha256 from this page */
138 if (crypt_s390_kimd(KIMD_SHA_256, h,
139 pg, PAGE_SIZE) != PAGE_SIZE) {
140 prng_errorflag = PRNG_GEN_ENTROPY_FAILED;
141 ret = -EIO;
142 goto out;
143 }
144 if (n < sizeof(hash))
145 memcpy(ebuf, hash, n);
146 ret += n;
147 ebuf += n;
148 nbytes -= n;
149 }
150
151out:
152 free_page((unsigned long)pg);
153 return ret;
53} 154}
54 155
55static void prng_add_entropy(void) 156
157/*** tdes functions ***/
158
159static void prng_tdes_add_entropy(void)
56{ 160{
57 __u64 entropy[4]; 161 __u64 entropy[4];
58 unsigned int i; 162 unsigned int i;
59 int ret; 163 int ret;
60 164
61 for (i = 0; i < 16; i++) { 165 for (i = 0; i < 16; i++) {
62 ret = crypt_s390_kmc(KMC_PRNG, parm_block, (char *)entropy, 166 ret = crypt_s390_kmc(KMC_PRNG, prng_data->prngws.parm_block,
63 (char *)entropy, sizeof(entropy)); 167 (char *)entropy, (char *)entropy,
168 sizeof(entropy));
64 BUG_ON(ret < 0 || ret != sizeof(entropy)); 169 BUG_ON(ret < 0 || ret != sizeof(entropy));
65 memcpy(parm_block, entropy, sizeof(entropy)); 170 memcpy(prng_data->prngws.parm_block, entropy, sizeof(entropy));
66 } 171 }
67} 172}
68 173
69static void prng_seed(int nbytes) 174
175static void prng_tdes_seed(int nbytes)
70{ 176{
71 char buf[16]; 177 char buf[16];
72 int i = 0; 178 int i = 0;
73 179
74 BUG_ON(nbytes > 16); 180 BUG_ON(nbytes > sizeof(buf));
181
75 get_random_bytes(buf, nbytes); 182 get_random_bytes(buf, nbytes);
76 183
77 /* Add the entropy */ 184 /* Add the entropy */
78 while (nbytes >= 8) { 185 while (nbytes >= 8) {
79 *((__u64 *)parm_block) ^= *((__u64 *)(buf+i)); 186 *((__u64 *)prng_data->prngws.parm_block) ^= *((__u64 *)(buf+i));
80 prng_add_entropy(); 187 prng_tdes_add_entropy();
81 i += 8; 188 i += 8;
82 nbytes -= 8; 189 nbytes -= 8;
83 } 190 }
84 prng_add_entropy(); 191 prng_tdes_add_entropy();
192 prng_data->prngws.reseed_counter = 0;
193}
194
195
196static int __init prng_tdes_instantiate(void)
197{
198 int datalen;
199
200 pr_debug("prng runs in TDES mode with "
201 "chunksize=%d and reseed_limit=%u\n",
202 prng_chunk_size, prng_reseed_limit);
203
204 /* memory allocation, prng_data struct init, mutex init */
205 datalen = sizeof(struct prng_data_s) + prng_chunk_size;
206 prng_data = kzalloc(datalen, GFP_KERNEL);
207 if (!prng_data) {
208 prng_errorflag = PRNG_INSTANTIATE_FAILED;
209 return -ENOMEM;
210 }
211 mutex_init(&prng_data->mutex);
212 prng_data->buf = ((u8 *)prng_data) + sizeof(struct prng_data_s);
213 memcpy(prng_data->prngws.parm_block, initial_parm_block, 32);
214
215 /* initialize the PRNG, add 128 bits of entropy */
216 prng_tdes_seed(16);
217
218 return 0;
85} 219}
86 220
87static ssize_t prng_read(struct file *file, char __user *ubuf, size_t nbytes, 221
88 loff_t *ppos) 222static void prng_tdes_deinstantiate(void)
223{
224 pr_debug("The prng module stopped "
225 "after running in triple DES mode\n");
226 kzfree(prng_data);
227}
228
229
230/*** sha512 functions ***/
231
232static int __init prng_sha512_selftest(void)
89{ 233{
90 int chunk, n; 234 /* NIST DRBG testvector for Hash Drbg, Sha-512, Count #0 */
235 static const u8 seed[] __initconst = {
236 0x6b, 0x50, 0xa7, 0xd8, 0xf8, 0xa5, 0x5d, 0x7a,
237 0x3d, 0xf8, 0xbb, 0x40, 0xbc, 0xc3, 0xb7, 0x22,
238 0xd8, 0x70, 0x8d, 0xe6, 0x7f, 0xda, 0x01, 0x0b,
239 0x03, 0xc4, 0xc8, 0x4d, 0x72, 0x09, 0x6f, 0x8c,
240 0x3e, 0xc6, 0x49, 0xcc, 0x62, 0x56, 0xd9, 0xfa,
241 0x31, 0xdb, 0x7a, 0x29, 0x04, 0xaa, 0xf0, 0x25 };
242 static const u8 V0[] __initconst = {
243 0x00, 0xad, 0xe3, 0x6f, 0x9a, 0x01, 0xc7, 0x76,
244 0x61, 0x34, 0x35, 0xf5, 0x4e, 0x24, 0x74, 0x22,
245 0x21, 0x9a, 0x29, 0x89, 0xc7, 0x93, 0x2e, 0x60,
246 0x1e, 0xe8, 0x14, 0x24, 0x8d, 0xd5, 0x03, 0xf1,
247 0x65, 0x5d, 0x08, 0x22, 0x72, 0xd5, 0xad, 0x95,
248 0xe1, 0x23, 0x1e, 0x8a, 0xa7, 0x13, 0xd9, 0x2b,
249 0x5e, 0xbc, 0xbb, 0x80, 0xab, 0x8d, 0xe5, 0x79,
250 0xab, 0x5b, 0x47, 0x4e, 0xdd, 0xee, 0x6b, 0x03,
251 0x8f, 0x0f, 0x5c, 0x5e, 0xa9, 0x1a, 0x83, 0xdd,
252 0xd3, 0x88, 0xb2, 0x75, 0x4b, 0xce, 0x83, 0x36,
253 0x57, 0x4b, 0xf1, 0x5c, 0xca, 0x7e, 0x09, 0xc0,
254 0xd3, 0x89, 0xc6, 0xe0, 0xda, 0xc4, 0x81, 0x7e,
255 0x5b, 0xf9, 0xe1, 0x01, 0xc1, 0x92, 0x05, 0xea,
256 0xf5, 0x2f, 0xc6, 0xc6, 0xc7, 0x8f, 0xbc, 0xf4 };
257 static const u8 C0[] __initconst = {
258 0x00, 0xf4, 0xa3, 0xe5, 0xa0, 0x72, 0x63, 0x95,
259 0xc6, 0x4f, 0x48, 0xd0, 0x8b, 0x5b, 0x5f, 0x8e,
260 0x6b, 0x96, 0x1f, 0x16, 0xed, 0xbc, 0x66, 0x94,
261 0x45, 0x31, 0xd7, 0x47, 0x73, 0x22, 0xa5, 0x86,
262 0xce, 0xc0, 0x4c, 0xac, 0x63, 0xb8, 0x39, 0x50,
263 0xbf, 0xe6, 0x59, 0x6c, 0x38, 0x58, 0x99, 0x1f,
264 0x27, 0xa7, 0x9d, 0x71, 0x2a, 0xb3, 0x7b, 0xf9,
265 0xfb, 0x17, 0x86, 0xaa, 0x99, 0x81, 0xaa, 0x43,
266 0xe4, 0x37, 0xd3, 0x1e, 0x6e, 0xe5, 0xe6, 0xee,
267 0xc2, 0xed, 0x95, 0x4f, 0x53, 0x0e, 0x46, 0x8a,
268 0xcc, 0x45, 0xa5, 0xdb, 0x69, 0x0d, 0x81, 0xc9,
269 0x32, 0x92, 0xbc, 0x8f, 0x33, 0xe6, 0xf6, 0x09,
270 0x7c, 0x8e, 0x05, 0x19, 0x0d, 0xf1, 0xb6, 0xcc,
271 0xf3, 0x02, 0x21, 0x90, 0x25, 0xec, 0xed, 0x0e };
272 static const u8 random[] __initconst = {
273 0x95, 0xb7, 0xf1, 0x7e, 0x98, 0x02, 0xd3, 0x57,
274 0x73, 0x92, 0xc6, 0xa9, 0xc0, 0x80, 0x83, 0xb6,
275 0x7d, 0xd1, 0x29, 0x22, 0x65, 0xb5, 0xf4, 0x2d,
276 0x23, 0x7f, 0x1c, 0x55, 0xbb, 0x9b, 0x10, 0xbf,
277 0xcf, 0xd8, 0x2c, 0x77, 0xa3, 0x78, 0xb8, 0x26,
278 0x6a, 0x00, 0x99, 0x14, 0x3b, 0x3c, 0x2d, 0x64,
279 0x61, 0x1e, 0xee, 0xb6, 0x9a, 0xcd, 0xc0, 0x55,
280 0x95, 0x7c, 0x13, 0x9e, 0x8b, 0x19, 0x0c, 0x7a,
281 0x06, 0x95, 0x5f, 0x2c, 0x79, 0x7c, 0x27, 0x78,
282 0xde, 0x94, 0x03, 0x96, 0xa5, 0x01, 0xf4, 0x0e,
283 0x91, 0x39, 0x6a, 0xcf, 0x8d, 0x7e, 0x45, 0xeb,
284 0xdb, 0xb5, 0x3b, 0xbf, 0x8c, 0x97, 0x52, 0x30,
285 0xd2, 0xf0, 0xff, 0x91, 0x06, 0xc7, 0x61, 0x19,
286 0xae, 0x49, 0x8e, 0x7f, 0xbc, 0x03, 0xd9, 0x0f,
287 0x8e, 0x4c, 0x51, 0x62, 0x7a, 0xed, 0x5c, 0x8d,
288 0x42, 0x63, 0xd5, 0xd2, 0xb9, 0x78, 0x87, 0x3a,
289 0x0d, 0xe5, 0x96, 0xee, 0x6d, 0xc7, 0xf7, 0xc2,
290 0x9e, 0x37, 0xee, 0xe8, 0xb3, 0x4c, 0x90, 0xdd,
291 0x1c, 0xf6, 0xa9, 0xdd, 0xb2, 0x2b, 0x4c, 0xbd,
292 0x08, 0x6b, 0x14, 0xb3, 0x5d, 0xe9, 0x3d, 0xa2,
293 0xd5, 0xcb, 0x18, 0x06, 0x69, 0x8c, 0xbd, 0x7b,
294 0xbb, 0x67, 0xbf, 0xe3, 0xd3, 0x1f, 0xd2, 0xd1,
295 0xdb, 0xd2, 0xa1, 0xe0, 0x58, 0xa3, 0xeb, 0x99,
296 0xd7, 0xe5, 0x1f, 0x1a, 0x93, 0x8e, 0xed, 0x5e,
297 0x1c, 0x1d, 0xe2, 0x3a, 0x6b, 0x43, 0x45, 0xd3,
298 0x19, 0x14, 0x09, 0xf9, 0x2f, 0x39, 0xb3, 0x67,
299 0x0d, 0x8d, 0xbf, 0xb6, 0x35, 0xd8, 0xe6, 0xa3,
300 0x69, 0x32, 0xd8, 0x10, 0x33, 0xd1, 0x44, 0x8d,
301 0x63, 0xb4, 0x03, 0xdd, 0xf8, 0x8e, 0x12, 0x1b,
302 0x6e, 0x81, 0x9a, 0xc3, 0x81, 0x22, 0x6c, 0x13,
303 0x21, 0xe4, 0xb0, 0x86, 0x44, 0xf6, 0x72, 0x7c,
304 0x36, 0x8c, 0x5a, 0x9f, 0x7a, 0x4b, 0x3e, 0xe2 };
305
91 int ret = 0; 306 int ret = 0;
92 int tmp; 307 u8 buf[sizeof(random)];
308 struct ppno_ws_s ws;
309
310 memset(&ws, 0, sizeof(ws));
311
312 /* initial seed */
313 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_SEED,
314 &ws, NULL, 0,
315 seed, sizeof(seed));
316 if (ret < 0) {
317 pr_err("The prng self test seed operation for the "
318 "SHA-512 mode failed with rc=%d\n", ret);
319 prng_errorflag = PRNG_SELFTEST_FAILED;
320 return -EIO;
321 }
322
323 /* check working states V and C */
324 if (memcmp(ws.V, V0, sizeof(V0)) != 0
325 || memcmp(ws.C, C0, sizeof(C0)) != 0) {
326 pr_err("The prng self test state test "
327 "for the SHA-512 mode failed\n");
328 prng_errorflag = PRNG_SELFTEST_FAILED;
329 return -EIO;
330 }
331
332 /* generate random bytes */
333 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
334 &ws, buf, sizeof(buf),
335 NULL, 0);
336 if (ret < 0) {
337 pr_err("The prng self test generate operation for "
338 "the SHA-512 mode failed with rc=%d\n", ret);
339 prng_errorflag = PRNG_SELFTEST_FAILED;
340 return -EIO;
341 }
342 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
343 &ws, buf, sizeof(buf),
344 NULL, 0);
345 if (ret < 0) {
346 pr_err("The prng self test generate operation for "
347 "the SHA-512 mode failed with rc=%d\n", ret);
348 prng_errorflag = PRNG_SELFTEST_FAILED;
349 return -EIO;
350 }
351
352 /* check against expected data */
353 if (memcmp(buf, random, sizeof(random)) != 0) {
354 pr_err("The prng self test data test "
355 "for the SHA-512 mode failed\n");
356 prng_errorflag = PRNG_SELFTEST_FAILED;
357 return -EIO;
358 }
359
360 return 0;
361}
362
363
364static int __init prng_sha512_instantiate(void)
365{
366 int ret, datalen;
367 u8 seed[64];
368
369 pr_debug("prng runs in SHA-512 mode "
370 "with chunksize=%d and reseed_limit=%u\n",
371 prng_chunk_size, prng_reseed_limit);
372
373 /* memory allocation, prng_data struct init, mutex init */
374 datalen = sizeof(struct prng_data_s) + prng_chunk_size;
375 if (fips_enabled)
376 datalen += prng_chunk_size;
377 prng_data = kzalloc(datalen, GFP_KERNEL);
378 if (!prng_data) {
379 prng_errorflag = PRNG_INSTANTIATE_FAILED;
380 return -ENOMEM;
381 }
382 mutex_init(&prng_data->mutex);
383 prng_data->buf = ((u8 *)prng_data) + sizeof(struct prng_data_s);
384
385 /* selftest */
386 ret = prng_sha512_selftest();
387 if (ret)
388 goto outfree;
389
390 /* generate initial seed bytestring, first 48 bytes of entropy */
391 ret = generate_entropy(seed, 48);
392 if (ret != 48)
393 goto outfree;
394 /* followed by 16 bytes of unique nonce */
395 get_tod_clock_ext(seed + 48);
396
397 /* initial seed of the ppno drng */
398 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_SEED,
399 &prng_data->ppnows, NULL, 0,
400 seed, sizeof(seed));
401 if (ret < 0) {
402 prng_errorflag = PRNG_SEED_FAILED;
403 ret = -EIO;
404 goto outfree;
405 }
406
407 /* if fips mode is enabled, generate a first block of random
408 bytes for the FIPS 140-2 Conditional Self Test */
409 if (fips_enabled) {
410 prng_data->prev = prng_data->buf + prng_chunk_size;
411 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
412 &prng_data->ppnows,
413 prng_data->prev,
414 prng_chunk_size,
415 NULL, 0);
416 if (ret < 0 || ret != prng_chunk_size) {
417 prng_errorflag = PRNG_GEN_FAILED;
418 ret = -EIO;
419 goto outfree;
420 }
421 }
422
423 return 0;
424
425outfree:
426 kfree(prng_data);
427 return ret;
428}
429
430
431static void prng_sha512_deinstantiate(void)
432{
433 pr_debug("The prng module stopped after running in SHA-512 mode\n");
434 kzfree(prng_data);
435}
436
437
438static int prng_sha512_reseed(void)
439{
440 int ret;
441 u8 seed[32];
442
443 /* generate 32 bytes of fresh entropy */
444 ret = generate_entropy(seed, sizeof(seed));
445 if (ret != sizeof(seed))
446 return ret;
447
448 /* do a reseed of the ppno drng with this bytestring */
449 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_SEED,
450 &prng_data->ppnows, NULL, 0,
451 seed, sizeof(seed));
452 if (ret) {
453 prng_errorflag = PRNG_RESEED_FAILED;
454 return -EIO;
455 }
456
457 return 0;
458}
459
460
461static int prng_sha512_generate(u8 *buf, size_t nbytes)
462{
463 int ret;
464
465 /* reseed needed ? */
466 if (prng_data->ppnows.reseed_counter > prng_reseed_limit) {
467 ret = prng_sha512_reseed();
468 if (ret)
469 return ret;
470 }
471
472 /* PPNO generate */
473 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
474 &prng_data->ppnows, buf, nbytes,
475 NULL, 0);
476 if (ret < 0 || ret != nbytes) {
477 prng_errorflag = PRNG_GEN_FAILED;
478 return -EIO;
479 }
480
481 /* FIPS 140-2 Conditional Self Test */
482 if (fips_enabled) {
483 if (!memcmp(prng_data->prev, buf, nbytes)) {
484 prng_errorflag = PRNG_GEN_FAILED;
485 return -EILSEQ;
486 }
487 memcpy(prng_data->prev, buf, nbytes);
488 }
489
490 return ret;
491}
492
493
494/*** file io functions ***/
495
496static int prng_open(struct inode *inode, struct file *file)
497{
498 return nonseekable_open(inode, file);
499}
500
501
502static ssize_t prng_tdes_read(struct file *file, char __user *ubuf,
503 size_t nbytes, loff_t *ppos)
504{
505 int chunk, n, tmp, ret = 0;
506
507 /* lock prng_data struct */
508 if (mutex_lock_interruptible(&prng_data->mutex))
509 return -ERESTARTSYS;
93 510
94 /* nbytes can be arbitrary length, we split it into chunks */
95 while (nbytes) { 511 while (nbytes) {
96 /* same as in extract_entropy_user in random.c */
97 if (need_resched()) { 512 if (need_resched()) {
98 if (signal_pending(current)) { 513 if (signal_pending(current)) {
99 if (ret == 0) 514 if (ret == 0)
100 ret = -ERESTARTSYS; 515 ret = -ERESTARTSYS;
101 break; 516 break;
102 } 517 }
518 /* give mutex free before calling schedule() */
519 mutex_unlock(&prng_data->mutex);
103 schedule(); 520 schedule();
521 /* occopy mutex again */
522 if (mutex_lock_interruptible(&prng_data->mutex)) {
523 if (ret == 0)
524 ret = -ERESTARTSYS;
525 return ret;
526 }
104 } 527 }
105 528
106 /* 529 /*
@@ -112,12 +535,11 @@ static ssize_t prng_read(struct file *file, char __user *ubuf, size_t nbytes,
112 /* PRNG only likes multiples of 8 bytes */ 535 /* PRNG only likes multiples of 8 bytes */
113 n = (chunk + 7) & -8; 536 n = (chunk + 7) & -8;
114 537
115 if (p->count > prng_entropy_limit) 538 if (prng_data->prngws.reseed_counter > prng_reseed_limit)
116 prng_seed(8); 539 prng_tdes_seed(8);
117 540
118 /* if the CPU supports PRNG stckf is present too */ 541 /* if the CPU supports PRNG stckf is present too */
119 asm volatile(".insn s,0xb27c0000,%0" 542 *((unsigned long long *)prng_data->buf) = get_tod_clock_fast();
120 : "=m" (*((unsigned long long *)p->buf)) : : "cc");
121 543
122 /* 544 /*
123 * Beside the STCKF the input for the TDES-EDE is the output 545 * Beside the STCKF the input for the TDES-EDE is the output
@@ -132,35 +554,259 @@ static ssize_t prng_read(struct file *file, char __user *ubuf, size_t nbytes,
132 * Note: you can still get strict X9.17 conformity by setting 554 * Note: you can still get strict X9.17 conformity by setting
133 * prng_chunk_size to 8 bytes. 555 * prng_chunk_size to 8 bytes.
134 */ 556 */
135 tmp = crypt_s390_kmc(KMC_PRNG, parm_block, p->buf, p->buf, n); 557 tmp = crypt_s390_kmc(KMC_PRNG, prng_data->prngws.parm_block,
136 BUG_ON((tmp < 0) || (tmp != n)); 558 prng_data->buf, prng_data->buf, n);
559 if (tmp < 0 || tmp != n) {
560 ret = -EIO;
561 break;
562 }
137 563
138 p->count += n; 564 prng_data->prngws.byte_counter += n;
565 prng_data->prngws.reseed_counter += n;
139 566
140 if (copy_to_user(ubuf, p->buf, chunk)) 567 if (copy_to_user(ubuf, prng_data->buf, chunk))
141 return -EFAULT; 568 return -EFAULT;
142 569
143 nbytes -= chunk; 570 nbytes -= chunk;
144 ret += chunk; 571 ret += chunk;
145 ubuf += chunk; 572 ubuf += chunk;
146 } 573 }
574
575 /* unlock prng_data struct */
576 mutex_unlock(&prng_data->mutex);
577
147 return ret; 578 return ret;
148} 579}
149 580
150static const struct file_operations prng_fops = { 581
582static ssize_t prng_sha512_read(struct file *file, char __user *ubuf,
583 size_t nbytes, loff_t *ppos)
584{
585 int n, ret = 0;
586 u8 *p;
587
588 /* if errorflag is set do nothing and return 'broken pipe' */
589 if (prng_errorflag)
590 return -EPIPE;
591
592 /* lock prng_data struct */
593 if (mutex_lock_interruptible(&prng_data->mutex))
594 return -ERESTARTSYS;
595
596 while (nbytes) {
597 if (need_resched()) {
598 if (signal_pending(current)) {
599 if (ret == 0)
600 ret = -ERESTARTSYS;
601 break;
602 }
603 /* give mutex free before calling schedule() */
604 mutex_unlock(&prng_data->mutex);
605 schedule();
606 /* occopy mutex again */
607 if (mutex_lock_interruptible(&prng_data->mutex)) {
608 if (ret == 0)
609 ret = -ERESTARTSYS;
610 return ret;
611 }
612 }
613 if (prng_data->rest) {
614 /* push left over random bytes from the previous read */
615 p = prng_data->buf + prng_chunk_size - prng_data->rest;
616 n = (nbytes < prng_data->rest) ?
617 nbytes : prng_data->rest;
618 prng_data->rest -= n;
619 } else {
620 /* generate one chunk of random bytes into read buf */
621 p = prng_data->buf;
622 n = prng_sha512_generate(p, prng_chunk_size);
623 if (n < 0) {
624 ret = n;
625 break;
626 }
627 if (nbytes < prng_chunk_size) {
628 n = nbytes;
629 prng_data->rest = prng_chunk_size - n;
630 } else {
631 n = prng_chunk_size;
632 prng_data->rest = 0;
633 }
634 }
635 if (copy_to_user(ubuf, p, n)) {
636 ret = -EFAULT;
637 break;
638 }
639 ubuf += n;
640 nbytes -= n;
641 ret += n;
642 }
643
644 /* unlock prng_data struct */
645 mutex_unlock(&prng_data->mutex);
646
647 return ret;
648}
649
650
651/*** sysfs stuff ***/
652
653static const struct file_operations prng_sha512_fops = {
654 .owner = THIS_MODULE,
655 .open = &prng_open,
656 .release = NULL,
657 .read = &prng_sha512_read,
658 .llseek = noop_llseek,
659};
660static const struct file_operations prng_tdes_fops = {
151 .owner = THIS_MODULE, 661 .owner = THIS_MODULE,
152 .open = &prng_open, 662 .open = &prng_open,
153 .release = NULL, 663 .release = NULL,
154 .read = &prng_read, 664 .read = &prng_tdes_read,
155 .llseek = noop_llseek, 665 .llseek = noop_llseek,
156}; 666};
157 667
158static struct miscdevice prng_dev = { 668static struct miscdevice prng_sha512_dev = {
669 .name = "prandom",
670 .minor = MISC_DYNAMIC_MINOR,
671 .fops = &prng_sha512_fops,
672};
673static struct miscdevice prng_tdes_dev = {
159 .name = "prandom", 674 .name = "prandom",
160 .minor = MISC_DYNAMIC_MINOR, 675 .minor = MISC_DYNAMIC_MINOR,
161 .fops = &prng_fops, 676 .fops = &prng_tdes_fops,
162}; 677};
163 678
679
680/* chunksize attribute (ro) */
681static ssize_t prng_chunksize_show(struct device *dev,
682 struct device_attribute *attr,
683 char *buf)
684{
685 return snprintf(buf, PAGE_SIZE, "%u\n", prng_chunk_size);
686}
687static DEVICE_ATTR(chunksize, 0444, prng_chunksize_show, NULL);
688
689/* counter attribute (ro) */
690static ssize_t prng_counter_show(struct device *dev,
691 struct device_attribute *attr,
692 char *buf)
693{
694 u64 counter;
695
696 if (mutex_lock_interruptible(&prng_data->mutex))
697 return -ERESTARTSYS;
698 if (prng_mode == PRNG_MODE_SHA512)
699 counter = prng_data->ppnows.stream_bytes;
700 else
701 counter = prng_data->prngws.byte_counter;
702 mutex_unlock(&prng_data->mutex);
703
704 return snprintf(buf, PAGE_SIZE, "%llu\n", counter);
705}
706static DEVICE_ATTR(byte_counter, 0444, prng_counter_show, NULL);
707
708/* errorflag attribute (ro) */
709static ssize_t prng_errorflag_show(struct device *dev,
710 struct device_attribute *attr,
711 char *buf)
712{
713 return snprintf(buf, PAGE_SIZE, "%d\n", prng_errorflag);
714}
715static DEVICE_ATTR(errorflag, 0444, prng_errorflag_show, NULL);
716
717/* mode attribute (ro) */
718static ssize_t prng_mode_show(struct device *dev,
719 struct device_attribute *attr,
720 char *buf)
721{
722 if (prng_mode == PRNG_MODE_TDES)
723 return snprintf(buf, PAGE_SIZE, "TDES\n");
724 else
725 return snprintf(buf, PAGE_SIZE, "SHA512\n");
726}
727static DEVICE_ATTR(mode, 0444, prng_mode_show, NULL);
728
729/* reseed attribute (w) */
730static ssize_t prng_reseed_store(struct device *dev,
731 struct device_attribute *attr,
732 const char *buf, size_t count)
733{
734 if (mutex_lock_interruptible(&prng_data->mutex))
735 return -ERESTARTSYS;
736 prng_sha512_reseed();
737 mutex_unlock(&prng_data->mutex);
738
739 return count;
740}
741static DEVICE_ATTR(reseed, 0200, NULL, prng_reseed_store);
742
743/* reseed limit attribute (rw) */
744static ssize_t prng_reseed_limit_show(struct device *dev,
745 struct device_attribute *attr,
746 char *buf)
747{
748 return snprintf(buf, PAGE_SIZE, "%u\n", prng_reseed_limit);
749}
750static ssize_t prng_reseed_limit_store(struct device *dev,
751 struct device_attribute *attr,
752 const char *buf, size_t count)
753{
754 unsigned limit;
755
756 if (sscanf(buf, "%u\n", &limit) != 1)
757 return -EINVAL;
758
759 if (prng_mode == PRNG_MODE_SHA512) {
760 if (limit < PRNG_RESEED_LIMIT_SHA512_LOWER)
761 return -EINVAL;
762 } else {
763 if (limit < PRNG_RESEED_LIMIT_TDES_LOWER)
764 return -EINVAL;
765 }
766
767 prng_reseed_limit = limit;
768
769 return count;
770}
771static DEVICE_ATTR(reseed_limit, 0644,
772 prng_reseed_limit_show, prng_reseed_limit_store);
773
774/* strength attribute (ro) */
775static ssize_t prng_strength_show(struct device *dev,
776 struct device_attribute *attr,
777 char *buf)
778{
779 return snprintf(buf, PAGE_SIZE, "256\n");
780}
781static DEVICE_ATTR(strength, 0444, prng_strength_show, NULL);
782
783static struct attribute *prng_sha512_dev_attrs[] = {
784 &dev_attr_errorflag.attr,
785 &dev_attr_chunksize.attr,
786 &dev_attr_byte_counter.attr,
787 &dev_attr_mode.attr,
788 &dev_attr_reseed.attr,
789 &dev_attr_reseed_limit.attr,
790 &dev_attr_strength.attr,
791 NULL
792};
793static struct attribute *prng_tdes_dev_attrs[] = {
794 &dev_attr_chunksize.attr,
795 &dev_attr_byte_counter.attr,
796 &dev_attr_mode.attr,
797 NULL
798};
799
800static struct attribute_group prng_sha512_dev_attr_group = {
801 .attrs = prng_sha512_dev_attrs
802};
803static struct attribute_group prng_tdes_dev_attr_group = {
804 .attrs = prng_tdes_dev_attrs
805};
806
807
808/*** module init and exit ***/
809
164static int __init prng_init(void) 810static int __init prng_init(void)
165{ 811{
166 int ret; 812 int ret;
@@ -169,43 +815,105 @@ static int __init prng_init(void)
169 if (!crypt_s390_func_available(KMC_PRNG, CRYPT_S390_MSA)) 815 if (!crypt_s390_func_available(KMC_PRNG, CRYPT_S390_MSA))
170 return -EOPNOTSUPP; 816 return -EOPNOTSUPP;
171 817
172 if (prng_chunk_size < 8) 818 /* choose prng mode */
173 return -EINVAL; 819 if (prng_mode != PRNG_MODE_TDES) {
820 /* check for MSA5 support for PPNO operations */
821 if (!crypt_s390_func_available(PPNO_SHA512_DRNG_GEN,
822 CRYPT_S390_MSA5)) {
823 if (prng_mode == PRNG_MODE_SHA512) {
824 pr_err("The prng module cannot "
825 "start in SHA-512 mode\n");
826 return -EOPNOTSUPP;
827 }
828 prng_mode = PRNG_MODE_TDES;
829 } else
830 prng_mode = PRNG_MODE_SHA512;
831 }
174 832
175 p = kmalloc(sizeof(struct s390_prng_data), GFP_KERNEL); 833 if (prng_mode == PRNG_MODE_SHA512) {
176 if (!p)
177 return -ENOMEM;
178 p->count = 0;
179 834
180 p->buf = kmalloc(prng_chunk_size, GFP_KERNEL); 835 /* SHA512 mode */
181 if (!p->buf) {
182 ret = -ENOMEM;
183 goto out_free;
184 }
185 836
186 /* initialize the PRNG, add 128 bits of entropy */ 837 if (prng_chunk_size < PRNG_CHUNKSIZE_SHA512_MIN
187 prng_seed(16); 838 || prng_chunk_size > PRNG_CHUNKSIZE_SHA512_MAX)
839 return -EINVAL;
840 prng_chunk_size = (prng_chunk_size + 0x3f) & ~0x3f;
188 841
189 ret = misc_register(&prng_dev); 842 if (prng_reseed_limit == 0)
190 if (ret) 843 prng_reseed_limit = PRNG_RESEED_LIMIT_SHA512;
191 goto out_buf; 844 else if (prng_reseed_limit < PRNG_RESEED_LIMIT_SHA512_LOWER)
192 return 0; 845 return -EINVAL;
846
847 ret = prng_sha512_instantiate();
848 if (ret)
849 goto out;
850
851 ret = misc_register(&prng_sha512_dev);
852 if (ret) {
853 prng_sha512_deinstantiate();
854 goto out;
855 }
856 ret = sysfs_create_group(&prng_sha512_dev.this_device->kobj,
857 &prng_sha512_dev_attr_group);
858 if (ret) {
859 misc_deregister(&prng_sha512_dev);
860 prng_sha512_deinstantiate();
861 goto out;
862 }
193 863
194out_buf: 864 } else {
195 kfree(p->buf); 865
196out_free: 866 /* TDES mode */
197 kfree(p); 867
868 if (prng_chunk_size < PRNG_CHUNKSIZE_TDES_MIN
869 || prng_chunk_size > PRNG_CHUNKSIZE_TDES_MAX)
870 return -EINVAL;
871 prng_chunk_size = (prng_chunk_size + 0x07) & ~0x07;
872
873 if (prng_reseed_limit == 0)
874 prng_reseed_limit = PRNG_RESEED_LIMIT_TDES;
875 else if (prng_reseed_limit < PRNG_RESEED_LIMIT_TDES_LOWER)
876 return -EINVAL;
877
878 ret = prng_tdes_instantiate();
879 if (ret)
880 goto out;
881
882 ret = misc_register(&prng_tdes_dev);
883 if (ret) {
884 prng_tdes_deinstantiate();
885 goto out;
886 }
887 ret = sysfs_create_group(&prng_tdes_dev.this_device->kobj,
888 &prng_tdes_dev_attr_group);
889 if (ret) {
890 misc_deregister(&prng_tdes_dev);
891 prng_tdes_deinstantiate();
892 goto out;
893 }
894
895 }
896
897out:
198 return ret; 898 return ret;
199} 899}
200 900
901
201static void __exit prng_exit(void) 902static void __exit prng_exit(void)
202{ 903{
203 /* wipe me */ 904 if (prng_mode == PRNG_MODE_SHA512) {
204 kzfree(p->buf); 905 sysfs_remove_group(&prng_sha512_dev.this_device->kobj,
205 kfree(p); 906 &prng_sha512_dev_attr_group);
206 907 misc_deregister(&prng_sha512_dev);
207 misc_deregister(&prng_dev); 908 prng_sha512_deinstantiate();
909 } else {
910 sysfs_remove_group(&prng_tdes_dev.this_device->kobj,
911 &prng_tdes_dev_attr_group);
912 misc_deregister(&prng_tdes_dev);
913 prng_tdes_deinstantiate();
914 }
208} 915}
209 916
917
210module_init(prng_init); 918module_init(prng_init);
211module_exit(prng_exit); 919module_exit(prng_exit);
diff --git a/arch/s390/include/asm/kexec.h b/arch/s390/include/asm/kexec.h
index 694bcd6bd927..2f924bc30e35 100644
--- a/arch/s390/include/asm/kexec.h
+++ b/arch/s390/include/asm/kexec.h
@@ -26,6 +26,9 @@
26/* Not more than 2GB */ 26/* Not more than 2GB */
27#define KEXEC_CONTROL_MEMORY_LIMIT (1UL<<31) 27#define KEXEC_CONTROL_MEMORY_LIMIT (1UL<<31)
28 28
29/* Allocate control page with GFP_DMA */
30#define KEXEC_CONTROL_MEMORY_GFP GFP_DMA
31
29/* Maximum address we can use for the crash control pages */ 32/* Maximum address we can use for the crash control pages */
30#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT (-1UL) 33#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT (-1UL)
31 34
diff --git a/arch/s390/include/asm/mmu.h b/arch/s390/include/asm/mmu.h
index a5e656260a70..d29ad9545b41 100644
--- a/arch/s390/include/asm/mmu.h
+++ b/arch/s390/include/asm/mmu.h
@@ -14,7 +14,9 @@ typedef struct {
14 unsigned long asce_bits; 14 unsigned long asce_bits;
15 unsigned long asce_limit; 15 unsigned long asce_limit;
16 unsigned long vdso_base; 16 unsigned long vdso_base;
17 /* The mmu context has extended page tables. */ 17 /* The mmu context allocates 4K page tables. */
18 unsigned int alloc_pgste:1;
19 /* The mmu context uses extended page tables. */
18 unsigned int has_pgste:1; 20 unsigned int has_pgste:1;
19 /* The mmu context uses storage keys. */ 21 /* The mmu context uses storage keys. */
20 unsigned int use_skey:1; 22 unsigned int use_skey:1;
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
index d25d9ff10ba8..fb1b93ea3e3f 100644
--- a/arch/s390/include/asm/mmu_context.h
+++ b/arch/s390/include/asm/mmu_context.h
@@ -20,8 +20,11 @@ static inline int init_new_context(struct task_struct *tsk,
20 mm->context.flush_mm = 0; 20 mm->context.flush_mm = 0;
21 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS; 21 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
22 mm->context.asce_bits |= _ASCE_TYPE_REGION3; 22 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
23#ifdef CONFIG_PGSTE
24 mm->context.alloc_pgste = page_table_allocate_pgste;
23 mm->context.has_pgste = 0; 25 mm->context.has_pgste = 0;
24 mm->context.use_skey = 0; 26 mm->context.use_skey = 0;
27#endif
25 mm->context.asce_limit = STACK_TOP_MAX; 28 mm->context.asce_limit = STACK_TOP_MAX;
26 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm)); 29 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
27 return 0; 30 return 0;
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index 51e7fb634ebc..7b7858f158b4 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -21,6 +21,7 @@ void crst_table_free(struct mm_struct *, unsigned long *);
21unsigned long *page_table_alloc(struct mm_struct *); 21unsigned long *page_table_alloc(struct mm_struct *);
22void page_table_free(struct mm_struct *, unsigned long *); 22void page_table_free(struct mm_struct *, unsigned long *);
23void page_table_free_rcu(struct mmu_gather *, unsigned long *, unsigned long); 23void page_table_free_rcu(struct mmu_gather *, unsigned long *, unsigned long);
24extern int page_table_allocate_pgste;
24 25
25int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, 26int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
26 unsigned long key, bool nq); 27 unsigned long key, bool nq);
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 989cfae9e202..ef24a212eeb7 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -12,12 +12,9 @@
12#define _ASM_S390_PGTABLE_H 12#define _ASM_S390_PGTABLE_H
13 13
14/* 14/*
15 * The Linux memory management assumes a three-level page table setup. For 15 * The Linux memory management assumes a three-level page table setup.
16 * s390 31 bit we "fold" the mid level into the top-level page table, so 16 * For s390 64 bit we use up to four of the five levels the hardware
17 * that we physically have the same two-level page table as the s390 mmu 17 * provides (region first tables are not used).
18 * expects in 31 bit mode. For s390 64 bit we use three of the five levels
19 * the hardware provides (region first and region second tables are not
20 * used).
21 * 18 *
22 * The "pgd_xxx()" functions are trivial for a folded two-level 19 * The "pgd_xxx()" functions are trivial for a folded two-level
23 * setup: the pgd is never bad, and a pmd always exists (as it's folded 20 * setup: the pgd is never bad, and a pmd always exists (as it's folded
@@ -101,8 +98,8 @@ extern unsigned long zero_page_mask;
101 98
102#ifndef __ASSEMBLY__ 99#ifndef __ASSEMBLY__
103/* 100/*
104 * The vmalloc and module area will always be on the topmost area of the kernel 101 * The vmalloc and module area will always be on the topmost area of the
105 * mapping. We reserve 96MB (31bit) / 128GB (64bit) for vmalloc and modules. 102 * kernel mapping. We reserve 128GB (64bit) for vmalloc and modules.
106 * On 64 bit kernels we have a 2GB area at the top of the vmalloc area where 103 * On 64 bit kernels we have a 2GB area at the top of the vmalloc area where
107 * modules will reside. That makes sure that inter module branches always 104 * modules will reside. That makes sure that inter module branches always
108 * happen without trampolines and in addition the placement within a 2GB frame 105 * happen without trampolines and in addition the placement within a 2GB frame
@@ -131,38 +128,6 @@ static inline int is_module_addr(void *addr)
131} 128}
132 129
133/* 130/*
134 * A 31 bit pagetable entry of S390 has following format:
135 * | PFRA | | OS |
136 * 0 0IP0
137 * 00000000001111111111222222222233
138 * 01234567890123456789012345678901
139 *
140 * I Page-Invalid Bit: Page is not available for address-translation
141 * P Page-Protection Bit: Store access not possible for page
142 *
143 * A 31 bit segmenttable entry of S390 has following format:
144 * | P-table origin | |PTL
145 * 0 IC
146 * 00000000001111111111222222222233
147 * 01234567890123456789012345678901
148 *
149 * I Segment-Invalid Bit: Segment is not available for address-translation
150 * C Common-Segment Bit: Segment is not private (PoP 3-30)
151 * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256)
152 *
153 * The 31 bit segmenttable origin of S390 has following format:
154 *
155 * |S-table origin | | STL |
156 * X **GPS
157 * 00000000001111111111222222222233
158 * 01234567890123456789012345678901
159 *
160 * X Space-Switch event:
161 * G Segment-Invalid Bit: *
162 * P Private-Space Bit: Segment is not private (PoP 3-30)
163 * S Storage-Alteration:
164 * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048)
165 *
166 * A 64 bit pagetable entry of S390 has following format: 131 * A 64 bit pagetable entry of S390 has following format:
167 * | PFRA |0IPC| OS | 132 * | PFRA |0IPC| OS |
168 * 0000000000111111111122222222223333333333444444444455555555556666 133 * 0000000000111111111122222222223333333333444444444455555555556666
@@ -220,7 +185,6 @@ static inline int is_module_addr(void *addr)
220 185
221/* Software bits in the page table entry */ 186/* Software bits in the page table entry */
222#define _PAGE_PRESENT 0x001 /* SW pte present bit */ 187#define _PAGE_PRESENT 0x001 /* SW pte present bit */
223#define _PAGE_TYPE 0x002 /* SW pte type bit */
224#define _PAGE_YOUNG 0x004 /* SW pte young bit */ 188#define _PAGE_YOUNG 0x004 /* SW pte young bit */
225#define _PAGE_DIRTY 0x008 /* SW pte dirty bit */ 189#define _PAGE_DIRTY 0x008 /* SW pte dirty bit */
226#define _PAGE_READ 0x010 /* SW pte read bit */ 190#define _PAGE_READ 0x010 /* SW pte read bit */
@@ -240,31 +204,34 @@ static inline int is_module_addr(void *addr)
240 * table lock held. 204 * table lock held.
241 * 205 *
242 * The following table gives the different possible bit combinations for 206 * The following table gives the different possible bit combinations for
243 * the pte hardware and software bits in the last 12 bits of a pte: 207 * the pte hardware and software bits in the last 12 bits of a pte
208 * (. unassigned bit, x don't care, t swap type):
244 * 209 *
245 * 842100000000 210 * 842100000000
246 * 000084210000 211 * 000084210000
247 * 000000008421 212 * 000000008421
248 * .IR...wrdytp 213 * .IR.uswrdy.p
249 * empty .10...000000 214 * empty .10.00000000
250 * swap .10...xxxx10 215 * swap .11..ttttt.0
251 * file .11...xxxxx0 216 * prot-none, clean, old .11.xx0000.1
252 * prot-none, clean, old .11...000001 217 * prot-none, clean, young .11.xx0001.1
253 * prot-none, clean, young .11...000101 218 * prot-none, dirty, old .10.xx0010.1
254 * prot-none, dirty, old .10...001001 219 * prot-none, dirty, young .10.xx0011.1
255 * prot-none, dirty, young .10...001101 220 * read-only, clean, old .11.xx0100.1
256 * read-only, clean, old .11...010001 221 * read-only, clean, young .01.xx0101.1
257 * read-only, clean, young .01...010101 222 * read-only, dirty, old .11.xx0110.1
258 * read-only, dirty, old .11...011001 223 * read-only, dirty, young .01.xx0111.1
259 * read-only, dirty, young .01...011101 224 * read-write, clean, old .11.xx1100.1
260 * read-write, clean, old .11...110001 225 * read-write, clean, young .01.xx1101.1
261 * read-write, clean, young .01...110101 226 * read-write, dirty, old .10.xx1110.1
262 * read-write, dirty, old .10...111001 227 * read-write, dirty, young .00.xx1111.1
263 * read-write, dirty, young .00...111101 228 * HW-bits: R read-only, I invalid
229 * SW-bits: p present, y young, d dirty, r read, w write, s special,
230 * u unused, l large
264 * 231 *
265 * pte_present is true for the bit pattern .xx...xxxxx1, (pte & 0x001) == 0x001 232 * pte_none is true for the bit pattern .10.00000000, pte == 0x400
266 * pte_none is true for the bit pattern .10...xxxx00, (pte & 0x603) == 0x400 233 * pte_swap is true for the bit pattern .11..ooooo.0, (pte & 0x201) == 0x200
267 * pte_swap is true for the bit pattern .10...xxxx10, (pte & 0x603) == 0x402 234 * pte_present is true for the bit pattern .xx.xxxxxx.1, (pte & 0x001) == 0x001
268 */ 235 */
269 236
270/* Bits in the segment/region table address-space-control-element */ 237/* Bits in the segment/region table address-space-control-element */
@@ -335,6 +302,8 @@ static inline int is_module_addr(void *addr)
335 * read-write, dirty, young 11..0...0...11 302 * read-write, dirty, young 11..0...0...11
336 * The segment table origin is used to distinguish empty (origin==0) from 303 * The segment table origin is used to distinguish empty (origin==0) from
337 * read-write, old segment table entries (origin!=0) 304 * read-write, old segment table entries (origin!=0)
305 * HW-bits: R read-only, I invalid
306 * SW-bits: y young, d dirty, r read, w write
338 */ 307 */
339 308
340#define _SEGMENT_ENTRY_SPLIT_BIT 11 /* THP splitting bit number */ 309#define _SEGMENT_ENTRY_SPLIT_BIT 11 /* THP splitting bit number */
@@ -423,6 +392,15 @@ static inline int mm_has_pgste(struct mm_struct *mm)
423 return 0; 392 return 0;
424} 393}
425 394
395static inline int mm_alloc_pgste(struct mm_struct *mm)
396{
397#ifdef CONFIG_PGSTE
398 if (unlikely(mm->context.alloc_pgste))
399 return 1;
400#endif
401 return 0;
402}
403
426/* 404/*
427 * In the case that a guest uses storage keys 405 * In the case that a guest uses storage keys
428 * faults should no longer be backed by zero pages 406 * faults should no longer be backed by zero pages
@@ -516,7 +494,7 @@ static inline int pmd_large(pmd_t pmd)
516 return (pmd_val(pmd) & _SEGMENT_ENTRY_LARGE) != 0; 494 return (pmd_val(pmd) & _SEGMENT_ENTRY_LARGE) != 0;
517} 495}
518 496
519static inline int pmd_pfn(pmd_t pmd) 497static inline unsigned long pmd_pfn(pmd_t pmd)
520{ 498{
521 unsigned long origin_mask; 499 unsigned long origin_mask;
522 500
@@ -582,10 +560,9 @@ static inline int pte_none(pte_t pte)
582 560
583static inline int pte_swap(pte_t pte) 561static inline int pte_swap(pte_t pte)
584{ 562{
585 /* Bit pattern: (pte & 0x603) == 0x402 */ 563 /* Bit pattern: (pte & 0x201) == 0x200 */
586 return (pte_val(pte) & (_PAGE_INVALID | _PAGE_PROTECT | 564 return (pte_val(pte) & (_PAGE_PROTECT | _PAGE_PRESENT))
587 _PAGE_TYPE | _PAGE_PRESENT)) 565 == _PAGE_PROTECT;
588 == (_PAGE_INVALID | _PAGE_TYPE);
589} 566}
590 567
591static inline int pte_special(pte_t pte) 568static inline int pte_special(pte_t pte)
@@ -1586,51 +1563,51 @@ static inline int has_transparent_hugepage(void)
1586#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 1563#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
1587 1564
1588/* 1565/*
1589 * 31 bit swap entry format:
1590 * A page-table entry has some bits we have to treat in a special way.
1591 * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
1592 * exception will occur instead of a page translation exception. The
1593 * specifiation exception has the bad habit not to store necessary
1594 * information in the lowcore.
1595 * Bits 21, 22, 30 and 31 are used to indicate the page type.
1596 * A swap pte is indicated by bit pattern (pte & 0x603) == 0x402
1597 * This leaves the bits 1-19 and bits 24-29 to store type and offset.
1598 * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
1599 * plus 24 for the offset.
1600 * 0| offset |0110|o|type |00|
1601 * 0 0000000001111111111 2222 2 22222 33
1602 * 0 1234567890123456789 0123 4 56789 01
1603 *
1604 * 64 bit swap entry format: 1566 * 64 bit swap entry format:
1605 * A page-table entry has some bits we have to treat in a special way. 1567 * A page-table entry has some bits we have to treat in a special way.
1606 * Bits 52 and bit 55 have to be zero, otherwise an specification 1568 * Bits 52 and bit 55 have to be zero, otherwise an specification
1607 * exception will occur instead of a page translation exception. The 1569 * exception will occur instead of a page translation exception. The
1608 * specifiation exception has the bad habit not to store necessary 1570 * specifiation exception has the bad habit not to store necessary
1609 * information in the lowcore. 1571 * information in the lowcore.
1610 * Bits 53, 54, 62 and 63 are used to indicate the page type. 1572 * Bits 54 and 63 are used to indicate the page type.
1611 * A swap pte is indicated by bit pattern (pte & 0x603) == 0x402 1573 * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200
1612 * This leaves the bits 0-51 and bits 56-61 to store type and offset. 1574 * This leaves the bits 0-51 and bits 56-62 to store type and offset.
1613 * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51 1575 * We use the 5 bits from 57-61 for the type and the 52 bits from 0-51
1614 * plus 56 for the offset. 1576 * for the offset.
1615 * | offset |0110|o|type |00| 1577 * | offset |01100|type |00|
1616 * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66 1578 * |0000000000111111111122222222223333333333444444444455|55555|55566|66|
1617 * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23 1579 * |0123456789012345678901234567890123456789012345678901|23456|78901|23|
1618 */ 1580 */
1619 1581
1620#define __SWP_OFFSET_MASK (~0UL >> 11) 1582#define __SWP_OFFSET_MASK ((1UL << 52) - 1)
1583#define __SWP_OFFSET_SHIFT 12
1584#define __SWP_TYPE_MASK ((1UL << 5) - 1)
1585#define __SWP_TYPE_SHIFT 2
1621 1586
1622static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset) 1587static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
1623{ 1588{
1624 pte_t pte; 1589 pte_t pte;
1625 offset &= __SWP_OFFSET_MASK; 1590
1626 pte_val(pte) = _PAGE_INVALID | _PAGE_TYPE | ((type & 0x1f) << 2) | 1591 pte_val(pte) = _PAGE_INVALID | _PAGE_PROTECT;
1627 ((offset & 1UL) << 7) | ((offset & ~1UL) << 11); 1592 pte_val(pte) |= (offset & __SWP_OFFSET_MASK) << __SWP_OFFSET_SHIFT;
1593 pte_val(pte) |= (type & __SWP_TYPE_MASK) << __SWP_TYPE_SHIFT;
1628 return pte; 1594 return pte;
1629} 1595}
1630 1596
1631#define __swp_type(entry) (((entry).val >> 2) & 0x1f) 1597static inline unsigned long __swp_type(swp_entry_t entry)
1632#define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1)) 1598{
1633#define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) }) 1599 return (entry.val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK;
1600}
1601
1602static inline unsigned long __swp_offset(swp_entry_t entry)
1603{
1604 return (entry.val >> __SWP_OFFSET_SHIFT) & __SWP_OFFSET_MASK;
1605}
1606
1607static inline swp_entry_t __swp_entry(unsigned long type, unsigned long offset)
1608{
1609 return (swp_entry_t) { pte_val(mk_swap_pte(type, offset)) };
1610}
1634 1611
1635#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 1612#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
1636#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 1613#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index 210ffede0153..e617e74b7be2 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -14,20 +14,23 @@ static inline pmd_t __pte_to_pmd(pte_t pte)
14 14
15 /* 15 /*
16 * Convert encoding pte bits pmd bits 16 * Convert encoding pte bits pmd bits
17 * .IR...wrdytp dy..R...I...wr 17 * lIR.uswrdy.p dy..R...I...wr
18 * empty .10...000000 -> 00..0...1...00 18 * empty 010.000000.0 -> 00..0...1...00
19 * prot-none, clean, old .11...000001 -> 00..1...1...00 19 * prot-none, clean, old 111.000000.1 -> 00..1...1...00
20 * prot-none, clean, young .11...000101 -> 01..1...1...00 20 * prot-none, clean, young 111.000001.1 -> 01..1...1...00
21 * prot-none, dirty, old .10...001001 -> 10..1...1...00 21 * prot-none, dirty, old 111.000010.1 -> 10..1...1...00
22 * prot-none, dirty, young .10...001101 -> 11..1...1...00 22 * prot-none, dirty, young 111.000011.1 -> 11..1...1...00
23 * read-only, clean, old .11...010001 -> 00..1...1...01 23 * read-only, clean, old 111.000100.1 -> 00..1...1...01
24 * read-only, clean, young .01...010101 -> 01..1...0...01 24 * read-only, clean, young 101.000101.1 -> 01..1...0...01
25 * read-only, dirty, old .11...011001 -> 10..1...1...01 25 * read-only, dirty, old 111.000110.1 -> 10..1...1...01
26 * read-only, dirty, young .01...011101 -> 11..1...0...01 26 * read-only, dirty, young 101.000111.1 -> 11..1...0...01
27 * read-write, clean, old .11...110001 -> 00..0...1...11 27 * read-write, clean, old 111.001100.1 -> 00..1...1...11
28 * read-write, clean, young .01...110101 -> 01..0...0...11 28 * read-write, clean, young 101.001101.1 -> 01..1...0...11
29 * read-write, dirty, old .10...111001 -> 10..0...1...11 29 * read-write, dirty, old 110.001110.1 -> 10..0...1...11
30 * read-write, dirty, young .00...111101 -> 11..0...0...11 30 * read-write, dirty, young 100.001111.1 -> 11..0...0...11
31 * HW-bits: R read-only, I invalid
32 * SW-bits: p present, y young, d dirty, r read, w write, s special,
33 * u unused, l large
31 */ 34 */
32 if (pte_present(pte)) { 35 if (pte_present(pte)) {
33 pmd_val(pmd) = pte_val(pte) & PAGE_MASK; 36 pmd_val(pmd) = pte_val(pte) & PAGE_MASK;
@@ -48,20 +51,23 @@ static inline pte_t __pmd_to_pte(pmd_t pmd)
48 51
49 /* 52 /*
50 * Convert encoding pmd bits pte bits 53 * Convert encoding pmd bits pte bits
51 * dy..R...I...wr .IR...wrdytp 54 * dy..R...I...wr lIR.uswrdy.p
52 * empty 00..0...1...00 -> .10...001100 55 * empty 00..0...1...00 -> 010.000000.0
53 * prot-none, clean, old 00..0...1...00 -> .10...000001 56 * prot-none, clean, old 00..1...1...00 -> 111.000000.1
54 * prot-none, clean, young 01..0...1...00 -> .10...000101 57 * prot-none, clean, young 01..1...1...00 -> 111.000001.1
55 * prot-none, dirty, old 10..0...1...00 -> .10...001001 58 * prot-none, dirty, old 10..1...1...00 -> 111.000010.1
56 * prot-none, dirty, young 11..0...1...00 -> .10...001101 59 * prot-none, dirty, young 11..1...1...00 -> 111.000011.1
57 * read-only, clean, old 00..1...1...01 -> .11...010001 60 * read-only, clean, old 00..1...1...01 -> 111.000100.1
58 * read-only, clean, young 01..1...1...01 -> .11...010101 61 * read-only, clean, young 01..1...0...01 -> 101.000101.1
59 * read-only, dirty, old 10..1...1...01 -> .11...011001 62 * read-only, dirty, old 10..1...1...01 -> 111.000110.1
60 * read-only, dirty, young 11..1...1...01 -> .11...011101 63 * read-only, dirty, young 11..1...0...01 -> 101.000111.1
61 * read-write, clean, old 00..0...1...11 -> .10...110001 64 * read-write, clean, old 00..1...1...11 -> 111.001100.1
62 * read-write, clean, young 01..0...1...11 -> .10...110101 65 * read-write, clean, young 01..1...0...11 -> 101.001101.1
63 * read-write, dirty, old 10..0...1...11 -> .10...111001 66 * read-write, dirty, old 10..0...1...11 -> 110.001110.1
64 * read-write, dirty, young 11..0...1...11 -> .10...111101 67 * read-write, dirty, young 11..0...0...11 -> 100.001111.1
68 * HW-bits: R read-only, I invalid
69 * SW-bits: p present, y young, d dirty, r read, w write, s special,
70 * u unused, l large
65 */ 71 */
66 if (pmd_present(pmd)) { 72 if (pmd_present(pmd)) {
67 pte_val(pte) = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN_LARGE; 73 pte_val(pte) = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN_LARGE;
@@ -70,8 +76,8 @@ static inline pte_t __pmd_to_pte(pmd_t pmd)
70 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE) << 4; 76 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE) << 4;
71 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_INVALID) << 5; 77 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_INVALID) << 5;
72 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT); 78 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT);
73 pmd_val(pmd) |= (pte_val(pte) & _PAGE_DIRTY) << 10; 79 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY) >> 10;
74 pmd_val(pmd) |= (pte_val(pte) & _PAGE_YOUNG) << 10; 80 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_YOUNG) >> 10;
75 } else 81 } else
76 pte_val(pte) = _PAGE_INVALID; 82 pte_val(pte) = _PAGE_INVALID;
77 return pte; 83 return pte;
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 33f589459113..b33f66110ca9 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -18,6 +18,7 @@
18#include <linux/rcupdate.h> 18#include <linux/rcupdate.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/swapops.h> 20#include <linux/swapops.h>
21#include <linux/sysctl.h>
21#include <linux/ksm.h> 22#include <linux/ksm.h>
22#include <linux/mman.h> 23#include <linux/mman.h>
23 24
@@ -920,6 +921,40 @@ unsigned long get_guest_storage_key(struct mm_struct *mm, unsigned long addr)
920} 921}
921EXPORT_SYMBOL(get_guest_storage_key); 922EXPORT_SYMBOL(get_guest_storage_key);
922 923
924static int page_table_allocate_pgste_min = 0;
925static int page_table_allocate_pgste_max = 1;
926int page_table_allocate_pgste = 0;
927EXPORT_SYMBOL(page_table_allocate_pgste);
928
929static struct ctl_table page_table_sysctl[] = {
930 {
931 .procname = "allocate_pgste",
932 .data = &page_table_allocate_pgste,
933 .maxlen = sizeof(int),
934 .mode = S_IRUGO | S_IWUSR,
935 .proc_handler = proc_dointvec,
936 .extra1 = &page_table_allocate_pgste_min,
937 .extra2 = &page_table_allocate_pgste_max,
938 },
939 { }
940};
941
942static struct ctl_table page_table_sysctl_dir[] = {
943 {
944 .procname = "vm",
945 .maxlen = 0,
946 .mode = 0555,
947 .child = page_table_sysctl,
948 },
949 { }
950};
951
952static int __init page_table_register_sysctl(void)
953{
954 return register_sysctl_table(page_table_sysctl_dir) ? 0 : -ENOMEM;
955}
956__initcall(page_table_register_sysctl);
957
923#else /* CONFIG_PGSTE */ 958#else /* CONFIG_PGSTE */
924 959
925static inline int page_table_with_pgste(struct page *page) 960static inline int page_table_with_pgste(struct page *page)
@@ -963,7 +998,7 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
963 struct page *uninitialized_var(page); 998 struct page *uninitialized_var(page);
964 unsigned int mask, bit; 999 unsigned int mask, bit;
965 1000
966 if (mm_has_pgste(mm)) 1001 if (mm_alloc_pgste(mm))
967 return page_table_alloc_pgste(mm); 1002 return page_table_alloc_pgste(mm);
968 /* Allocate fragments of a 4K page as 1K/2K page table */ 1003 /* Allocate fragments of a 4K page as 1K/2K page table */
969 spin_lock_bh(&mm->context.list_lock); 1004 spin_lock_bh(&mm->context.list_lock);
@@ -1165,116 +1200,25 @@ static inline void thp_split_mm(struct mm_struct *mm)
1165} 1200}
1166#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 1201#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
1167 1202
1168static unsigned long page_table_realloc_pmd(struct mmu_gather *tlb,
1169 struct mm_struct *mm, pud_t *pud,
1170 unsigned long addr, unsigned long end)
1171{
1172 unsigned long next, *table, *new;
1173 struct page *page;
1174 spinlock_t *ptl;
1175 pmd_t *pmd;
1176
1177 pmd = pmd_offset(pud, addr);
1178 do {
1179 next = pmd_addr_end(addr, end);
1180again:
1181 if (pmd_none_or_clear_bad(pmd))
1182 continue;
1183 table = (unsigned long *) pmd_deref(*pmd);
1184 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
1185 if (page_table_with_pgste(page))
1186 continue;
1187 /* Allocate new page table with pgstes */
1188 new = page_table_alloc_pgste(mm);
1189 if (!new)
1190 return -ENOMEM;
1191
1192 ptl = pmd_lock(mm, pmd);
1193 if (likely((unsigned long *) pmd_deref(*pmd) == table)) {
1194 /* Nuke pmd entry pointing to the "short" page table */
1195 pmdp_flush_lazy(mm, addr, pmd);
1196 pmd_clear(pmd);
1197 /* Copy ptes from old table to new table */
1198 memcpy(new, table, PAGE_SIZE/2);
1199 clear_table(table, _PAGE_INVALID, PAGE_SIZE/2);
1200 /* Establish new table */
1201 pmd_populate(mm, pmd, (pte_t *) new);
1202 /* Free old table with rcu, there might be a walker! */
1203 page_table_free_rcu(tlb, table, addr);
1204 new = NULL;
1205 }
1206 spin_unlock(ptl);
1207 if (new) {
1208 page_table_free_pgste(new);
1209 goto again;
1210 }
1211 } while (pmd++, addr = next, addr != end);
1212
1213 return addr;
1214}
1215
1216static unsigned long page_table_realloc_pud(struct mmu_gather *tlb,
1217 struct mm_struct *mm, pgd_t *pgd,
1218 unsigned long addr, unsigned long end)
1219{
1220 unsigned long next;
1221 pud_t *pud;
1222
1223 pud = pud_offset(pgd, addr);
1224 do {
1225 next = pud_addr_end(addr, end);
1226 if (pud_none_or_clear_bad(pud))
1227 continue;
1228 next = page_table_realloc_pmd(tlb, mm, pud, addr, next);
1229 if (unlikely(IS_ERR_VALUE(next)))
1230 return next;
1231 } while (pud++, addr = next, addr != end);
1232
1233 return addr;
1234}
1235
1236static unsigned long page_table_realloc(struct mmu_gather *tlb, struct mm_struct *mm,
1237 unsigned long addr, unsigned long end)
1238{
1239 unsigned long next;
1240 pgd_t *pgd;
1241
1242 pgd = pgd_offset(mm, addr);
1243 do {
1244 next = pgd_addr_end(addr, end);
1245 if (pgd_none_or_clear_bad(pgd))
1246 continue;
1247 next = page_table_realloc_pud(tlb, mm, pgd, addr, next);
1248 if (unlikely(IS_ERR_VALUE(next)))
1249 return next;
1250 } while (pgd++, addr = next, addr != end);
1251
1252 return 0;
1253}
1254
1255/* 1203/*
1256 * switch on pgstes for its userspace process (for kvm) 1204 * switch on pgstes for its userspace process (for kvm)
1257 */ 1205 */
1258int s390_enable_sie(void) 1206int s390_enable_sie(void)
1259{ 1207{
1260 struct task_struct *tsk = current; 1208 struct mm_struct *mm = current->mm;
1261 struct mm_struct *mm = tsk->mm;
1262 struct mmu_gather tlb;
1263 1209
1264 /* Do we have pgstes? if yes, we are done */ 1210 /* Do we have pgstes? if yes, we are done */
1265 if (mm_has_pgste(tsk->mm)) 1211 if (mm_has_pgste(mm))
1266 return 0; 1212 return 0;
1267 1213 /* Fail if the page tables are 2K */
1214 if (!mm_alloc_pgste(mm))
1215 return -EINVAL;
1268 down_write(&mm->mmap_sem); 1216 down_write(&mm->mmap_sem);
1217 mm->context.has_pgste = 1;
1269 /* split thp mappings and disable thp for future mappings */ 1218 /* split thp mappings and disable thp for future mappings */
1270 thp_split_mm(mm); 1219 thp_split_mm(mm);
1271 /* Reallocate the page tables with pgstes */
1272 tlb_gather_mmu(&tlb, mm, 0, TASK_SIZE);
1273 if (!page_table_realloc(&tlb, mm, 0, TASK_SIZE))
1274 mm->context.has_pgste = 1;
1275 tlb_finish_mmu(&tlb, 0, TASK_SIZE);
1276 up_write(&mm->mmap_sem); 1220 up_write(&mm->mmap_sem);
1277 return mm->context.has_pgste ? 0 : -ENOMEM; 1221 return 0;
1278} 1222}
1279EXPORT_SYMBOL_GPL(s390_enable_sie); 1223EXPORT_SYMBOL_GPL(s390_enable_sie);
1280 1224
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 7690dc8e1ab5..20c146d1251a 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -443,8 +443,11 @@ static void bpf_jit_epilogue(struct bpf_jit *jit)
443 443
444/* 444/*
445 * Compile one eBPF instruction into s390x code 445 * Compile one eBPF instruction into s390x code
446 *
447 * NOTE: Use noinline because for gcov (-fprofile-arcs) gcc allocates a lot of
448 * stack space for the large switch statement.
446 */ 449 */
447static int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i) 450static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i)
448{ 451{
449 struct bpf_insn *insn = &fp->insnsi[i]; 452 struct bpf_insn *insn = &fp->insnsi[i];
450 int jmp_off, last, insn_count = 1; 453 int jmp_off, last, insn_count = 1;
@@ -588,8 +591,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i)
588 EMIT4(0xb9160000, dst_reg, rc_reg); 591 EMIT4(0xb9160000, dst_reg, rc_reg);
589 break; 592 break;
590 } 593 }
591 case BPF_ALU64 | BPF_DIV | BPF_X: /* dst = dst / (u32) src */ 594 case BPF_ALU64 | BPF_DIV | BPF_X: /* dst = dst / src */
592 case BPF_ALU64 | BPF_MOD | BPF_X: /* dst = dst % (u32) src */ 595 case BPF_ALU64 | BPF_MOD | BPF_X: /* dst = dst % src */
593 { 596 {
594 int rc_reg = BPF_OP(insn->code) == BPF_DIV ? REG_W1 : REG_W0; 597 int rc_reg = BPF_OP(insn->code) == BPF_DIV ? REG_W1 : REG_W0;
595 598
@@ -602,10 +605,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i)
602 EMIT4_IMM(0xa7090000, REG_W0, 0); 605 EMIT4_IMM(0xa7090000, REG_W0, 0);
603 /* lgr %w1,%dst */ 606 /* lgr %w1,%dst */
604 EMIT4(0xb9040000, REG_W1, dst_reg); 607 EMIT4(0xb9040000, REG_W1, dst_reg);
605 /* llgfr %dst,%src (u32 cast) */
606 EMIT4(0xb9160000, dst_reg, src_reg);
607 /* dlgr %w0,%dst */ 608 /* dlgr %w0,%dst */
608 EMIT4(0xb9870000, REG_W0, dst_reg); 609 EMIT4(0xb9870000, REG_W0, src_reg);
609 /* lgr %dst,%rc */ 610 /* lgr %dst,%rc */
610 EMIT4(0xb9040000, dst_reg, rc_reg); 611 EMIT4(0xb9040000, dst_reg, rc_reg);
611 break; 612 break;
@@ -632,8 +633,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i)
632 EMIT4(0xb9160000, dst_reg, rc_reg); 633 EMIT4(0xb9160000, dst_reg, rc_reg);
633 break; 634 break;
634 } 635 }
635 case BPF_ALU64 | BPF_DIV | BPF_K: /* dst = dst / (u32) imm */ 636 case BPF_ALU64 | BPF_DIV | BPF_K: /* dst = dst / imm */
636 case BPF_ALU64 | BPF_MOD | BPF_K: /* dst = dst % (u32) imm */ 637 case BPF_ALU64 | BPF_MOD | BPF_K: /* dst = dst % imm */
637 { 638 {
638 int rc_reg = BPF_OP(insn->code) == BPF_DIV ? REG_W1 : REG_W0; 639 int rc_reg = BPF_OP(insn->code) == BPF_DIV ? REG_W1 : REG_W0;
639 640
@@ -649,7 +650,7 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i)
649 EMIT4(0xb9040000, REG_W1, dst_reg); 650 EMIT4(0xb9040000, REG_W1, dst_reg);
650 /* dlg %w0,<d(imm)>(%l) */ 651 /* dlg %w0,<d(imm)>(%l) */
651 EMIT6_DISP_LH(0xe3000000, 0x0087, REG_W0, REG_0, REG_L, 652 EMIT6_DISP_LH(0xe3000000, 0x0087, REG_W0, REG_0, REG_L,
652 EMIT_CONST_U64((u32) imm)); 653 EMIT_CONST_U64(imm));
653 /* lgr %dst,%rc */ 654 /* lgr %dst,%rc */
654 EMIT4(0xb9040000, dst_reg, rc_reg); 655 EMIT4(0xb9040000, dst_reg, rc_reg);
655 break; 656 break;
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index 6873f006f7d0..d366675e4bf8 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -774,7 +774,7 @@ static void __init zone_sizes_init(void)
774 * though, there'll be no lowmem, so we just alloc_bootmem 774 * though, there'll be no lowmem, so we just alloc_bootmem
775 * the memmap. There will be no percpu memory either. 775 * the memmap. There will be no percpu memory either.
776 */ 776 */
777 if (i != 0 && cpumask_test_cpu(i, &isolnodes)) { 777 if (i != 0 && node_isset(i, isolnodes)) {
778 node_memmap_pfn[i] = 778 node_memmap_pfn[i] =
779 alloc_bootmem_pfn(0, memmap_size, 0); 779 alloc_bootmem_pfn(0, memmap_size, 0);
780 BUG_ON(node_percpu[i] != 0); 780 BUG_ON(node_percpu[i] != 0);
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index ef17683484e9..48304b89b601 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -1109,6 +1109,8 @@ struct boot_params *make_boot_params(struct efi_config *c)
1109 if (!cmdline_ptr) 1109 if (!cmdline_ptr)
1110 goto fail; 1110 goto fail;
1111 hdr->cmd_line_ptr = (unsigned long)cmdline_ptr; 1111 hdr->cmd_line_ptr = (unsigned long)cmdline_ptr;
1112 /* Fill in upper bits of command line address, NOP on 32 bit */
1113 boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32;
1112 1114
1113 hdr->ramdisk_image = 0; 1115 hdr->ramdisk_image = 0;
1114 hdr->ramdisk_size = 0; 1116 hdr->ramdisk_size = 0;
diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
index e42f758a0fbd..055ea9941dd5 100644
--- a/arch/x86/include/asm/hypervisor.h
+++ b/arch/x86/include/asm/hypervisor.h
@@ -50,7 +50,7 @@ extern const struct hypervisor_x86 *x86_hyper;
50/* Recognized hypervisors */ 50/* Recognized hypervisors */
51extern const struct hypervisor_x86 x86_hyper_vmware; 51extern const struct hypervisor_x86 x86_hyper_vmware;
52extern const struct hypervisor_x86 x86_hyper_ms_hyperv; 52extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
53extern const struct hypervisor_x86 x86_hyper_xen_hvm; 53extern const struct hypervisor_x86 x86_hyper_xen;
54extern const struct hypervisor_x86 x86_hyper_kvm; 54extern const struct hypervisor_x86 x86_hyper_kvm;
55 55
56extern void init_hypervisor(struct cpuinfo_x86 *c); 56extern void init_hypervisor(struct cpuinfo_x86 *c);
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index dea2e7e962e3..f4a555beef19 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -207,6 +207,7 @@ union kvm_mmu_page_role {
207 unsigned nxe:1; 207 unsigned nxe:1;
208 unsigned cr0_wp:1; 208 unsigned cr0_wp:1;
209 unsigned smep_andnot_wp:1; 209 unsigned smep_andnot_wp:1;
210 unsigned smap_andnot_wp:1;
210 }; 211 };
211}; 212};
212 213
@@ -400,6 +401,7 @@ struct kvm_vcpu_arch {
400 struct kvm_mmu_memory_cache mmu_page_header_cache; 401 struct kvm_mmu_memory_cache mmu_page_header_cache;
401 402
402 struct fpu guest_fpu; 403 struct fpu guest_fpu;
404 bool eager_fpu;
403 u64 xcr0; 405 u64 xcr0;
404 u64 guest_supported_xcr0; 406 u64 guest_supported_xcr0;
405 u32 guest_xstate_size; 407 u32 guest_xstate_size;
@@ -743,6 +745,7 @@ struct kvm_x86_ops {
743 void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg); 745 void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg);
744 unsigned long (*get_rflags)(struct kvm_vcpu *vcpu); 746 unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);
745 void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); 747 void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
748 void (*fpu_activate)(struct kvm_vcpu *vcpu);
746 void (*fpu_deactivate)(struct kvm_vcpu *vcpu); 749 void (*fpu_deactivate)(struct kvm_vcpu *vcpu);
747 750
748 void (*tlb_flush)(struct kvm_vcpu *vcpu); 751 void (*tlb_flush)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index 25b1cc07d496..d6b078e9fa28 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -95,7 +95,6 @@ unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src,
95 95
96struct pvclock_vsyscall_time_info { 96struct pvclock_vsyscall_time_info {
97 struct pvclock_vcpu_time_info pvti; 97 struct pvclock_vcpu_time_info pvti;
98 u32 migrate_count;
99} __attribute__((__aligned__(SMP_CACHE_BYTES))); 98} __attribute__((__aligned__(SMP_CACHE_BYTES)));
100 99
101#define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info) 100#define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info)
diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
index cf87de3fc390..64b611782ef0 100644
--- a/arch/x86/include/asm/spinlock.h
+++ b/arch/x86/include/asm/spinlock.h
@@ -169,7 +169,7 @@ static inline int arch_spin_is_contended(arch_spinlock_t *lock)
169 struct __raw_tickets tmp = READ_ONCE(lock->tickets); 169 struct __raw_tickets tmp = READ_ONCE(lock->tickets);
170 170
171 tmp.head &= ~TICKET_SLOWPATH_FLAG; 171 tmp.head &= ~TICKET_SLOWPATH_FLAG;
172 return (tmp.tail - tmp.head) > TICKET_LOCK_INC; 172 return (__ticket_t)(tmp.tail - tmp.head) > TICKET_LOCK_INC;
173} 173}
174#define arch_spin_is_contended arch_spin_is_contended 174#define arch_spin_is_contended arch_spin_is_contended
175 175
diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
index 358dcd338915..c44a5d53e464 100644
--- a/arch/x86/include/asm/xen/page.h
+++ b/arch/x86/include/asm/xen/page.h
@@ -269,4 +269,9 @@ static inline bool xen_arch_need_swiotlb(struct device *dev,
269 return false; 269 return false;
270} 270}
271 271
272static inline unsigned long xen_get_swiotlb_free_pages(unsigned int order)
273{
274 return __get_free_pages(__GFP_NOWARN, order);
275}
276
272#endif /* _ASM_X86_XEN_PAGE_H */ 277#endif /* _ASM_X86_XEN_PAGE_H */
diff --git a/arch/x86/include/uapi/asm/msr-index.h b/arch/x86/include/uapi/asm/msr-index.h
index c469490db4a8..3c6bb342a48f 100644
--- a/arch/x86/include/uapi/asm/msr-index.h
+++ b/arch/x86/include/uapi/asm/msr-index.h
@@ -140,6 +140,7 @@
140#define MSR_CORE_C3_RESIDENCY 0x000003fc 140#define MSR_CORE_C3_RESIDENCY 0x000003fc
141#define MSR_CORE_C6_RESIDENCY 0x000003fd 141#define MSR_CORE_C6_RESIDENCY 0x000003fd
142#define MSR_CORE_C7_RESIDENCY 0x000003fe 142#define MSR_CORE_C7_RESIDENCY 0x000003fe
143#define MSR_KNL_CORE_C6_RESIDENCY 0x000003ff
143#define MSR_PKG_C2_RESIDENCY 0x0000060d 144#define MSR_PKG_C2_RESIDENCY 0x0000060d
144#define MSR_PKG_C8_RESIDENCY 0x00000630 145#define MSR_PKG_C8_RESIDENCY 0x00000630
145#define MSR_PKG_C9_RESIDENCY 0x00000631 146#define MSR_PKG_C9_RESIDENCY 0x00000631
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c
index 36ce402a3fa5..d820d8eae96b 100644
--- a/arch/x86/kernel/cpu/hypervisor.c
+++ b/arch/x86/kernel/cpu/hypervisor.c
@@ -27,8 +27,8 @@
27 27
28static const __initconst struct hypervisor_x86 * const hypervisors[] = 28static const __initconst struct hypervisor_x86 * const hypervisors[] =
29{ 29{
30#ifdef CONFIG_XEN_PVHVM 30#ifdef CONFIG_XEN
31 &x86_hyper_xen_hvm, 31 &x86_hyper_xen,
32#endif 32#endif
33 &x86_hyper_vmware, 33 &x86_hyper_vmware,
34 &x86_hyper_ms_hyperv, 34 &x86_hyper_ms_hyperv,
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index e535533d5ab8..20190bdac9d5 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -708,6 +708,7 @@ static int mce_no_way_out(struct mce *m, char **msg, unsigned long *validp,
708 struct pt_regs *regs) 708 struct pt_regs *regs)
709{ 709{
710 int i, ret = 0; 710 int i, ret = 0;
711 char *tmp;
711 712
712 for (i = 0; i < mca_cfg.banks; i++) { 713 for (i = 0; i < mca_cfg.banks; i++) {
713 m->status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i)); 714 m->status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
@@ -716,9 +717,11 @@ static int mce_no_way_out(struct mce *m, char **msg, unsigned long *validp,
716 if (quirk_no_way_out) 717 if (quirk_no_way_out)
717 quirk_no_way_out(i, m, regs); 718 quirk_no_way_out(i, m, regs);
718 } 719 }
719 if (mce_severity(m, mca_cfg.tolerant, msg, true) >= 720
720 MCE_PANIC_SEVERITY) 721 if (mce_severity(m, mca_cfg.tolerant, &tmp, true) >= MCE_PANIC_SEVERITY) {
722 *msg = tmp;
721 ret = 1; 723 ret = 1;
724 }
722 } 725 }
723 return ret; 726 return ret;
724} 727}
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 219d3fb423a1..3998131d1a68 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -1134,7 +1134,7 @@ static __initconst const u64 slm_hw_cache_extra_regs
1134 [ C(LL ) ] = { 1134 [ C(LL ) ] = {
1135 [ C(OP_READ) ] = { 1135 [ C(OP_READ) ] = {
1136 [ C(RESULT_ACCESS) ] = SLM_DMND_READ|SLM_LLC_ACCESS, 1136 [ C(RESULT_ACCESS) ] = SLM_DMND_READ|SLM_LLC_ACCESS,
1137 [ C(RESULT_MISS) ] = SLM_DMND_READ|SLM_LLC_MISS, 1137 [ C(RESULT_MISS) ] = 0,
1138 }, 1138 },
1139 [ C(OP_WRITE) ] = { 1139 [ C(OP_WRITE) ] = {
1140 [ C(RESULT_ACCESS) ] = SLM_DMND_WRITE|SLM_LLC_ACCESS, 1140 [ C(RESULT_ACCESS) ] = SLM_DMND_WRITE|SLM_LLC_ACCESS,
@@ -1184,8 +1184,7 @@ static __initconst const u64 slm_hw_cache_event_ids
1184 [ C(OP_READ) ] = { 1184 [ C(OP_READ) ] = {
1185 /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ 1185 /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
1186 [ C(RESULT_ACCESS) ] = 0x01b7, 1186 [ C(RESULT_ACCESS) ] = 0x01b7,
1187 /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ 1187 [ C(RESULT_MISS) ] = 0,
1188 [ C(RESULT_MISS) ] = 0x01b7,
1189 }, 1188 },
1190 [ C(OP_WRITE) ] = { 1189 [ C(OP_WRITE) ] = {
1191 /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ 1190 /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
@@ -1217,7 +1216,7 @@ static __initconst const u64 slm_hw_cache_event_ids
1217 [ C(ITLB) ] = { 1216 [ C(ITLB) ] = {
1218 [ C(OP_READ) ] = { 1217 [ C(OP_READ) ] = {
1219 [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ 1218 [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
1220 [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */ 1219 [ C(RESULT_MISS) ] = 0x40205, /* PAGE_WALKS.I_SIDE_WALKS */
1221 }, 1220 },
1222 [ C(OP_WRITE) ] = { 1221 [ C(OP_WRITE) ] = {
1223 [ C(RESULT_ACCESS) ] = -1, 1222 [ C(RESULT_ACCESS) ] = -1,
@@ -2533,34 +2532,6 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
2533 return x86_event_sysfs_show(page, config, event); 2532 return x86_event_sysfs_show(page, config, event);
2534} 2533}
2535 2534
2536static __initconst const struct x86_pmu core_pmu = {
2537 .name = "core",
2538 .handle_irq = x86_pmu_handle_irq,
2539 .disable_all = x86_pmu_disable_all,
2540 .enable_all = core_pmu_enable_all,
2541 .enable = core_pmu_enable_event,
2542 .disable = x86_pmu_disable_event,
2543 .hw_config = x86_pmu_hw_config,
2544 .schedule_events = x86_schedule_events,
2545 .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
2546 .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
2547 .event_map = intel_pmu_event_map,
2548 .max_events = ARRAY_SIZE(intel_perfmon_event_map),
2549 .apic = 1,
2550 /*
2551 * Intel PMCs cannot be accessed sanely above 32 bit width,
2552 * so we install an artificial 1<<31 period regardless of
2553 * the generic event period:
2554 */
2555 .max_period = (1ULL << 31) - 1,
2556 .get_event_constraints = intel_get_event_constraints,
2557 .put_event_constraints = intel_put_event_constraints,
2558 .event_constraints = intel_core_event_constraints,
2559 .guest_get_msrs = core_guest_get_msrs,
2560 .format_attrs = intel_arch_formats_attr,
2561 .events_sysfs_show = intel_event_sysfs_show,
2562};
2563
2564struct intel_shared_regs *allocate_shared_regs(int cpu) 2535struct intel_shared_regs *allocate_shared_regs(int cpu)
2565{ 2536{
2566 struct intel_shared_regs *regs; 2537 struct intel_shared_regs *regs;
@@ -2743,6 +2714,44 @@ static struct attribute *intel_arch3_formats_attr[] = {
2743 NULL, 2714 NULL,
2744}; 2715};
2745 2716
2717static __initconst const struct x86_pmu core_pmu = {
2718 .name = "core",
2719 .handle_irq = x86_pmu_handle_irq,
2720 .disable_all = x86_pmu_disable_all,
2721 .enable_all = core_pmu_enable_all,
2722 .enable = core_pmu_enable_event,
2723 .disable = x86_pmu_disable_event,
2724 .hw_config = x86_pmu_hw_config,
2725 .schedule_events = x86_schedule_events,
2726 .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
2727 .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
2728 .event_map = intel_pmu_event_map,
2729 .max_events = ARRAY_SIZE(intel_perfmon_event_map),
2730 .apic = 1,
2731 /*
2732 * Intel PMCs cannot be accessed sanely above 32-bit width,
2733 * so we install an artificial 1<<31 period regardless of
2734 * the generic event period:
2735 */
2736 .max_period = (1ULL<<31) - 1,
2737 .get_event_constraints = intel_get_event_constraints,
2738 .put_event_constraints = intel_put_event_constraints,
2739 .event_constraints = intel_core_event_constraints,
2740 .guest_get_msrs = core_guest_get_msrs,
2741 .format_attrs = intel_arch_formats_attr,
2742 .events_sysfs_show = intel_event_sysfs_show,
2743
2744 /*
2745 * Virtual (or funny metal) CPU can define x86_pmu.extra_regs
2746 * together with PMU version 1 and thus be using core_pmu with
2747 * shared_regs. We need following callbacks here to allocate
2748 * it properly.
2749 */
2750 .cpu_prepare = intel_pmu_cpu_prepare,
2751 .cpu_starting = intel_pmu_cpu_starting,
2752 .cpu_dying = intel_pmu_cpu_dying,
2753};
2754
2746static __initconst const struct x86_pmu intel_pmu = { 2755static __initconst const struct x86_pmu intel_pmu = {
2747 .name = "Intel", 2756 .name = "Intel",
2748 .handle_irq = intel_pmu_handle_irq, 2757 .handle_irq = intel_pmu_handle_irq,
diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
index 999289b94025..358c54ad20d4 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
@@ -722,6 +722,7 @@ static int __init rapl_pmu_init(void)
722 break; 722 break;
723 case 60: /* Haswell */ 723 case 60: /* Haswell */
724 case 69: /* Haswell-Celeron */ 724 case 69: /* Haswell-Celeron */
725 case 61: /* Broadwell */
725 rapl_cntr_mask = RAPL_IDX_HSW; 726 rapl_cntr_mask = RAPL_IDX_HSW;
726 rapl_pmu_events_group.attrs = rapl_events_hsw_attr; 727 rapl_pmu_events_group.attrs = rapl_events_hsw_attr;
727 break; 728 break;
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c b/arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c
index 3001015b755c..4562e9e22c60 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c
@@ -1,6 +1,13 @@
1/* Nehalem/SandBridge/Haswell uncore support */ 1/* Nehalem/SandBridge/Haswell uncore support */
2#include "perf_event_intel_uncore.h" 2#include "perf_event_intel_uncore.h"
3 3
4/* Uncore IMC PCI IDs */
5#define PCI_DEVICE_ID_INTEL_SNB_IMC 0x0100
6#define PCI_DEVICE_ID_INTEL_IVB_IMC 0x0154
7#define PCI_DEVICE_ID_INTEL_IVB_E3_IMC 0x0150
8#define PCI_DEVICE_ID_INTEL_HSW_IMC 0x0c00
9#define PCI_DEVICE_ID_INTEL_HSW_U_IMC 0x0a04
10
4/* SNB event control */ 11/* SNB event control */
5#define SNB_UNC_CTL_EV_SEL_MASK 0x000000ff 12#define SNB_UNC_CTL_EV_SEL_MASK 0x000000ff
6#define SNB_UNC_CTL_UMASK_MASK 0x0000ff00 13#define SNB_UNC_CTL_UMASK_MASK 0x0000ff00
@@ -472,6 +479,10 @@ static const struct pci_device_id hsw_uncore_pci_ids[] = {
472 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_IMC), 479 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_IMC),
473 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0), 480 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
474 }, 481 },
482 { /* IMC */
483 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_U_IMC),
484 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
485 },
475 { /* end: all zeroes */ }, 486 { /* end: all zeroes */ },
476}; 487};
477 488
@@ -502,6 +513,7 @@ static const struct imc_uncore_pci_dev desktop_imc_pci_ids[] = {
502 IMC_DEV(IVB_IMC, &ivb_uncore_pci_driver), /* 3rd Gen Core processor */ 513 IMC_DEV(IVB_IMC, &ivb_uncore_pci_driver), /* 3rd Gen Core processor */
503 IMC_DEV(IVB_E3_IMC, &ivb_uncore_pci_driver), /* Xeon E3-1200 v2/3rd Gen Core processor */ 514 IMC_DEV(IVB_E3_IMC, &ivb_uncore_pci_driver), /* Xeon E3-1200 v2/3rd Gen Core processor */
504 IMC_DEV(HSW_IMC, &hsw_uncore_pci_driver), /* 4th Gen Core Processor */ 515 IMC_DEV(HSW_IMC, &hsw_uncore_pci_driver), /* 4th Gen Core Processor */
516 IMC_DEV(HSW_U_IMC, &hsw_uncore_pci_driver), /* 4th Gen Core ULT Mobile Processor */
505 { /* end marker */ } 517 { /* end marker */ }
506}; 518};
507 519
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index 009183276bb7..6185d3141219 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -173,6 +173,21 @@ static void init_thread_xstate(void)
173 xstate_size = sizeof(struct i387_fxsave_struct); 173 xstate_size = sizeof(struct i387_fxsave_struct);
174 else 174 else
175 xstate_size = sizeof(struct i387_fsave_struct); 175 xstate_size = sizeof(struct i387_fsave_struct);
176
177 /*
178 * Quirk: we don't yet handle the XSAVES* instructions
179 * correctly, as we don't correctly convert between
180 * standard and compacted format when interfacing
181 * with user-space - so disable it for now.
182 *
183 * The difference is small: with recent CPUs the
184 * compacted format is only marginally smaller than
185 * the standard FPU state format.
186 *
187 * ( This is easy to backport while we are fixing
188 * XSAVES* support. )
189 */
190 setup_clear_cpu_cap(X86_FEATURE_XSAVES);
176} 191}
177 192
178/* 193/*
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 8213da62b1b7..6e338e3b1dc0 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -57,7 +57,7 @@ __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss) = {
57 .io_bitmap = { [0 ... IO_BITMAP_LONGS] = ~0 }, 57 .io_bitmap = { [0 ... IO_BITMAP_LONGS] = ~0 },
58#endif 58#endif
59}; 59};
60EXPORT_PER_CPU_SYMBOL_GPL(cpu_tss); 60EXPORT_PER_CPU_SYMBOL(cpu_tss);
61 61
62#ifdef CONFIG_X86_64 62#ifdef CONFIG_X86_64
63static DEFINE_PER_CPU(unsigned char, is_idle); 63static DEFINE_PER_CPU(unsigned char, is_idle);
@@ -156,11 +156,13 @@ void flush_thread(void)
156 /* FPU state will be reallocated lazily at the first use. */ 156 /* FPU state will be reallocated lazily at the first use. */
157 drop_fpu(tsk); 157 drop_fpu(tsk);
158 free_thread_xstate(tsk); 158 free_thread_xstate(tsk);
159 } else if (!used_math()) { 159 } else {
160 /* kthread execs. TODO: cleanup this horror. */ 160 if (!tsk_used_math(tsk)) {
161 if (WARN_ON(init_fpu(tsk))) 161 /* kthread execs. TODO: cleanup this horror. */
162 force_sig(SIGKILL, tsk); 162 if (WARN_ON(init_fpu(tsk)))
163 user_fpu_begin(); 163 force_sig(SIGKILL, tsk);
164 user_fpu_begin();
165 }
164 restore_init_xstate(); 166 restore_init_xstate();
165 } 167 }
166} 168}
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index e5ecd20e72dd..2f355d229a58 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -141,46 +141,7 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
141 set_normalized_timespec(ts, now.tv_sec, now.tv_nsec); 141 set_normalized_timespec(ts, now.tv_sec, now.tv_nsec);
142} 142}
143 143
144static struct pvclock_vsyscall_time_info *pvclock_vdso_info;
145
146static struct pvclock_vsyscall_time_info *
147pvclock_get_vsyscall_user_time_info(int cpu)
148{
149 if (!pvclock_vdso_info) {
150 BUG();
151 return NULL;
152 }
153
154 return &pvclock_vdso_info[cpu];
155}
156
157struct pvclock_vcpu_time_info *pvclock_get_vsyscall_time_info(int cpu)
158{
159 return &pvclock_get_vsyscall_user_time_info(cpu)->pvti;
160}
161
162#ifdef CONFIG_X86_64 144#ifdef CONFIG_X86_64
163static int pvclock_task_migrate(struct notifier_block *nb, unsigned long l,
164 void *v)
165{
166 struct task_migration_notifier *mn = v;
167 struct pvclock_vsyscall_time_info *pvti;
168
169 pvti = pvclock_get_vsyscall_user_time_info(mn->from_cpu);
170
171 /* this is NULL when pvclock vsyscall is not initialized */
172 if (unlikely(pvti == NULL))
173 return NOTIFY_DONE;
174
175 pvti->migrate_count++;
176
177 return NOTIFY_DONE;
178}
179
180static struct notifier_block pvclock_migrate = {
181 .notifier_call = pvclock_task_migrate,
182};
183
184/* 145/*
185 * Initialize the generic pvclock vsyscall state. This will allocate 146 * Initialize the generic pvclock vsyscall state. This will allocate
186 * a/some page(s) for the per-vcpu pvclock information, set up a 147 * a/some page(s) for the per-vcpu pvclock information, set up a
@@ -194,17 +155,12 @@ int __init pvclock_init_vsyscall(struct pvclock_vsyscall_time_info *i,
194 155
195 WARN_ON (size != PVCLOCK_VSYSCALL_NR_PAGES*PAGE_SIZE); 156 WARN_ON (size != PVCLOCK_VSYSCALL_NR_PAGES*PAGE_SIZE);
196 157
197 pvclock_vdso_info = i;
198
199 for (idx = 0; idx <= (PVCLOCK_FIXMAP_END-PVCLOCK_FIXMAP_BEGIN); idx++) { 158 for (idx = 0; idx <= (PVCLOCK_FIXMAP_END-PVCLOCK_FIXMAP_BEGIN); idx++) {
200 __set_fixmap(PVCLOCK_FIXMAP_BEGIN + idx, 159 __set_fixmap(PVCLOCK_FIXMAP_BEGIN + idx,
201 __pa(i) + (idx*PAGE_SIZE), 160 __pa(i) + (idx*PAGE_SIZE),
202 PAGE_KERNEL_VVAR); 161 PAGE_KERNEL_VVAR);
203 } 162 }
204 163
205
206 register_task_migration_notifier(&pvclock_migrate);
207
208 return 0; 164 return 0;
209} 165}
210#endif 166#endif
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 59b69f6a2844..1d08ad3582d0 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -16,6 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/vmalloc.h> 17#include <linux/vmalloc.h>
18#include <linux/uaccess.h> 18#include <linux/uaccess.h>
19#include <asm/i387.h> /* For use_eager_fpu. Ugh! */
20#include <asm/fpu-internal.h> /* For use_eager_fpu. Ugh! */
19#include <asm/user.h> 21#include <asm/user.h>
20#include <asm/xsave.h> 22#include <asm/xsave.h>
21#include "cpuid.h" 23#include "cpuid.h"
@@ -95,6 +97,8 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
95 if (best && (best->eax & (F(XSAVES) | F(XSAVEC)))) 97 if (best && (best->eax & (F(XSAVES) | F(XSAVEC))))
96 best->ebx = xstate_required_size(vcpu->arch.xcr0, true); 98 best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
97 99
100 vcpu->arch.eager_fpu = guest_cpuid_has_mpx(vcpu);
101
98 /* 102 /*
99 * The existing code assumes virtual address is 48-bit in the canonical 103 * The existing code assumes virtual address is 48-bit in the canonical
100 * address checks; exit if it is ever changed. 104 * address checks; exit if it is ever changed.
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index c3b1ad9fca81..496b3695d3d3 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -117,4 +117,12 @@ static inline bool guest_cpuid_has_rtm(struct kvm_vcpu *vcpu)
117 best = kvm_find_cpuid_entry(vcpu, 7, 0); 117 best = kvm_find_cpuid_entry(vcpu, 7, 0);
118 return best && (best->ebx & bit(X86_FEATURE_RTM)); 118 return best && (best->ebx & bit(X86_FEATURE_RTM));
119} 119}
120
121static inline bool guest_cpuid_has_mpx(struct kvm_vcpu *vcpu)
122{
123 struct kvm_cpuid_entry2 *best;
124
125 best = kvm_find_cpuid_entry(vcpu, 7, 0);
126 return best && (best->ebx & bit(X86_FEATURE_MPX));
127}
120#endif 128#endif
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index d43867c33bc4..44a7d2515497 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3736,8 +3736,8 @@ static void reset_rsvds_bits_mask_ept(struct kvm_vcpu *vcpu,
3736 } 3736 }
3737} 3737}
3738 3738
3739void update_permission_bitmask(struct kvm_vcpu *vcpu, 3739static void update_permission_bitmask(struct kvm_vcpu *vcpu,
3740 struct kvm_mmu *mmu, bool ept) 3740 struct kvm_mmu *mmu, bool ept)
3741{ 3741{
3742 unsigned bit, byte, pfec; 3742 unsigned bit, byte, pfec;
3743 u8 map; 3743 u8 map;
@@ -3918,6 +3918,7 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
3918void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu) 3918void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu)
3919{ 3919{
3920 bool smep = kvm_read_cr4_bits(vcpu, X86_CR4_SMEP); 3920 bool smep = kvm_read_cr4_bits(vcpu, X86_CR4_SMEP);
3921 bool smap = kvm_read_cr4_bits(vcpu, X86_CR4_SMAP);
3921 struct kvm_mmu *context = &vcpu->arch.mmu; 3922 struct kvm_mmu *context = &vcpu->arch.mmu;
3922 3923
3923 MMU_WARN_ON(VALID_PAGE(context->root_hpa)); 3924 MMU_WARN_ON(VALID_PAGE(context->root_hpa));
@@ -3936,6 +3937,8 @@ void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu)
3936 context->base_role.cr0_wp = is_write_protection(vcpu); 3937 context->base_role.cr0_wp = is_write_protection(vcpu);
3937 context->base_role.smep_andnot_wp 3938 context->base_role.smep_andnot_wp
3938 = smep && !is_write_protection(vcpu); 3939 = smep && !is_write_protection(vcpu);
3940 context->base_role.smap_andnot_wp
3941 = smap && !is_write_protection(vcpu);
3939} 3942}
3940EXPORT_SYMBOL_GPL(kvm_init_shadow_mmu); 3943EXPORT_SYMBOL_GPL(kvm_init_shadow_mmu);
3941 3944
@@ -4207,12 +4210,18 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
4207 const u8 *new, int bytes) 4210 const u8 *new, int bytes)
4208{ 4211{
4209 gfn_t gfn = gpa >> PAGE_SHIFT; 4212 gfn_t gfn = gpa >> PAGE_SHIFT;
4210 union kvm_mmu_page_role mask = { .word = 0 };
4211 struct kvm_mmu_page *sp; 4213 struct kvm_mmu_page *sp;
4212 LIST_HEAD(invalid_list); 4214 LIST_HEAD(invalid_list);
4213 u64 entry, gentry, *spte; 4215 u64 entry, gentry, *spte;
4214 int npte; 4216 int npte;
4215 bool remote_flush, local_flush, zap_page; 4217 bool remote_flush, local_flush, zap_page;
4218 union kvm_mmu_page_role mask = (union kvm_mmu_page_role) {
4219 .cr0_wp = 1,
4220 .cr4_pae = 1,
4221 .nxe = 1,
4222 .smep_andnot_wp = 1,
4223 .smap_andnot_wp = 1,
4224 };
4216 4225
4217 /* 4226 /*
4218 * If we don't have indirect shadow pages, it means no page is 4227 * If we don't have indirect shadow pages, it means no page is
@@ -4238,7 +4247,6 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
4238 ++vcpu->kvm->stat.mmu_pte_write; 4247 ++vcpu->kvm->stat.mmu_pte_write;
4239 kvm_mmu_audit(vcpu, AUDIT_PRE_PTE_WRITE); 4248 kvm_mmu_audit(vcpu, AUDIT_PRE_PTE_WRITE);
4240 4249
4241 mask.cr0_wp = mask.cr4_pae = mask.nxe = 1;
4242 for_each_gfn_indirect_valid_sp(vcpu->kvm, sp, gfn) { 4250 for_each_gfn_indirect_valid_sp(vcpu->kvm, sp, gfn) {
4243 if (detect_write_misaligned(sp, gpa, bytes) || 4251 if (detect_write_misaligned(sp, gpa, bytes) ||
4244 detect_write_flooding(sp)) { 4252 detect_write_flooding(sp)) {
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index c7d65637c851..0ada65ecddcf 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -71,8 +71,6 @@ enum {
71int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct); 71int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct);
72void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu); 72void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu);
73void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly); 73void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly);
74void update_permission_bitmask(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
75 bool ept);
76 74
77static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm) 75static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm)
78{ 76{
@@ -166,6 +164,8 @@ static inline bool permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
166 int index = (pfec >> 1) + 164 int index = (pfec >> 1) +
167 (smap >> (X86_EFLAGS_AC_BIT - PFERR_RSVD_BIT + 1)); 165 (smap >> (X86_EFLAGS_AC_BIT - PFERR_RSVD_BIT + 1));
168 166
167 WARN_ON(pfec & PFERR_RSVD_MASK);
168
169 return (mmu->permissions[index] >> pte_access) & 1; 169 return (mmu->permissions[index] >> pte_access) & 1;
170} 170}
171 171
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index fd49c867b25a..6e6d115fe9b5 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -718,6 +718,13 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, u32 error_code,
718 mmu_is_nested(vcpu)); 718 mmu_is_nested(vcpu));
719 if (likely(r != RET_MMIO_PF_INVALID)) 719 if (likely(r != RET_MMIO_PF_INVALID))
720 return r; 720 return r;
721
722 /*
723 * page fault with PFEC.RSVD = 1 is caused by shadow
724 * page fault, should not be used to walk guest page
725 * table.
726 */
727 error_code &= ~PFERR_RSVD_MASK;
721 }; 728 };
722 729
723 r = mmu_topup_memory_caches(vcpu); 730 r = mmu_topup_memory_caches(vcpu);
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index ce741b8650f6..9afa233b5482 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -4381,6 +4381,7 @@ static struct kvm_x86_ops svm_x86_ops = {
4381 .cache_reg = svm_cache_reg, 4381 .cache_reg = svm_cache_reg,
4382 .get_rflags = svm_get_rflags, 4382 .get_rflags = svm_get_rflags,
4383 .set_rflags = svm_set_rflags, 4383 .set_rflags = svm_set_rflags,
4384 .fpu_activate = svm_fpu_activate,
4384 .fpu_deactivate = svm_fpu_deactivate, 4385 .fpu_deactivate = svm_fpu_deactivate,
4385 4386
4386 .tlb_flush = svm_flush_tlb, 4387 .tlb_flush = svm_flush_tlb,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f7b61687bd79..2d73807f0d31 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10185,6 +10185,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
10185 .cache_reg = vmx_cache_reg, 10185 .cache_reg = vmx_cache_reg,
10186 .get_rflags = vmx_get_rflags, 10186 .get_rflags = vmx_get_rflags,
10187 .set_rflags = vmx_set_rflags, 10187 .set_rflags = vmx_set_rflags,
10188 .fpu_activate = vmx_fpu_activate,
10188 .fpu_deactivate = vmx_fpu_deactivate, 10189 .fpu_deactivate = vmx_fpu_deactivate,
10189 10190
10190 .tlb_flush = vmx_flush_tlb, 10191 .tlb_flush = vmx_flush_tlb,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ed31c31b2485..ea306adbbc13 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -702,8 +702,9 @@ EXPORT_SYMBOL_GPL(kvm_set_xcr);
702int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) 702int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
703{ 703{
704 unsigned long old_cr4 = kvm_read_cr4(vcpu); 704 unsigned long old_cr4 = kvm_read_cr4(vcpu);
705 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | 705 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE |
706 X86_CR4_PAE | X86_CR4_SMEP; 706 X86_CR4_SMEP | X86_CR4_SMAP;
707
707 if (cr4 & CR4_RESERVED_BITS) 708 if (cr4 & CR4_RESERVED_BITS)
708 return 1; 709 return 1;
709 710
@@ -744,9 +745,6 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
744 (!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE))) 745 (!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE)))
745 kvm_mmu_reset_context(vcpu); 746 kvm_mmu_reset_context(vcpu);
746 747
747 if ((cr4 ^ old_cr4) & X86_CR4_SMAP)
748 update_permission_bitmask(vcpu, vcpu->arch.walk_mmu, false);
749
750 if ((cr4 ^ old_cr4) & X86_CR4_OSXSAVE) 748 if ((cr4 ^ old_cr4) & X86_CR4_OSXSAVE)
751 kvm_update_cpuid(vcpu); 749 kvm_update_cpuid(vcpu);
752 750
@@ -1669,12 +1667,28 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
1669 &guest_hv_clock, sizeof(guest_hv_clock)))) 1667 &guest_hv_clock, sizeof(guest_hv_clock))))
1670 return 0; 1668 return 0;
1671 1669
1672 /* 1670 /* This VCPU is paused, but it's legal for a guest to read another
1673 * The interface expects us to write an even number signaling that the 1671 * VCPU's kvmclock, so we really have to follow the specification where
1674 * update is finished. Since the guest won't see the intermediate 1672 * it says that version is odd if data is being modified, and even after
1675 * state, we just increase by 2 at the end. 1673 * it is consistent.
1674 *
1675 * Version field updates must be kept separate. This is because
1676 * kvm_write_guest_cached might use a "rep movs" instruction, and
1677 * writes within a string instruction are weakly ordered. So there
1678 * are three writes overall.
1679 *
1680 * As a small optimization, only write the version field in the first
1681 * and third write. The vcpu->pv_time cache is still valid, because the
1682 * version field is the first in the struct.
1676 */ 1683 */
1677 vcpu->hv_clock.version = guest_hv_clock.version + 2; 1684 BUILD_BUG_ON(offsetof(struct pvclock_vcpu_time_info, version) != 0);
1685
1686 vcpu->hv_clock.version = guest_hv_clock.version + 1;
1687 kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
1688 &vcpu->hv_clock,
1689 sizeof(vcpu->hv_clock.version));
1690
1691 smp_wmb();
1678 1692
1679 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */ 1693 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
1680 pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED); 1694 pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
@@ -1695,6 +1709,13 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
1695 kvm_write_guest_cached(v->kvm, &vcpu->pv_time, 1709 kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
1696 &vcpu->hv_clock, 1710 &vcpu->hv_clock,
1697 sizeof(vcpu->hv_clock)); 1711 sizeof(vcpu->hv_clock));
1712
1713 smp_wmb();
1714
1715 vcpu->hv_clock.version++;
1716 kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
1717 &vcpu->hv_clock,
1718 sizeof(vcpu->hv_clock.version));
1698 return 0; 1719 return 0;
1699} 1720}
1700 1721
@@ -6174,6 +6195,8 @@ void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
6174 return; 6195 return;
6175 6196
6176 page = gfn_to_page(vcpu->kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT); 6197 page = gfn_to_page(vcpu->kvm, APIC_DEFAULT_PHYS_BASE >> PAGE_SHIFT);
6198 if (is_error_page(page))
6199 return;
6177 kvm_x86_ops->set_apic_access_page_addr(vcpu, page_to_phys(page)); 6200 kvm_x86_ops->set_apic_access_page_addr(vcpu, page_to_phys(page));
6178 6201
6179 /* 6202 /*
@@ -7037,7 +7060,9 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
7037 fpu_save_init(&vcpu->arch.guest_fpu); 7060 fpu_save_init(&vcpu->arch.guest_fpu);
7038 __kernel_fpu_end(); 7061 __kernel_fpu_end();
7039 ++vcpu->stat.fpu_reload; 7062 ++vcpu->stat.fpu_reload;
7040 kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu); 7063 if (!vcpu->arch.eager_fpu)
7064 kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu);
7065
7041 trace_kvm_fpu(0); 7066 trace_kvm_fpu(0);
7042} 7067}
7043 7068
@@ -7053,11 +7078,21 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
7053struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, 7078struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
7054 unsigned int id) 7079 unsigned int id)
7055{ 7080{
7081 struct kvm_vcpu *vcpu;
7082
7056 if (check_tsc_unstable() && atomic_read(&kvm->online_vcpus) != 0) 7083 if (check_tsc_unstable() && atomic_read(&kvm->online_vcpus) != 0)
7057 printk_once(KERN_WARNING 7084 printk_once(KERN_WARNING
7058 "kvm: SMP vm created on host with unstable TSC; " 7085 "kvm: SMP vm created on host with unstable TSC; "
7059 "guest TSC will not be reliable\n"); 7086 "guest TSC will not be reliable\n");
7060 return kvm_x86_ops->vcpu_create(kvm, id); 7087
7088 vcpu = kvm_x86_ops->vcpu_create(kvm, id);
7089
7090 /*
7091 * Activate fpu unconditionally in case the guest needs eager FPU. It will be
7092 * deactivated soon if it doesn't.
7093 */
7094 kvm_x86_ops->fpu_activate(vcpu);
7095 return vcpu;
7061} 7096}
7062 7097
7063int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 7098int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 5ead4d6cf3a7..70e7444c6835 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -351,18 +351,20 @@ int arch_ioremap_pmd_supported(void)
351 */ 351 */
352void *xlate_dev_mem_ptr(phys_addr_t phys) 352void *xlate_dev_mem_ptr(phys_addr_t phys)
353{ 353{
354 void *addr; 354 unsigned long start = phys & PAGE_MASK;
355 unsigned long start = phys & PAGE_MASK; 355 unsigned long offset = phys & ~PAGE_MASK;
356 unsigned long vaddr;
356 357
357 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */ 358 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
358 if (page_is_ram(start >> PAGE_SHIFT)) 359 if (page_is_ram(start >> PAGE_SHIFT))
359 return __va(phys); 360 return __va(phys);
360 361
361 addr = (void __force *)ioremap_cache(start, PAGE_SIZE); 362 vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
362 if (addr) 363 /* Only add the offset on success and return NULL if the ioremap() failed: */
363 addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK)); 364 if (vaddr)
365 vaddr += offset;
364 366
365 return addr; 367 return (void *)vaddr;
366} 368}
367 369
368void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr) 370void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 987514396c1e..ddeff4844a10 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -559,6 +559,13 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
559 if (is_ereg(dst_reg)) 559 if (is_ereg(dst_reg))
560 EMIT1(0x41); 560 EMIT1(0x41);
561 EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8); 561 EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
562
563 /* emit 'movzwl eax, ax' */
564 if (is_ereg(dst_reg))
565 EMIT3(0x45, 0x0F, 0xB7);
566 else
567 EMIT2(0x0F, 0xB7);
568 EMIT1(add_2reg(0xC0, dst_reg, dst_reg));
562 break; 569 break;
563 case 32: 570 case 32:
564 /* emit 'bswap eax' to swap lower 4 bytes */ 571 /* emit 'bswap eax' to swap lower 4 bytes */
@@ -577,6 +584,27 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
577 break; 584 break;
578 585
579 case BPF_ALU | BPF_END | BPF_FROM_LE: 586 case BPF_ALU | BPF_END | BPF_FROM_LE:
587 switch (imm32) {
588 case 16:
589 /* emit 'movzwl eax, ax' to zero extend 16-bit
590 * into 64 bit
591 */
592 if (is_ereg(dst_reg))
593 EMIT3(0x45, 0x0F, 0xB7);
594 else
595 EMIT2(0x0F, 0xB7);
596 EMIT1(add_2reg(0xC0, dst_reg, dst_reg));
597 break;
598 case 32:
599 /* emit 'mov eax, eax' to clear upper 32-bits */
600 if (is_ereg(dst_reg))
601 EMIT1(0x45);
602 EMIT2(0x89, add_2reg(0xC0, dst_reg, dst_reg));
603 break;
604 case 64:
605 /* nop */
606 break;
607 }
580 break; 608 break;
581 609
582 /* ST: *(u8*)(dst_reg + off) = imm */ 610 /* ST: *(u8*)(dst_reg + off) = imm */
@@ -938,7 +966,12 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
938 } 966 }
939 ctx.cleanup_addr = proglen; 967 ctx.cleanup_addr = proglen;
940 968
941 for (pass = 0; pass < 10; pass++) { 969 /* JITed image shrinks with every pass and the loop iterates
970 * until the image stops shrinking. Very large bpf programs
971 * may converge on the last pass. In such case do one more
972 * pass to emit the final image
973 */
974 for (pass = 0; pass < 10 || image; pass++) {
942 proglen = do_jit(prog, addrs, image, oldproglen, &ctx); 975 proglen = do_jit(prog, addrs, image, oldproglen, &ctx);
943 if (proglen <= 0) { 976 if (proglen <= 0) {
944 image = NULL; 977 image = NULL;
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index e4695985f9de..14a63ed6fe09 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -325,6 +325,26 @@ static void release_pci_root_info(struct pci_host_bridge *bridge)
325 kfree(info); 325 kfree(info);
326} 326}
327 327
328/*
329 * An IO port or MMIO resource assigned to a PCI host bridge may be
330 * consumed by the host bridge itself or available to its child
331 * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
332 * to tell whether the resource is consumed by the host bridge itself,
333 * but firmware hasn't used that bit consistently, so we can't rely on it.
334 *
335 * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
336 * to be available to child bus/devices except one special case:
337 * IO port [0xCF8-0xCFF] is consumed by the host bridge itself
338 * to access PCI configuration space.
339 *
340 * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
341 */
342static bool resource_is_pcicfg_ioport(struct resource *res)
343{
344 return (res->flags & IORESOURCE_IO) &&
345 res->start == 0xCF8 && res->end == 0xCFF;
346}
347
328static void probe_pci_root_info(struct pci_root_info *info, 348static void probe_pci_root_info(struct pci_root_info *info,
329 struct acpi_device *device, 349 struct acpi_device *device,
330 int busnum, int domain, 350 int busnum, int domain,
@@ -346,8 +366,8 @@ static void probe_pci_root_info(struct pci_root_info *info,
346 "no IO and memory resources present in _CRS\n"); 366 "no IO and memory resources present in _CRS\n");
347 else 367 else
348 resource_list_for_each_entry_safe(entry, tmp, list) { 368 resource_list_for_each_entry_safe(entry, tmp, list) {
349 if ((entry->res->flags & IORESOURCE_WINDOW) == 0 || 369 if ((entry->res->flags & IORESOURCE_DISABLED) ||
350 (entry->res->flags & IORESOURCE_DISABLED)) 370 resource_is_pcicfg_ioport(entry->res))
351 resource_list_destroy_entry(entry); 371 resource_list_destroy_entry(entry);
352 else 372 else
353 entry->res->name = info->name; 373 entry->res->name = info->name;
@@ -462,9 +482,16 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
462 482
463int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) 483int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
464{ 484{
465 struct pci_sysdata *sd = bridge->bus->sysdata; 485 /*
466 486 * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL
467 ACPI_COMPANION_SET(&bridge->dev, sd->companion); 487 * here, pci_create_root_bus() has been called by someone else and
488 * sysdata is likely to be different from what we expect. Let it go in
489 * that case.
490 */
491 if (!bridge->dev.parent) {
492 struct pci_sysdata *sd = bridge->bus->sysdata;
493 ACPI_COMPANION_SET(&bridge->dev, sd->companion);
494 }
468 return 0; 495 return 0;
469} 496}
470 497
diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
index 275a3a8b78af..e97032069f88 100644
--- a/arch/x86/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
@@ -51,7 +51,7 @@ VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
51$(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE 51$(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE
52 $(call if_changed,vdso) 52 $(call if_changed,vdso)
53 53
54HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi 54HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/x86/include/uapi
55hostprogs-y += vdso2c 55hostprogs-y += vdso2c
56 56
57quiet_cmd_vdso2c = VDSO2C $@ 57quiet_cmd_vdso2c = VDSO2C $@
diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
index 40d2473836c9..9793322751e0 100644
--- a/arch/x86/vdso/vclock_gettime.c
+++ b/arch/x86/vdso/vclock_gettime.c
@@ -82,15 +82,18 @@ static notrace cycle_t vread_pvclock(int *mode)
82 cycle_t ret; 82 cycle_t ret;
83 u64 last; 83 u64 last;
84 u32 version; 84 u32 version;
85 u32 migrate_count;
86 u8 flags; 85 u8 flags;
87 unsigned cpu, cpu1; 86 unsigned cpu, cpu1;
88 87
89 88
90 /* 89 /*
91 * When looping to get a consistent (time-info, tsc) pair, we 90 * Note: hypervisor must guarantee that:
92 * also need to deal with the possibility we can switch vcpus, 91 * 1. cpu ID number maps 1:1 to per-CPU pvclock time info.
93 * so make sure we always re-fetch time-info for the current vcpu. 92 * 2. that per-CPU pvclock time info is updated if the
93 * underlying CPU changes.
94 * 3. that version is increased whenever underlying CPU
95 * changes.
96 *
94 */ 97 */
95 do { 98 do {
96 cpu = __getcpu() & VGETCPU_CPU_MASK; 99 cpu = __getcpu() & VGETCPU_CPU_MASK;
@@ -99,27 +102,20 @@ static notrace cycle_t vread_pvclock(int *mode)
99 * __getcpu() calls (Gleb). 102 * __getcpu() calls (Gleb).
100 */ 103 */
101 104
102 /* Make sure migrate_count will change if we leave the VCPU. */ 105 pvti = get_pvti(cpu);
103 do {
104 pvti = get_pvti(cpu);
105 migrate_count = pvti->migrate_count;
106
107 cpu1 = cpu;
108 cpu = __getcpu() & VGETCPU_CPU_MASK;
109 } while (unlikely(cpu != cpu1));
110 106
111 version = __pvclock_read_cycles(&pvti->pvti, &ret, &flags); 107 version = __pvclock_read_cycles(&pvti->pvti, &ret, &flags);
112 108
113 /* 109 /*
114 * Test we're still on the cpu as well as the version. 110 * Test we're still on the cpu as well as the version.
115 * - We must read TSC of pvti's VCPU. 111 * We could have been migrated just after the first
116 * - KVM doesn't follow the versioning protocol, so data could 112 * vgetcpu but before fetching the version, so we
117 * change before version if we left the VCPU. 113 * wouldn't notice a version change.
118 */ 114 */
119 smp_rmb(); 115 cpu1 = __getcpu() & VGETCPU_CPU_MASK;
120 } while (unlikely((pvti->pvti.version & 1) || 116 } while (unlikely(cpu != cpu1 ||
121 pvti->pvti.version != version || 117 (pvti->pvti.version & 1) ||
122 pvti->migrate_count != migrate_count)); 118 pvti->pvti.version != version));
123 119
124 if (unlikely(!(flags & PVCLOCK_TSC_STABLE_BIT))) 120 if (unlikely(!(flags & PVCLOCK_TSC_STABLE_BIT)))
125 *mode = VCLOCK_NONE; 121 *mode = VCLOCK_NONE;
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 94578efd3067..46957ead3060 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1760,6 +1760,9 @@ static struct notifier_block xen_hvm_cpu_notifier = {
1760 1760
1761static void __init xen_hvm_guest_init(void) 1761static void __init xen_hvm_guest_init(void)
1762{ 1762{
1763 if (xen_pv_domain())
1764 return;
1765
1763 init_hvm_pv_info(); 1766 init_hvm_pv_info();
1764 1767
1765 xen_hvm_init_shared_info(); 1768 xen_hvm_init_shared_info();
@@ -1775,6 +1778,7 @@ static void __init xen_hvm_guest_init(void)
1775 xen_hvm_init_time_ops(); 1778 xen_hvm_init_time_ops();
1776 xen_hvm_init_mmu_ops(); 1779 xen_hvm_init_mmu_ops();
1777} 1780}
1781#endif
1778 1782
1779static bool xen_nopv = false; 1783static bool xen_nopv = false;
1780static __init int xen_parse_nopv(char *arg) 1784static __init int xen_parse_nopv(char *arg)
@@ -1784,14 +1788,11 @@ static __init int xen_parse_nopv(char *arg)
1784} 1788}
1785early_param("xen_nopv", xen_parse_nopv); 1789early_param("xen_nopv", xen_parse_nopv);
1786 1790
1787static uint32_t __init xen_hvm_platform(void) 1791static uint32_t __init xen_platform(void)
1788{ 1792{
1789 if (xen_nopv) 1793 if (xen_nopv)
1790 return 0; 1794 return 0;
1791 1795
1792 if (xen_pv_domain())
1793 return 0;
1794
1795 return xen_cpuid_base(); 1796 return xen_cpuid_base();
1796} 1797}
1797 1798
@@ -1809,11 +1810,19 @@ bool xen_hvm_need_lapic(void)
1809} 1810}
1810EXPORT_SYMBOL_GPL(xen_hvm_need_lapic); 1811EXPORT_SYMBOL_GPL(xen_hvm_need_lapic);
1811 1812
1812const struct hypervisor_x86 x86_hyper_xen_hvm __refconst = { 1813static void xen_set_cpu_features(struct cpuinfo_x86 *c)
1813 .name = "Xen HVM", 1814{
1814 .detect = xen_hvm_platform, 1815 if (xen_pv_domain())
1816 clear_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS);
1817}
1818
1819const struct hypervisor_x86 x86_hyper_xen = {
1820 .name = "Xen",
1821 .detect = xen_platform,
1822#ifdef CONFIG_XEN_PVHVM
1815 .init_platform = xen_hvm_guest_init, 1823 .init_platform = xen_hvm_guest_init,
1824#endif
1816 .x2apic_available = xen_x2apic_para_available, 1825 .x2apic_available = xen_x2apic_para_available,
1826 .set_cpu_features = xen_set_cpu_features,
1817}; 1827};
1818EXPORT_SYMBOL(x86_hyper_xen_hvm); 1828EXPORT_SYMBOL(x86_hyper_xen);
1819#endif
diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c
index d9497698645a..53b4c0811f4f 100644
--- a/arch/x86/xen/suspend.c
+++ b/arch/x86/xen/suspend.c
@@ -88,7 +88,17 @@ static void xen_vcpu_notify_restore(void *data)
88 tick_resume_local(); 88 tick_resume_local();
89} 89}
90 90
91static void xen_vcpu_notify_suspend(void *data)
92{
93 tick_suspend_local();
94}
95
91void xen_arch_resume(void) 96void xen_arch_resume(void)
92{ 97{
93 on_each_cpu(xen_vcpu_notify_restore, NULL, 1); 98 on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
94} 99}
100
101void xen_arch_suspend(void)
102{
103 on_each_cpu(xen_vcpu_notify_suspend, NULL, 1);
104}
diff --git a/arch/xtensa/include/asm/dma-mapping.h b/arch/xtensa/include/asm/dma-mapping.h
index 172a02a6ad14..ba78ccf651e7 100644
--- a/arch/xtensa/include/asm/dma-mapping.h
+++ b/arch/xtensa/include/asm/dma-mapping.h
@@ -185,4 +185,17 @@ static inline int dma_get_sgtable(struct device *dev, struct sg_table *sgt,
185 return -EINVAL; 185 return -EINVAL;
186} 186}
187 187
188static inline void *dma_alloc_attrs(struct device *dev, size_t size,
189 dma_addr_t *dma_handle, gfp_t flag,
190 struct dma_attrs *attrs)
191{
192 return NULL;
193}
194
195static inline void dma_free_attrs(struct device *dev, size_t size,
196 void *vaddr, dma_addr_t dma_handle,
197 struct dma_attrs *attrs)
198{
199}
200
188#endif /* _XTENSA_DMA_MAPPING_H */ 201#endif /* _XTENSA_DMA_MAPPING_H */
diff --git a/block/blk-core.c b/block/blk-core.c
index fd154b94447a..03b5f8d77f37 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -552,6 +552,8 @@ void blk_cleanup_queue(struct request_queue *q)
552 q->queue_lock = &q->__queue_lock; 552 q->queue_lock = &q->__queue_lock;
553 spin_unlock_irq(lock); 553 spin_unlock_irq(lock);
554 554
555 bdi_destroy(&q->backing_dev_info);
556
555 /* @q is and will stay empty, shutdown and put */ 557 /* @q is and will stay empty, shutdown and put */
556 blk_put_queue(q); 558 blk_put_queue(q);
557} 559}
@@ -732,6 +734,8 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id)
732} 734}
733EXPORT_SYMBOL(blk_init_queue_node); 735EXPORT_SYMBOL(blk_init_queue_node);
734 736
737static void blk_queue_bio(struct request_queue *q, struct bio *bio);
738
735struct request_queue * 739struct request_queue *
736blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn, 740blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn,
737 spinlock_t *lock) 741 spinlock_t *lock)
@@ -1576,7 +1580,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
1576 blk_rq_bio_prep(req->q, req, bio); 1580 blk_rq_bio_prep(req->q, req, bio);
1577} 1581}
1578 1582
1579void blk_queue_bio(struct request_queue *q, struct bio *bio) 1583static void blk_queue_bio(struct request_queue *q, struct bio *bio)
1580{ 1584{
1581 const bool sync = !!(bio->bi_rw & REQ_SYNC); 1585 const bool sync = !!(bio->bi_rw & REQ_SYNC);
1582 struct blk_plug *plug; 1586 struct blk_plug *plug;
@@ -1684,7 +1688,6 @@ out_unlock:
1684 spin_unlock_irq(q->queue_lock); 1688 spin_unlock_irq(q->queue_lock);
1685 } 1689 }
1686} 1690}
1687EXPORT_SYMBOL_GPL(blk_queue_bio); /* for device mapper only */
1688 1691
1689/* 1692/*
1690 * If bio->bi_dev is a partition, remap the location 1693 * If bio->bi_dev is a partition, remap the location
diff --git a/block/blk-mq.c b/block/blk-mq.c
index ade8a2d1b0aa..e68b71b85a7e 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -677,8 +677,11 @@ static void blk_mq_rq_timer(unsigned long priv)
677 data.next = blk_rq_timeout(round_jiffies_up(data.next)); 677 data.next = blk_rq_timeout(round_jiffies_up(data.next));
678 mod_timer(&q->timeout, data.next); 678 mod_timer(&q->timeout, data.next);
679 } else { 679 } else {
680 queue_for_each_hw_ctx(q, hctx, i) 680 queue_for_each_hw_ctx(q, hctx, i) {
681 blk_mq_tag_idle(hctx); 681 /* the hctx may be unmapped, so check it here */
682 if (blk_mq_hw_queue_mapped(hctx))
683 blk_mq_tag_idle(hctx);
684 }
682 } 685 }
683} 686}
684 687
@@ -855,6 +858,16 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
855 spin_lock(&hctx->lock); 858 spin_lock(&hctx->lock);
856 list_splice(&rq_list, &hctx->dispatch); 859 list_splice(&rq_list, &hctx->dispatch);
857 spin_unlock(&hctx->lock); 860 spin_unlock(&hctx->lock);
861 /*
862 * the queue is expected stopped with BLK_MQ_RQ_QUEUE_BUSY, but
863 * it's possible the queue is stopped and restarted again
864 * before this. Queue restart will dispatch requests. And since
865 * requests in rq_list aren't added into hctx->dispatch yet,
866 * the requests in rq_list might get lost.
867 *
868 * blk_mq_run_hw_queue() already checks the STOPPED bit
869 **/
870 blk_mq_run_hw_queue(hctx, true);
858 } 871 }
859} 872}
860 873
@@ -1571,22 +1584,6 @@ static int blk_mq_hctx_cpu_offline(struct blk_mq_hw_ctx *hctx, int cpu)
1571 return NOTIFY_OK; 1584 return NOTIFY_OK;
1572} 1585}
1573 1586
1574static int blk_mq_hctx_cpu_online(struct blk_mq_hw_ctx *hctx, int cpu)
1575{
1576 struct request_queue *q = hctx->queue;
1577 struct blk_mq_tag_set *set = q->tag_set;
1578
1579 if (set->tags[hctx->queue_num])
1580 return NOTIFY_OK;
1581
1582 set->tags[hctx->queue_num] = blk_mq_init_rq_map(set, hctx->queue_num);
1583 if (!set->tags[hctx->queue_num])
1584 return NOTIFY_STOP;
1585
1586 hctx->tags = set->tags[hctx->queue_num];
1587 return NOTIFY_OK;
1588}
1589
1590static int blk_mq_hctx_notify(void *data, unsigned long action, 1587static int blk_mq_hctx_notify(void *data, unsigned long action,
1591 unsigned int cpu) 1588 unsigned int cpu)
1592{ 1589{
@@ -1594,8 +1591,11 @@ static int blk_mq_hctx_notify(void *data, unsigned long action,
1594 1591
1595 if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) 1592 if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
1596 return blk_mq_hctx_cpu_offline(hctx, cpu); 1593 return blk_mq_hctx_cpu_offline(hctx, cpu);
1597 else if (action == CPU_ONLINE || action == CPU_ONLINE_FROZEN) 1594
1598 return blk_mq_hctx_cpu_online(hctx, cpu); 1595 /*
1596 * In case of CPU online, tags may be reallocated
1597 * in blk_mq_map_swqueue() after mapping is updated.
1598 */
1599 1599
1600 return NOTIFY_OK; 1600 return NOTIFY_OK;
1601} 1601}
@@ -1775,6 +1775,7 @@ static void blk_mq_map_swqueue(struct request_queue *q)
1775 unsigned int i; 1775 unsigned int i;
1776 struct blk_mq_hw_ctx *hctx; 1776 struct blk_mq_hw_ctx *hctx;
1777 struct blk_mq_ctx *ctx; 1777 struct blk_mq_ctx *ctx;
1778 struct blk_mq_tag_set *set = q->tag_set;
1778 1779
1779 queue_for_each_hw_ctx(q, hctx, i) { 1780 queue_for_each_hw_ctx(q, hctx, i) {
1780 cpumask_clear(hctx->cpumask); 1781 cpumask_clear(hctx->cpumask);
@@ -1803,16 +1804,20 @@ static void blk_mq_map_swqueue(struct request_queue *q)
1803 * disable it and free the request entries. 1804 * disable it and free the request entries.
1804 */ 1805 */
1805 if (!hctx->nr_ctx) { 1806 if (!hctx->nr_ctx) {
1806 struct blk_mq_tag_set *set = q->tag_set;
1807
1808 if (set->tags[i]) { 1807 if (set->tags[i]) {
1809 blk_mq_free_rq_map(set, set->tags[i], i); 1808 blk_mq_free_rq_map(set, set->tags[i], i);
1810 set->tags[i] = NULL; 1809 set->tags[i] = NULL;
1811 hctx->tags = NULL;
1812 } 1810 }
1811 hctx->tags = NULL;
1813 continue; 1812 continue;
1814 } 1813 }
1815 1814
1815 /* unmapped hw queue can be remapped after CPU topo changed */
1816 if (!set->tags[i])
1817 set->tags[i] = blk_mq_init_rq_map(set, i);
1818 hctx->tags = set->tags[i];
1819 WARN_ON(!hctx->tags);
1820
1816 /* 1821 /*
1817 * Set the map size to the number of mapped software queues. 1822 * Set the map size to the number of mapped software queues.
1818 * This is more accurate and more efficient than looping 1823 * This is more accurate and more efficient than looping
@@ -2090,9 +2095,16 @@ static int blk_mq_queue_reinit_notify(struct notifier_block *nb,
2090 */ 2095 */
2091 list_for_each_entry(q, &all_q_list, all_q_node) 2096 list_for_each_entry(q, &all_q_list, all_q_node)
2092 blk_mq_freeze_queue_start(q); 2097 blk_mq_freeze_queue_start(q);
2093 list_for_each_entry(q, &all_q_list, all_q_node) 2098 list_for_each_entry(q, &all_q_list, all_q_node) {
2094 blk_mq_freeze_queue_wait(q); 2099 blk_mq_freeze_queue_wait(q);
2095 2100
2101 /*
2102 * timeout handler can't touch hw queue during the
2103 * reinitialization
2104 */
2105 del_timer_sync(&q->timeout);
2106 }
2107
2096 list_for_each_entry(q, &all_q_list, all_q_node) 2108 list_for_each_entry(q, &all_q_list, all_q_node)
2097 blk_mq_queue_reinit(q); 2109 blk_mq_queue_reinit(q);
2098 2110
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index faaf36ade7eb..2b8fd302f677 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -522,8 +522,6 @@ static void blk_release_queue(struct kobject *kobj)
522 522
523 blk_trace_shutdown(q); 523 blk_trace_shutdown(q);
524 524
525 bdi_destroy(&q->backing_dev_info);
526
527 ida_simple_remove(&blk_queue_ida, q->id); 525 ida_simple_remove(&blk_queue_ida, q->id);
528 call_rcu(&q->rcu_head, blk_free_queue_rcu); 526 call_rcu(&q->rcu_head, blk_free_queue_rcu);
529} 527}
diff --git a/block/bounce.c b/block/bounce.c
index ab21ba203d5c..ed9dd8067120 100644
--- a/block/bounce.c
+++ b/block/bounce.c
@@ -221,8 +221,8 @@ bounce:
221 if (page_to_pfn(page) <= queue_bounce_pfn(q) && !force) 221 if (page_to_pfn(page) <= queue_bounce_pfn(q) && !force)
222 continue; 222 continue;
223 223
224 inc_zone_page_state(to->bv_page, NR_BOUNCE);
225 to->bv_page = mempool_alloc(pool, q->bounce_gfp); 224 to->bv_page = mempool_alloc(pool, q->bounce_gfp);
225 inc_zone_page_state(to->bv_page, NR_BOUNCE);
226 226
227 if (rw == WRITE) { 227 if (rw == WRITE) {
228 char *vto, *vfrom; 228 char *vto, *vfrom;
diff --git a/block/elevator.c b/block/elevator.c
index 59794d0d38e3..8985038f398c 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -157,7 +157,7 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
157 157
158 eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node); 158 eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node);
159 if (unlikely(!eq)) 159 if (unlikely(!eq))
160 goto err; 160 return NULL;
161 161
162 eq->type = e; 162 eq->type = e;
163 kobject_init(&eq->kobj, &elv_ktype); 163 kobject_init(&eq->kobj, &elv_ktype);
@@ -165,10 +165,6 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
165 hash_init(eq->hash); 165 hash_init(eq->hash);
166 166
167 return eq; 167 return eq;
168err:
169 kfree(eq);
170 elevator_put(e);
171 return NULL;
172} 168}
173EXPORT_SYMBOL(elevator_alloc); 169EXPORT_SYMBOL(elevator_alloc);
174 170
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 8aaf298a80e1..362905e7c841 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1512,15 +1512,6 @@ config CRYPTO_USER_API_RNG
1512 This option enables the user-spaces interface for random 1512 This option enables the user-spaces interface for random
1513 number generator algorithms. 1513 number generator algorithms.
1514 1514
1515config CRYPTO_USER_API_AEAD
1516 tristate "User-space interface for AEAD cipher algorithms"
1517 depends on NET
1518 select CRYPTO_AEAD
1519 select CRYPTO_USER_API
1520 help
1521 This option enables the user-spaces interface for AEAD
1522 cipher algorithms.
1523
1524config CRYPTO_HASH_INFO 1515config CRYPTO_HASH_INFO
1525 bool 1516 bool
1526 1517
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
index 00a6fe166fed..69abada22373 100644
--- a/crypto/algif_aead.c
+++ b/crypto/algif_aead.c
@@ -33,7 +33,7 @@ struct aead_ctx {
33 /* 33 /*
34 * RSGL_MAX_ENTRIES is an artificial limit where user space at maximum 34 * RSGL_MAX_ENTRIES is an artificial limit where user space at maximum
35 * can cause the kernel to allocate RSGL_MAX_ENTRIES * ALG_MAX_PAGES 35 * can cause the kernel to allocate RSGL_MAX_ENTRIES * ALG_MAX_PAGES
36 * bytes 36 * pages
37 */ 37 */
38#define RSGL_MAX_ENTRIES ALG_MAX_PAGES 38#define RSGL_MAX_ENTRIES ALG_MAX_PAGES
39 struct af_alg_sgl rsgl[RSGL_MAX_ENTRIES]; 39 struct af_alg_sgl rsgl[RSGL_MAX_ENTRIES];
@@ -435,11 +435,10 @@ static int aead_recvmsg(struct socket *sock, struct msghdr *msg, size_t ignored,
435 if (err < 0) 435 if (err < 0)
436 goto unlock; 436 goto unlock;
437 usedpages += err; 437 usedpages += err;
438 /* chain the new scatterlist with initial list */ 438 /* chain the new scatterlist with previous one */
439 if (cnt) 439 if (cnt)
440 scatterwalk_crypto_chain(ctx->rsgl[0].sg, 440 af_alg_link_sg(&ctx->rsgl[cnt-1], &ctx->rsgl[cnt]);
441 ctx->rsgl[cnt].sg, 1, 441
442 sg_nents(ctx->rsgl[cnt-1].sg));
443 /* we do not need more iovecs as we have sufficient memory */ 442 /* we do not need more iovecs as we have sufficient memory */
444 if (outlen <= usedpages) 443 if (outlen <= usedpages)
445 break; 444 break;
diff --git a/drivers/acpi/acpi_pnp.c b/drivers/acpi/acpi_pnp.c
index b193f8425999..ff6d8adc9cda 100644
--- a/drivers/acpi/acpi_pnp.c
+++ b/drivers/acpi/acpi_pnp.c
@@ -304,6 +304,8 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
304 {"PNPb006"}, 304 {"PNPb006"},
305 /* cs423x-pnpbios */ 305 /* cs423x-pnpbios */
306 {"CSC0100"}, 306 {"CSC0100"},
307 {"CSC0103"},
308 {"CSC0110"},
307 {"CSC0000"}, 309 {"CSC0000"},
308 {"GIM0100"}, /* Guillemot Turtlebeach something appears to be cs4232 compatible */ 310 {"GIM0100"}, /* Guillemot Turtlebeach something appears to be cs4232 compatible */
309 /* es18xx-pnpbios */ 311 /* es18xx-pnpbios */
diff --git a/drivers/acpi/acpica/utglobal.c b/drivers/acpi/acpica/utglobal.c
index a72685c1e819..5e8df9177da4 100644
--- a/drivers/acpi/acpica/utglobal.c
+++ b/drivers/acpi/acpica/utglobal.c
@@ -102,19 +102,12 @@ const struct acpi_predefined_names acpi_gbl_pre_defined_names[] = {
102 {"_SB_", ACPI_TYPE_DEVICE, NULL}, 102 {"_SB_", ACPI_TYPE_DEVICE, NULL},
103 {"_SI_", ACPI_TYPE_LOCAL_SCOPE, NULL}, 103 {"_SI_", ACPI_TYPE_LOCAL_SCOPE, NULL},
104 {"_TZ_", ACPI_TYPE_DEVICE, NULL}, 104 {"_TZ_", ACPI_TYPE_DEVICE, NULL},
105 /* 105 {"_REV", ACPI_TYPE_INTEGER, (char *)ACPI_CA_SUPPORT_LEVEL},
106 * March, 2015:
107 * The _REV object is in the process of being deprecated, because
108 * other ACPI implementations permanently return 2. Thus, it
109 * has little or no value. Return 2 for compatibility with
110 * other ACPI implementations.
111 */
112 {"_REV", ACPI_TYPE_INTEGER, ACPI_CAST_PTR(char, 2)},
113 {"_OS_", ACPI_TYPE_STRING, ACPI_OS_NAME}, 106 {"_OS_", ACPI_TYPE_STRING, ACPI_OS_NAME},
114 {"_GL_", ACPI_TYPE_MUTEX, ACPI_CAST_PTR(char, 1)}, 107 {"_GL_", ACPI_TYPE_MUTEX, (char *)1},
115 108
116#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY) 109#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
117 {"_OSI", ACPI_TYPE_METHOD, ACPI_CAST_PTR(char, 1)}, 110 {"_OSI", ACPI_TYPE_METHOD, (char *)1},
118#endif 111#endif
119 112
120 /* Table terminator */ 113 /* Table terminator */
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 39748bb3a543..7ccba395c9dd 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -182,7 +182,7 @@ static void __init acpi_request_region (struct acpi_generic_address *gas,
182 request_mem_region(addr, length, desc); 182 request_mem_region(addr, length, desc);
183} 183}
184 184
185static int __init acpi_reserve_resources(void) 185static void __init acpi_reserve_resources(void)
186{ 186{
187 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length, 187 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
188 "ACPI PM1a_EVT_BLK"); 188 "ACPI PM1a_EVT_BLK");
@@ -211,10 +211,7 @@ static int __init acpi_reserve_resources(void)
211 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1)) 211 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
212 acpi_request_region(&acpi_gbl_FADT.xgpe1_block, 212 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
213 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK"); 213 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
214
215 return 0;
216} 214}
217device_initcall(acpi_reserve_resources);
218 215
219void acpi_os_printf(const char *fmt, ...) 216void acpi_os_printf(const char *fmt, ...)
220{ 217{
@@ -1845,6 +1842,7 @@ acpi_status __init acpi_os_initialize(void)
1845 1842
1846acpi_status __init acpi_os_initialize1(void) 1843acpi_status __init acpi_os_initialize1(void)
1847{ 1844{
1845 acpi_reserve_resources();
1848 kacpid_wq = alloc_workqueue("kacpid", 0, 1); 1846 kacpid_wq = alloc_workqueue("kacpid", 0, 1);
1849 kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1); 1847 kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
1850 kacpi_hotplug_wq = alloc_ordered_workqueue("kacpi_hotplug", 0); 1848 kacpi_hotplug_wq = alloc_ordered_workqueue("kacpi_hotplug", 0);
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 5589a6e2a023..8244f013f210 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -573,7 +573,7 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
573 * @ares: Input ACPI resource object. 573 * @ares: Input ACPI resource object.
574 * @types: Valid resource types of IORESOURCE_XXX 574 * @types: Valid resource types of IORESOURCE_XXX
575 * 575 *
576 * This is a hepler function to support acpi_dev_get_resources(), which filters 576 * This is a helper function to support acpi_dev_get_resources(), which filters
577 * ACPI resource objects according to resource types. 577 * ACPI resource objects according to resource types.
578 */ 578 */
579int acpi_dev_filter_resource_type(struct acpi_resource *ares, 579int acpi_dev_filter_resource_type(struct acpi_resource *ares,
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index cd827625cf07..01504c819e8f 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -684,7 +684,7 @@ static int acpi_sbs_add(struct acpi_device *device)
684 if (!sbs_manager_broken) { 684 if (!sbs_manager_broken) {
685 result = acpi_manager_get_info(sbs); 685 result = acpi_manager_get_info(sbs);
686 if (!result) { 686 if (!result) {
687 sbs->manager_present = 0; 687 sbs->manager_present = 1;
688 for (id = 0; id < MAX_SBS_BAT; ++id) 688 for (id = 0; id < MAX_SBS_BAT; ++id)
689 if ((sbs->batteries_supported & (1 << id))) 689 if ((sbs->batteries_supported & (1 << id)))
690 acpi_battery_add(sbs, id); 690 acpi_battery_add(sbs, id);
diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
index 26e5b5060523..bf034f8b7c1a 100644
--- a/drivers/acpi/sbshc.c
+++ b/drivers/acpi/sbshc.c
@@ -14,6 +14,7 @@
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/dmi.h>
17#include "sbshc.h" 18#include "sbshc.h"
18 19
19#define PREFIX "ACPI: " 20#define PREFIX "ACPI: "
@@ -87,6 +88,8 @@ enum acpi_smb_offset {
87 ACPI_SMB_ALARM_DATA = 0x26, /* 2 bytes alarm data */ 88 ACPI_SMB_ALARM_DATA = 0x26, /* 2 bytes alarm data */
88}; 89};
89 90
91static bool macbook;
92
90static inline int smb_hc_read(struct acpi_smb_hc *hc, u8 address, u8 *data) 93static inline int smb_hc_read(struct acpi_smb_hc *hc, u8 address, u8 *data)
91{ 94{
92 return ec_read(hc->offset + address, data); 95 return ec_read(hc->offset + address, data);
@@ -132,6 +135,8 @@ static int acpi_smbus_transaction(struct acpi_smb_hc *hc, u8 protocol,
132 } 135 }
133 136
134 mutex_lock(&hc->lock); 137 mutex_lock(&hc->lock);
138 if (macbook)
139 udelay(5);
135 if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp)) 140 if (smb_hc_read(hc, ACPI_SMB_PROTOCOL, &temp))
136 goto end; 141 goto end;
137 if (temp) { 142 if (temp) {
@@ -257,12 +262,29 @@ extern int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
257 acpi_handle handle, acpi_ec_query_func func, 262 acpi_handle handle, acpi_ec_query_func func,
258 void *data); 263 void *data);
259 264
265static int macbook_dmi_match(const struct dmi_system_id *d)
266{
267 pr_debug("Detected MacBook, enabling workaround\n");
268 macbook = true;
269 return 0;
270}
271
272static struct dmi_system_id acpi_smbus_dmi_table[] = {
273 { macbook_dmi_match, "Apple MacBook", {
274 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
275 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook") },
276 },
277 { },
278};
279
260static int acpi_smbus_hc_add(struct acpi_device *device) 280static int acpi_smbus_hc_add(struct acpi_device *device)
261{ 281{
262 int status; 282 int status;
263 unsigned long long val; 283 unsigned long long val;
264 struct acpi_smb_hc *hc; 284 struct acpi_smb_hc *hc;
265 285
286 dmi_check_system(acpi_smbus_dmi_table);
287
266 if (!device) 288 if (!device)
267 return -EINVAL; 289 return -EINVAL;
268 290
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 5f601553b9b0..9dca4b995be0 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -270,6 +270,7 @@ config ATA_PIIX
270config SATA_DWC 270config SATA_DWC
271 tristate "DesignWare Cores SATA support" 271 tristate "DesignWare Cores SATA support"
272 depends on 460EX 272 depends on 460EX
273 select DW_DMAC
273 help 274 help
274 This option enables support for the on-chip SATA controller of the 275 This option enables support for the on-chip SATA controller of the
275 AppliedMicro processor 460EX. 276 AppliedMicro processor 460EX.
@@ -729,15 +730,6 @@ config PATA_SC1200
729 730
730 If unsure, say N. 731 If unsure, say N.
731 732
732config PATA_SCC
733 tristate "Toshiba's Cell Reference Set IDE support"
734 depends on PCI && PPC_CELLEB
735 help
736 This option enables support for the built-in IDE controller on
737 Toshiba Cell Reference Board.
738
739 If unsure, say N.
740
741config PATA_SCH 733config PATA_SCH
742 tristate "Intel SCH PATA support" 734 tristate "Intel SCH PATA support"
743 depends on PCI 735 depends on PCI
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index b67e995179a9..40f7865f20a1 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -75,7 +75,6 @@ obj-$(CONFIG_PATA_PDC_OLD) += pata_pdc202xx_old.o
75obj-$(CONFIG_PATA_RADISYS) += pata_radisys.o 75obj-$(CONFIG_PATA_RADISYS) += pata_radisys.o
76obj-$(CONFIG_PATA_RDC) += pata_rdc.o 76obj-$(CONFIG_PATA_RDC) += pata_rdc.o
77obj-$(CONFIG_PATA_SC1200) += pata_sc1200.o 77obj-$(CONFIG_PATA_SC1200) += pata_sc1200.o
78obj-$(CONFIG_PATA_SCC) += pata_scc.o
79obj-$(CONFIG_PATA_SCH) += pata_sch.o 78obj-$(CONFIG_PATA_SCH) += pata_sch.o
80obj-$(CONFIG_PATA_SERVERWORKS) += pata_serverworks.o 79obj-$(CONFIG_PATA_SERVERWORKS) += pata_serverworks.o
81obj-$(CONFIG_PATA_SIL680) += pata_sil680.o 80obj-$(CONFIG_PATA_SIL680) += pata_sil680.o
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index c7a92a743ed0..65ee94454bbd 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -66,6 +66,7 @@ enum board_ids {
66 board_ahci_yes_fbs, 66 board_ahci_yes_fbs,
67 67
68 /* board IDs for specific chipsets in alphabetical order */ 68 /* board IDs for specific chipsets in alphabetical order */
69 board_ahci_avn,
69 board_ahci_mcp65, 70 board_ahci_mcp65,
70 board_ahci_mcp77, 71 board_ahci_mcp77,
71 board_ahci_mcp89, 72 board_ahci_mcp89,
@@ -84,6 +85,8 @@ enum board_ids {
84static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 85static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
85static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class, 86static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
86 unsigned long deadline); 87 unsigned long deadline);
88static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
89 unsigned long deadline);
87static void ahci_mcp89_apple_enable(struct pci_dev *pdev); 90static void ahci_mcp89_apple_enable(struct pci_dev *pdev);
88static bool is_mcp89_apple(struct pci_dev *pdev); 91static bool is_mcp89_apple(struct pci_dev *pdev);
89static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class, 92static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
@@ -107,6 +110,11 @@ static struct ata_port_operations ahci_p5wdh_ops = {
107 .hardreset = ahci_p5wdh_hardreset, 110 .hardreset = ahci_p5wdh_hardreset,
108}; 111};
109 112
113static struct ata_port_operations ahci_avn_ops = {
114 .inherits = &ahci_ops,
115 .hardreset = ahci_avn_hardreset,
116};
117
110static const struct ata_port_info ahci_port_info[] = { 118static const struct ata_port_info ahci_port_info[] = {
111 /* by features */ 119 /* by features */
112 [board_ahci] = { 120 [board_ahci] = {
@@ -151,6 +159,12 @@ static const struct ata_port_info ahci_port_info[] = {
151 .port_ops = &ahci_ops, 159 .port_ops = &ahci_ops,
152 }, 160 },
153 /* by chipsets */ 161 /* by chipsets */
162 [board_ahci_avn] = {
163 .flags = AHCI_FLAG_COMMON,
164 .pio_mask = ATA_PIO4,
165 .udma_mask = ATA_UDMA6,
166 .port_ops = &ahci_avn_ops,
167 },
154 [board_ahci_mcp65] = { 168 [board_ahci_mcp65] = {
155 AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP | 169 AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP |
156 AHCI_HFLAG_YES_NCQ), 170 AHCI_HFLAG_YES_NCQ),
@@ -290,14 +304,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
290 { PCI_VDEVICE(INTEL, 0x1f27), board_ahci }, /* Avoton RAID */ 304 { PCI_VDEVICE(INTEL, 0x1f27), board_ahci }, /* Avoton RAID */
291 { PCI_VDEVICE(INTEL, 0x1f2e), board_ahci }, /* Avoton RAID */ 305 { PCI_VDEVICE(INTEL, 0x1f2e), board_ahci }, /* Avoton RAID */
292 { PCI_VDEVICE(INTEL, 0x1f2f), board_ahci }, /* Avoton RAID */ 306 { PCI_VDEVICE(INTEL, 0x1f2f), board_ahci }, /* Avoton RAID */
293 { PCI_VDEVICE(INTEL, 0x1f32), board_ahci }, /* Avoton AHCI */ 307 { PCI_VDEVICE(INTEL, 0x1f32), board_ahci_avn }, /* Avoton AHCI */
294 { PCI_VDEVICE(INTEL, 0x1f33), board_ahci }, /* Avoton AHCI */ 308 { PCI_VDEVICE(INTEL, 0x1f33), board_ahci_avn }, /* Avoton AHCI */
295 { PCI_VDEVICE(INTEL, 0x1f34), board_ahci }, /* Avoton RAID */ 309 { PCI_VDEVICE(INTEL, 0x1f34), board_ahci_avn }, /* Avoton RAID */
296 { PCI_VDEVICE(INTEL, 0x1f35), board_ahci }, /* Avoton RAID */ 310 { PCI_VDEVICE(INTEL, 0x1f35), board_ahci_avn }, /* Avoton RAID */
297 { PCI_VDEVICE(INTEL, 0x1f36), board_ahci }, /* Avoton RAID */ 311 { PCI_VDEVICE(INTEL, 0x1f36), board_ahci_avn }, /* Avoton RAID */
298 { PCI_VDEVICE(INTEL, 0x1f37), board_ahci }, /* Avoton RAID */ 312 { PCI_VDEVICE(INTEL, 0x1f37), board_ahci_avn }, /* Avoton RAID */
299 { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci }, /* Avoton RAID */ 313 { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci_avn }, /* Avoton RAID */
300 { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci }, /* Avoton RAID */ 314 { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci_avn }, /* Avoton RAID */
301 { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */ 315 { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */
302 { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */ 316 { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */
303 { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */ 317 { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */
@@ -670,6 +684,79 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
670 return rc; 684 return rc;
671} 685}
672 686
687/*
688 * ahci_avn_hardreset - attempt more aggressive recovery of Avoton ports.
689 *
690 * It has been observed with some SSDs that the timing of events in the
691 * link synchronization phase can leave the port in a state that can not
692 * be recovered by a SATA-hard-reset alone. The failing signature is
693 * SStatus.DET stuck at 1 ("Device presence detected but Phy
694 * communication not established"). It was found that unloading and
695 * reloading the driver when this problem occurs allows the drive
696 * connection to be recovered (DET advanced to 0x3). The critical
697 * component of reloading the driver is that the port state machines are
698 * reset by bouncing "port enable" in the AHCI PCS configuration
699 * register. So, reproduce that effect by bouncing a port whenever we
700 * see DET==1 after a reset.
701 */
702static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
703 unsigned long deadline)
704{
705 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
706 struct ata_port *ap = link->ap;
707 struct ahci_port_priv *pp = ap->private_data;
708 struct ahci_host_priv *hpriv = ap->host->private_data;
709 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
710 unsigned long tmo = deadline - jiffies;
711 struct ata_taskfile tf;
712 bool online;
713 int rc, i;
714
715 DPRINTK("ENTER\n");
716
717 ahci_stop_engine(ap);
718
719 for (i = 0; i < 2; i++) {
720 u16 val;
721 u32 sstatus;
722 int port = ap->port_no;
723 struct ata_host *host = ap->host;
724 struct pci_dev *pdev = to_pci_dev(host->dev);
725
726 /* clear D2H reception area to properly wait for D2H FIS */
727 ata_tf_init(link->device, &tf);
728 tf.command = ATA_BUSY;
729 ata_tf_to_fis(&tf, 0, 0, d2h_fis);
730
731 rc = sata_link_hardreset(link, timing, deadline, &online,
732 ahci_check_ready);
733
734 if (sata_scr_read(link, SCR_STATUS, &sstatus) != 0 ||
735 (sstatus & 0xf) != 1)
736 break;
737
738 ata_link_printk(link, KERN_INFO, "avn bounce port%d\n",
739 port);
740
741 pci_read_config_word(pdev, 0x92, &val);
742 val &= ~(1 << port);
743 pci_write_config_word(pdev, 0x92, val);
744 ata_msleep(ap, 1000);
745 val |= 1 << port;
746 pci_write_config_word(pdev, 0x92, val);
747 deadline += tmo;
748 }
749
750 hpriv->start_engine(ap);
751
752 if (online)
753 *class = ahci_dev_classify(ap);
754
755 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
756 return rc;
757}
758
759
673#ifdef CONFIG_PM 760#ifdef CONFIG_PM
674static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) 761static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
675{ 762{
diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
index ea0ff005b86c..8ff428fe8e0f 100644
--- a/drivers/ata/ahci_st.c
+++ b/drivers/ata/ahci_st.c
@@ -37,7 +37,6 @@ struct st_ahci_drv_data {
37 struct reset_control *pwr; 37 struct reset_control *pwr;
38 struct reset_control *sw_rst; 38 struct reset_control *sw_rst;
39 struct reset_control *pwr_rst; 39 struct reset_control *pwr_rst;
40 struct ahci_host_priv *hpriv;
41}; 40};
42 41
43static void st_ahci_configure_oob(void __iomem *mmio) 42static void st_ahci_configure_oob(void __iomem *mmio)
@@ -55,9 +54,10 @@ static void st_ahci_configure_oob(void __iomem *mmio)
55 writel(new_val, mmio + ST_AHCI_OOBR); 54 writel(new_val, mmio + ST_AHCI_OOBR);
56} 55}
57 56
58static int st_ahci_deassert_resets(struct device *dev) 57static int st_ahci_deassert_resets(struct ahci_host_priv *hpriv,
58 struct device *dev)
59{ 59{
60 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev); 60 struct st_ahci_drv_data *drv_data = hpriv->plat_data;
61 int err; 61 int err;
62 62
63 if (drv_data->pwr) { 63 if (drv_data->pwr) {
@@ -90,8 +90,8 @@ static int st_ahci_deassert_resets(struct device *dev)
90static void st_ahci_host_stop(struct ata_host *host) 90static void st_ahci_host_stop(struct ata_host *host)
91{ 91{
92 struct ahci_host_priv *hpriv = host->private_data; 92 struct ahci_host_priv *hpriv = host->private_data;
93 struct st_ahci_drv_data *drv_data = hpriv->plat_data;
93 struct device *dev = host->dev; 94 struct device *dev = host->dev;
94 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev);
95 int err; 95 int err;
96 96
97 if (drv_data->pwr) { 97 if (drv_data->pwr) {
@@ -103,29 +103,30 @@ static void st_ahci_host_stop(struct ata_host *host)
103 ahci_platform_disable_resources(hpriv); 103 ahci_platform_disable_resources(hpriv);
104} 104}
105 105
106static int st_ahci_probe_resets(struct platform_device *pdev) 106static int st_ahci_probe_resets(struct ahci_host_priv *hpriv,
107 struct device *dev)
107{ 108{
108 struct st_ahci_drv_data *drv_data = platform_get_drvdata(pdev); 109 struct st_ahci_drv_data *drv_data = hpriv->plat_data;
109 110
110 drv_data->pwr = devm_reset_control_get(&pdev->dev, "pwr-dwn"); 111 drv_data->pwr = devm_reset_control_get(dev, "pwr-dwn");
111 if (IS_ERR(drv_data->pwr)) { 112 if (IS_ERR(drv_data->pwr)) {
112 dev_info(&pdev->dev, "power reset control not defined\n"); 113 dev_info(dev, "power reset control not defined\n");
113 drv_data->pwr = NULL; 114 drv_data->pwr = NULL;
114 } 115 }
115 116
116 drv_data->sw_rst = devm_reset_control_get(&pdev->dev, "sw-rst"); 117 drv_data->sw_rst = devm_reset_control_get(dev, "sw-rst");
117 if (IS_ERR(drv_data->sw_rst)) { 118 if (IS_ERR(drv_data->sw_rst)) {
118 dev_info(&pdev->dev, "soft reset control not defined\n"); 119 dev_info(dev, "soft reset control not defined\n");
119 drv_data->sw_rst = NULL; 120 drv_data->sw_rst = NULL;
120 } 121 }
121 122
122 drv_data->pwr_rst = devm_reset_control_get(&pdev->dev, "pwr-rst"); 123 drv_data->pwr_rst = devm_reset_control_get(dev, "pwr-rst");
123 if (IS_ERR(drv_data->pwr_rst)) { 124 if (IS_ERR(drv_data->pwr_rst)) {
124 dev_dbg(&pdev->dev, "power soft reset control not defined\n"); 125 dev_dbg(dev, "power soft reset control not defined\n");
125 drv_data->pwr_rst = NULL; 126 drv_data->pwr_rst = NULL;
126 } 127 }
127 128
128 return st_ahci_deassert_resets(&pdev->dev); 129 return st_ahci_deassert_resets(hpriv, dev);
129} 130}
130 131
131static struct ata_port_operations st_ahci_port_ops = { 132static struct ata_port_operations st_ahci_port_ops = {
@@ -154,15 +155,12 @@ static int st_ahci_probe(struct platform_device *pdev)
154 if (!drv_data) 155 if (!drv_data)
155 return -ENOMEM; 156 return -ENOMEM;
156 157
157 platform_set_drvdata(pdev, drv_data);
158
159 hpriv = ahci_platform_get_resources(pdev); 158 hpriv = ahci_platform_get_resources(pdev);
160 if (IS_ERR(hpriv)) 159 if (IS_ERR(hpriv))
161 return PTR_ERR(hpriv); 160 return PTR_ERR(hpriv);
161 hpriv->plat_data = drv_data;
162 162
163 drv_data->hpriv = hpriv; 163 err = st_ahci_probe_resets(hpriv, &pdev->dev);
164
165 err = st_ahci_probe_resets(pdev);
166 if (err) 164 if (err)
167 return err; 165 return err;
168 166
@@ -170,7 +168,7 @@ static int st_ahci_probe(struct platform_device *pdev)
170 if (err) 168 if (err)
171 return err; 169 return err;
172 170
173 st_ahci_configure_oob(drv_data->hpriv->mmio); 171 st_ahci_configure_oob(hpriv->mmio);
174 172
175 err = ahci_platform_init_host(pdev, hpriv, &st_ahci_port_info, 173 err = ahci_platform_init_host(pdev, hpriv, &st_ahci_port_info,
176 &ahci_platform_sht); 174 &ahci_platform_sht);
@@ -185,8 +183,9 @@ static int st_ahci_probe(struct platform_device *pdev)
185#ifdef CONFIG_PM_SLEEP 183#ifdef CONFIG_PM_SLEEP
186static int st_ahci_suspend(struct device *dev) 184static int st_ahci_suspend(struct device *dev)
187{ 185{
188 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev); 186 struct ata_host *host = dev_get_drvdata(dev);
189 struct ahci_host_priv *hpriv = drv_data->hpriv; 187 struct ahci_host_priv *hpriv = host->private_data;
188 struct st_ahci_drv_data *drv_data = hpriv->plat_data;
190 int err; 189 int err;
191 190
192 err = ahci_platform_suspend_host(dev); 191 err = ahci_platform_suspend_host(dev);
@@ -208,21 +207,21 @@ static int st_ahci_suspend(struct device *dev)
208 207
209static int st_ahci_resume(struct device *dev) 208static int st_ahci_resume(struct device *dev)
210{ 209{
211 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev); 210 struct ata_host *host = dev_get_drvdata(dev);
212 struct ahci_host_priv *hpriv = drv_data->hpriv; 211 struct ahci_host_priv *hpriv = host->private_data;
213 int err; 212 int err;
214 213
215 err = ahci_platform_enable_resources(hpriv); 214 err = ahci_platform_enable_resources(hpriv);
216 if (err) 215 if (err)
217 return err; 216 return err;
218 217
219 err = st_ahci_deassert_resets(dev); 218 err = st_ahci_deassert_resets(hpriv, dev);
220 if (err) { 219 if (err) {
221 ahci_platform_disable_resources(hpriv); 220 ahci_platform_disable_resources(hpriv);
222 return err; 221 return err;
223 } 222 }
224 223
225 st_ahci_configure_oob(drv_data->hpriv->mmio); 224 st_ahci_configure_oob(hpriv->mmio);
226 225
227 return ahci_platform_resume_host(dev); 226 return ahci_platform_resume_host(dev);
228} 227}
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 61a9c07e0dff..287c4ba0219f 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -1707,8 +1707,7 @@ static void ahci_handle_port_interrupt(struct ata_port *ap,
1707 if (unlikely(resetting)) 1707 if (unlikely(resetting))
1708 status &= ~PORT_IRQ_BAD_PMP; 1708 status &= ~PORT_IRQ_BAD_PMP;
1709 1709
1710 /* if LPM is enabled, PHYRDY doesn't mean anything */ 1710 if (sata_lpm_ignore_phy_events(&ap->link)) {
1711 if (ap->link.lpm_policy > ATA_LPM_MAX_POWER) {
1712 status &= ~PORT_IRQ_PHYRDY; 1711 status &= ~PORT_IRQ_PHYRDY;
1713 ahci_scr_write(&ap->link, SCR_ERROR, SERR_PHYRDY_CHG); 1712 ahci_scr_write(&ap->link, SCR_ERROR, SERR_PHYRDY_CHG);
1714 } 1713 }
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index f6cb1f1b30b7..577849c6611a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4235,7 +4235,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4235 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4235 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4236 { "Crucial_CT*MX100*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM | 4236 { "Crucial_CT*MX100*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM |
4237 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4237 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4238 { "Samsung SSD 850 PRO*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | 4238 { "Samsung SSD 8*", NULL, ATA_HORKAGE_NO_NCQ_TRIM |
4239 ATA_HORKAGE_ZERO_AFTER_TRIM, }, 4239 ATA_HORKAGE_ZERO_AFTER_TRIM, },
4240 4240
4241 /* 4241 /*
@@ -6752,6 +6752,38 @@ u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,
6752 return tmp; 6752 return tmp;
6753} 6753}
6754 6754
6755/**
6756 * sata_lpm_ignore_phy_events - test if PHY event should be ignored
6757 * @link: Link receiving the event
6758 *
6759 * Test whether the received PHY event has to be ignored or not.
6760 *
6761 * LOCKING:
6762 * None:
6763 *
6764 * RETURNS:
6765 * True if the event has to be ignored.
6766 */
6767bool sata_lpm_ignore_phy_events(struct ata_link *link)
6768{
6769 unsigned long lpm_timeout = link->last_lpm_change +
6770 msecs_to_jiffies(ATA_TMOUT_SPURIOUS_PHY);
6771
6772 /* if LPM is enabled, PHYRDY doesn't mean anything */
6773 if (link->lpm_policy > ATA_LPM_MAX_POWER)
6774 return true;
6775
6776 /* ignore the first PHY event after the LPM policy changed
6777 * as it is might be spurious
6778 */
6779 if ((link->flags & ATA_LFLAG_CHANGED) &&
6780 time_before(jiffies, lpm_timeout))
6781 return true;
6782
6783 return false;
6784}
6785EXPORT_SYMBOL_GPL(sata_lpm_ignore_phy_events);
6786
6755/* 6787/*
6756 * Dummy port_ops 6788 * Dummy port_ops
6757 */ 6789 */
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 07f41be38fbe..cf0022ec07f2 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -3597,6 +3597,9 @@ static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
3597 } 3597 }
3598 } 3598 }
3599 3599
3600 link->last_lpm_change = jiffies;
3601 link->flags |= ATA_LFLAG_CHANGED;
3602
3600 return 0; 3603 return 0;
3601 3604
3602fail: 3605fail:
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
deleted file mode 100644
index 5cd60d6388ec..000000000000
--- a/drivers/ata/pata_scc.c
+++ /dev/null
@@ -1,1110 +0,0 @@
1/*
2 * Support for IDE interfaces on Celleb platform
3 *
4 * (C) Copyright 2006 TOSHIBA CORPORATION
5 *
6 * This code is based on drivers/ata/ata_piix.c:
7 * Copyright 2003-2005 Red Hat Inc
8 * Copyright 2003-2005 Jeff Garzik
9 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
10 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
11 * Copyright (C) 2003 Red Hat Inc
12 *
13 * and drivers/ata/ahci.c:
14 * Copyright 2004-2005 Red Hat, Inc.
15 *
16 * and drivers/ata/libata-core.c:
17 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
18 * Copyright 2003-2004 Jeff Garzik
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/pci.h>
38#include <linux/blkdev.h>
39#include <linux/delay.h>
40#include <linux/device.h>
41#include <scsi/scsi_host.h>
42#include <linux/libata.h>
43
44#define DRV_NAME "pata_scc"
45#define DRV_VERSION "0.3"
46
47#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
48
49/* PCI BARs */
50#define SCC_CTRL_BAR 0
51#define SCC_BMID_BAR 1
52
53/* offset of CTRL registers */
54#define SCC_CTL_PIOSHT 0x000
55#define SCC_CTL_PIOCT 0x004
56#define SCC_CTL_MDMACT 0x008
57#define SCC_CTL_MCRCST 0x00C
58#define SCC_CTL_SDMACT 0x010
59#define SCC_CTL_SCRCST 0x014
60#define SCC_CTL_UDENVT 0x018
61#define SCC_CTL_TDVHSEL 0x020
62#define SCC_CTL_MODEREG 0x024
63#define SCC_CTL_ECMODE 0xF00
64#define SCC_CTL_MAEA0 0xF50
65#define SCC_CTL_MAEC0 0xF54
66#define SCC_CTL_CCKCTRL 0xFF0
67
68/* offset of BMID registers */
69#define SCC_DMA_CMD 0x000
70#define SCC_DMA_STATUS 0x004
71#define SCC_DMA_TABLE_OFS 0x008
72#define SCC_DMA_INTMASK 0x010
73#define SCC_DMA_INTST 0x014
74#define SCC_DMA_PTERADD 0x018
75#define SCC_REG_CMD_ADDR 0x020
76#define SCC_REG_DATA 0x000
77#define SCC_REG_ERR 0x004
78#define SCC_REG_FEATURE 0x004
79#define SCC_REG_NSECT 0x008
80#define SCC_REG_LBAL 0x00C
81#define SCC_REG_LBAM 0x010
82#define SCC_REG_LBAH 0x014
83#define SCC_REG_DEVICE 0x018
84#define SCC_REG_STATUS 0x01C
85#define SCC_REG_CMD 0x01C
86#define SCC_REG_ALTSTATUS 0x020
87
88/* register value */
89#define TDVHSEL_MASTER 0x00000001
90#define TDVHSEL_SLAVE 0x00000004
91
92#define MODE_JCUSFEN 0x00000080
93
94#define ECMODE_VALUE 0x01
95
96#define CCKCTRL_ATARESET 0x00040000
97#define CCKCTRL_BUFCNT 0x00020000
98#define CCKCTRL_CRST 0x00010000
99#define CCKCTRL_OCLKEN 0x00000100
100#define CCKCTRL_ATACLKOEN 0x00000002
101#define CCKCTRL_LCLKEN 0x00000001
102
103#define QCHCD_IOS_SS 0x00000001
104
105#define QCHSD_STPDIAG 0x00020000
106
107#define INTMASK_MSK 0xD1000012
108#define INTSTS_SERROR 0x80000000
109#define INTSTS_PRERR 0x40000000
110#define INTSTS_RERR 0x10000000
111#define INTSTS_ICERR 0x01000000
112#define INTSTS_BMSINT 0x00000010
113#define INTSTS_BMHE 0x00000008
114#define INTSTS_IOIRQS 0x00000004
115#define INTSTS_INTRQ 0x00000002
116#define INTSTS_ACTEINT 0x00000001
117
118
119/* PIO transfer mode table */
120/* JCHST */
121static const unsigned long JCHSTtbl[2][7] = {
122 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
123 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
124};
125
126/* JCHHT */
127static const unsigned long JCHHTtbl[2][7] = {
128 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
129 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
130};
131
132/* JCHCT */
133static const unsigned long JCHCTtbl[2][7] = {
134 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
135 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
136};
137
138/* DMA transfer mode table */
139/* JCHDCTM/JCHDCTS */
140static const unsigned long JCHDCTxtbl[2][7] = {
141 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
142 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
143};
144
145/* JCSTWTM/JCSTWTS */
146static const unsigned long JCSTWTxtbl[2][7] = {
147 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
148 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
149};
150
151/* JCTSS */
152static const unsigned long JCTSStbl[2][7] = {
153 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
154 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
155};
156
157/* JCENVT */
158static const unsigned long JCENVTtbl[2][7] = {
159 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
160 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
161};
162
163/* JCACTSELS/JCACTSELM */
164static const unsigned long JCACTSELtbl[2][7] = {
165 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
166 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
167};
168
169static const struct pci_device_id scc_pci_tbl[] = {
170 { PCI_VDEVICE(TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA), 0},
171 { } /* terminate list */
172};
173
174/**
175 * scc_set_piomode - Initialize host controller PATA PIO timings
176 * @ap: Port whose timings we are configuring
177 * @adev: um
178 *
179 * Set PIO mode for device.
180 *
181 * LOCKING:
182 * None (inherited from caller).
183 */
184
185static void scc_set_piomode (struct ata_port *ap, struct ata_device *adev)
186{
187 unsigned int pio = adev->pio_mode - XFER_PIO_0;
188 void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
189 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
190 void __iomem *piosht_port = ctrl_base + SCC_CTL_PIOSHT;
191 void __iomem *pioct_port = ctrl_base + SCC_CTL_PIOCT;
192 unsigned long reg;
193 int offset;
194
195 reg = in_be32(cckctrl_port);
196 if (reg & CCKCTRL_ATACLKOEN)
197 offset = 1; /* 133MHz */
198 else
199 offset = 0; /* 100MHz */
200
201 reg = JCHSTtbl[offset][pio] << 16 | JCHHTtbl[offset][pio];
202 out_be32(piosht_port, reg);
203 reg = JCHCTtbl[offset][pio];
204 out_be32(pioct_port, reg);
205}
206
207/**
208 * scc_set_dmamode - Initialize host controller PATA DMA timings
209 * @ap: Port whose timings we are configuring
210 * @adev: um
211 *
212 * Set UDMA mode for device.
213 *
214 * LOCKING:
215 * None (inherited from caller).
216 */
217
218static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev)
219{
220 unsigned int udma = adev->dma_mode;
221 unsigned int is_slave = (adev->devno != 0);
222 u8 speed = udma;
223 void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
224 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
225 void __iomem *mdmact_port = ctrl_base + SCC_CTL_MDMACT;
226 void __iomem *mcrcst_port = ctrl_base + SCC_CTL_MCRCST;
227 void __iomem *sdmact_port = ctrl_base + SCC_CTL_SDMACT;
228 void __iomem *scrcst_port = ctrl_base + SCC_CTL_SCRCST;
229 void __iomem *udenvt_port = ctrl_base + SCC_CTL_UDENVT;
230 void __iomem *tdvhsel_port = ctrl_base + SCC_CTL_TDVHSEL;
231 int offset, idx;
232
233 if (in_be32(cckctrl_port) & CCKCTRL_ATACLKOEN)
234 offset = 1; /* 133MHz */
235 else
236 offset = 0; /* 100MHz */
237
238 if (speed >= XFER_UDMA_0)
239 idx = speed - XFER_UDMA_0;
240 else
241 return;
242
243 if (is_slave) {
244 out_be32(sdmact_port, JCHDCTxtbl[offset][idx]);
245 out_be32(scrcst_port, JCSTWTxtbl[offset][idx]);
246 out_be32(tdvhsel_port,
247 (in_be32(tdvhsel_port) & ~TDVHSEL_SLAVE) | (JCACTSELtbl[offset][idx] << 2));
248 } else {
249 out_be32(mdmact_port, JCHDCTxtbl[offset][idx]);
250 out_be32(mcrcst_port, JCSTWTxtbl[offset][idx]);
251 out_be32(tdvhsel_port,
252 (in_be32(tdvhsel_port) & ~TDVHSEL_MASTER) | JCACTSELtbl[offset][idx]);
253 }
254 out_be32(udenvt_port,
255 JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]);
256}
257
258unsigned long scc_mode_filter(struct ata_device *adev, unsigned long mask)
259{
260 /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */
261 if (adev->class == ATA_DEV_ATAPI &&
262 (mask & (0xE0 << ATA_SHIFT_UDMA))) {
263 printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);
264 mask &= ~(0xE0 << ATA_SHIFT_UDMA);
265 }
266 return mask;
267}
268
269/**
270 * scc_tf_load - send taskfile registers to host controller
271 * @ap: Port to which output is sent
272 * @tf: ATA taskfile register set
273 *
274 * Note: Original code is ata_sff_tf_load().
275 */
276
277static void scc_tf_load (struct ata_port *ap, const struct ata_taskfile *tf)
278{
279 struct ata_ioports *ioaddr = &ap->ioaddr;
280 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
281
282 if (tf->ctl != ap->last_ctl) {
283 out_be32(ioaddr->ctl_addr, tf->ctl);
284 ap->last_ctl = tf->ctl;
285 ata_wait_idle(ap);
286 }
287
288 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
289 out_be32(ioaddr->feature_addr, tf->hob_feature);
290 out_be32(ioaddr->nsect_addr, tf->hob_nsect);
291 out_be32(ioaddr->lbal_addr, tf->hob_lbal);
292 out_be32(ioaddr->lbam_addr, tf->hob_lbam);
293 out_be32(ioaddr->lbah_addr, tf->hob_lbah);
294 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
295 tf->hob_feature,
296 tf->hob_nsect,
297 tf->hob_lbal,
298 tf->hob_lbam,
299 tf->hob_lbah);
300 }
301
302 if (is_addr) {
303 out_be32(ioaddr->feature_addr, tf->feature);
304 out_be32(ioaddr->nsect_addr, tf->nsect);
305 out_be32(ioaddr->lbal_addr, tf->lbal);
306 out_be32(ioaddr->lbam_addr, tf->lbam);
307 out_be32(ioaddr->lbah_addr, tf->lbah);
308 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
309 tf->feature,
310 tf->nsect,
311 tf->lbal,
312 tf->lbam,
313 tf->lbah);
314 }
315
316 if (tf->flags & ATA_TFLAG_DEVICE) {
317 out_be32(ioaddr->device_addr, tf->device);
318 VPRINTK("device 0x%X\n", tf->device);
319 }
320
321 ata_wait_idle(ap);
322}
323
324/**
325 * scc_check_status - Read device status reg & clear interrupt
326 * @ap: port where the device is
327 *
328 * Note: Original code is ata_check_status().
329 */
330
331static u8 scc_check_status (struct ata_port *ap)
332{
333 return in_be32(ap->ioaddr.status_addr);
334}
335
336/**
337 * scc_tf_read - input device's ATA taskfile shadow registers
338 * @ap: Port from which input is read
339 * @tf: ATA taskfile register set for storing input
340 *
341 * Note: Original code is ata_sff_tf_read().
342 */
343
344static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf)
345{
346 struct ata_ioports *ioaddr = &ap->ioaddr;
347
348 tf->command = scc_check_status(ap);
349 tf->feature = in_be32(ioaddr->error_addr);
350 tf->nsect = in_be32(ioaddr->nsect_addr);
351 tf->lbal = in_be32(ioaddr->lbal_addr);
352 tf->lbam = in_be32(ioaddr->lbam_addr);
353 tf->lbah = in_be32(ioaddr->lbah_addr);
354 tf->device = in_be32(ioaddr->device_addr);
355
356 if (tf->flags & ATA_TFLAG_LBA48) {
357 out_be32(ioaddr->ctl_addr, tf->ctl | ATA_HOB);
358 tf->hob_feature = in_be32(ioaddr->error_addr);
359 tf->hob_nsect = in_be32(ioaddr->nsect_addr);
360 tf->hob_lbal = in_be32(ioaddr->lbal_addr);
361 tf->hob_lbam = in_be32(ioaddr->lbam_addr);
362 tf->hob_lbah = in_be32(ioaddr->lbah_addr);
363 out_be32(ioaddr->ctl_addr, tf->ctl);
364 ap->last_ctl = tf->ctl;
365 }
366}
367
368/**
369 * scc_exec_command - issue ATA command to host controller
370 * @ap: port to which command is being issued
371 * @tf: ATA taskfile register set
372 *
373 * Note: Original code is ata_sff_exec_command().
374 */
375
376static void scc_exec_command (struct ata_port *ap,
377 const struct ata_taskfile *tf)
378{
379 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
380
381 out_be32(ap->ioaddr.command_addr, tf->command);
382 ata_sff_pause(ap);
383}
384
385/**
386 * scc_check_altstatus - Read device alternate status reg
387 * @ap: port where the device is
388 */
389
390static u8 scc_check_altstatus (struct ata_port *ap)
391{
392 return in_be32(ap->ioaddr.altstatus_addr);
393}
394
395/**
396 * scc_dev_select - Select device 0/1 on ATA bus
397 * @ap: ATA channel to manipulate
398 * @device: ATA device (numbered from zero) to select
399 *
400 * Note: Original code is ata_sff_dev_select().
401 */
402
403static void scc_dev_select (struct ata_port *ap, unsigned int device)
404{
405 u8 tmp;
406
407 if (device == 0)
408 tmp = ATA_DEVICE_OBS;
409 else
410 tmp = ATA_DEVICE_OBS | ATA_DEV1;
411
412 out_be32(ap->ioaddr.device_addr, tmp);
413 ata_sff_pause(ap);
414}
415
416/**
417 * scc_set_devctl - Write device control reg
418 * @ap: port where the device is
419 * @ctl: value to write
420 */
421
422static void scc_set_devctl(struct ata_port *ap, u8 ctl)
423{
424 out_be32(ap->ioaddr.ctl_addr, ctl);
425}
426
427/**
428 * scc_bmdma_setup - Set up PCI IDE BMDMA transaction
429 * @qc: Info associated with this ATA transaction.
430 *
431 * Note: Original code is ata_bmdma_setup().
432 */
433
434static void scc_bmdma_setup (struct ata_queued_cmd *qc)
435{
436 struct ata_port *ap = qc->ap;
437 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
438 u8 dmactl;
439 void __iomem *mmio = ap->ioaddr.bmdma_addr;
440
441 /* load PRD table addr */
442 out_be32(mmio + SCC_DMA_TABLE_OFS, ap->bmdma_prd_dma);
443
444 /* specify data direction, triple-check start bit is clear */
445 dmactl = in_be32(mmio + SCC_DMA_CMD);
446 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
447 if (!rw)
448 dmactl |= ATA_DMA_WR;
449 out_be32(mmio + SCC_DMA_CMD, dmactl);
450
451 /* issue r/w command */
452 ap->ops->sff_exec_command(ap, &qc->tf);
453}
454
455/**
456 * scc_bmdma_start - Start a PCI IDE BMDMA transaction
457 * @qc: Info associated with this ATA transaction.
458 *
459 * Note: Original code is ata_bmdma_start().
460 */
461
462static void scc_bmdma_start (struct ata_queued_cmd *qc)
463{
464 struct ata_port *ap = qc->ap;
465 u8 dmactl;
466 void __iomem *mmio = ap->ioaddr.bmdma_addr;
467
468 /* start host DMA transaction */
469 dmactl = in_be32(mmio + SCC_DMA_CMD);
470 out_be32(mmio + SCC_DMA_CMD, dmactl | ATA_DMA_START);
471}
472
473/**
474 * scc_devchk - PATA device presence detection
475 * @ap: ATA channel to examine
476 * @device: Device to examine (starting at zero)
477 *
478 * Note: Original code is ata_devchk().
479 */
480
481static unsigned int scc_devchk (struct ata_port *ap,
482 unsigned int device)
483{
484 struct ata_ioports *ioaddr = &ap->ioaddr;
485 u8 nsect, lbal;
486
487 ap->ops->sff_dev_select(ap, device);
488
489 out_be32(ioaddr->nsect_addr, 0x55);
490 out_be32(ioaddr->lbal_addr, 0xaa);
491
492 out_be32(ioaddr->nsect_addr, 0xaa);
493 out_be32(ioaddr->lbal_addr, 0x55);
494
495 out_be32(ioaddr->nsect_addr, 0x55);
496 out_be32(ioaddr->lbal_addr, 0xaa);
497
498 nsect = in_be32(ioaddr->nsect_addr);
499 lbal = in_be32(ioaddr->lbal_addr);
500
501 if ((nsect == 0x55) && (lbal == 0xaa))
502 return 1; /* we found a device */
503
504 return 0; /* nothing found */
505}
506
507/**
508 * scc_wait_after_reset - wait for devices to become ready after reset
509 *
510 * Note: Original code is ata_sff_wait_after_reset
511 */
512
513static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
514 unsigned long deadline)
515{
516 struct ata_port *ap = link->ap;
517 struct ata_ioports *ioaddr = &ap->ioaddr;
518 unsigned int dev0 = devmask & (1 << 0);
519 unsigned int dev1 = devmask & (1 << 1);
520 int rc, ret = 0;
521
522 /* Spec mandates ">= 2ms" before checking status. We wait
523 * 150ms, because that was the magic delay used for ATAPI
524 * devices in Hale Landis's ATADRVR, for the period of time
525 * between when the ATA command register is written, and then
526 * status is checked. Because waiting for "a while" before
527 * checking status is fine, post SRST, we perform this magic
528 * delay here as well.
529 *
530 * Old drivers/ide uses the 2mS rule and then waits for ready.
531 */
532 ata_msleep(ap, 150);
533
534 /* always check readiness of the master device */
535 rc = ata_sff_wait_ready(link, deadline);
536 /* -ENODEV means the odd clown forgot the D7 pulldown resistor
537 * and TF status is 0xff, bail out on it too.
538 */
539 if (rc)
540 return rc;
541
542 /* if device 1 was found in ata_devchk, wait for register
543 * access briefly, then wait for BSY to clear.
544 */
545 if (dev1) {
546 int i;
547
548 ap->ops->sff_dev_select(ap, 1);
549
550 /* Wait for register access. Some ATAPI devices fail
551 * to set nsect/lbal after reset, so don't waste too
552 * much time on it. We're gonna wait for !BSY anyway.
553 */
554 for (i = 0; i < 2; i++) {
555 u8 nsect, lbal;
556
557 nsect = in_be32(ioaddr->nsect_addr);
558 lbal = in_be32(ioaddr->lbal_addr);
559 if ((nsect == 1) && (lbal == 1))
560 break;
561 ata_msleep(ap, 50); /* give drive a breather */
562 }
563
564 rc = ata_sff_wait_ready(link, deadline);
565 if (rc) {
566 if (rc != -ENODEV)
567 return rc;
568 ret = rc;
569 }
570 }
571
572 /* is all this really necessary? */
573 ap->ops->sff_dev_select(ap, 0);
574 if (dev1)
575 ap->ops->sff_dev_select(ap, 1);
576 if (dev0)
577 ap->ops->sff_dev_select(ap, 0);
578
579 return ret;
580}
581
582/**
583 * scc_bus_softreset - PATA device software reset
584 *
585 * Note: Original code is ata_bus_softreset().
586 */
587
588static int scc_bus_softreset(struct ata_port *ap, unsigned int devmask,
589 unsigned long deadline)
590{
591 struct ata_ioports *ioaddr = &ap->ioaddr;
592
593 DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
594
595 /* software reset. causes dev0 to be selected */
596 out_be32(ioaddr->ctl_addr, ap->ctl);
597 udelay(20);
598 out_be32(ioaddr->ctl_addr, ap->ctl | ATA_SRST);
599 udelay(20);
600 out_be32(ioaddr->ctl_addr, ap->ctl);
601
602 return scc_wait_after_reset(&ap->link, devmask, deadline);
603}
604
605/**
606 * scc_softreset - reset host port via ATA SRST
607 * @ap: port to reset
608 * @classes: resulting classes of attached devices
609 * @deadline: deadline jiffies for the operation
610 *
611 * Note: Original code is ata_sff_softreset().
612 */
613
614static int scc_softreset(struct ata_link *link, unsigned int *classes,
615 unsigned long deadline)
616{
617 struct ata_port *ap = link->ap;
618 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
619 unsigned int devmask = 0;
620 int rc;
621 u8 err;
622
623 DPRINTK("ENTER\n");
624
625 /* determine if device 0/1 are present */
626 if (scc_devchk(ap, 0))
627 devmask |= (1 << 0);
628 if (slave_possible && scc_devchk(ap, 1))
629 devmask |= (1 << 1);
630
631 /* select device 0 again */
632 ap->ops->sff_dev_select(ap, 0);
633
634 /* issue bus reset */
635 DPRINTK("about to softreset, devmask=%x\n", devmask);
636 rc = scc_bus_softreset(ap, devmask, deadline);
637 if (rc) {
638 ata_port_err(ap, "SRST failed (err_mask=0x%x)\n", rc);
639 return -EIO;
640 }
641
642 /* determine by signature whether we have ATA or ATAPI devices */
643 classes[0] = ata_sff_dev_classify(&ap->link.device[0],
644 devmask & (1 << 0), &err);
645 if (slave_possible && err != 0x81)
646 classes[1] = ata_sff_dev_classify(&ap->link.device[1],
647 devmask & (1 << 1), &err);
648
649 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
650 return 0;
651}
652
653/**
654 * scc_bmdma_stop - Stop PCI IDE BMDMA transfer
655 * @qc: Command we are ending DMA for
656 */
657
658static void scc_bmdma_stop (struct ata_queued_cmd *qc)
659{
660 struct ata_port *ap = qc->ap;
661 void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
662 void __iomem *bmid_base = ap->host->iomap[SCC_BMID_BAR];
663 u32 reg;
664
665 while (1) {
666 reg = in_be32(bmid_base + SCC_DMA_INTST);
667
668 if (reg & INTSTS_SERROR) {
669 printk(KERN_WARNING "%s: SERROR\n", DRV_NAME);
670 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_SERROR|INTSTS_BMSINT);
671 out_be32(bmid_base + SCC_DMA_CMD,
672 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
673 continue;
674 }
675
676 if (reg & INTSTS_PRERR) {
677 u32 maea0, maec0;
678 maea0 = in_be32(ctrl_base + SCC_CTL_MAEA0);
679 maec0 = in_be32(ctrl_base + SCC_CTL_MAEC0);
680 printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", DRV_NAME, maea0, maec0);
681 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_PRERR|INTSTS_BMSINT);
682 out_be32(bmid_base + SCC_DMA_CMD,
683 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
684 continue;
685 }
686
687 if (reg & INTSTS_RERR) {
688 printk(KERN_WARNING "%s: Response Error\n", DRV_NAME);
689 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_RERR|INTSTS_BMSINT);
690 out_be32(bmid_base + SCC_DMA_CMD,
691 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
692 continue;
693 }
694
695 if (reg & INTSTS_ICERR) {
696 out_be32(bmid_base + SCC_DMA_CMD,
697 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
698 printk(KERN_WARNING "%s: Illegal Configuration\n", DRV_NAME);
699 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ICERR|INTSTS_BMSINT);
700 continue;
701 }
702
703 if (reg & INTSTS_BMSINT) {
704 unsigned int classes;
705 unsigned long deadline = ata_deadline(jiffies, ATA_TMOUT_BOOT);
706 printk(KERN_WARNING "%s: Internal Bus Error\n", DRV_NAME);
707 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMSINT);
708 /* TBD: SW reset */
709 scc_softreset(&ap->link, &classes, deadline);
710 continue;
711 }
712
713 if (reg & INTSTS_BMHE) {
714 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMHE);
715 continue;
716 }
717
718 if (reg & INTSTS_ACTEINT) {
719 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ACTEINT);
720 continue;
721 }
722
723 if (reg & INTSTS_IOIRQS) {
724 out_be32(bmid_base + SCC_DMA_INTST, INTSTS_IOIRQS);
725 continue;
726 }
727 break;
728 }
729
730 /* clear start/stop bit */
731 out_be32(bmid_base + SCC_DMA_CMD,
732 in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
733
734 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
735 ata_sff_dma_pause(ap); /* dummy read */
736}
737
738/**
739 * scc_bmdma_status - Read PCI IDE BMDMA status
740 * @ap: Port associated with this ATA transaction.
741 */
742
743static u8 scc_bmdma_status (struct ata_port *ap)
744{
745 void __iomem *mmio = ap->ioaddr.bmdma_addr;
746 u8 host_stat = in_be32(mmio + SCC_DMA_STATUS);
747 u32 int_status = in_be32(mmio + SCC_DMA_INTST);
748 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
749 static int retry = 0;
750
751 /* return if IOS_SS is cleared */
752 if (!(in_be32(mmio + SCC_DMA_CMD) & ATA_DMA_START))
753 return host_stat;
754
755 /* errata A252,A308 workaround: Step4 */
756 if ((scc_check_altstatus(ap) & ATA_ERR)
757 && (int_status & INTSTS_INTRQ))
758 return (host_stat | ATA_DMA_INTR);
759
760 /* errata A308 workaround Step5 */
761 if (int_status & INTSTS_IOIRQS) {
762 host_stat |= ATA_DMA_INTR;
763
764 /* We don't check ATAPI DMA because it is limited to UDMA4 */
765 if ((qc->tf.protocol == ATA_PROT_DMA &&
766 qc->dev->xfer_mode > XFER_UDMA_4)) {
767 if (!(int_status & INTSTS_ACTEINT)) {
768 printk(KERN_WARNING "ata%u: operation failed (transfer data loss)\n",
769 ap->print_id);
770 host_stat |= ATA_DMA_ERR;
771 if (retry++)
772 ap->udma_mask &= ~(1 << qc->dev->xfer_mode);
773 } else
774 retry = 0;
775 }
776 }
777
778 return host_stat;
779}
780
781/**
782 * scc_data_xfer - Transfer data by PIO
783 * @dev: device for this I/O
784 * @buf: data buffer
785 * @buflen: buffer length
786 * @rw: read/write
787 *
788 * Note: Original code is ata_sff_data_xfer().
789 */
790
791static unsigned int scc_data_xfer (struct ata_device *dev, unsigned char *buf,
792 unsigned int buflen, int rw)
793{
794 struct ata_port *ap = dev->link->ap;
795 unsigned int words = buflen >> 1;
796 unsigned int i;
797 __le16 *buf16 = (__le16 *) buf;
798 void __iomem *mmio = ap->ioaddr.data_addr;
799
800 /* Transfer multiple of 2 bytes */
801 if (rw == READ)
802 for (i = 0; i < words; i++)
803 buf16[i] = cpu_to_le16(in_be32(mmio));
804 else
805 for (i = 0; i < words; i++)
806 out_be32(mmio, le16_to_cpu(buf16[i]));
807
808 /* Transfer trailing 1 byte, if any. */
809 if (unlikely(buflen & 0x01)) {
810 __le16 align_buf[1] = { 0 };
811 unsigned char *trailing_buf = buf + buflen - 1;
812
813 if (rw == READ) {
814 align_buf[0] = cpu_to_le16(in_be32(mmio));
815 memcpy(trailing_buf, align_buf, 1);
816 } else {
817 memcpy(align_buf, trailing_buf, 1);
818 out_be32(mmio, le16_to_cpu(align_buf[0]));
819 }
820 words++;
821 }
822
823 return words << 1;
824}
825
826/**
827 * scc_postreset - standard postreset callback
828 * @ap: the target ata_port
829 * @classes: classes of attached devices
830 *
831 * Note: Original code is ata_sff_postreset().
832 */
833
834static void scc_postreset(struct ata_link *link, unsigned int *classes)
835{
836 struct ata_port *ap = link->ap;
837
838 DPRINTK("ENTER\n");
839
840 /* is double-select really necessary? */
841 if (classes[0] != ATA_DEV_NONE)
842 ap->ops->sff_dev_select(ap, 1);
843 if (classes[1] != ATA_DEV_NONE)
844 ap->ops->sff_dev_select(ap, 0);
845
846 /* bail out if no device is present */
847 if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
848 DPRINTK("EXIT, no device\n");
849 return;
850 }
851
852 /* set up device control */
853 out_be32(ap->ioaddr.ctl_addr, ap->ctl);
854
855 DPRINTK("EXIT\n");
856}
857
858/**
859 * scc_irq_clear - Clear PCI IDE BMDMA interrupt.
860 * @ap: Port associated with this ATA transaction.
861 *
862 * Note: Original code is ata_bmdma_irq_clear().
863 */
864
865static void scc_irq_clear (struct ata_port *ap)
866{
867 void __iomem *mmio = ap->ioaddr.bmdma_addr;
868
869 if (!mmio)
870 return;
871
872 out_be32(mmio + SCC_DMA_STATUS, in_be32(mmio + SCC_DMA_STATUS));
873}
874
875/**
876 * scc_port_start - Set port up for dma.
877 * @ap: Port to initialize
878 *
879 * Allocate space for PRD table using ata_bmdma_port_start().
880 * Set PRD table address for PTERADD. (PRD Transfer End Read)
881 */
882
883static int scc_port_start (struct ata_port *ap)
884{
885 void __iomem *mmio = ap->ioaddr.bmdma_addr;
886 int rc;
887
888 rc = ata_bmdma_port_start(ap);
889 if (rc)
890 return rc;
891
892 out_be32(mmio + SCC_DMA_PTERADD, ap->bmdma_prd_dma);
893 return 0;
894}
895
896/**
897 * scc_port_stop - Undo scc_port_start()
898 * @ap: Port to shut down
899 *
900 * Reset PTERADD.
901 */
902
903static void scc_port_stop (struct ata_port *ap)
904{
905 void __iomem *mmio = ap->ioaddr.bmdma_addr;
906
907 out_be32(mmio + SCC_DMA_PTERADD, 0);
908}
909
910static struct scsi_host_template scc_sht = {
911 ATA_BMDMA_SHT(DRV_NAME),
912};
913
914static struct ata_port_operations scc_pata_ops = {
915 .inherits = &ata_bmdma_port_ops,
916
917 .set_piomode = scc_set_piomode,
918 .set_dmamode = scc_set_dmamode,
919 .mode_filter = scc_mode_filter,
920
921 .sff_tf_load = scc_tf_load,
922 .sff_tf_read = scc_tf_read,
923 .sff_exec_command = scc_exec_command,
924 .sff_check_status = scc_check_status,
925 .sff_check_altstatus = scc_check_altstatus,
926 .sff_dev_select = scc_dev_select,
927 .sff_set_devctl = scc_set_devctl,
928
929 .bmdma_setup = scc_bmdma_setup,
930 .bmdma_start = scc_bmdma_start,
931 .bmdma_stop = scc_bmdma_stop,
932 .bmdma_status = scc_bmdma_status,
933 .sff_data_xfer = scc_data_xfer,
934
935 .cable_detect = ata_cable_80wire,
936 .softreset = scc_softreset,
937 .postreset = scc_postreset,
938
939 .sff_irq_clear = scc_irq_clear,
940
941 .port_start = scc_port_start,
942 .port_stop = scc_port_stop,
943};
944
945static struct ata_port_info scc_port_info[] = {
946 {
947 .flags = ATA_FLAG_SLAVE_POSS,
948 .pio_mask = ATA_PIO4,
949 /* No MWDMA */
950 .udma_mask = ATA_UDMA6,
951 .port_ops = &scc_pata_ops,
952 },
953};
954
955/**
956 * scc_reset_controller - initialize SCC PATA controller.
957 */
958
959static int scc_reset_controller(struct ata_host *host)
960{
961 void __iomem *ctrl_base = host->iomap[SCC_CTRL_BAR];
962 void __iomem *bmid_base = host->iomap[SCC_BMID_BAR];
963 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
964 void __iomem *mode_port = ctrl_base + SCC_CTL_MODEREG;
965 void __iomem *ecmode_port = ctrl_base + SCC_CTL_ECMODE;
966 void __iomem *intmask_port = bmid_base + SCC_DMA_INTMASK;
967 void __iomem *dmastatus_port = bmid_base + SCC_DMA_STATUS;
968 u32 reg = 0;
969
970 out_be32(cckctrl_port, reg);
971 reg |= CCKCTRL_ATACLKOEN;
972 out_be32(cckctrl_port, reg);
973 reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
974 out_be32(cckctrl_port, reg);
975 reg |= CCKCTRL_CRST;
976 out_be32(cckctrl_port, reg);
977
978 for (;;) {
979 reg = in_be32(cckctrl_port);
980 if (reg & CCKCTRL_CRST)
981 break;
982 udelay(5000);
983 }
984
985 reg |= CCKCTRL_ATARESET;
986 out_be32(cckctrl_port, reg);
987 out_be32(ecmode_port, ECMODE_VALUE);
988 out_be32(mode_port, MODE_JCUSFEN);
989 out_be32(intmask_port, INTMASK_MSK);
990
991 if (in_be32(dmastatus_port) & QCHSD_STPDIAG) {
992 printk(KERN_WARNING "%s: failed to detect 80c cable. (PDIAG# is high)\n", DRV_NAME);
993 return -EIO;
994 }
995
996 return 0;
997}
998
999/**
1000 * scc_setup_ports - initialize ioaddr with SCC PATA port offsets.
1001 * @ioaddr: IO address structure to be initialized
1002 * @base: base address of BMID region
1003 */
1004
1005static void scc_setup_ports (struct ata_ioports *ioaddr, void __iomem *base)
1006{
1007 ioaddr->cmd_addr = base + SCC_REG_CMD_ADDR;
1008 ioaddr->altstatus_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
1009 ioaddr->ctl_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
1010 ioaddr->bmdma_addr = base;
1011 ioaddr->data_addr = ioaddr->cmd_addr + SCC_REG_DATA;
1012 ioaddr->error_addr = ioaddr->cmd_addr + SCC_REG_ERR;
1013 ioaddr->feature_addr = ioaddr->cmd_addr + SCC_REG_FEATURE;
1014 ioaddr->nsect_addr = ioaddr->cmd_addr + SCC_REG_NSECT;
1015 ioaddr->lbal_addr = ioaddr->cmd_addr + SCC_REG_LBAL;
1016 ioaddr->lbam_addr = ioaddr->cmd_addr + SCC_REG_LBAM;
1017 ioaddr->lbah_addr = ioaddr->cmd_addr + SCC_REG_LBAH;
1018 ioaddr->device_addr = ioaddr->cmd_addr + SCC_REG_DEVICE;
1019 ioaddr->status_addr = ioaddr->cmd_addr + SCC_REG_STATUS;
1020 ioaddr->command_addr = ioaddr->cmd_addr + SCC_REG_CMD;
1021}
1022
1023static int scc_host_init(struct ata_host *host)
1024{
1025 struct pci_dev *pdev = to_pci_dev(host->dev);
1026 int rc;
1027
1028 rc = scc_reset_controller(host);
1029 if (rc)
1030 return rc;
1031
1032 rc = dma_set_mask(&pdev->dev, ATA_DMA_MASK);
1033 if (rc)
1034 return rc;
1035 rc = dma_set_coherent_mask(&pdev->dev, ATA_DMA_MASK);
1036 if (rc)
1037 return rc;
1038
1039 scc_setup_ports(&host->ports[0]->ioaddr, host->iomap[SCC_BMID_BAR]);
1040
1041 pci_set_master(pdev);
1042
1043 return 0;
1044}
1045
1046/**
1047 * scc_init_one - Register SCC PATA device with kernel services
1048 * @pdev: PCI device to register
1049 * @ent: Entry in scc_pci_tbl matching with @pdev
1050 *
1051 * LOCKING:
1052 * Inherited from PCI layer (may sleep).
1053 *
1054 * RETURNS:
1055 * Zero on success, or -ERRNO value.
1056 */
1057
1058static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1059{
1060 unsigned int board_idx = (unsigned int) ent->driver_data;
1061 const struct ata_port_info *ppi[] = { &scc_port_info[board_idx], NULL };
1062 struct ata_host *host;
1063 int rc;
1064
1065 ata_print_version_once(&pdev->dev, DRV_VERSION);
1066
1067 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 1);
1068 if (!host)
1069 return -ENOMEM;
1070
1071 rc = pcim_enable_device(pdev);
1072 if (rc)
1073 return rc;
1074
1075 rc = pcim_iomap_regions(pdev, (1 << SCC_CTRL_BAR) | (1 << SCC_BMID_BAR), DRV_NAME);
1076 if (rc == -EBUSY)
1077 pcim_pin_device(pdev);
1078 if (rc)
1079 return rc;
1080 host->iomap = pcim_iomap_table(pdev);
1081
1082 ata_port_pbar_desc(host->ports[0], SCC_CTRL_BAR, -1, "ctrl");
1083 ata_port_pbar_desc(host->ports[0], SCC_BMID_BAR, -1, "bmid");
1084
1085 rc = scc_host_init(host);
1086 if (rc)
1087 return rc;
1088
1089 return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
1090 IRQF_SHARED, &scc_sht);
1091}
1092
1093static struct pci_driver scc_pci_driver = {
1094 .name = DRV_NAME,
1095 .id_table = scc_pci_tbl,
1096 .probe = scc_init_one,
1097 .remove = ata_pci_remove_one,
1098#ifdef CONFIG_PM_SLEEP
1099 .suspend = ata_pci_device_suspend,
1100 .resume = ata_pci_device_resume,
1101#endif
1102};
1103
1104module_pci_driver(scc_pci_driver);
1105
1106MODULE_AUTHOR("Toshiba corp");
1107MODULE_DESCRIPTION("SCSI low-level driver for Toshiba SCC PATA controller");
1108MODULE_LICENSE("GPL");
1109MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
1110MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ae3fcb4199e9..d7173cb1ea76 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1620,8 +1620,8 @@ out:
1620 1620
1621static void loop_remove(struct loop_device *lo) 1621static void loop_remove(struct loop_device *lo)
1622{ 1622{
1623 del_gendisk(lo->lo_disk);
1624 blk_cleanup_queue(lo->lo_queue); 1623 blk_cleanup_queue(lo->lo_queue);
1624 del_gendisk(lo->lo_disk);
1625 blk_mq_free_tag_set(&lo->tag_set); 1625 blk_mq_free_tag_set(&lo->tag_set);
1626 put_disk(lo->lo_disk); 1626 put_disk(lo->lo_disk);
1627 kfree(lo); 1627 kfree(lo);
diff --git a/drivers/block/nvme-scsi.c b/drivers/block/nvme-scsi.c
index 6b736b00f63e..44f2514fb775 100644
--- a/drivers/block/nvme-scsi.c
+++ b/drivers/block/nvme-scsi.c
@@ -944,7 +944,8 @@ static int nvme_trans_ext_inq_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
944static int nvme_trans_bdev_limits_page(struct nvme_ns *ns, struct sg_io_hdr *hdr, 944static int nvme_trans_bdev_limits_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
945 u8 *inq_response, int alloc_len) 945 u8 *inq_response, int alloc_len)
946{ 946{
947 __be32 max_sectors = cpu_to_be32(queue_max_hw_sectors(ns->queue)); 947 __be32 max_sectors = cpu_to_be32(
948 nvme_block_nr(ns, queue_max_hw_sectors(ns->queue)));
948 __be32 max_discard = cpu_to_be32(ns->queue->limits.max_discard_sectors); 949 __be32 max_discard = cpu_to_be32(ns->queue->limits.max_discard_sectors);
949 __be32 discard_desc_count = cpu_to_be32(0x100); 950 __be32 discard_desc_count = cpu_to_be32(0x100);
950 951
@@ -2256,7 +2257,8 @@ static int nvme_trans_inquiry(struct nvme_ns *ns, struct sg_io_hdr *hdr,
2256 page_code = GET_INQ_PAGE_CODE(cmd); 2257 page_code = GET_INQ_PAGE_CODE(cmd);
2257 alloc_len = GET_INQ_ALLOC_LENGTH(cmd); 2258 alloc_len = GET_INQ_ALLOC_LENGTH(cmd);
2258 2259
2259 inq_response = kmalloc(alloc_len, GFP_KERNEL); 2260 inq_response = kmalloc(max(alloc_len, STANDARD_INQUIRY_LENGTH),
2261 GFP_KERNEL);
2260 if (inq_response == NULL) { 2262 if (inq_response == NULL) {
2261 res = -ENOMEM; 2263 res = -ENOMEM;
2262 goto out_mem; 2264 goto out_mem;
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 812523330a78..ec6c5c6e1ac9 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2264,6 +2264,11 @@ static bool rbd_img_obj_end_request(struct rbd_obj_request *obj_request)
2264 result, xferred); 2264 result, xferred);
2265 if (!img_request->result) 2265 if (!img_request->result)
2266 img_request->result = result; 2266 img_request->result = result;
2267 /*
2268 * Need to end I/O on the entire obj_request worth of
2269 * bytes in case of error.
2270 */
2271 xferred = obj_request->length;
2267 } 2272 }
2268 2273
2269 /* Image object requests don't own their page array */ 2274 /* Image object requests don't own their page array */
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index bd2b3bbbb22c..713fc9ff1149 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -265,17 +265,6 @@ static void put_persistent_gnt(struct xen_blkif *blkif,
265 atomic_dec(&blkif->persistent_gnt_in_use); 265 atomic_dec(&blkif->persistent_gnt_in_use);
266} 266}
267 267
268static void free_persistent_gnts_unmap_callback(int result,
269 struct gntab_unmap_queue_data *data)
270{
271 struct completion *c = data->data;
272
273 /* BUG_ON used to reproduce existing behaviour,
274 but is this the best way to deal with this? */
275 BUG_ON(result);
276 complete(c);
277}
278
279static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, 268static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
280 unsigned int num) 269 unsigned int num)
281{ 270{
@@ -285,12 +274,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
285 struct rb_node *n; 274 struct rb_node *n;
286 int segs_to_unmap = 0; 275 int segs_to_unmap = 0;
287 struct gntab_unmap_queue_data unmap_data; 276 struct gntab_unmap_queue_data unmap_data;
288 struct completion unmap_completion;
289 277
290 init_completion(&unmap_completion);
291
292 unmap_data.data = &unmap_completion;
293 unmap_data.done = &free_persistent_gnts_unmap_callback;
294 unmap_data.pages = pages; 278 unmap_data.pages = pages;
295 unmap_data.unmap_ops = unmap; 279 unmap_data.unmap_ops = unmap;
296 unmap_data.kunmap_ops = NULL; 280 unmap_data.kunmap_ops = NULL;
@@ -310,8 +294,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
310 !rb_next(&persistent_gnt->node)) { 294 !rb_next(&persistent_gnt->node)) {
311 295
312 unmap_data.count = segs_to_unmap; 296 unmap_data.count = segs_to_unmap;
313 gnttab_unmap_refs_async(&unmap_data); 297 BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
314 wait_for_completion(&unmap_completion);
315 298
316 put_free_pages(blkif, pages, segs_to_unmap); 299 put_free_pages(blkif, pages, segs_to_unmap);
317 segs_to_unmap = 0; 300 segs_to_unmap = 0;
@@ -329,8 +312,13 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
329 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 312 struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
330 struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 313 struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
331 struct persistent_gnt *persistent_gnt; 314 struct persistent_gnt *persistent_gnt;
332 int ret, segs_to_unmap = 0; 315 int segs_to_unmap = 0;
333 struct xen_blkif *blkif = container_of(work, typeof(*blkif), persistent_purge_work); 316 struct xen_blkif *blkif = container_of(work, typeof(*blkif), persistent_purge_work);
317 struct gntab_unmap_queue_data unmap_data;
318
319 unmap_data.pages = pages;
320 unmap_data.unmap_ops = unmap;
321 unmap_data.kunmap_ops = NULL;
334 322
335 while(!list_empty(&blkif->persistent_purge_list)) { 323 while(!list_empty(&blkif->persistent_purge_list)) {
336 persistent_gnt = list_first_entry(&blkif->persistent_purge_list, 324 persistent_gnt = list_first_entry(&blkif->persistent_purge_list,
@@ -346,17 +334,16 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
346 pages[segs_to_unmap] = persistent_gnt->page; 334 pages[segs_to_unmap] = persistent_gnt->page;
347 335
348 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) { 336 if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
349 ret = gnttab_unmap_refs(unmap, NULL, pages, 337 unmap_data.count = segs_to_unmap;
350 segs_to_unmap); 338 BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
351 BUG_ON(ret);
352 put_free_pages(blkif, pages, segs_to_unmap); 339 put_free_pages(blkif, pages, segs_to_unmap);
353 segs_to_unmap = 0; 340 segs_to_unmap = 0;
354 } 341 }
355 kfree(persistent_gnt); 342 kfree(persistent_gnt);
356 } 343 }
357 if (segs_to_unmap > 0) { 344 if (segs_to_unmap > 0) {
358 ret = gnttab_unmap_refs(unmap, NULL, pages, segs_to_unmap); 345 unmap_data.count = segs_to_unmap;
359 BUG_ON(ret); 346 BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
360 put_free_pages(blkif, pages, segs_to_unmap); 347 put_free_pages(blkif, pages, segs_to_unmap);
361 } 348 }
362} 349}
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index c94386aa563d..8dcbced0eafd 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -74,6 +74,27 @@ static inline struct zram *dev_to_zram(struct device *dev)
74 return (struct zram *)dev_to_disk(dev)->private_data; 74 return (struct zram *)dev_to_disk(dev)->private_data;
75} 75}
76 76
77static ssize_t compact_store(struct device *dev,
78 struct device_attribute *attr, const char *buf, size_t len)
79{
80 unsigned long nr_migrated;
81 struct zram *zram = dev_to_zram(dev);
82 struct zram_meta *meta;
83
84 down_read(&zram->init_lock);
85 if (!init_done(zram)) {
86 up_read(&zram->init_lock);
87 return -EINVAL;
88 }
89
90 meta = zram->meta;
91 nr_migrated = zs_compact(meta->mem_pool);
92 atomic64_add(nr_migrated, &zram->stats.num_migrated);
93 up_read(&zram->init_lock);
94
95 return len;
96}
97
77static ssize_t disksize_show(struct device *dev, 98static ssize_t disksize_show(struct device *dev,
78 struct device_attribute *attr, char *buf) 99 struct device_attribute *attr, char *buf)
79{ 100{
@@ -1038,6 +1059,7 @@ static const struct block_device_operations zram_devops = {
1038 .owner = THIS_MODULE 1059 .owner = THIS_MODULE
1039}; 1060};
1040 1061
1062static DEVICE_ATTR_WO(compact);
1041static DEVICE_ATTR_RW(disksize); 1063static DEVICE_ATTR_RW(disksize);
1042static DEVICE_ATTR_RO(initstate); 1064static DEVICE_ATTR_RO(initstate);
1043static DEVICE_ATTR_WO(reset); 1065static DEVICE_ATTR_WO(reset);
@@ -1114,6 +1136,7 @@ static struct attribute *zram_disk_attrs[] = {
1114 &dev_attr_num_writes.attr, 1136 &dev_attr_num_writes.attr,
1115 &dev_attr_failed_reads.attr, 1137 &dev_attr_failed_reads.attr,
1116 &dev_attr_failed_writes.attr, 1138 &dev_attr_failed_writes.attr,
1139 &dev_attr_compact.attr,
1117 &dev_attr_invalid_io.attr, 1140 &dev_attr_invalid_io.attr,
1118 &dev_attr_notify_free.attr, 1141 &dev_attr_notify_free.attr,
1119 &dev_attr_zero_pages.attr, 1142 &dev_attr_zero_pages.attr,
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 288547a3c566..8c81af6dbe06 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -88,6 +88,7 @@ static const struct usb_device_id ath3k_table[] = {
88 { USB_DEVICE(0x04CA, 0x3007) }, 88 { USB_DEVICE(0x04CA, 0x3007) },
89 { USB_DEVICE(0x04CA, 0x3008) }, 89 { USB_DEVICE(0x04CA, 0x3008) },
90 { USB_DEVICE(0x04CA, 0x300b) }, 90 { USB_DEVICE(0x04CA, 0x300b) },
91 { USB_DEVICE(0x04CA, 0x300f) },
91 { USB_DEVICE(0x04CA, 0x3010) }, 92 { USB_DEVICE(0x04CA, 0x3010) },
92 { USB_DEVICE(0x0930, 0x0219) }, 93 { USB_DEVICE(0x0930, 0x0219) },
93 { USB_DEVICE(0x0930, 0x0220) }, 94 { USB_DEVICE(0x0930, 0x0220) },
@@ -104,6 +105,7 @@ static const struct usb_device_id ath3k_table[] = {
104 { USB_DEVICE(0x0cf3, 0xe003) }, 105 { USB_DEVICE(0x0cf3, 0xe003) },
105 { USB_DEVICE(0x0CF3, 0xE004) }, 106 { USB_DEVICE(0x0CF3, 0xE004) },
106 { USB_DEVICE(0x0CF3, 0xE005) }, 107 { USB_DEVICE(0x0CF3, 0xE005) },
108 { USB_DEVICE(0x0CF3, 0xE006) },
107 { USB_DEVICE(0x13d3, 0x3362) }, 109 { USB_DEVICE(0x13d3, 0x3362) },
108 { USB_DEVICE(0x13d3, 0x3375) }, 110 { USB_DEVICE(0x13d3, 0x3375) },
109 { USB_DEVICE(0x13d3, 0x3393) }, 111 { USB_DEVICE(0x13d3, 0x3393) },
@@ -143,6 +145,7 @@ static const struct usb_device_id ath3k_blist_tbl[] = {
143 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 }, 145 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
144 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, 146 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
145 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 }, 147 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
148 { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
146 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 }, 149 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
147 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, 150 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
148 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 }, 151 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
@@ -158,6 +161,7 @@ static const struct usb_device_id ath3k_blist_tbl[] = {
158 { USB_DEVICE(0x0CF3, 0x817a), .driver_info = BTUSB_ATH3012 }, 161 { USB_DEVICE(0x0CF3, 0x817a), .driver_info = BTUSB_ATH3012 },
159 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, 162 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
160 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 }, 163 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
164 { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
161 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 }, 165 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
162 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, 166 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
163 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 167 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 4f7e8d400bc0..6de97b3871b0 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -227,7 +227,6 @@ static void bt3c_receive(struct bt3c_info *info)
227 iobase = info->p_dev->resource[0]->start; 227 iobase = info->p_dev->resource[0]->start;
228 228
229 avail = bt3c_read(iobase, 0x7006); 229 avail = bt3c_read(iobase, 0x7006);
230 //printk("bt3c_cs: receiving %d bytes\n", avail);
231 230
232 bt3c_address(iobase, 0x7480); 231 bt3c_address(iobase, 0x7480);
233 while (size < avail) { 232 while (size < avail) {
@@ -250,7 +249,6 @@ static void bt3c_receive(struct bt3c_info *info)
250 249
251 bt_cb(info->rx_skb)->pkt_type = inb(iobase + DATA_L); 250 bt_cb(info->rx_skb)->pkt_type = inb(iobase + DATA_L);
252 inb(iobase + DATA_H); 251 inb(iobase + DATA_H);
253 //printk("bt3c: PACKET_TYPE=%02x\n", bt_cb(info->rx_skb)->pkt_type);
254 252
255 switch (bt_cb(info->rx_skb)->pkt_type) { 253 switch (bt_cb(info->rx_skb)->pkt_type) {
256 254
@@ -364,7 +362,6 @@ static irqreturn_t bt3c_interrupt(int irq, void *dev_inst)
364 if (stat & 0x0001) 362 if (stat & 0x0001)
365 bt3c_receive(info); 363 bt3c_receive(info);
366 if (stat & 0x0002) { 364 if (stat & 0x0002) {
367 //BT_ERR("Ack (stat=0x%04x)", stat);
368 clear_bit(XMIT_SENDING, &(info->tx_state)); 365 clear_bit(XMIT_SENDING, &(info->tx_state));
369 bt3c_write_wakeup(info); 366 bt3c_write_wakeup(info);
370 } 367 }
diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c
index d0741f3ed7ec..4bba86677adc 100644
--- a/drivers/bluetooth/btbcm.c
+++ b/drivers/bluetooth/btbcm.c
@@ -95,6 +95,78 @@ int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
95} 95}
96EXPORT_SYMBOL_GPL(btbcm_set_bdaddr); 96EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
97 97
98int btbcm_patchram(struct hci_dev *hdev, const char *firmware)
99{
100 const struct hci_command_hdr *cmd;
101 const struct firmware *fw;
102 const u8 *fw_ptr;
103 size_t fw_size;
104 struct sk_buff *skb;
105 u16 opcode;
106 int err;
107
108 err = request_firmware(&fw, firmware, &hdev->dev);
109 if (err < 0) {
110 BT_INFO("%s: BCM: Patch %s not found", hdev->name, firmware);
111 return err;
112 }
113
114 /* Start Download */
115 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
116 if (IS_ERR(skb)) {
117 err = PTR_ERR(skb);
118 BT_ERR("%s: BCM: Download Minidrv command failed (%d)",
119 hdev->name, err);
120 goto done;
121 }
122 kfree_skb(skb);
123
124 /* 50 msec delay after Download Minidrv completes */
125 msleep(50);
126
127 fw_ptr = fw->data;
128 fw_size = fw->size;
129
130 while (fw_size >= sizeof(*cmd)) {
131 const u8 *cmd_param;
132
133 cmd = (struct hci_command_hdr *)fw_ptr;
134 fw_ptr += sizeof(*cmd);
135 fw_size -= sizeof(*cmd);
136
137 if (fw_size < cmd->plen) {
138 BT_ERR("%s: BCM: Patch %s is corrupted", hdev->name,
139 firmware);
140 err = -EINVAL;
141 goto done;
142 }
143
144 cmd_param = fw_ptr;
145 fw_ptr += cmd->plen;
146 fw_size -= cmd->plen;
147
148 opcode = le16_to_cpu(cmd->opcode);
149
150 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
151 HCI_INIT_TIMEOUT);
152 if (IS_ERR(skb)) {
153 err = PTR_ERR(skb);
154 BT_ERR("%s: BCM: Patch command %04x failed (%d)",
155 hdev->name, opcode, err);
156 goto done;
157 }
158 kfree_skb(skb);
159 }
160
161 /* 250 msec delay after Launch Ram completes */
162 msleep(250);
163
164done:
165 release_firmware(fw);
166 return err;
167}
168EXPORT_SYMBOL(btbcm_patchram);
169
98static int btbcm_reset(struct hci_dev *hdev) 170static int btbcm_reset(struct hci_dev *hdev)
99{ 171{
100 struct sk_buff *skb; 172 struct sk_buff *skb;
@@ -198,12 +270,8 @@ static const struct {
198 270
199int btbcm_setup_patchram(struct hci_dev *hdev) 271int btbcm_setup_patchram(struct hci_dev *hdev)
200{ 272{
201 const struct hci_command_hdr *cmd;
202 const struct firmware *fw;
203 const u8 *fw_ptr;
204 size_t fw_size;
205 char fw_name[64]; 273 char fw_name[64];
206 u16 opcode, subver, rev, pid, vid; 274 u16 subver, rev, pid, vid;
207 const char *hw_name = NULL; 275 const char *hw_name = NULL;
208 struct sk_buff *skb; 276 struct sk_buff *skb;
209 struct hci_rp_read_local_version *ver; 277 struct hci_rp_read_local_version *ver;
@@ -273,74 +341,19 @@ int btbcm_setup_patchram(struct hci_dev *hdev)
273 hw_name ? : "BCM", (subver & 0x7000) >> 13, 341 hw_name ? : "BCM", (subver & 0x7000) >> 13,
274 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff); 342 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
275 343
276 err = request_firmware(&fw, fw_name, &hdev->dev); 344 err = btbcm_patchram(hdev, fw_name);
277 if (err < 0) { 345 if (err == -ENOENT)
278 BT_INFO("%s: BCM: patch %s not found", hdev->name, fw_name);
279 return 0; 346 return 0;
280 }
281
282 /* Start Download */
283 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
284 if (IS_ERR(skb)) {
285 err = PTR_ERR(skb);
286 BT_ERR("%s: BCM: Download Minidrv command failed (%d)",
287 hdev->name, err);
288 goto reset;
289 }
290 kfree_skb(skb);
291
292 /* 50 msec delay after Download Minidrv completes */
293 msleep(50);
294
295 fw_ptr = fw->data;
296 fw_size = fw->size;
297
298 while (fw_size >= sizeof(*cmd)) {
299 const u8 *cmd_param;
300
301 cmd = (struct hci_command_hdr *)fw_ptr;
302 fw_ptr += sizeof(*cmd);
303 fw_size -= sizeof(*cmd);
304
305 if (fw_size < cmd->plen) {
306 BT_ERR("%s: BCM: patch %s is corrupted", hdev->name,
307 fw_name);
308 err = -EINVAL;
309 goto reset;
310 }
311 347
312 cmd_param = fw_ptr;
313 fw_ptr += cmd->plen;
314 fw_size -= cmd->plen;
315
316 opcode = le16_to_cpu(cmd->opcode);
317
318 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
319 HCI_INIT_TIMEOUT);
320 if (IS_ERR(skb)) {
321 err = PTR_ERR(skb);
322 BT_ERR("%s: BCM: patch command %04x failed (%d)",
323 hdev->name, opcode, err);
324 goto reset;
325 }
326 kfree_skb(skb);
327 }
328
329 /* 250 msec delay after Launch Ram completes */
330 msleep(250);
331
332reset:
333 /* Reset */ 348 /* Reset */
334 err = btbcm_reset(hdev); 349 err = btbcm_reset(hdev);
335 if (err) 350 if (err)
336 goto done; 351 return err;
337 352
338 /* Read Local Version Info */ 353 /* Read Local Version Info */
339 skb = btbcm_read_local_version(hdev); 354 skb = btbcm_read_local_version(hdev);
340 if (IS_ERR(skb)) { 355 if (IS_ERR(skb))
341 err = PTR_ERR(skb); 356 return PTR_ERR(skb);
342 goto done;
343 }
344 357
345 ver = (struct hci_rp_read_local_version *)skb->data; 358 ver = (struct hci_rp_read_local_version *)skb->data;
346 rev = le16_to_cpu(ver->hci_rev); 359 rev = le16_to_cpu(ver->hci_rev);
@@ -355,10 +368,7 @@ reset:
355 368
356 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); 369 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
357 370
358done: 371 return 0;
359 release_firmware(fw);
360
361 return err;
362} 372}
363EXPORT_SYMBOL_GPL(btbcm_setup_patchram); 373EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
364 374
diff --git a/drivers/bluetooth/btbcm.h b/drivers/bluetooth/btbcm.h
index 34268ae3eb46..eb6ab5f9483d 100644
--- a/drivers/bluetooth/btbcm.h
+++ b/drivers/bluetooth/btbcm.h
@@ -25,6 +25,7 @@
25 25
26int btbcm_check_bdaddr(struct hci_dev *hdev); 26int btbcm_check_bdaddr(struct hci_dev *hdev);
27int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr); 27int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
28int btbcm_patchram(struct hci_dev *hdev, const char *firmware);
28 29
29int btbcm_setup_patchram(struct hci_dev *hdev); 30int btbcm_setup_patchram(struct hci_dev *hdev);
30int btbcm_setup_apple(struct hci_dev *hdev); 31int btbcm_setup_apple(struct hci_dev *hdev);
@@ -41,6 +42,11 @@ static inline int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
41 return -EOPNOTSUPP; 42 return -EOPNOTSUPP;
42} 43}
43 44
45static inline int btbcm_patchram(struct hci_dev *hdev, const char *firmware)
46{
47 return -EOPNOTSUPP;
48}
49
44static inline int btbcm_setup_patchram(struct hci_dev *hdev) 50static inline int btbcm_setup_patchram(struct hci_dev *hdev)
45{ 51{
46 return 0; 52 return 0;
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index de7b236eeae7..3c10d4dfe9a7 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -24,6 +24,7 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/firmware.h> 26#include <linux/firmware.h>
27#include <asm/unaligned.h>
27 28
28#include <net/bluetooth/bluetooth.h> 29#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/hci_core.h> 30#include <net/bluetooth/hci_core.h>
@@ -57,6 +58,7 @@ static struct usb_driver btusb_driver;
57#define BTUSB_AMP 0x4000 58#define BTUSB_AMP 0x4000
58#define BTUSB_QCA_ROME 0x8000 59#define BTUSB_QCA_ROME 0x8000
59#define BTUSB_BCM_APPLE 0x10000 60#define BTUSB_BCM_APPLE 0x10000
61#define BTUSB_REALTEK 0x20000
60 62
61static const struct usb_device_id btusb_table[] = { 63static const struct usb_device_id btusb_table[] = {
62 /* Generic Bluetooth USB device */ 64 /* Generic Bluetooth USB device */
@@ -184,6 +186,7 @@ static const struct usb_device_id blacklist_table[] = {
184 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 }, 186 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
185 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, 187 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
186 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 }, 188 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
189 { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
187 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 }, 190 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
188 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, 191 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
189 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 }, 192 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
@@ -200,6 +203,7 @@ static const struct usb_device_id blacklist_table[] = {
200 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 }, 203 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
201 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, 204 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
202 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 }, 205 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
206 { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
203 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, 207 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
204 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 208 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
205 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 }, 209 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
@@ -216,6 +220,7 @@ static const struct usb_device_id blacklist_table[] = {
216 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, 220 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
217 221
218 /* QCA ROME chipset */ 222 /* QCA ROME chipset */
223 { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME },
219 { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME }, 224 { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME },
220 { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME }, 225 { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME },
221 226
@@ -288,6 +293,28 @@ static const struct usb_device_id blacklist_table[] = {
288 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), 293 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
289 .driver_info = BTUSB_IGNORE }, 294 .driver_info = BTUSB_IGNORE },
290 295
296 /* Realtek Bluetooth devices */
297 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
298 .driver_info = BTUSB_REALTEK },
299
300 /* Additional Realtek 8723AE Bluetooth devices */
301 { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK },
302 { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK },
303
304 /* Additional Realtek 8723BE Bluetooth devices */
305 { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK },
306 { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK },
307 { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK },
308 { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK },
309 { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK },
310
311 /* Additional Realtek 8821AE Bluetooth devices */
312 { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK },
313 { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK },
314 { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK },
315 { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK },
316 { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK },
317
291 { } /* Terminating entry */ 318 { } /* Terminating entry */
292}; 319};
293 320
@@ -892,7 +919,7 @@ static int btusb_open(struct hci_dev *hdev)
892 */ 919 */
893 if (data->setup_on_usb) { 920 if (data->setup_on_usb) {
894 err = data->setup_on_usb(hdev); 921 err = data->setup_on_usb(hdev);
895 if (err <0) 922 if (err < 0)
896 return err; 923 return err;
897 } 924 }
898 925
@@ -1345,6 +1372,378 @@ static int btusb_setup_csr(struct hci_dev *hdev)
1345 return ret; 1372 return ret;
1346} 1373}
1347 1374
1375#define RTL_FRAG_LEN 252
1376
1377struct rtl_download_cmd {
1378 __u8 index;
1379 __u8 data[RTL_FRAG_LEN];
1380} __packed;
1381
1382struct rtl_download_response {
1383 __u8 status;
1384 __u8 index;
1385} __packed;
1386
1387struct rtl_rom_version_evt {
1388 __u8 status;
1389 __u8 version;
1390} __packed;
1391
1392struct rtl_epatch_header {
1393 __u8 signature[8];
1394 __le32 fw_version;
1395 __le16 num_patches;
1396} __packed;
1397
1398#define RTL_EPATCH_SIGNATURE "Realtech"
1399#define RTL_ROM_LMP_3499 0x3499
1400#define RTL_ROM_LMP_8723A 0x1200
1401#define RTL_ROM_LMP_8723B 0x8723
1402#define RTL_ROM_LMP_8821A 0x8821
1403#define RTL_ROM_LMP_8761A 0x8761
1404
1405static int rtl_read_rom_version(struct hci_dev *hdev, u8 *version)
1406{
1407 struct rtl_rom_version_evt *rom_version;
1408 struct sk_buff *skb;
1409 int ret;
1410
1411 /* Read RTL ROM version command */
1412 skb = __hci_cmd_sync(hdev, 0xfc6d, 0, NULL, HCI_INIT_TIMEOUT);
1413 if (IS_ERR(skb)) {
1414 BT_ERR("%s: Read ROM version failed (%ld)",
1415 hdev->name, PTR_ERR(skb));
1416 return PTR_ERR(skb);
1417 }
1418
1419 if (skb->len != sizeof(*rom_version)) {
1420 BT_ERR("%s: RTL version event length mismatch", hdev->name);
1421 kfree_skb(skb);
1422 return -EIO;
1423 }
1424
1425 rom_version = (struct rtl_rom_version_evt *)skb->data;
1426 BT_INFO("%s: rom_version status=%x version=%x",
1427 hdev->name, rom_version->status, rom_version->version);
1428
1429 ret = rom_version->status;
1430 if (ret == 0)
1431 *version = rom_version->version;
1432
1433 kfree_skb(skb);
1434 return ret;
1435}
1436
1437static int rtl8723b_parse_firmware(struct hci_dev *hdev, u16 lmp_subver,
1438 const struct firmware *fw,
1439 unsigned char **_buf)
1440{
1441 const u8 extension_sig[] = { 0x51, 0x04, 0xfd, 0x77 };
1442 struct rtl_epatch_header *epatch_info;
1443 unsigned char *buf;
1444 int i, ret, len;
1445 size_t min_size;
1446 u8 opcode, length, data, rom_version = 0;
1447 int project_id = -1;
1448 const unsigned char *fwptr, *chip_id_base;
1449 const unsigned char *patch_length_base, *patch_offset_base;
1450 u32 patch_offset = 0;
1451 u16 patch_length, num_patches;
1452 const u16 project_id_to_lmp_subver[] = {
1453 RTL_ROM_LMP_8723A,
1454 RTL_ROM_LMP_8723B,
1455 RTL_ROM_LMP_8821A,
1456 RTL_ROM_LMP_8761A
1457 };
1458
1459 ret = rtl_read_rom_version(hdev, &rom_version);
1460 if (ret)
1461 return -bt_to_errno(ret);
1462
1463 min_size = sizeof(struct rtl_epatch_header) + sizeof(extension_sig) + 3;
1464 if (fw->size < min_size)
1465 return -EINVAL;
1466
1467 fwptr = fw->data + fw->size - sizeof(extension_sig);
1468 if (memcmp(fwptr, extension_sig, sizeof(extension_sig)) != 0) {
1469 BT_ERR("%s: extension section signature mismatch", hdev->name);
1470 return -EINVAL;
1471 }
1472
1473 /* Loop from the end of the firmware parsing instructions, until
1474 * we find an instruction that identifies the "project ID" for the
1475 * hardware supported by this firwmare file.
1476 * Once we have that, we double-check that that project_id is suitable
1477 * for the hardware we are working with.
1478 */
1479 while (fwptr >= fw->data + (sizeof(struct rtl_epatch_header) + 3)) {
1480 opcode = *--fwptr;
1481 length = *--fwptr;
1482 data = *--fwptr;
1483
1484 BT_DBG("check op=%x len=%x data=%x", opcode, length, data);
1485
1486 if (opcode == 0xff) /* EOF */
1487 break;
1488
1489 if (length == 0) {
1490 BT_ERR("%s: found instruction with length 0",
1491 hdev->name);
1492 return -EINVAL;
1493 }
1494
1495 if (opcode == 0 && length == 1) {
1496 project_id = data;
1497 break;
1498 }
1499
1500 fwptr -= length;
1501 }
1502
1503 if (project_id < 0) {
1504 BT_ERR("%s: failed to find version instruction", hdev->name);
1505 return -EINVAL;
1506 }
1507
1508 if (project_id >= ARRAY_SIZE(project_id_to_lmp_subver)) {
1509 BT_ERR("%s: unknown project id %d", hdev->name, project_id);
1510 return -EINVAL;
1511 }
1512
1513 if (lmp_subver != project_id_to_lmp_subver[project_id]) {
1514 BT_ERR("%s: firmware is for %x but this is a %x", hdev->name,
1515 project_id_to_lmp_subver[project_id], lmp_subver);
1516 return -EINVAL;
1517 }
1518
1519 epatch_info = (struct rtl_epatch_header *)fw->data;
1520 if (memcmp(epatch_info->signature, RTL_EPATCH_SIGNATURE, 8) != 0) {
1521 BT_ERR("%s: bad EPATCH signature", hdev->name);
1522 return -EINVAL;
1523 }
1524
1525 num_patches = le16_to_cpu(epatch_info->num_patches);
1526 BT_DBG("fw_version=%x, num_patches=%d",
1527 le32_to_cpu(epatch_info->fw_version), num_patches);
1528
1529 /* After the rtl_epatch_header there is a funky patch metadata section.
1530 * Assuming 2 patches, the layout is:
1531 * ChipID1 ChipID2 PatchLength1 PatchLength2 PatchOffset1 PatchOffset2
1532 *
1533 * Find the right patch for this chip.
1534 */
1535 min_size += 8 * num_patches;
1536 if (fw->size < min_size)
1537 return -EINVAL;
1538
1539 chip_id_base = fw->data + sizeof(struct rtl_epatch_header);
1540 patch_length_base = chip_id_base + (sizeof(u16) * num_patches);
1541 patch_offset_base = patch_length_base + (sizeof(u16) * num_patches);
1542 for (i = 0; i < num_patches; i++) {
1543 u16 chip_id = get_unaligned_le16(chip_id_base +
1544 (i * sizeof(u16)));
1545 if (chip_id == rom_version + 1) {
1546 patch_length = get_unaligned_le16(patch_length_base +
1547 (i * sizeof(u16)));
1548 patch_offset = get_unaligned_le32(patch_offset_base +
1549 (i * sizeof(u32)));
1550 break;
1551 }
1552 }
1553
1554 if (!patch_offset) {
1555 BT_ERR("%s: didn't find patch for chip id %d",
1556 hdev->name, rom_version);
1557 return -EINVAL;
1558 }
1559
1560 BT_DBG("length=%x offset=%x index %d", patch_length, patch_offset, i);
1561 min_size = patch_offset + patch_length;
1562 if (fw->size < min_size)
1563 return -EINVAL;
1564
1565 /* Copy the firmware into a new buffer and write the version at
1566 * the end.
1567 */
1568 len = patch_length;
1569 buf = kmemdup(fw->data + patch_offset, patch_length, GFP_KERNEL);
1570 if (!buf)
1571 return -ENOMEM;
1572
1573 memcpy(buf + patch_length - 4, &epatch_info->fw_version, 4);
1574
1575 *_buf = buf;
1576 return len;
1577}
1578
1579static int rtl_download_firmware(struct hci_dev *hdev,
1580 const unsigned char *data, int fw_len)
1581{
1582 struct rtl_download_cmd *dl_cmd;
1583 int frag_num = fw_len / RTL_FRAG_LEN + 1;
1584 int frag_len = RTL_FRAG_LEN;
1585 int ret = 0;
1586 int i;
1587
1588 dl_cmd = kmalloc(sizeof(struct rtl_download_cmd), GFP_KERNEL);
1589 if (!dl_cmd)
1590 return -ENOMEM;
1591
1592 for (i = 0; i < frag_num; i++) {
1593 struct rtl_download_response *dl_resp;
1594 struct sk_buff *skb;
1595
1596 BT_DBG("download fw (%d/%d)", i, frag_num);
1597
1598 dl_cmd->index = i;
1599 if (i == (frag_num - 1)) {
1600 dl_cmd->index |= 0x80; /* data end */
1601 frag_len = fw_len % RTL_FRAG_LEN;
1602 }
1603 memcpy(dl_cmd->data, data, frag_len);
1604
1605 /* Send download command */
1606 skb = __hci_cmd_sync(hdev, 0xfc20, frag_len + 1, dl_cmd,
1607 HCI_INIT_TIMEOUT);
1608 if (IS_ERR(skb)) {
1609 BT_ERR("%s: download fw command failed (%ld)",
1610 hdev->name, PTR_ERR(skb));
1611 ret = -PTR_ERR(skb);
1612 goto out;
1613 }
1614
1615 if (skb->len != sizeof(*dl_resp)) {
1616 BT_ERR("%s: download fw event length mismatch",
1617 hdev->name);
1618 kfree_skb(skb);
1619 ret = -EIO;
1620 goto out;
1621 }
1622
1623 dl_resp = (struct rtl_download_response *)skb->data;
1624 if (dl_resp->status != 0) {
1625 kfree_skb(skb);
1626 ret = bt_to_errno(dl_resp->status);
1627 goto out;
1628 }
1629
1630 kfree_skb(skb);
1631 data += RTL_FRAG_LEN;
1632 }
1633
1634out:
1635 kfree(dl_cmd);
1636 return ret;
1637}
1638
1639static int btusb_setup_rtl8723a(struct hci_dev *hdev)
1640{
1641 struct btusb_data *data = dev_get_drvdata(&hdev->dev);
1642 struct usb_device *udev = interface_to_usbdev(data->intf);
1643 const struct firmware *fw;
1644 int ret;
1645
1646 BT_INFO("%s: rtl: loading rtl_bt/rtl8723a_fw.bin", hdev->name);
1647 ret = request_firmware(&fw, "rtl_bt/rtl8723a_fw.bin", &udev->dev);
1648 if (ret < 0) {
1649 BT_ERR("%s: Failed to load rtl_bt/rtl8723a_fw.bin", hdev->name);
1650 return ret;
1651 }
1652
1653 if (fw->size < 8) {
1654 ret = -EINVAL;
1655 goto out;
1656 }
1657
1658 /* Check that the firmware doesn't have the epatch signature
1659 * (which is only for RTL8723B and newer).
1660 */
1661 if (!memcmp(fw->data, RTL_EPATCH_SIGNATURE, 8)) {
1662 BT_ERR("%s: unexpected EPATCH signature!", hdev->name);
1663 ret = -EINVAL;
1664 goto out;
1665 }
1666
1667 ret = rtl_download_firmware(hdev, fw->data, fw->size);
1668
1669out:
1670 release_firmware(fw);
1671 return ret;
1672}
1673
1674static int btusb_setup_rtl8723b(struct hci_dev *hdev, u16 lmp_subver,
1675 const char *fw_name)
1676{
1677 struct btusb_data *data = dev_get_drvdata(&hdev->dev);
1678 struct usb_device *udev = interface_to_usbdev(data->intf);
1679 unsigned char *fw_data = NULL;
1680 const struct firmware *fw;
1681 int ret;
1682
1683 BT_INFO("%s: rtl: loading %s", hdev->name, fw_name);
1684 ret = request_firmware(&fw, fw_name, &udev->dev);
1685 if (ret < 0) {
1686 BT_ERR("%s: Failed to load %s", hdev->name, fw_name);
1687 return ret;
1688 }
1689
1690 ret = rtl8723b_parse_firmware(hdev, lmp_subver, fw, &fw_data);
1691 if (ret < 0)
1692 goto out;
1693
1694 ret = rtl_download_firmware(hdev, fw_data, ret);
1695 kfree(fw_data);
1696 if (ret < 0)
1697 goto out;
1698
1699out:
1700 release_firmware(fw);
1701 return ret;
1702}
1703
1704static int btusb_setup_realtek(struct hci_dev *hdev)
1705{
1706 struct sk_buff *skb;
1707 struct hci_rp_read_local_version *resp;
1708 u16 lmp_subver;
1709
1710 skb = btusb_read_local_version(hdev);
1711 if (IS_ERR(skb))
1712 return -PTR_ERR(skb);
1713
1714 resp = (struct hci_rp_read_local_version *)skb->data;
1715 BT_INFO("%s: rtl: examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
1716 "lmp_subver=%04x", hdev->name, resp->hci_ver, resp->hci_rev,
1717 resp->lmp_ver, resp->lmp_subver);
1718
1719 lmp_subver = le16_to_cpu(resp->lmp_subver);
1720 kfree_skb(skb);
1721
1722 /* Match a set of subver values that correspond to stock firmware,
1723 * which is not compatible with standard btusb.
1724 * If matched, upload an alternative firmware that does conform to
1725 * standard btusb. Once that firmware is uploaded, the subver changes
1726 * to a different value.
1727 */
1728 switch (lmp_subver) {
1729 case RTL_ROM_LMP_8723A:
1730 case RTL_ROM_LMP_3499:
1731 return btusb_setup_rtl8723a(hdev);
1732 case RTL_ROM_LMP_8723B:
1733 return btusb_setup_rtl8723b(hdev, lmp_subver,
1734 "rtl_bt/rtl8723b_fw.bin");
1735 case RTL_ROM_LMP_8821A:
1736 return btusb_setup_rtl8723b(hdev, lmp_subver,
1737 "rtl_bt/rtl8821a_fw.bin");
1738 case RTL_ROM_LMP_8761A:
1739 return btusb_setup_rtl8723b(hdev, lmp_subver,
1740 "rtl_bt/rtl8761a_fw.bin");
1741 default:
1742 BT_INFO("rtl: assuming no firmware upload needed.");
1743 return 0;
1744 }
1745}
1746
1348static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev, 1747static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev,
1349 struct intel_version *ver) 1748 struct intel_version *ver)
1350{ 1749{
@@ -2577,7 +2976,7 @@ static int btusb_setup_qca(struct hci_dev *hdev)
2577 int i, err; 2976 int i, err;
2578 2977
2579 err = btusb_qca_send_vendor_req(hdev, QCA_GET_TARGET_VERSION, &ver, 2978 err = btusb_qca_send_vendor_req(hdev, QCA_GET_TARGET_VERSION, &ver,
2580 sizeof(ver)); 2979 sizeof(ver));
2581 if (err < 0) 2980 if (err < 0)
2582 return err; 2981 return err;
2583 2982
@@ -2776,6 +3175,9 @@ static int btusb_probe(struct usb_interface *intf,
2776 hdev->set_bdaddr = btusb_set_bdaddr_ath3012; 3175 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
2777 } 3176 }
2778 3177
3178 if (id->driver_info & BTUSB_REALTEK)
3179 hdev->setup = btusb_setup_realtek;
3180
2779 if (id->driver_info & BTUSB_AMP) { 3181 if (id->driver_info & BTUSB_AMP) {
2780 /* AMP controllers do not support SCO packets */ 3182 /* AMP controllers do not support SCO packets */
2781 data->isoc = NULL; 3183 data->isoc = NULL;
diff --git a/drivers/bluetooth/hci_ath.c b/drivers/bluetooth/hci_ath.c
index 1b3f8647ea2f..ec8fa0e0f036 100644
--- a/drivers/bluetooth/hci_ath.c
+++ b/drivers/bluetooth/hci_ath.c
@@ -95,7 +95,6 @@ static void ath_hci_uart_work(struct work_struct *work)
95 hci_uart_tx_wakeup(hu); 95 hci_uart_tx_wakeup(hu);
96} 96}
97 97
98/* Initialize protocol */
99static int ath_open(struct hci_uart *hu) 98static int ath_open(struct hci_uart *hu)
100{ 99{
101 struct ath_struct *ath; 100 struct ath_struct *ath;
@@ -116,8 +115,7 @@ static int ath_open(struct hci_uart *hu)
116 return 0; 115 return 0;
117} 116}
118 117
119/* Flush protocol data */ 118static int ath_close(struct hci_uart *hu)
120static int ath_flush(struct hci_uart *hu)
121{ 119{
122 struct ath_struct *ath = hu->priv; 120 struct ath_struct *ath = hu->priv;
123 121
@@ -125,11 +123,17 @@ static int ath_flush(struct hci_uart *hu)
125 123
126 skb_queue_purge(&ath->txq); 124 skb_queue_purge(&ath->txq);
127 125
126 kfree_skb(ath->rx_skb);
127
128 cancel_work_sync(&ath->ctxtsw);
129
130 hu->priv = NULL;
131 kfree(ath);
132
128 return 0; 133 return 0;
129} 134}
130 135
131/* Close protocol */ 136static int ath_flush(struct hci_uart *hu)
132static int ath_close(struct hci_uart *hu)
133{ 137{
134 struct ath_struct *ath = hu->priv; 138 struct ath_struct *ath = hu->priv;
135 139
@@ -137,19 +141,65 @@ static int ath_close(struct hci_uart *hu)
137 141
138 skb_queue_purge(&ath->txq); 142 skb_queue_purge(&ath->txq);
139 143
140 kfree_skb(ath->rx_skb); 144 return 0;
145}
141 146
142 cancel_work_sync(&ath->ctxtsw); 147static int ath_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
148{
149 struct sk_buff *skb;
150 u8 buf[10];
151 int err;
152
153 buf[0] = 0x01;
154 buf[1] = 0x01;
155 buf[2] = 0x00;
156 buf[3] = sizeof(bdaddr_t);
157 memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
158
159 skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
160 if (IS_ERR(skb)) {
161 err = PTR_ERR(skb);
162 BT_ERR("%s: Change address command failed (%d)",
163 hdev->name, err);
164 return err;
165 }
166 kfree_skb(skb);
143 167
144 hu->priv = NULL; 168 return 0;
145 kfree(ath); 169}
170
171static int ath_setup(struct hci_uart *hu)
172{
173 BT_DBG("hu %p", hu);
174
175 hu->hdev->set_bdaddr = ath_set_bdaddr;
146 176
147 return 0; 177 return 0;
148} 178}
149 179
180static const struct h4_recv_pkt ath_recv_pkts[] = {
181 { H4_RECV_ACL, .recv = hci_recv_frame },
182 { H4_RECV_SCO, .recv = hci_recv_frame },
183 { H4_RECV_EVENT, .recv = hci_recv_frame },
184};
185
186static int ath_recv(struct hci_uart *hu, const void *data, int count)
187{
188 struct ath_struct *ath = hu->priv;
189
190 ath->rx_skb = h4_recv_buf(hu->hdev, ath->rx_skb, data, count,
191 ath_recv_pkts, ARRAY_SIZE(ath_recv_pkts));
192 if (IS_ERR(ath->rx_skb)) {
193 int err = PTR_ERR(ath->rx_skb);
194 BT_ERR("%s: Frame reassembly failed (%d)", hu->hdev->name, err);
195 return err;
196 }
197
198 return count;
199}
200
150#define HCI_OP_ATH_SLEEP 0xFC04 201#define HCI_OP_ATH_SLEEP 0xFC04
151 202
152/* Enqueue frame for transmittion */
153static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb) 203static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb)
154{ 204{
155 struct ath_struct *ath = hu->priv; 205 struct ath_struct *ath = hu->priv;
@@ -159,8 +209,7 @@ static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb)
159 return 0; 209 return 0;
160 } 210 }
161 211
162 /* 212 /* Update power management enable flag with parameters of
163 * Update power management enable flag with parameters of
164 * HCI sleep enable vendor specific HCI command. 213 * HCI sleep enable vendor specific HCI command.
165 */ 214 */
166 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { 215 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
@@ -190,37 +239,16 @@ static struct sk_buff *ath_dequeue(struct hci_uart *hu)
190 return skb_dequeue(&ath->txq); 239 return skb_dequeue(&ath->txq);
191} 240}
192 241
193static const struct h4_recv_pkt ath_recv_pkts[] = {
194 { H4_RECV_ACL, .recv = hci_recv_frame },
195 { H4_RECV_SCO, .recv = hci_recv_frame },
196 { H4_RECV_EVENT, .recv = hci_recv_frame },
197};
198
199/* Recv data */
200static int ath_recv(struct hci_uart *hu, const void *data, int count)
201{
202 struct ath_struct *ath = hu->priv;
203
204 ath->rx_skb = h4_recv_buf(hu->hdev, ath->rx_skb, data, count,
205 ath_recv_pkts, ARRAY_SIZE(ath_recv_pkts));
206 if (IS_ERR(ath->rx_skb)) {
207 int err = PTR_ERR(ath->rx_skb);
208 BT_ERR("%s: Frame reassembly failed (%d)", hu->hdev->name, err);
209 return err;
210 }
211
212 return count;
213}
214
215static const struct hci_uart_proto athp = { 242static const struct hci_uart_proto athp = {
216 .id = HCI_UART_ATH3K, 243 .id = HCI_UART_ATH3K,
217 .name = "ATH3K", 244 .name = "ATH3K",
218 .open = ath_open, 245 .open = ath_open,
219 .close = ath_close, 246 .close = ath_close,
247 .flush = ath_flush,
248 .setup = ath_setup,
220 .recv = ath_recv, 249 .recv = ath_recv,
221 .enqueue = ath_enqueue, 250 .enqueue = ath_enqueue,
222 .dequeue = ath_dequeue, 251 .dequeue = ath_dequeue,
223 .flush = ath_flush,
224}; 252};
225 253
226int __init ath_init(void) 254int __init ath_init(void)
diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
index b854125e4831..5340604b23a4 100644
--- a/drivers/bus/arm-cci.c
+++ b/drivers/bus/arm-cci.c
@@ -660,7 +660,7 @@ validate_group(struct perf_event *event)
660 * Initialise the fake PMU. We only need to populate the 660 * Initialise the fake PMU. We only need to populate the
661 * used_mask for the purposes of validation. 661 * used_mask for the purposes of validation.
662 */ 662 */
663 .used_mask = CPU_BITS_NONE, 663 .used_mask = { 0 },
664 }; 664 };
665 665
666 if (!validate_event(event->pmu, &fake_pmu, leader)) 666 if (!validate_event(event->pmu, &fake_pmu, leader))
diff --git a/drivers/bus/mips_cdmm.c b/drivers/bus/mips_cdmm.c
index 5bd792c68f9b..ab3bde16ecb4 100644
--- a/drivers/bus/mips_cdmm.c
+++ b/drivers/bus/mips_cdmm.c
@@ -453,7 +453,7 @@ void __iomem *mips_cdmm_early_probe(unsigned int dev_type)
453 453
454 /* Look for a specific device type */ 454 /* Look for a specific device type */
455 for (; drb < bus->drbs; drb += size + 1) { 455 for (; drb < bus->drbs; drb += size + 1) {
456 acsr = readl(cdmm + drb * CDMM_DRB_SIZE); 456 acsr = __raw_readl(cdmm + drb * CDMM_DRB_SIZE);
457 type = (acsr & CDMM_ACSR_DEVTYPE) >> CDMM_ACSR_DEVTYPE_SHIFT; 457 type = (acsr & CDMM_ACSR_DEVTYPE) >> CDMM_ACSR_DEVTYPE_SHIFT;
458 if (type == dev_type) 458 if (type == dev_type)
459 return cdmm + drb * CDMM_DRB_SIZE; 459 return cdmm + drb * CDMM_DRB_SIZE;
@@ -500,7 +500,7 @@ static void mips_cdmm_bus_discover(struct mips_cdmm_bus *bus)
500 bus->discovered = true; 500 bus->discovered = true;
501 pr_info("cdmm%u discovery (%u blocks)\n", cpu, bus->drbs); 501 pr_info("cdmm%u discovery (%u blocks)\n", cpu, bus->drbs);
502 for (; drb < bus->drbs; drb += size + 1) { 502 for (; drb < bus->drbs; drb += size + 1) {
503 acsr = readl(cdmm + drb * CDMM_DRB_SIZE); 503 acsr = __raw_readl(cdmm + drb * CDMM_DRB_SIZE);
504 type = (acsr & CDMM_ACSR_DEVTYPE) >> CDMM_ACSR_DEVTYPE_SHIFT; 504 type = (acsr & CDMM_ACSR_DEVTYPE) >> CDMM_ACSR_DEVTYPE_SHIFT;
505 size = (acsr & CDMM_ACSR_DEVSIZE) >> CDMM_ACSR_DEVSIZE_SHIFT; 505 size = (acsr & CDMM_ACSR_DEVSIZE) >> CDMM_ACSR_DEVSIZE_SHIFT;
506 rev = (acsr & CDMM_ACSR_DEVREV) >> CDMM_ACSR_DEVREV_SHIFT; 506 rev = (acsr & CDMM_ACSR_DEVREV) >> CDMM_ACSR_DEVREV_SHIFT;
diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index 11f7982cbdb3..ebee57d715d2 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * OMAP L3 Interconnect error handling driver 2 * OMAP L3 Interconnect error handling driver
3 * 3 *
4 * Copyright (C) 2011-2014 Texas Instruments Incorporated - http://www.ti.com/ 4 * Copyright (C) 2011-2015 Texas Instruments Incorporated - http://www.ti.com/
5 * Santosh Shilimkar <santosh.shilimkar@ti.com> 5 * Santosh Shilimkar <santosh.shilimkar@ti.com>
6 * Sricharan <r.sricharan@ti.com> 6 * Sricharan <r.sricharan@ti.com>
7 * 7 *
@@ -233,7 +233,8 @@ static irqreturn_t l3_interrupt_handler(int irq, void *_l3)
233} 233}
234 234
235static const struct of_device_id l3_noc_match[] = { 235static const struct of_device_id l3_noc_match[] = {
236 {.compatible = "ti,omap4-l3-noc", .data = &omap_l3_data}, 236 {.compatible = "ti,omap4-l3-noc", .data = &omap4_l3_data},
237 {.compatible = "ti,omap5-l3-noc", .data = &omap5_l3_data},
237 {.compatible = "ti,dra7-l3-noc", .data = &dra_l3_data}, 238 {.compatible = "ti,dra7-l3-noc", .data = &dra_l3_data},
238 {.compatible = "ti,am4372-l3-noc", .data = &am4372_l3_data}, 239 {.compatible = "ti,am4372-l3-noc", .data = &am4372_l3_data},
239 {}, 240 {},
diff --git a/drivers/bus/omap_l3_noc.h b/drivers/bus/omap_l3_noc.h
index 95254585db86..73431f81da28 100644
--- a/drivers/bus/omap_l3_noc.h
+++ b/drivers/bus/omap_l3_noc.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * OMAP L3 Interconnect error handling driver header 2 * OMAP L3 Interconnect error handling driver header
3 * 3 *
4 * Copyright (C) 2011-2014 Texas Instruments Incorporated - http://www.ti.com/ 4 * Copyright (C) 2011-2015 Texas Instruments Incorporated - http://www.ti.com/
5 * Santosh Shilimkar <santosh.shilimkar@ti.com> 5 * Santosh Shilimkar <santosh.shilimkar@ti.com>
6 * sricharan <r.sricharan@ti.com> 6 * sricharan <r.sricharan@ti.com>
7 * 7 *
@@ -175,16 +175,14 @@ static struct l3_flagmux_data omap_l3_flagmux_clk2 = {
175}; 175};
176 176
177 177
178static struct l3_target_data omap_l3_target_data_clk3[] = { 178static struct l3_target_data omap4_l3_target_data_clk3[] = {
179 {0x0100, "EMUSS",}, 179 {0x0100, "DEBUGSS",},
180 {0x0300, "DEBUG SOURCE",},
181 {0x0, "HOST CLK3",},
182}; 180};
183 181
184static struct l3_flagmux_data omap_l3_flagmux_clk3 = { 182static struct l3_flagmux_data omap4_l3_flagmux_clk3 = {
185 .offset = 0x0200, 183 .offset = 0x0200,
186 .l3_targ = omap_l3_target_data_clk3, 184 .l3_targ = omap4_l3_target_data_clk3,
187 .num_targ_data = ARRAY_SIZE(omap_l3_target_data_clk3), 185 .num_targ_data = ARRAY_SIZE(omap4_l3_target_data_clk3),
188}; 186};
189 187
190static struct l3_masters_data omap_l3_masters[] = { 188static struct l3_masters_data omap_l3_masters[] = {
@@ -215,21 +213,49 @@ static struct l3_masters_data omap_l3_masters[] = {
215 { 0x32, "USBHOSTFS"} 213 { 0x32, "USBHOSTFS"}
216}; 214};
217 215
218static struct l3_flagmux_data *omap_l3_flagmux[] = { 216static struct l3_flagmux_data *omap4_l3_flagmux[] = {
219 &omap_l3_flagmux_clk1, 217 &omap_l3_flagmux_clk1,
220 &omap_l3_flagmux_clk2, 218 &omap_l3_flagmux_clk2,
221 &omap_l3_flagmux_clk3, 219 &omap4_l3_flagmux_clk3,
222}; 220};
223 221
224static const struct omap_l3 omap_l3_data = { 222static const struct omap_l3 omap4_l3_data = {
225 .l3_flagmux = omap_l3_flagmux, 223 .l3_flagmux = omap4_l3_flagmux,
226 .num_modules = ARRAY_SIZE(omap_l3_flagmux), 224 .num_modules = ARRAY_SIZE(omap4_l3_flagmux),
227 .l3_masters = omap_l3_masters, 225 .l3_masters = omap_l3_masters,
228 .num_masters = ARRAY_SIZE(omap_l3_masters), 226 .num_masters = ARRAY_SIZE(omap_l3_masters),
229 /* The 6 MSBs of register field used to distinguish initiator */ 227 /* The 6 MSBs of register field used to distinguish initiator */
230 .mst_addr_mask = 0xFC, 228 .mst_addr_mask = 0xFC,
231}; 229};
232 230
231/* OMAP5 data */
232static struct l3_target_data omap5_l3_target_data_clk3[] = {
233 {0x0100, "L3INSTR",},
234 {0x0300, "DEBUGSS",},
235 {0x0, "HOSTCLK3",},
236};
237
238static struct l3_flagmux_data omap5_l3_flagmux_clk3 = {
239 .offset = 0x0200,
240 .l3_targ = omap5_l3_target_data_clk3,
241 .num_targ_data = ARRAY_SIZE(omap5_l3_target_data_clk3),
242};
243
244static struct l3_flagmux_data *omap5_l3_flagmux[] = {
245 &omap_l3_flagmux_clk1,
246 &omap_l3_flagmux_clk2,
247 &omap5_l3_flagmux_clk3,
248};
249
250static const struct omap_l3 omap5_l3_data = {
251 .l3_flagmux = omap5_l3_flagmux,
252 .num_modules = ARRAY_SIZE(omap5_l3_flagmux),
253 .l3_masters = omap_l3_masters,
254 .num_masters = ARRAY_SIZE(omap_l3_masters),
255 /* The 6 MSBs of register field used to distinguish initiator */
256 .mst_addr_mask = 0x7E0,
257};
258
233/* DRA7 data */ 259/* DRA7 data */
234static struct l3_target_data dra_l3_target_data_clk1[] = { 260static struct l3_target_data dra_l3_target_data_clk1[] = {
235 {0x2a00, "AES1",}, 261 {0x2a00, "AES1",},
@@ -274,7 +300,7 @@ static struct l3_flagmux_data dra_l3_flagmux_clk1 = {
274 300
275static struct l3_target_data dra_l3_target_data_clk2[] = { 301static struct l3_target_data dra_l3_target_data_clk2[] = {
276 {0x0, "HOST CLK1",}, 302 {0x0, "HOST CLK1",},
277 {0x0, "HOST CLK2",}, 303 {0x800000, "HOST CLK2",},
278 {0xdead, L3_TARGET_NOT_SUPPORTED,}, 304 {0xdead, L3_TARGET_NOT_SUPPORTED,},
279 {0x3400, "SHA2_2",}, 305 {0x3400, "SHA2_2",},
280 {0x0900, "BB2D",}, 306 {0x0900, "BB2D",},
diff --git a/drivers/char/hw_random/bcm63xx-rng.c b/drivers/char/hw_random/bcm63xx-rng.c
index d1494ecd9e11..4b31f1387f37 100644
--- a/drivers/char/hw_random/bcm63xx-rng.c
+++ b/drivers/char/hw_random/bcm63xx-rng.c
@@ -57,7 +57,7 @@ static void bcm63xx_rng_cleanup(struct hwrng *rng)
57 val &= ~RNG_EN; 57 val &= ~RNG_EN;
58 __raw_writel(val, priv->regs + RNG_CTRL); 58 __raw_writel(val, priv->regs + RNG_CTRL);
59 59
60 clk_didsable_unprepare(prov->clk); 60 clk_disable_unprepare(priv->clk);
61} 61}
62 62
63static int bcm63xx_rng_data_present(struct hwrng *rng, int wait) 63static int bcm63xx_rng_data_present(struct hwrng *rng, int wait)
@@ -97,14 +97,14 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
97 priv->rng.name = pdev->name; 97 priv->rng.name = pdev->name;
98 priv->rng.init = bcm63xx_rng_init; 98 priv->rng.init = bcm63xx_rng_init;
99 priv->rng.cleanup = bcm63xx_rng_cleanup; 99 priv->rng.cleanup = bcm63xx_rng_cleanup;
100 prov->rng.data_present = bcm63xx_rng_data_present; 100 priv->rng.data_present = bcm63xx_rng_data_present;
101 priv->rng.data_read = bcm63xx_rng_data_read; 101 priv->rng.data_read = bcm63xx_rng_data_read;
102 102
103 priv->clk = devm_clk_get(&pdev->dev, "ipsec"); 103 priv->clk = devm_clk_get(&pdev->dev, "ipsec");
104 if (IS_ERR(priv->clk)) { 104 if (IS_ERR(priv->clk)) {
105 error = PTR_ERR(priv->clk); 105 ret = PTR_ERR(priv->clk);
106 dev_err(&pdev->dev, "no clock for device: %d\n", error); 106 dev_err(&pdev->dev, "no clock for device: %d\n", ret);
107 return error; 107 return ret;
108 } 108 }
109 109
110 if (!devm_request_mem_region(&pdev->dev, r->start, 110 if (!devm_request_mem_region(&pdev->dev, r->start,
@@ -120,11 +120,11 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
120 return -ENOMEM; 120 return -ENOMEM;
121 } 121 }
122 122
123 error = devm_hwrng_register(&pdev->dev, &priv->rng); 123 ret = devm_hwrng_register(&pdev->dev, &priv->rng);
124 if (error) { 124 if (ret) {
125 dev_err(&pdev->dev, "failed to register rng device: %d\n", 125 dev_err(&pdev->dev, "failed to register rng device: %d\n",
126 error); 126 ret);
127 return error; 127 return ret;
128 } 128 }
129 129
130 dev_info(&pdev->dev, "registered RNG driver\n"); 130 dev_info(&pdev->dev, "registered RNG driver\n");
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 9bb592872532..bf75f6361773 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2000,7 +2000,7 @@ static int smi_ipmb_proc_show(struct seq_file *m, void *v)
2000 seq_printf(m, " %x", intf->channels[i].address); 2000 seq_printf(m, " %x", intf->channels[i].address);
2001 seq_putc(m, '\n'); 2001 seq_putc(m, '\n');
2002 2002
2003 return seq_has_overflowed(m); 2003 return 0;
2004} 2004}
2005 2005
2006static int smi_ipmb_proc_open(struct inode *inode, struct file *file) 2006static int smi_ipmb_proc_open(struct inode *inode, struct file *file)
@@ -2023,7 +2023,7 @@ static int smi_version_proc_show(struct seq_file *m, void *v)
2023 ipmi_version_major(&intf->bmc->id), 2023 ipmi_version_major(&intf->bmc->id),
2024 ipmi_version_minor(&intf->bmc->id)); 2024 ipmi_version_minor(&intf->bmc->id));
2025 2025
2026 return seq_has_overflowed(m); 2026 return 0;
2027} 2027}
2028 2028
2029static int smi_version_proc_open(struct inode *inode, struct file *file) 2029static int smi_version_proc_open(struct inode *inode, struct file *file)
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 5e90a18afbaf..8a45e92ff60c 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -942,8 +942,7 @@ static void sender(void *send_info,
942 * If we are running to completion, start it and run 942 * If we are running to completion, start it and run
943 * transactions until everything is clear. 943 * transactions until everything is clear.
944 */ 944 */
945 smi_info->curr_msg = msg; 945 smi_info->waiting_msg = msg;
946 smi_info->waiting_msg = NULL;
947 946
948 /* 947 /*
949 * Run to completion means we are single-threaded, no 948 * Run to completion means we are single-threaded, no
@@ -2244,7 +2243,7 @@ static int ipmi_pnp_probe(struct pnp_dev *dev,
2244 acpi_handle handle; 2243 acpi_handle handle;
2245 acpi_status status; 2244 acpi_status status;
2246 unsigned long long tmp; 2245 unsigned long long tmp;
2247 int rv; 2246 int rv = -EINVAL;
2248 2247
2249 acpi_dev = pnp_acpi_device(dev); 2248 acpi_dev = pnp_acpi_device(dev);
2250 if (!acpi_dev) 2249 if (!acpi_dev)
@@ -2262,8 +2261,10 @@ static int ipmi_pnp_probe(struct pnp_dev *dev,
2262 2261
2263 /* _IFT tells us the interface type: KCS, BT, etc */ 2262 /* _IFT tells us the interface type: KCS, BT, etc */
2264 status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp); 2263 status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp);
2265 if (ACPI_FAILURE(status)) 2264 if (ACPI_FAILURE(status)) {
2265 dev_err(&dev->dev, "Could not find ACPI IPMI interface type\n");
2266 goto err_free; 2266 goto err_free;
2267 }
2267 2268
2268 switch (tmp) { 2269 switch (tmp) {
2269 case 1: 2270 case 1:
@@ -2276,6 +2277,7 @@ static int ipmi_pnp_probe(struct pnp_dev *dev,
2276 info->si_type = SI_BT; 2277 info->si_type = SI_BT;
2277 break; 2278 break;
2278 case 4: /* SSIF, just ignore */ 2279 case 4: /* SSIF, just ignore */
2280 rv = -ENODEV;
2279 goto err_free; 2281 goto err_free;
2280 default: 2282 default:
2281 dev_info(&dev->dev, "unknown IPMI type %lld\n", tmp); 2283 dev_info(&dev->dev, "unknown IPMI type %lld\n", tmp);
@@ -2336,7 +2338,7 @@ static int ipmi_pnp_probe(struct pnp_dev *dev,
2336 2338
2337err_free: 2339err_free:
2338 kfree(info); 2340 kfree(info);
2339 return -EINVAL; 2341 return rv;
2340} 2342}
2341 2343
2342static void ipmi_pnp_remove(struct pnp_dev *dev) 2344static void ipmi_pnp_remove(struct pnp_dev *dev)
@@ -3080,7 +3082,7 @@ static int smi_type_proc_show(struct seq_file *m, void *v)
3080 3082
3081 seq_printf(m, "%s\n", si_to_str[smi->si_type]); 3083 seq_printf(m, "%s\n", si_to_str[smi->si_type]);
3082 3084
3083 return seq_has_overflowed(m); 3085 return 0;
3084} 3086}
3085 3087
3086static int smi_type_proc_open(struct inode *inode, struct file *file) 3088static int smi_type_proc_open(struct inode *inode, struct file *file)
@@ -3153,7 +3155,7 @@ static int smi_params_proc_show(struct seq_file *m, void *v)
3153 smi->irq, 3155 smi->irq,
3154 smi->slave_addr); 3156 smi->slave_addr);
3155 3157
3156 return seq_has_overflowed(m); 3158 return 0;
3157} 3159}
3158 3160
3159static int smi_params_proc_open(struct inode *inode, struct file *file) 3161static int smi_params_proc_open(struct inode *inode, struct file *file)
diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index f40e3bd2c69c..207689c444a8 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -31,7 +31,6 @@
31 * interface into the I2C driver, I believe. 31 * interface into the I2C driver, I believe.
32 */ 32 */
33 33
34#include <linux/version.h>
35#if defined(MODVERSIONS) 34#if defined(MODVERSIONS)
36#include <linux/modversions.h> 35#include <linux/modversions.h>
37#endif 36#endif
@@ -166,6 +165,9 @@ enum ssif_stat_indexes {
166 /* Number of watchdog pretimeouts. */ 165 /* Number of watchdog pretimeouts. */
167 SSIF_STAT_watchdog_pretimeouts, 166 SSIF_STAT_watchdog_pretimeouts,
168 167
168 /* Number of alers received. */
169 SSIF_STAT_alerts,
170
169 /* Always add statistics before this value, it must be last. */ 171 /* Always add statistics before this value, it must be last. */
170 SSIF_NUM_STATS 172 SSIF_NUM_STATS
171}; 173};
@@ -214,7 +216,16 @@ struct ssif_info {
214#define WDT_PRE_TIMEOUT_INT 0x08 216#define WDT_PRE_TIMEOUT_INT 0x08
215 unsigned char msg_flags; 217 unsigned char msg_flags;
216 218
219 u8 global_enables;
217 bool has_event_buffer; 220 bool has_event_buffer;
221 bool supports_alert;
222
223 /*
224 * Used to tell what we should do with alerts. If we are
225 * waiting on a response, read the data immediately.
226 */
227 bool got_alert;
228 bool waiting_alert;
218 229
219 /* 230 /*
220 * If set to true, this will request events the next time the 231 * If set to true, this will request events the next time the
@@ -478,13 +489,13 @@ static int ipmi_ssif_thread(void *data)
478 489
479 if (ssif_info->i2c_read_write == I2C_SMBUS_WRITE) { 490 if (ssif_info->i2c_read_write == I2C_SMBUS_WRITE) {
480 result = i2c_smbus_write_block_data( 491 result = i2c_smbus_write_block_data(
481 ssif_info->client, SSIF_IPMI_REQUEST, 492 ssif_info->client, ssif_info->i2c_command,
482 ssif_info->i2c_data[0], 493 ssif_info->i2c_data[0],
483 ssif_info->i2c_data + 1); 494 ssif_info->i2c_data + 1);
484 ssif_info->done_handler(ssif_info, result, NULL, 0); 495 ssif_info->done_handler(ssif_info, result, NULL, 0);
485 } else { 496 } else {
486 result = i2c_smbus_read_block_data( 497 result = i2c_smbus_read_block_data(
487 ssif_info->client, SSIF_IPMI_RESPONSE, 498 ssif_info->client, ssif_info->i2c_command,
488 ssif_info->i2c_data); 499 ssif_info->i2c_data);
489 if (result < 0) 500 if (result < 0)
490 ssif_info->done_handler(ssif_info, result, 501 ssif_info->done_handler(ssif_info, result,
@@ -518,15 +529,12 @@ static int ssif_i2c_send(struct ssif_info *ssif_info,
518static void msg_done_handler(struct ssif_info *ssif_info, int result, 529static void msg_done_handler(struct ssif_info *ssif_info, int result,
519 unsigned char *data, unsigned int len); 530 unsigned char *data, unsigned int len);
520 531
521static void retry_timeout(unsigned long data) 532static void start_get(struct ssif_info *ssif_info)
522{ 533{
523 struct ssif_info *ssif_info = (void *) data;
524 int rv; 534 int rv;
525 535
526 if (ssif_info->stopping)
527 return;
528
529 ssif_info->rtc_us_timer = 0; 536 ssif_info->rtc_us_timer = 0;
537 ssif_info->multi_pos = 0;
530 538
531 rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ, 539 rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
532 SSIF_IPMI_RESPONSE, 540 SSIF_IPMI_RESPONSE,
@@ -540,6 +548,46 @@ static void retry_timeout(unsigned long data)
540 } 548 }
541} 549}
542 550
551static void retry_timeout(unsigned long data)
552{
553 struct ssif_info *ssif_info = (void *) data;
554 unsigned long oflags, *flags;
555 bool waiting;
556
557 if (ssif_info->stopping)
558 return;
559
560 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
561 waiting = ssif_info->waiting_alert;
562 ssif_info->waiting_alert = false;
563 ipmi_ssif_unlock_cond(ssif_info, flags);
564
565 if (waiting)
566 start_get(ssif_info);
567}
568
569
570static void ssif_alert(struct i2c_client *client, unsigned int data)
571{
572 struct ssif_info *ssif_info = i2c_get_clientdata(client);
573 unsigned long oflags, *flags;
574 bool do_get = false;
575
576 ssif_inc_stat(ssif_info, alerts);
577
578 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
579 if (ssif_info->waiting_alert) {
580 ssif_info->waiting_alert = false;
581 del_timer(&ssif_info->retry_timer);
582 do_get = true;
583 } else if (ssif_info->curr_msg) {
584 ssif_info->got_alert = true;
585 }
586 ipmi_ssif_unlock_cond(ssif_info, flags);
587 if (do_get)
588 start_get(ssif_info);
589}
590
543static int start_resend(struct ssif_info *ssif_info); 591static int start_resend(struct ssif_info *ssif_info);
544 592
545static void msg_done_handler(struct ssif_info *ssif_info, int result, 593static void msg_done_handler(struct ssif_info *ssif_info, int result,
@@ -559,9 +607,12 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
559 if (ssif_info->retries_left > 0) { 607 if (ssif_info->retries_left > 0) {
560 ssif_inc_stat(ssif_info, receive_retries); 608 ssif_inc_stat(ssif_info, receive_retries);
561 609
610 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
611 ssif_info->waiting_alert = true;
612 ssif_info->rtc_us_timer = SSIF_MSG_USEC;
562 mod_timer(&ssif_info->retry_timer, 613 mod_timer(&ssif_info->retry_timer,
563 jiffies + SSIF_MSG_JIFFIES); 614 jiffies + SSIF_MSG_JIFFIES);
564 ssif_info->rtc_us_timer = SSIF_MSG_USEC; 615 ipmi_ssif_unlock_cond(ssif_info, flags);
565 return; 616 return;
566 } 617 }
567 618
@@ -581,9 +632,9 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
581 ssif_inc_stat(ssif_info, received_message_parts); 632 ssif_inc_stat(ssif_info, received_message_parts);
582 633
583 /* Remove the multi-part read marker. */ 634 /* Remove the multi-part read marker. */
584 for (i = 0; i < (len-2); i++)
585 ssif_info->data[i] = data[i+2];
586 len -= 2; 635 len -= 2;
636 for (i = 0; i < len; i++)
637 ssif_info->data[i] = data[i+2];
587 ssif_info->multi_len = len; 638 ssif_info->multi_len = len;
588 ssif_info->multi_pos = 1; 639 ssif_info->multi_pos = 1;
589 640
@@ -610,9 +661,9 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
610 goto continue_op; 661 goto continue_op;
611 } 662 }
612 663
613 blocknum = data[ssif_info->multi_len]; 664 blocknum = data[0];
614 665
615 if (ssif_info->multi_len+len-1 > IPMI_MAX_MSG_LENGTH) { 666 if (ssif_info->multi_len + len - 1 > IPMI_MAX_MSG_LENGTH) {
616 /* Received message too big, abort the operation. */ 667 /* Received message too big, abort the operation. */
617 result = -E2BIG; 668 result = -E2BIG;
618 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) 669 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
@@ -622,15 +673,15 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
622 } 673 }
623 674
624 /* Remove the blocknum from the data. */ 675 /* Remove the blocknum from the data. */
625 for (i = 0; i < (len-1); i++)
626 ssif_info->data[i+ssif_info->multi_len] = data[i+1];
627 len--; 676 len--;
677 for (i = 0; i < len; i++)
678 ssif_info->data[i + ssif_info->multi_len] = data[i + 1];
628 ssif_info->multi_len += len; 679 ssif_info->multi_len += len;
629 if (blocknum == 0xff) { 680 if (blocknum == 0xff) {
630 /* End of read */ 681 /* End of read */
631 len = ssif_info->multi_len; 682 len = ssif_info->multi_len;
632 data = ssif_info->data; 683 data = ssif_info->data;
633 } else if ((blocknum+1) != ssif_info->multi_pos) { 684 } else if (blocknum + 1 != ssif_info->multi_pos) {
634 /* 685 /*
635 * Out of sequence block, just abort. Block 686 * Out of sequence block, just abort. Block
636 * numbers start at zero for the second block, 687 * numbers start at zero for the second block,
@@ -650,7 +701,7 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
650 if (rv < 0) { 701 if (rv < 0) {
651 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) 702 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
652 pr_info(PFX 703 pr_info(PFX
653 "Error from i2c_non_blocking_op(2)\n"); 704 "Error from ssif_i2c_send\n");
654 705
655 result = -EIO; 706 result = -EIO;
656 } else 707 } else
@@ -830,7 +881,11 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result,
830 } 881 }
831 882
832 if (ssif_info->multi_data) { 883 if (ssif_info->multi_data) {
833 /* In the middle of a multi-data write. */ 884 /*
885 * In the middle of a multi-data write. See the comment
886 * in the SSIF_MULTI_n_PART case in the probe function
887 * for details on the intricacies of this.
888 */
834 int left; 889 int left;
835 890
836 ssif_inc_stat(ssif_info, sent_messages_parts); 891 ssif_inc_stat(ssif_info, sent_messages_parts);
@@ -864,15 +919,32 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result,
864 msg_done_handler(ssif_info, -EIO, NULL, 0); 919 msg_done_handler(ssif_info, -EIO, NULL, 0);
865 } 920 }
866 } else { 921 } else {
922 unsigned long oflags, *flags;
923 bool got_alert;
924
867 ssif_inc_stat(ssif_info, sent_messages); 925 ssif_inc_stat(ssif_info, sent_messages);
868 ssif_inc_stat(ssif_info, sent_messages_parts); 926 ssif_inc_stat(ssif_info, sent_messages_parts);
869 927
870 /* Wait a jiffie then request the next message */ 928 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
871 ssif_info->retries_left = SSIF_RECV_RETRIES; 929 got_alert = ssif_info->got_alert;
872 ssif_info->rtc_us_timer = SSIF_MSG_PART_USEC; 930 if (got_alert) {
873 mod_timer(&ssif_info->retry_timer, 931 ssif_info->got_alert = false;
874 jiffies + SSIF_MSG_PART_JIFFIES); 932 ssif_info->waiting_alert = false;
875 return; 933 }
934
935 if (got_alert) {
936 ipmi_ssif_unlock_cond(ssif_info, flags);
937 /* The alert already happened, try now. */
938 retry_timeout((unsigned long) ssif_info);
939 } else {
940 /* Wait a jiffie then request the next message */
941 ssif_info->waiting_alert = true;
942 ssif_info->retries_left = SSIF_RECV_RETRIES;
943 ssif_info->rtc_us_timer = SSIF_MSG_PART_USEC;
944 mod_timer(&ssif_info->retry_timer,
945 jiffies + SSIF_MSG_PART_JIFFIES);
946 ipmi_ssif_unlock_cond(ssif_info, flags);
947 }
876 } 948 }
877} 949}
878 950
@@ -881,6 +953,8 @@ static int start_resend(struct ssif_info *ssif_info)
881 int rv; 953 int rv;
882 int command; 954 int command;
883 955
956 ssif_info->got_alert = false;
957
884 if (ssif_info->data_len > 32) { 958 if (ssif_info->data_len > 32) {
885 command = SSIF_IPMI_MULTI_PART_REQUEST_START; 959 command = SSIF_IPMI_MULTI_PART_REQUEST_START;
886 ssif_info->multi_data = ssif_info->data; 960 ssif_info->multi_data = ssif_info->data;
@@ -915,7 +989,7 @@ static int start_send(struct ssif_info *ssif_info,
915 return -E2BIG; 989 return -E2BIG;
916 990
917 ssif_info->retries_left = SSIF_SEND_RETRIES; 991 ssif_info->retries_left = SSIF_SEND_RETRIES;
918 memcpy(ssif_info->data+1, data, len); 992 memcpy(ssif_info->data + 1, data, len);
919 ssif_info->data_len = len; 993 ssif_info->data_len = len;
920 return start_resend(ssif_info); 994 return start_resend(ssif_info);
921} 995}
@@ -1200,7 +1274,7 @@ static int smi_type_proc_show(struct seq_file *m, void *v)
1200{ 1274{
1201 seq_puts(m, "ssif\n"); 1275 seq_puts(m, "ssif\n");
1202 1276
1203 return seq_has_overflowed(m); 1277 return 0;
1204} 1278}
1205 1279
1206static int smi_type_proc_open(struct inode *inode, struct file *file) 1280static int smi_type_proc_open(struct inode *inode, struct file *file)
@@ -1243,6 +1317,8 @@ static int smi_stats_proc_show(struct seq_file *m, void *v)
1243 ssif_get_stat(ssif_info, events)); 1317 ssif_get_stat(ssif_info, events));
1244 seq_printf(m, "watchdog_pretimeouts: %u\n", 1318 seq_printf(m, "watchdog_pretimeouts: %u\n",
1245 ssif_get_stat(ssif_info, watchdog_pretimeouts)); 1319 ssif_get_stat(ssif_info, watchdog_pretimeouts));
1320 seq_printf(m, "alerts: %u\n",
1321 ssif_get_stat(ssif_info, alerts));
1246 return 0; 1322 return 0;
1247} 1323}
1248 1324
@@ -1258,6 +1334,23 @@ static const struct file_operations smi_stats_proc_ops = {
1258 .release = single_release, 1334 .release = single_release,
1259}; 1335};
1260 1336
1337static int strcmp_nospace(char *s1, char *s2)
1338{
1339 while (*s1 && *s2) {
1340 while (isspace(*s1))
1341 s1++;
1342 while (isspace(*s2))
1343 s2++;
1344 if (*s1 > *s2)
1345 return 1;
1346 if (*s1 < *s2)
1347 return -1;
1348 s1++;
1349 s2++;
1350 }
1351 return 0;
1352}
1353
1261static struct ssif_addr_info *ssif_info_find(unsigned short addr, 1354static struct ssif_addr_info *ssif_info_find(unsigned short addr,
1262 char *adapter_name, 1355 char *adapter_name,
1263 bool match_null_name) 1356 bool match_null_name)
@@ -1272,8 +1365,10 @@ restart:
1272 /* One is NULL and one is not */ 1365 /* One is NULL and one is not */
1273 continue; 1366 continue;
1274 } 1367 }
1275 if (strcmp(info->adapter_name, adapter_name)) 1368 if (adapter_name &&
1276 /* Names to not match */ 1369 strcmp_nospace(info->adapter_name,
1370 adapter_name))
1371 /* Names do not match */
1277 continue; 1372 continue;
1278 } 1373 }
1279 found = info; 1374 found = info;
@@ -1306,6 +1401,12 @@ static bool check_acpi(struct ssif_info *ssif_info, struct device *dev)
1306 return false; 1401 return false;
1307} 1402}
1308 1403
1404/*
1405 * Global enables we care about.
1406 */
1407#define GLOBAL_ENABLES_MASK (IPMI_BMC_EVT_MSG_BUFF | IPMI_BMC_RCV_MSG_INTR | \
1408 IPMI_BMC_EVT_MSG_INTR)
1409
1309static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) 1410static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1310{ 1411{
1311 unsigned char msg[3]; 1412 unsigned char msg[3];
@@ -1391,13 +1492,33 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1391 break; 1492 break;
1392 1493
1393 case SSIF_MULTI_2_PART: 1494 case SSIF_MULTI_2_PART:
1394 if (ssif_info->max_xmit_msg_size > 64) 1495 if (ssif_info->max_xmit_msg_size > 63)
1395 ssif_info->max_xmit_msg_size = 64; 1496 ssif_info->max_xmit_msg_size = 63;
1396 if (ssif_info->max_recv_msg_size > 62) 1497 if (ssif_info->max_recv_msg_size > 62)
1397 ssif_info->max_recv_msg_size = 62; 1498 ssif_info->max_recv_msg_size = 62;
1398 break; 1499 break;
1399 1500
1400 case SSIF_MULTI_n_PART: 1501 case SSIF_MULTI_n_PART:
1502 /*
1503 * The specification is rather confusing at
1504 * this point, but I think I understand what
1505 * is meant. At least I have a workable
1506 * solution. With multi-part messages, you
1507 * cannot send a message that is a multiple of
1508 * 32-bytes in length, because the start and
1509 * middle messages are 32-bytes and the end
1510 * message must be at least one byte. You
1511 * can't fudge on an extra byte, that would
1512 * screw up things like fru data writes. So
1513 * we limit the length to 63 bytes. That way
1514 * a 32-byte message gets sent as a single
1515 * part. A larger message will be a 32-byte
1516 * start and the next message is always going
1517 * to be 1-31 bytes in length. Not ideal, but
1518 * it should work.
1519 */
1520 if (ssif_info->max_xmit_msg_size > 63)
1521 ssif_info->max_xmit_msg_size = 63;
1401 break; 1522 break;
1402 1523
1403 default: 1524 default:
@@ -1407,7 +1528,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1407 } else { 1528 } else {
1408 no_support: 1529 no_support:
1409 /* Assume no multi-part or PEC support */ 1530 /* Assume no multi-part or PEC support */
1410 pr_info(PFX "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n", 1531 pr_info(PFX "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n",
1411 rv, len, resp[2]); 1532 rv, len, resp[2]);
1412 1533
1413 ssif_info->max_xmit_msg_size = 32; 1534 ssif_info->max_xmit_msg_size = 32;
@@ -1436,6 +1557,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1436 goto found; 1557 goto found;
1437 } 1558 }
1438 1559
1560 ssif_info->global_enables = resp[3];
1561
1439 if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) { 1562 if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) {
1440 ssif_info->has_event_buffer = true; 1563 ssif_info->has_event_buffer = true;
1441 /* buffer is already enabled, nothing to do. */ 1564 /* buffer is already enabled, nothing to do. */
@@ -1444,18 +1567,37 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1444 1567
1445 msg[0] = IPMI_NETFN_APP_REQUEST << 2; 1568 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1446 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; 1569 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
1447 msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF; 1570 msg[2] = ssif_info->global_enables | IPMI_BMC_EVT_MSG_BUFF;
1448 rv = do_cmd(client, 3, msg, &len, resp); 1571 rv = do_cmd(client, 3, msg, &len, resp);
1449 if (rv || (len < 2)) { 1572 if (rv || (len < 2)) {
1450 pr_warn(PFX "Error getting global enables: %d %d %2.2x\n", 1573 pr_warn(PFX "Error setting global enables: %d %d %2.2x\n",
1451 rv, len, resp[2]); 1574 rv, len, resp[2]);
1452 rv = 0; /* Not fatal */ 1575 rv = 0; /* Not fatal */
1453 goto found; 1576 goto found;
1454 } 1577 }
1455 1578
1456 if (resp[2] == 0) 1579 if (resp[2] == 0) {
1457 /* A successful return means the event buffer is supported. */ 1580 /* A successful return means the event buffer is supported. */
1458 ssif_info->has_event_buffer = true; 1581 ssif_info->has_event_buffer = true;
1582 ssif_info->global_enables |= IPMI_BMC_EVT_MSG_BUFF;
1583 }
1584
1585 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1586 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
1587 msg[2] = ssif_info->global_enables | IPMI_BMC_RCV_MSG_INTR;
1588 rv = do_cmd(client, 3, msg, &len, resp);
1589 if (rv || (len < 2)) {
1590 pr_warn(PFX "Error setting global enables: %d %d %2.2x\n",
1591 rv, len, resp[2]);
1592 rv = 0; /* Not fatal */
1593 goto found;
1594 }
1595
1596 if (resp[2] == 0) {
1597 /* A successful return means the alert is supported. */
1598 ssif_info->supports_alert = true;
1599 ssif_info->global_enables |= IPMI_BMC_RCV_MSG_INTR;
1600 }
1459 1601
1460 found: 1602 found:
1461 ssif_info->intf_num = atomic_inc_return(&next_intf); 1603 ssif_info->intf_num = atomic_inc_return(&next_intf);
@@ -1813,6 +1955,7 @@ static struct i2c_driver ssif_i2c_driver = {
1813 }, 1955 },
1814 .probe = ssif_probe, 1956 .probe = ssif_probe,
1815 .remove = ssif_remove, 1957 .remove = ssif_remove,
1958 .alert = ssif_alert,
1816 .id_table = ssif_id, 1959 .id_table = ssif_id,
1817 .detect = ssif_detect 1960 .detect = ssif_detect
1818}; 1961};
@@ -1832,7 +1975,7 @@ static int init_ipmi_ssif(void)
1832 rv = new_ssif_client(addr[i], adapter_name[i], 1975 rv = new_ssif_client(addr[i], adapter_name[i],
1833 dbg[i], slave_addrs[i], 1976 dbg[i], slave_addrs[i],
1834 SI_HARDCODED); 1977 SI_HARDCODED);
1835 if (!rv) 1978 if (rv)
1836 pr_err(PFX 1979 pr_err(PFX
1837 "Couldn't add hardcoded device at addr 0x%x\n", 1980 "Couldn't add hardcoded device at addr 0x%x\n",
1838 addr[i]); 1981 addr[i]);
diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index 44ea107cfc67..30335d3b99af 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1128,13 +1128,6 @@ static int si5351_dt_parse(struct i2c_client *client,
1128 if (!pdata) 1128 if (!pdata)
1129 return -ENOMEM; 1129 return -ENOMEM;
1130 1130
1131 pdata->clk_xtal = of_clk_get(np, 0);
1132 if (!IS_ERR(pdata->clk_xtal))
1133 clk_put(pdata->clk_xtal);
1134 pdata->clk_clkin = of_clk_get(np, 1);
1135 if (!IS_ERR(pdata->clk_clkin))
1136 clk_put(pdata->clk_clkin);
1137
1138 /* 1131 /*
1139 * property silabs,pll-source : <num src>, [<..>] 1132 * property silabs,pll-source : <num src>, [<..>]
1140 * allow to selectively set pll source 1133 * allow to selectively set pll source
@@ -1328,8 +1321,22 @@ static int si5351_i2c_probe(struct i2c_client *client,
1328 i2c_set_clientdata(client, drvdata); 1321 i2c_set_clientdata(client, drvdata);
1329 drvdata->client = client; 1322 drvdata->client = client;
1330 drvdata->variant = variant; 1323 drvdata->variant = variant;
1331 drvdata->pxtal = pdata->clk_xtal; 1324 drvdata->pxtal = devm_clk_get(&client->dev, "xtal");
1332 drvdata->pclkin = pdata->clk_clkin; 1325 drvdata->pclkin = devm_clk_get(&client->dev, "clkin");
1326
1327 if (PTR_ERR(drvdata->pxtal) == -EPROBE_DEFER ||
1328 PTR_ERR(drvdata->pclkin) == -EPROBE_DEFER)
1329 return -EPROBE_DEFER;
1330
1331 /*
1332 * Check for valid parent clock: VARIANT_A and VARIANT_B need XTAL,
1333 * VARIANT_C can have CLKIN instead.
1334 */
1335 if (IS_ERR(drvdata->pxtal) &&
1336 (drvdata->variant != SI5351_VARIANT_C || IS_ERR(drvdata->pclkin))) {
1337 dev_err(&client->dev, "missing parent clock\n");
1338 return -EINVAL;
1339 }
1333 1340
1334 drvdata->regmap = devm_regmap_init_i2c(client, &si5351_regmap_config); 1341 drvdata->regmap = devm_regmap_init_i2c(client, &si5351_regmap_config);
1335 if (IS_ERR(drvdata->regmap)) { 1342 if (IS_ERR(drvdata->regmap)) {
@@ -1393,6 +1400,11 @@ static int si5351_i2c_probe(struct i2c_client *client,
1393 } 1400 }
1394 } 1401 }
1395 1402
1403 if (!IS_ERR(drvdata->pxtal))
1404 clk_prepare_enable(drvdata->pxtal);
1405 if (!IS_ERR(drvdata->pclkin))
1406 clk_prepare_enable(drvdata->pclkin);
1407
1396 /* register xtal input clock gate */ 1408 /* register xtal input clock gate */
1397 memset(&init, 0, sizeof(init)); 1409 memset(&init, 0, sizeof(init));
1398 init.name = si5351_input_names[0]; 1410 init.name = si5351_input_names[0];
@@ -1407,7 +1419,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
1407 clk = devm_clk_register(&client->dev, &drvdata->xtal); 1419 clk = devm_clk_register(&client->dev, &drvdata->xtal);
1408 if (IS_ERR(clk)) { 1420 if (IS_ERR(clk)) {
1409 dev_err(&client->dev, "unable to register %s\n", init.name); 1421 dev_err(&client->dev, "unable to register %s\n", init.name);
1410 return PTR_ERR(clk); 1422 ret = PTR_ERR(clk);
1423 goto err_clk;
1411 } 1424 }
1412 1425
1413 /* register clkin input clock gate */ 1426 /* register clkin input clock gate */
@@ -1425,7 +1438,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
1425 if (IS_ERR(clk)) { 1438 if (IS_ERR(clk)) {
1426 dev_err(&client->dev, "unable to register %s\n", 1439 dev_err(&client->dev, "unable to register %s\n",
1427 init.name); 1440 init.name);
1428 return PTR_ERR(clk); 1441 ret = PTR_ERR(clk);
1442 goto err_clk;
1429 } 1443 }
1430 } 1444 }
1431 1445
@@ -1447,7 +1461,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
1447 clk = devm_clk_register(&client->dev, &drvdata->pll[0].hw); 1461 clk = devm_clk_register(&client->dev, &drvdata->pll[0].hw);
1448 if (IS_ERR(clk)) { 1462 if (IS_ERR(clk)) {
1449 dev_err(&client->dev, "unable to register %s\n", init.name); 1463 dev_err(&client->dev, "unable to register %s\n", init.name);
1450 return -EINVAL; 1464 ret = PTR_ERR(clk);
1465 goto err_clk;
1451 } 1466 }
1452 1467
1453 /* register PLLB or VXCO (Si5351B) */ 1468 /* register PLLB or VXCO (Si5351B) */
@@ -1471,7 +1486,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
1471 clk = devm_clk_register(&client->dev, &drvdata->pll[1].hw); 1486 clk = devm_clk_register(&client->dev, &drvdata->pll[1].hw);
1472 if (IS_ERR(clk)) { 1487 if (IS_ERR(clk)) {
1473 dev_err(&client->dev, "unable to register %s\n", init.name); 1488 dev_err(&client->dev, "unable to register %s\n", init.name);
1474 return -EINVAL; 1489 ret = PTR_ERR(clk);
1490 goto err_clk;
1475 } 1491 }
1476 1492
1477 /* register clk multisync and clk out divider */ 1493 /* register clk multisync and clk out divider */
@@ -1492,8 +1508,10 @@ static int si5351_i2c_probe(struct i2c_client *client,
1492 num_clocks * sizeof(*drvdata->onecell.clks), GFP_KERNEL); 1508 num_clocks * sizeof(*drvdata->onecell.clks), GFP_KERNEL);
1493 1509
1494 if (WARN_ON(!drvdata->msynth || !drvdata->clkout || 1510 if (WARN_ON(!drvdata->msynth || !drvdata->clkout ||
1495 !drvdata->onecell.clks)) 1511 !drvdata->onecell.clks)) {
1496 return -ENOMEM; 1512 ret = -ENOMEM;
1513 goto err_clk;
1514 }
1497 1515
1498 for (n = 0; n < num_clocks; n++) { 1516 for (n = 0; n < num_clocks; n++) {
1499 drvdata->msynth[n].num = n; 1517 drvdata->msynth[n].num = n;
@@ -1511,7 +1529,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
1511 if (IS_ERR(clk)) { 1529 if (IS_ERR(clk)) {
1512 dev_err(&client->dev, "unable to register %s\n", 1530 dev_err(&client->dev, "unable to register %s\n",
1513 init.name); 1531 init.name);
1514 return -EINVAL; 1532 ret = PTR_ERR(clk);
1533 goto err_clk;
1515 } 1534 }
1516 } 1535 }
1517 1536
@@ -1538,7 +1557,8 @@ static int si5351_i2c_probe(struct i2c_client *client,
1538 if (IS_ERR(clk)) { 1557 if (IS_ERR(clk)) {
1539 dev_err(&client->dev, "unable to register %s\n", 1558 dev_err(&client->dev, "unable to register %s\n",
1540 init.name); 1559 init.name);
1541 return -EINVAL; 1560 ret = PTR_ERR(clk);
1561 goto err_clk;
1542 } 1562 }
1543 drvdata->onecell.clks[n] = clk; 1563 drvdata->onecell.clks[n] = clk;
1544 1564
@@ -1557,10 +1577,17 @@ static int si5351_i2c_probe(struct i2c_client *client,
1557 &drvdata->onecell); 1577 &drvdata->onecell);
1558 if (ret) { 1578 if (ret) {
1559 dev_err(&client->dev, "unable to add clk provider\n"); 1579 dev_err(&client->dev, "unable to add clk provider\n");
1560 return ret; 1580 goto err_clk;
1561 } 1581 }
1562 1582
1563 return 0; 1583 return 0;
1584
1585err_clk:
1586 if (!IS_ERR(drvdata->pxtal))
1587 clk_disable_unprepare(drvdata->pxtal);
1588 if (!IS_ERR(drvdata->pclkin))
1589 clk_disable_unprepare(drvdata->pclkin);
1590 return ret;
1564} 1591}
1565 1592
1566static const struct i2c_device_id si5351_i2c_ids[] = { 1593static const struct i2c_device_id si5351_i2c_ids[] = {
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 459ce9da13e0..5b0f41868b42 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1475,8 +1475,10 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *clk,
1475 */ 1475 */
1476 if (clk->prepare_count) { 1476 if (clk->prepare_count) {
1477 clk_core_prepare(parent); 1477 clk_core_prepare(parent);
1478 flags = clk_enable_lock();
1478 clk_core_enable(parent); 1479 clk_core_enable(parent);
1479 clk_core_enable(clk); 1480 clk_core_enable(clk);
1481 clk_enable_unlock(flags);
1480 } 1482 }
1481 1483
1482 /* update the clk tree topology */ 1484 /* update the clk tree topology */
@@ -1491,13 +1493,17 @@ static void __clk_set_parent_after(struct clk_core *core,
1491 struct clk_core *parent, 1493 struct clk_core *parent,
1492 struct clk_core *old_parent) 1494 struct clk_core *old_parent)
1493{ 1495{
1496 unsigned long flags;
1497
1494 /* 1498 /*
1495 * Finish the migration of prepare state and undo the changes done 1499 * Finish the migration of prepare state and undo the changes done
1496 * for preventing a race with clk_enable(). 1500 * for preventing a race with clk_enable().
1497 */ 1501 */
1498 if (core->prepare_count) { 1502 if (core->prepare_count) {
1503 flags = clk_enable_lock();
1499 clk_core_disable(core); 1504 clk_core_disable(core);
1500 clk_core_disable(old_parent); 1505 clk_core_disable(old_parent);
1506 clk_enable_unlock(flags);
1501 clk_core_unprepare(old_parent); 1507 clk_core_unprepare(old_parent);
1502 } 1508 }
1503} 1509}
@@ -1525,8 +1531,10 @@ static int __clk_set_parent(struct clk_core *clk, struct clk_core *parent,
1525 clk_enable_unlock(flags); 1531 clk_enable_unlock(flags);
1526 1532
1527 if (clk->prepare_count) { 1533 if (clk->prepare_count) {
1534 flags = clk_enable_lock();
1528 clk_core_disable(clk); 1535 clk_core_disable(clk);
1529 clk_core_disable(parent); 1536 clk_core_disable(parent);
1537 clk_enable_unlock(flags);
1530 clk_core_unprepare(parent); 1538 clk_core_unprepare(parent);
1531 } 1539 }
1532 return ret; 1540 return ret;
diff --git a/drivers/clk/qcom/gcc-msm8916.c b/drivers/clk/qcom/gcc-msm8916.c
index d3458474eb3a..c66f7bc2ae87 100644
--- a/drivers/clk/qcom/gcc-msm8916.c
+++ b/drivers/clk/qcom/gcc-msm8916.c
@@ -71,8 +71,8 @@ static const char *gcc_xo_gpll0_bimc[] = {
71static const struct parent_map gcc_xo_gpll0a_gpll1_gpll2a_map[] = { 71static const struct parent_map gcc_xo_gpll0a_gpll1_gpll2a_map[] = {
72 { P_XO, 0 }, 72 { P_XO, 0 },
73 { P_GPLL0_AUX, 3 }, 73 { P_GPLL0_AUX, 3 },
74 { P_GPLL2_AUX, 2 },
75 { P_GPLL1, 1 }, 74 { P_GPLL1, 1 },
75 { P_GPLL2_AUX, 2 },
76}; 76};
77 77
78static const char *gcc_xo_gpll0a_gpll1_gpll2a[] = { 78static const char *gcc_xo_gpll0a_gpll1_gpll2a[] = {
@@ -1115,7 +1115,7 @@ static struct clk_rcg2 usb_hs_system_clk_src = {
1115static const struct freq_tbl ftbl_gcc_venus0_vcodec0_clk[] = { 1115static const struct freq_tbl ftbl_gcc_venus0_vcodec0_clk[] = {
1116 F(100000000, P_GPLL0, 8, 0, 0), 1116 F(100000000, P_GPLL0, 8, 0, 0),
1117 F(160000000, P_GPLL0, 5, 0, 0), 1117 F(160000000, P_GPLL0, 5, 0, 0),
1118 F(228570000, P_GPLL0, 5, 0, 0), 1118 F(228570000, P_GPLL0, 3.5, 0, 0),
1119 { } 1119 { }
1120}; 1120};
1121 1121
diff --git a/drivers/clk/samsung/Makefile b/drivers/clk/samsung/Makefile
index 17e9af7fe81f..a17683b2cf27 100644
--- a/drivers/clk/samsung/Makefile
+++ b/drivers/clk/samsung/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_SOC_EXYNOS5250) += clk-exynos5250.o
10obj-$(CONFIG_SOC_EXYNOS5260) += clk-exynos5260.o 10obj-$(CONFIG_SOC_EXYNOS5260) += clk-exynos5260.o
11obj-$(CONFIG_SOC_EXYNOS5410) += clk-exynos5410.o 11obj-$(CONFIG_SOC_EXYNOS5410) += clk-exynos5410.o
12obj-$(CONFIG_SOC_EXYNOS5420) += clk-exynos5420.o 12obj-$(CONFIG_SOC_EXYNOS5420) += clk-exynos5420.o
13obj-$(CONFIG_ARCH_EXYNOS5433) += clk-exynos5433.o 13obj-$(CONFIG_ARCH_EXYNOS) += clk-exynos5433.o
14obj-$(CONFIG_SOC_EXYNOS5440) += clk-exynos5440.o 14obj-$(CONFIG_SOC_EXYNOS5440) += clk-exynos5440.o
15obj-$(CONFIG_ARCH_EXYNOS) += clk-exynos-audss.o 15obj-$(CONFIG_ARCH_EXYNOS) += clk-exynos-audss.o
16obj-$(CONFIG_ARCH_EXYNOS) += clk-exynos-clkout.o 16obj-$(CONFIG_ARCH_EXYNOS) += clk-exynos-clkout.o
diff --git a/drivers/clk/samsung/clk-exynos5420.c b/drivers/clk/samsung/clk-exynos5420.c
index 07d666cc6a29..bea4a173eef5 100644
--- a/drivers/clk/samsung/clk-exynos5420.c
+++ b/drivers/clk/samsung/clk-exynos5420.c
@@ -271,6 +271,7 @@ static const struct samsung_clk_reg_dump exynos5420_set_clksrc[] = {
271 { .offset = SRC_MASK_PERIC0, .value = 0x11111110, }, 271 { .offset = SRC_MASK_PERIC0, .value = 0x11111110, },
272 { .offset = SRC_MASK_PERIC1, .value = 0x11111100, }, 272 { .offset = SRC_MASK_PERIC1, .value = 0x11111100, },
273 { .offset = SRC_MASK_ISP, .value = 0x11111000, }, 273 { .offset = SRC_MASK_ISP, .value = 0x11111000, },
274 { .offset = GATE_BUS_TOP, .value = 0xffffffff, },
274 { .offset = GATE_BUS_DISP1, .value = 0xffffffff, }, 275 { .offset = GATE_BUS_DISP1, .value = 0xffffffff, },
275 { .offset = GATE_IP_PERIC, .value = 0xffffffff, }, 276 { .offset = GATE_IP_PERIC, .value = 0xffffffff, },
276}; 277};
diff --git a/drivers/clk/samsung/clk-exynos5433.c b/drivers/clk/samsung/clk-exynos5433.c
index 387e3e39e635..9e04ae2bb4d7 100644
--- a/drivers/clk/samsung/clk-exynos5433.c
+++ b/drivers/clk/samsung/clk-exynos5433.c
@@ -748,7 +748,7 @@ static struct samsung_pll_rate_table exynos5443_pll_rates[] = {
748 PLL_35XX_RATE(825000000U, 275, 4, 1), 748 PLL_35XX_RATE(825000000U, 275, 4, 1),
749 PLL_35XX_RATE(800000000U, 400, 6, 1), 749 PLL_35XX_RATE(800000000U, 400, 6, 1),
750 PLL_35XX_RATE(733000000U, 733, 12, 1), 750 PLL_35XX_RATE(733000000U, 733, 12, 1),
751 PLL_35XX_RATE(700000000U, 360, 6, 1), 751 PLL_35XX_RATE(700000000U, 175, 3, 1),
752 PLL_35XX_RATE(667000000U, 222, 4, 1), 752 PLL_35XX_RATE(667000000U, 222, 4, 1),
753 PLL_35XX_RATE(633000000U, 211, 4, 1), 753 PLL_35XX_RATE(633000000U, 211, 4, 1),
754 PLL_35XX_RATE(600000000U, 500, 5, 2), 754 PLL_35XX_RATE(600000000U, 500, 5, 2),
@@ -760,14 +760,14 @@ static struct samsung_pll_rate_table exynos5443_pll_rates[] = {
760 PLL_35XX_RATE(444000000U, 370, 5, 2), 760 PLL_35XX_RATE(444000000U, 370, 5, 2),
761 PLL_35XX_RATE(420000000U, 350, 5, 2), 761 PLL_35XX_RATE(420000000U, 350, 5, 2),
762 PLL_35XX_RATE(400000000U, 400, 6, 2), 762 PLL_35XX_RATE(400000000U, 400, 6, 2),
763 PLL_35XX_RATE(350000000U, 360, 6, 2), 763 PLL_35XX_RATE(350000000U, 350, 6, 2),
764 PLL_35XX_RATE(333000000U, 222, 4, 2), 764 PLL_35XX_RATE(333000000U, 222, 4, 2),
765 PLL_35XX_RATE(300000000U, 500, 5, 3), 765 PLL_35XX_RATE(300000000U, 500, 5, 3),
766 PLL_35XX_RATE(266000000U, 532, 6, 3), 766 PLL_35XX_RATE(266000000U, 532, 6, 3),
767 PLL_35XX_RATE(200000000U, 400, 6, 3), 767 PLL_35XX_RATE(200000000U, 400, 6, 3),
768 PLL_35XX_RATE(166000000U, 332, 6, 3), 768 PLL_35XX_RATE(166000000U, 332, 6, 3),
769 PLL_35XX_RATE(160000000U, 320, 6, 3), 769 PLL_35XX_RATE(160000000U, 320, 6, 3),
770 PLL_35XX_RATE(133000000U, 552, 6, 4), 770 PLL_35XX_RATE(133000000U, 532, 6, 4),
771 PLL_35XX_RATE(100000000U, 400, 6, 4), 771 PLL_35XX_RATE(100000000U, 400, 6, 4),
772 { /* sentinel */ } 772 { /* sentinel */ }
773}; 773};
@@ -1490,7 +1490,7 @@ static struct samsung_gate_clock mif_gate_clks[] __initdata = {
1490 1490
1491 /* ENABLE_PCLK_MIF_SECURE_MONOTONIC_CNT */ 1491 /* ENABLE_PCLK_MIF_SECURE_MONOTONIC_CNT */
1492 GATE(CLK_PCLK_MONOTONIC_CNT, "pclk_monotonic_cnt", "div_aclk_mif_133", 1492 GATE(CLK_PCLK_MONOTONIC_CNT, "pclk_monotonic_cnt", "div_aclk_mif_133",
1493 ENABLE_PCLK_MIF_SECURE_RTC, 0, 0, 0), 1493 ENABLE_PCLK_MIF_SECURE_MONOTONIC_CNT, 0, 0, 0),
1494 1494
1495 /* ENABLE_PCLK_MIF_SECURE_RTC */ 1495 /* ENABLE_PCLK_MIF_SECURE_RTC */
1496 GATE(CLK_PCLK_RTC, "pclk_rtc", "div_aclk_mif_133", 1496 GATE(CLK_PCLK_RTC, "pclk_rtc", "div_aclk_mif_133",
@@ -3665,7 +3665,7 @@ static struct samsung_gate_clock apollo_gate_clks[] __initdata = {
3665 ENABLE_SCLK_APOLLO, 3, CLK_IGNORE_UNUSED, 0), 3665 ENABLE_SCLK_APOLLO, 3, CLK_IGNORE_UNUSED, 0),
3666 GATE(CLK_SCLK_HPM_APOLLO, "sclk_hpm_apollo", "div_sclk_hpm_apollo", 3666 GATE(CLK_SCLK_HPM_APOLLO, "sclk_hpm_apollo", "div_sclk_hpm_apollo",
3667 ENABLE_SCLK_APOLLO, 1, CLK_IGNORE_UNUSED, 0), 3667 ENABLE_SCLK_APOLLO, 1, CLK_IGNORE_UNUSED, 0),
3668 GATE(CLK_SCLK_APOLLO, "sclk_apollo", "div_apollo_pll", 3668 GATE(CLK_SCLK_APOLLO, "sclk_apollo", "div_apollo2",
3669 ENABLE_SCLK_APOLLO, 0, CLK_IGNORE_UNUSED, 0), 3669 ENABLE_SCLK_APOLLO, 0, CLK_IGNORE_UNUSED, 0),
3670}; 3670};
3671 3671
@@ -3927,7 +3927,7 @@ CLK_OF_DECLARE(exynos5433_cmu_atlas, "samsung,exynos5433-cmu-atlas",
3927#define ENABLE_PCLK_MSCL 0x0900 3927#define ENABLE_PCLK_MSCL 0x0900
3928#define ENABLE_PCLK_MSCL_SECURE_SMMU_M2MSCALER0 0x0904 3928#define ENABLE_PCLK_MSCL_SECURE_SMMU_M2MSCALER0 0x0904
3929#define ENABLE_PCLK_MSCL_SECURE_SMMU_M2MSCALER1 0x0908 3929#define ENABLE_PCLK_MSCL_SECURE_SMMU_M2MSCALER1 0x0908
3930#define ENABLE_PCLK_MSCL_SECURE_SMMU_JPEG 0x000c 3930#define ENABLE_PCLK_MSCL_SECURE_SMMU_JPEG 0x090c
3931#define ENABLE_SCLK_MSCL 0x0a00 3931#define ENABLE_SCLK_MSCL 0x0a00
3932#define ENABLE_IP_MSCL0 0x0b00 3932#define ENABLE_IP_MSCL0 0x0b00
3933#define ENABLE_IP_MSCL1 0x0b04 3933#define ENABLE_IP_MSCL1 0x0b04
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 7a73a279e179..61c417b9e53f 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
158 int entered_state; 158 int entered_state;
159 159
160 struct cpuidle_state *target_state = &drv->states[index]; 160 struct cpuidle_state *target_state = &drv->states[index];
161 bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
161 ktime_t time_start, time_end; 162 ktime_t time_start, time_end;
162 s64 diff; 163 s64 diff;
163 164
165 /*
166 * Tell the time framework to switch to a broadcast timer because our
167 * local timer will be shut down. If a local timer is used from another
168 * CPU as a broadcast timer, this call may fail if it is not available.
169 */
170 if (broadcast && tick_broadcast_enter())
171 return -EBUSY;
172
164 trace_cpu_idle_rcuidle(index, dev->cpu); 173 trace_cpu_idle_rcuidle(index, dev->cpu);
165 time_start = ktime_get(); 174 time_start = ktime_get();
166 175
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
169 time_end = ktime_get(); 178 time_end = ktime_get();
170 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu); 179 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
171 180
181 if (broadcast) {
182 if (WARN_ON_ONCE(!irqs_disabled()))
183 local_irq_disable();
184
185 tick_broadcast_exit();
186 }
187
172 if (!cpuidle_state_is_coupled(dev, drv, entered_state)) 188 if (!cpuidle_state_is_coupled(dev, drv, entered_state))
173 local_irq_enable(); 189 local_irq_enable();
174 190
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index fd7ac13f2574..bda2cb06dc7a 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -437,6 +437,7 @@ config IMG_MDC_DMA
437 437
438config XGENE_DMA 438config XGENE_DMA
439 tristate "APM X-Gene DMA support" 439 tristate "APM X-Gene DMA support"
440 depends on ARCH_XGENE || COMPILE_TEST
440 select DMA_ENGINE 441 select DMA_ENGINE
441 select DMA_ENGINE_RAID 442 select DMA_ENGINE_RAID
442 select ASYNC_TX_ENABLE_CHANNEL_SWITCH 443 select ASYNC_TX_ENABLE_CHANNEL_SWITCH
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 0e035a8cf401..2890d744bb1b 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -571,11 +571,15 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device)
571 571
572 chan = private_candidate(&mask, device, NULL, NULL); 572 chan = private_candidate(&mask, device, NULL, NULL);
573 if (chan) { 573 if (chan) {
574 dma_cap_set(DMA_PRIVATE, device->cap_mask);
575 device->privatecnt++;
574 err = dma_chan_get(chan); 576 err = dma_chan_get(chan);
575 if (err) { 577 if (err) {
576 pr_debug("%s: failed to get %s: (%d)\n", 578 pr_debug("%s: failed to get %s: (%d)\n",
577 __func__, dma_chan_name(chan), err); 579 __func__, dma_chan_name(chan), err);
578 chan = NULL; 580 chan = NULL;
581 if (--device->privatecnt == 0)
582 dma_cap_clear(DMA_PRIVATE, device->cap_mask);
579 } 583 }
580 } 584 }
581 585
diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
index f705798ce3eb..ebd8a5f398b0 100644
--- a/drivers/dma/sh/usb-dmac.c
+++ b/drivers/dma/sh/usb-dmac.c
@@ -673,6 +673,7 @@ static struct dma_chan *usb_dmac_of_xlate(struct of_phandle_args *dma_spec,
673 * Power management 673 * Power management
674 */ 674 */
675 675
676#ifdef CONFIG_PM
676static int usb_dmac_runtime_suspend(struct device *dev) 677static int usb_dmac_runtime_suspend(struct device *dev)
677{ 678{
678 struct usb_dmac *dmac = dev_get_drvdata(dev); 679 struct usb_dmac *dmac = dev_get_drvdata(dev);
@@ -690,6 +691,7 @@ static int usb_dmac_runtime_resume(struct device *dev)
690 691
691 return usb_dmac_init(dmac); 692 return usb_dmac_init(dmac);
692} 693}
694#endif /* CONFIG_PM */
693 695
694static const struct dev_pm_ops usb_dmac_pm = { 696static const struct dev_pm_ops usb_dmac_pm = {
695 SET_RUNTIME_PM_OPS(usb_dmac_runtime_suspend, usb_dmac_runtime_resume, 697 SET_RUNTIME_PM_OPS(usb_dmac_runtime_suspend, usb_dmac_runtime_resume,
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
index de67fce18984..e45d1f13f445 100644
--- a/drivers/extcon/extcon-usb-gpio.c
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -119,6 +119,18 @@ static int usb_extcon_probe(struct platform_device *pdev)
119 return PTR_ERR(info->id_gpiod); 119 return PTR_ERR(info->id_gpiod);
120 } 120 }
121 121
122 info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
123 if (IS_ERR(info->edev)) {
124 dev_err(dev, "failed to allocate extcon device\n");
125 return -ENOMEM;
126 }
127
128 ret = devm_extcon_dev_register(dev, info->edev);
129 if (ret < 0) {
130 dev_err(dev, "failed to register extcon device\n");
131 return ret;
132 }
133
122 ret = gpiod_set_debounce(info->id_gpiod, 134 ret = gpiod_set_debounce(info->id_gpiod,
123 USB_GPIO_DEBOUNCE_MS * 1000); 135 USB_GPIO_DEBOUNCE_MS * 1000);
124 if (ret < 0) 136 if (ret < 0)
@@ -142,18 +154,6 @@ static int usb_extcon_probe(struct platform_device *pdev)
142 return ret; 154 return ret;
143 } 155 }
144 156
145 info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
146 if (IS_ERR(info->edev)) {
147 dev_err(dev, "failed to allocate extcon device\n");
148 return -ENOMEM;
149 }
150
151 ret = devm_extcon_dev_register(dev, info->edev);
152 if (ret < 0) {
153 dev_err(dev, "failed to register extcon device\n");
154 return ret;
155 }
156
157 platform_set_drvdata(pdev, info); 157 platform_set_drvdata(pdev, info);
158 device_init_wakeup(dev, 1); 158 device_init_wakeup(dev, 1);
159 159
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 6e45a43ffe84..97b1616aa391 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -499,19 +499,19 @@ static int __init dmi_present(const u8 *buf)
499 buf += 16; 499 buf += 16;
500 500
501 if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) { 501 if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
502 if (smbios_ver)
503 dmi_ver = smbios_ver;
504 else
505 dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F);
502 dmi_num = get_unaligned_le16(buf + 12); 506 dmi_num = get_unaligned_le16(buf + 12);
503 dmi_len = get_unaligned_le16(buf + 6); 507 dmi_len = get_unaligned_le16(buf + 6);
504 dmi_base = get_unaligned_le32(buf + 8); 508 dmi_base = get_unaligned_le32(buf + 8);
505 509
506 if (dmi_walk_early(dmi_decode) == 0) { 510 if (dmi_walk_early(dmi_decode) == 0) {
507 if (smbios_ver) { 511 if (smbios_ver) {
508 dmi_ver = smbios_ver; 512 pr_info("SMBIOS %d.%d present.\n",
509 pr_info("SMBIOS %d.%d%s present.\n", 513 dmi_ver >> 8, dmi_ver & 0xFF);
510 dmi_ver >> 8, dmi_ver & 0xFF,
511 (dmi_ver < 0x0300) ? "" : ".x");
512 } else { 514 } else {
513 dmi_ver = (buf[14] & 0xF0) << 4 |
514 (buf[14] & 0x0F);
515 pr_info("Legacy DMI %d.%d present.\n", 515 pr_info("Legacy DMI %d.%d present.\n",
516 dmi_ver >> 8, dmi_ver & 0xFF); 516 dmi_ver >> 8, dmi_ver & 0xFF);
517 } 517 }
diff --git a/drivers/firmware/efi/runtime-map.c b/drivers/firmware/efi/runtime-map.c
index 87b8e3b900d2..5c55227a34c8 100644
--- a/drivers/firmware/efi/runtime-map.c
+++ b/drivers/firmware/efi/runtime-map.c
@@ -120,7 +120,8 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
120 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 120 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
121 if (!entry) { 121 if (!entry) {
122 kset_unregister(map_kset); 122 kset_unregister(map_kset);
123 return entry; 123 map_kset = NULL;
124 return ERR_PTR(-ENOMEM);
124 } 125 }
125 126
126 memcpy(&entry->md, efi_runtime_map + nr * efi_memdesc_size, 127 memcpy(&entry->md, efi_runtime_map + nr * efi_memdesc_size,
@@ -132,6 +133,7 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
132 if (ret) { 133 if (ret) {
133 kobject_put(&entry->kobj); 134 kobject_put(&entry->kobj);
134 kset_unregister(map_kset); 135 kset_unregister(map_kset);
136 map_kset = NULL;
135 return ERR_PTR(ret); 137 return ERR_PTR(ret);
136 } 138 }
137 139
@@ -195,8 +197,6 @@ out_add_entry:
195 entry = *(map_entries + j); 197 entry = *(map_entries + j);
196 kobject_put(&entry->kobj); 198 kobject_put(&entry->kobj);
197 } 199 }
198 if (map_kset)
199 kset_unregister(map_kset);
200out: 200out:
201 return ret; 201 return ret;
202} 202}
diff --git a/drivers/gpio/gpio-kempld.c b/drivers/gpio/gpio-kempld.c
index 6b8115f34208..83f281dda1e0 100644
--- a/drivers/gpio/gpio-kempld.c
+++ b/drivers/gpio/gpio-kempld.c
@@ -117,7 +117,7 @@ static int kempld_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
117 = container_of(chip, struct kempld_gpio_data, chip); 117 = container_of(chip, struct kempld_gpio_data, chip);
118 struct kempld_device_data *pld = gpio->pld; 118 struct kempld_device_data *pld = gpio->pld;
119 119
120 return kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset); 120 return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset);
121} 121}
122 122
123static int kempld_gpio_pincount(struct kempld_device_data *pld) 123static int kempld_gpio_pincount(struct kempld_device_data *pld)
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index cd1d5bf48f36..b232397ad7ec 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1054,38 +1054,8 @@ static void omap_gpio_mod_init(struct gpio_bank *bank)
1054 dev_err(bank->dev, "Could not get gpio dbck\n"); 1054 dev_err(bank->dev, "Could not get gpio dbck\n");
1055} 1055}
1056 1056
1057static void
1058omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1059 unsigned int num)
1060{
1061 struct irq_chip_generic *gc;
1062 struct irq_chip_type *ct;
1063
1064 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1065 handle_simple_irq);
1066 if (!gc) {
1067 dev_err(bank->dev, "Memory alloc failed for gc\n");
1068 return;
1069 }
1070
1071 ct = gc->chip_types;
1072
1073 /* NOTE: No ack required, reading IRQ status clears it. */
1074 ct->chip.irq_mask = irq_gc_mask_set_bit;
1075 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
1076 ct->chip.irq_set_type = omap_gpio_irq_type;
1077
1078 if (bank->regs->wkup_en)
1079 ct->chip.irq_set_wake = omap_gpio_wake_enable;
1080
1081 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
1082 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
1083 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1084}
1085
1086static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) 1057static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
1087{ 1058{
1088 int j;
1089 static int gpio; 1059 static int gpio;
1090 int irq_base = 0; 1060 int irq_base = 0;
1091 int ret; 1061 int ret;
@@ -1132,6 +1102,15 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
1132 } 1102 }
1133#endif 1103#endif
1134 1104
1105 /* MPUIO is a bit different, reading IRQ status clears it */
1106 if (bank->is_mpuio) {
1107 irqc->irq_ack = dummy_irq_chip.irq_ack;
1108 irqc->irq_mask = irq_gc_mask_set_bit;
1109 irqc->irq_unmask = irq_gc_mask_clr_bit;
1110 if (!bank->regs->wkup_en)
1111 irqc->irq_set_wake = NULL;
1112 }
1113
1135 ret = gpiochip_irqchip_add(&bank->chip, irqc, 1114 ret = gpiochip_irqchip_add(&bank->chip, irqc,
1136 irq_base, omap_gpio_irq_handler, 1115 irq_base, omap_gpio_irq_handler,
1137 IRQ_TYPE_NONE); 1116 IRQ_TYPE_NONE);
@@ -1145,15 +1124,6 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
1145 gpiochip_set_chained_irqchip(&bank->chip, irqc, 1124 gpiochip_set_chained_irqchip(&bank->chip, irqc,
1146 bank->irq, omap_gpio_irq_handler); 1125 bank->irq, omap_gpio_irq_handler);
1147 1126
1148 for (j = 0; j < bank->width; j++) {
1149 int irq = irq_find_mapping(bank->chip.irqdomain, j);
1150 if (bank->is_mpuio) {
1151 omap_mpuio_alloc_gc(bank, irq, bank->width);
1152 irq_set_chip_and_handler(irq, NULL, NULL);
1153 set_irq_flags(irq, 0);
1154 }
1155 }
1156
1157 return 0; 1127 return 0;
1158} 1128}
1159 1129
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index d2303d50f561..725d16138b74 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -550,7 +550,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
550 550
551 length = min(agpio->pin_table_length, (u16)(pin_index + bits)); 551 length = min(agpio->pin_table_length, (u16)(pin_index + bits));
552 for (i = pin_index; i < length; ++i) { 552 for (i = pin_index; i < length; ++i) {
553 unsigned pin = agpio->pin_table[i]; 553 int pin = agpio->pin_table[i];
554 struct acpi_gpio_connection *conn; 554 struct acpi_gpio_connection *conn;
555 struct gpio_desc *desc; 555 struct gpio_desc *desc;
556 bool found; 556 bool found;
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 7722ed53bd65..af3bc7a8033b 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -551,6 +551,7 @@ static struct class gpio_class = {
551 */ 551 */
552int gpiod_export(struct gpio_desc *desc, bool direction_may_change) 552int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
553{ 553{
554 struct gpio_chip *chip;
554 unsigned long flags; 555 unsigned long flags;
555 int status; 556 int status;
556 const char *ioname = NULL; 557 const char *ioname = NULL;
@@ -568,8 +569,16 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
568 return -EINVAL; 569 return -EINVAL;
569 } 570 }
570 571
572 chip = desc->chip;
573
571 mutex_lock(&sysfs_lock); 574 mutex_lock(&sysfs_lock);
572 575
576 /* check if chip is being removed */
577 if (!chip || !chip->exported) {
578 status = -ENODEV;
579 goto fail_unlock;
580 }
581
573 spin_lock_irqsave(&gpio_lock, flags); 582 spin_lock_irqsave(&gpio_lock, flags);
574 if (!test_bit(FLAG_REQUESTED, &desc->flags) || 583 if (!test_bit(FLAG_REQUESTED, &desc->flags) ||
575 test_bit(FLAG_EXPORT, &desc->flags)) { 584 test_bit(FLAG_EXPORT, &desc->flags)) {
@@ -783,12 +792,15 @@ void gpiochip_unexport(struct gpio_chip *chip)
783{ 792{
784 int status; 793 int status;
785 struct device *dev; 794 struct device *dev;
795 struct gpio_desc *desc;
796 unsigned int i;
786 797
787 mutex_lock(&sysfs_lock); 798 mutex_lock(&sysfs_lock);
788 dev = class_find_device(&gpio_class, NULL, chip, match_export); 799 dev = class_find_device(&gpio_class, NULL, chip, match_export);
789 if (dev) { 800 if (dev) {
790 put_device(dev); 801 put_device(dev);
791 device_unregister(dev); 802 device_unregister(dev);
803 /* prevent further gpiod exports */
792 chip->exported = false; 804 chip->exported = false;
793 status = 0; 805 status = 0;
794 } else 806 } else
@@ -797,6 +809,13 @@ void gpiochip_unexport(struct gpio_chip *chip)
797 809
798 if (status) 810 if (status)
799 chip_dbg(chip, "%s: status %d\n", __func__, status); 811 chip_dbg(chip, "%s: status %d\n", __func__, status);
812
813 /* unregister gpiod class devices owned by sysfs */
814 for (i = 0; i < chip->ngpio; i++) {
815 desc = &chip->desc[i];
816 if (test_and_clear_bit(FLAG_SYSFS, &desc->flags))
817 gpiod_free(desc);
818 }
800} 819}
801 820
802static int __init gpiolib_sysfs_init(void) 821static int __init gpiolib_sysfs_init(void)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 59eaa23767d8..6bc612b8a49f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -53,6 +53,11 @@ static DEFINE_MUTEX(gpio_lookup_lock);
53static LIST_HEAD(gpio_lookup_list); 53static LIST_HEAD(gpio_lookup_list);
54LIST_HEAD(gpio_chips); 54LIST_HEAD(gpio_chips);
55 55
56
57static void gpiochip_free_hogs(struct gpio_chip *chip);
58static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
59
60
56static inline void desc_set_label(struct gpio_desc *d, const char *label) 61static inline void desc_set_label(struct gpio_desc *d, const char *label)
57{ 62{
58 d->label = label; 63 d->label = label;
@@ -297,6 +302,7 @@ int gpiochip_add(struct gpio_chip *chip)
297 302
298err_remove_chip: 303err_remove_chip:
299 acpi_gpiochip_remove(chip); 304 acpi_gpiochip_remove(chip);
305 gpiochip_free_hogs(chip);
300 of_gpiochip_remove(chip); 306 of_gpiochip_remove(chip);
301 spin_lock_irqsave(&gpio_lock, flags); 307 spin_lock_irqsave(&gpio_lock, flags);
302 list_del(&chip->list); 308 list_del(&chip->list);
@@ -313,10 +319,6 @@ err_free_descs:
313} 319}
314EXPORT_SYMBOL_GPL(gpiochip_add); 320EXPORT_SYMBOL_GPL(gpiochip_add);
315 321
316/* Forward-declaration */
317static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
318static void gpiochip_free_hogs(struct gpio_chip *chip);
319
320/** 322/**
321 * gpiochip_remove() - unregister a gpio_chip 323 * gpiochip_remove() - unregister a gpio_chip
322 * @chip: the chip to unregister 324 * @chip: the chip to unregister
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 69af73f15310..596ee5cd3b84 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -430,9 +430,10 @@ static int unregister_process_nocpsch(struct device_queue_manager *dqm,
430 430
431 BUG_ON(!dqm || !qpd); 431 BUG_ON(!dqm || !qpd);
432 432
433 BUG_ON(!list_empty(&qpd->queues_list)); 433 pr_debug("In func %s\n", __func__);
434 434
435 pr_debug("kfd: In func %s\n", __func__); 435 pr_debug("qpd->queues_list is %s\n",
436 list_empty(&qpd->queues_list) ? "empty" : "not empty");
436 437
437 retval = 0; 438 retval = 0;
438 mutex_lock(&dqm->lock); 439 mutex_lock(&dqm->lock);
@@ -882,6 +883,8 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
882 return -ENOMEM; 883 return -ENOMEM;
883 } 884 }
884 885
886 init_sdma_vm(dqm, q, qpd);
887
885 retval = mqd->init_mqd(mqd, &q->mqd, &q->mqd_mem_obj, 888 retval = mqd->init_mqd(mqd, &q->mqd, &q->mqd_mem_obj,
886 &q->gart_mqd_addr, &q->properties); 889 &q->gart_mqd_addr, &q->properties);
887 if (retval != 0) 890 if (retval != 0)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index 661c6605d31b..e469c4b2e8cc 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -728,9 +728,9 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
728 sysfs_show_32bit_prop(buffer, "max_engine_clk_fcompute", 728 sysfs_show_32bit_prop(buffer, "max_engine_clk_fcompute",
729 dev->gpu->kfd2kgd->get_max_engine_clock_in_mhz( 729 dev->gpu->kfd2kgd->get_max_engine_clock_in_mhz(
730 dev->gpu->kgd)); 730 dev->gpu->kgd));
731
731 sysfs_show_64bit_prop(buffer, "local_mem_size", 732 sysfs_show_64bit_prop(buffer, "local_mem_size",
732 dev->gpu->kfd2kgd->get_vmem_size( 733 (unsigned long long int) 0);
733 dev->gpu->kgd));
734 734
735 sysfs_show_32bit_prop(buffer, "fw_version", 735 sysfs_show_32bit_prop(buffer, "fw_version",
736 dev->gpu->kfd2kgd->get_fw_version( 736 dev->gpu->kfd2kgd->get_fw_version(
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index c8a34476570a..af9662e58272 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -131,12 +131,11 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)
131 131
132 /* Reinitialize corresponding vblank timestamp if high-precision query 132 /* Reinitialize corresponding vblank timestamp if high-precision query
133 * available. Skip this step if query unsupported or failed. Will 133 * available. Skip this step if query unsupported or failed. Will
134 * reinitialize delayed at next vblank interrupt in that case. 134 * reinitialize delayed at next vblank interrupt in that case and
135 * assign 0 for now, to mark the vblanktimestamp as invalid.
135 */ 136 */
136 if (rc) { 137 tslot = atomic_read(&vblank->count) + diff;
137 tslot = atomic_read(&vblank->count) + diff; 138 vblanktimestamp(dev, crtc, tslot) = rc ? t_vblank : (struct timeval) {0, 0};
138 vblanktimestamp(dev, crtc, tslot) = t_vblank;
139 }
140 139
141 smp_mb__before_atomic(); 140 smp_mb__before_atomic();
142 atomic_add(diff, &vblank->count); 141 atomic_add(diff, &vblank->count);
diff --git a/drivers/gpu/drm/drm_plane_helper.c b/drivers/gpu/drm/drm_plane_helper.c
index 40c1db9ad7c3..2f0ed11024eb 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -465,6 +465,9 @@ int drm_plane_helper_commit(struct drm_plane *plane,
465 if (!crtc[i]) 465 if (!crtc[i])
466 continue; 466 continue;
467 467
468 if (crtc[i]->cursor == plane)
469 continue;
470
468 /* There's no other way to figure out whether the crtc is running. */ 471 /* There's no other way to figure out whether the crtc is running. */
469 ret = drm_crtc_vblank_get(crtc[i]); 472 ret = drm_crtc_vblank_get(crtc[i]);
470 if (ret == 0) { 473 if (ret == 0) {
diff --git a/drivers/gpu/drm/exynos/exynos7_drm_decon.c b/drivers/gpu/drm/exynos/exynos7_drm_decon.c
index 1f7e33f59de6..6714e5b193ea 100644
--- a/drivers/gpu/drm/exynos/exynos7_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos7_drm_decon.c
@@ -91,7 +91,7 @@ static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc)
91 91
92static void decon_clear_channel(struct decon_context *ctx) 92static void decon_clear_channel(struct decon_context *ctx)
93{ 93{
94 int win, ch_enabled = 0; 94 unsigned int win, ch_enabled = 0;
95 95
96 DRM_DEBUG_KMS("%s\n", __FILE__); 96 DRM_DEBUG_KMS("%s\n", __FILE__);
97 97
@@ -710,7 +710,7 @@ static void decon_dpms(struct exynos_drm_crtc *crtc, int mode)
710 } 710 }
711} 711}
712 712
713static struct exynos_drm_crtc_ops decon_crtc_ops = { 713static const struct exynos_drm_crtc_ops decon_crtc_ops = {
714 .dpms = decon_dpms, 714 .dpms = decon_dpms,
715 .mode_fixup = decon_mode_fixup, 715 .mode_fixup = decon_mode_fixup,
716 .commit = decon_commit, 716 .commit = decon_commit,
diff --git a/drivers/gpu/drm/exynos/exynos_dp_core.c b/drivers/gpu/drm/exynos/exynos_dp_core.c
index 1dbfba58f909..30feb7d06624 100644
--- a/drivers/gpu/drm/exynos/exynos_dp_core.c
+++ b/drivers/gpu/drm/exynos/exynos_dp_core.c
@@ -32,7 +32,6 @@
32#include <drm/bridge/ptn3460.h> 32#include <drm/bridge/ptn3460.h>
33 33
34#include "exynos_dp_core.h" 34#include "exynos_dp_core.h"
35#include "exynos_drm_fimd.h"
36 35
37#define ctx_from_connector(c) container_of(c, struct exynos_dp_device, \ 36#define ctx_from_connector(c) container_of(c, struct exynos_dp_device, \
38 connector) 37 connector)
@@ -196,7 +195,7 @@ static int exynos_dp_read_edid(struct exynos_dp_device *dp)
196 } 195 }
197 } 196 }
198 197
199 dev_err(dp->dev, "EDID Read success!\n"); 198 dev_dbg(dp->dev, "EDID Read success!\n");
200 return 0; 199 return 0;
201} 200}
202 201
@@ -1066,6 +1065,8 @@ static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
1066 1065
1067static void exynos_dp_poweron(struct exynos_dp_device *dp) 1066static void exynos_dp_poweron(struct exynos_dp_device *dp)
1068{ 1067{
1068 struct exynos_drm_crtc *crtc = dp_to_crtc(dp);
1069
1069 if (dp->dpms_mode == DRM_MODE_DPMS_ON) 1070 if (dp->dpms_mode == DRM_MODE_DPMS_ON)
1070 return; 1071 return;
1071 1072
@@ -1076,7 +1077,8 @@ static void exynos_dp_poweron(struct exynos_dp_device *dp)
1076 } 1077 }
1077 } 1078 }
1078 1079
1079 fimd_dp_clock_enable(dp_to_crtc(dp), true); 1080 if (crtc->ops->clock_enable)
1081 crtc->ops->clock_enable(dp_to_crtc(dp), true);
1080 1082
1081 clk_prepare_enable(dp->clock); 1083 clk_prepare_enable(dp->clock);
1082 exynos_dp_phy_init(dp); 1084 exynos_dp_phy_init(dp);
@@ -1087,6 +1089,8 @@ static void exynos_dp_poweron(struct exynos_dp_device *dp)
1087 1089
1088static void exynos_dp_poweroff(struct exynos_dp_device *dp) 1090static void exynos_dp_poweroff(struct exynos_dp_device *dp)
1089{ 1091{
1092 struct exynos_drm_crtc *crtc = dp_to_crtc(dp);
1093
1090 if (dp->dpms_mode != DRM_MODE_DPMS_ON) 1094 if (dp->dpms_mode != DRM_MODE_DPMS_ON)
1091 return; 1095 return;
1092 1096
@@ -1102,7 +1106,8 @@ static void exynos_dp_poweroff(struct exynos_dp_device *dp)
1102 exynos_dp_phy_exit(dp); 1106 exynos_dp_phy_exit(dp);
1103 clk_disable_unprepare(dp->clock); 1107 clk_disable_unprepare(dp->clock);
1104 1108
1105 fimd_dp_clock_enable(dp_to_crtc(dp), false); 1109 if (crtc->ops->clock_enable)
1110 crtc->ops->clock_enable(dp_to_crtc(dp), false);
1106 1111
1107 if (dp->panel) { 1112 if (dp->panel) {
1108 if (drm_panel_unprepare(dp->panel)) 1113 if (drm_panel_unprepare(dp->panel))
diff --git a/drivers/gpu/drm/exynos/exynos_drm_crtc.c b/drivers/gpu/drm/exynos/exynos_drm_crtc.c
index eb49195cec5c..9006b947e03c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_crtc.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_crtc.c
@@ -238,11 +238,11 @@ static struct drm_crtc_funcs exynos_crtc_funcs = {
238}; 238};
239 239
240struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, 240struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
241 struct drm_plane *plane, 241 struct drm_plane *plane,
242 int pipe, 242 int pipe,
243 enum exynos_drm_output_type type, 243 enum exynos_drm_output_type type,
244 struct exynos_drm_crtc_ops *ops, 244 const struct exynos_drm_crtc_ops *ops,
245 void *ctx) 245 void *ctx)
246{ 246{
247 struct exynos_drm_crtc *exynos_crtc; 247 struct exynos_drm_crtc *exynos_crtc;
248 struct exynos_drm_private *private = drm_dev->dev_private; 248 struct exynos_drm_private *private = drm_dev->dev_private;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_crtc.h b/drivers/gpu/drm/exynos/exynos_drm_crtc.h
index 0ecd8fc45cff..0f3aa70818e3 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_crtc.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_crtc.h
@@ -18,11 +18,11 @@
18#include "exynos_drm_drv.h" 18#include "exynos_drm_drv.h"
19 19
20struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, 20struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
21 struct drm_plane *plane, 21 struct drm_plane *plane,
22 int pipe, 22 int pipe,
23 enum exynos_drm_output_type type, 23 enum exynos_drm_output_type type,
24 struct exynos_drm_crtc_ops *ops, 24 const struct exynos_drm_crtc_ops *ops,
25 void *context); 25 void *context);
26int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe); 26int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int pipe);
27void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe); 27void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int pipe);
28void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe); 28void exynos_drm_crtc_finish_pageflip(struct drm_device *dev, int pipe);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h
index e12ecb5d5d9a..29e3fb78c615 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h
@@ -71,13 +71,6 @@ enum exynos_drm_output_type {
71 * @dma_addr: array of bus(accessed by dma) address to the memory region 71 * @dma_addr: array of bus(accessed by dma) address to the memory region
72 * allocated for a overlay. 72 * allocated for a overlay.
73 * @zpos: order of overlay layer(z position). 73 * @zpos: order of overlay layer(z position).
74 * @index_color: if using color key feature then this value would be used
75 * as index color.
76 * @default_win: a window to be enabled.
77 * @color_key: color key on or off.
78 * @local_path: in case of lcd type, local path mode on or off.
79 * @transparency: transparency on or off.
80 * @activated: activated or not.
81 * @enabled: enabled or not. 74 * @enabled: enabled or not.
82 * @resume: to resume or not. 75 * @resume: to resume or not.
83 * 76 *
@@ -108,13 +101,7 @@ struct exynos_drm_plane {
108 uint32_t pixel_format; 101 uint32_t pixel_format;
109 dma_addr_t dma_addr[MAX_FB_BUFFER]; 102 dma_addr_t dma_addr[MAX_FB_BUFFER];
110 unsigned int zpos; 103 unsigned int zpos;
111 unsigned int index_color;
112 104
113 bool default_win:1;
114 bool color_key:1;
115 bool local_path:1;
116 bool transparency:1;
117 bool activated:1;
118 bool enabled:1; 105 bool enabled:1;
119 bool resume:1; 106 bool resume:1;
120}; 107};
@@ -181,6 +168,10 @@ struct exynos_drm_display {
181 * @win_disable: disable hardware specific overlay. 168 * @win_disable: disable hardware specific overlay.
182 * @te_handler: trigger to transfer video image at the tearing effect 169 * @te_handler: trigger to transfer video image at the tearing effect
183 * synchronization signal if there is a page flip request. 170 * synchronization signal if there is a page flip request.
171 * @clock_enable: optional function enabling/disabling display domain clock,
172 * called from exynos-dp driver before powering up (with
173 * 'enable' argument as true) and after powering down (with
174 * 'enable' as false).
184 */ 175 */
185struct exynos_drm_crtc; 176struct exynos_drm_crtc;
186struct exynos_drm_crtc_ops { 177struct exynos_drm_crtc_ops {
@@ -195,6 +186,7 @@ struct exynos_drm_crtc_ops {
195 void (*win_commit)(struct exynos_drm_crtc *crtc, unsigned int zpos); 186 void (*win_commit)(struct exynos_drm_crtc *crtc, unsigned int zpos);
196 void (*win_disable)(struct exynos_drm_crtc *crtc, unsigned int zpos); 187 void (*win_disable)(struct exynos_drm_crtc *crtc, unsigned int zpos);
197 void (*te_handler)(struct exynos_drm_crtc *crtc); 188 void (*te_handler)(struct exynos_drm_crtc *crtc);
189 void (*clock_enable)(struct exynos_drm_crtc *crtc, bool enable);
198}; 190};
199 191
200/* 192/*
@@ -221,7 +213,7 @@ struct exynos_drm_crtc {
221 unsigned int dpms; 213 unsigned int dpms;
222 wait_queue_head_t pending_flip_queue; 214 wait_queue_head_t pending_flip_queue;
223 struct drm_pending_vblank_event *event; 215 struct drm_pending_vblank_event *event;
224 struct exynos_drm_crtc_ops *ops; 216 const struct exynos_drm_crtc_ops *ops;
225 void *ctx; 217 void *ctx;
226}; 218};
227 219
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c b/drivers/gpu/drm/exynos/exynos_drm_fb.c
index 929cb03a8eab..142eb4e3f59e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fb.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c
@@ -171,43 +171,6 @@ exynos_drm_framebuffer_init(struct drm_device *dev,
171 return &exynos_fb->fb; 171 return &exynos_fb->fb;
172} 172}
173 173
174static u32 exynos_drm_format_num_buffers(struct drm_mode_fb_cmd2 *mode_cmd)
175{
176 unsigned int cnt = 0;
177
178 if (mode_cmd->pixel_format != DRM_FORMAT_NV12)
179 return drm_format_num_planes(mode_cmd->pixel_format);
180
181 while (cnt != MAX_FB_BUFFER) {
182 if (!mode_cmd->handles[cnt])
183 break;
184 cnt++;
185 }
186
187 /*
188 * check if NV12 or NV12M.
189 *
190 * NV12
191 * handles[0] = base1, offsets[0] = 0
192 * handles[1] = base1, offsets[1] = Y_size
193 *
194 * NV12M
195 * handles[0] = base1, offsets[0] = 0
196 * handles[1] = base2, offsets[1] = 0
197 */
198 if (cnt == 2) {
199 /*
200 * in case of NV12 format, offsets[1] is not 0 and
201 * handles[0] is same as handles[1].
202 */
203 if (mode_cmd->offsets[1] &&
204 mode_cmd->handles[0] == mode_cmd->handles[1])
205 cnt = 1;
206 }
207
208 return cnt;
209}
210
211static struct drm_framebuffer * 174static struct drm_framebuffer *
212exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, 175exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv,
213 struct drm_mode_fb_cmd2 *mode_cmd) 176 struct drm_mode_fb_cmd2 *mode_cmd)
@@ -230,7 +193,7 @@ exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv,
230 193
231 drm_helper_mode_fill_fb_struct(&exynos_fb->fb, mode_cmd); 194 drm_helper_mode_fill_fb_struct(&exynos_fb->fb, mode_cmd);
232 exynos_fb->exynos_gem_obj[0] = to_exynos_gem_obj(obj); 195 exynos_fb->exynos_gem_obj[0] = to_exynos_gem_obj(obj);
233 exynos_fb->buf_cnt = exynos_drm_format_num_buffers(mode_cmd); 196 exynos_fb->buf_cnt = drm_format_num_planes(mode_cmd->pixel_format);
234 197
235 DRM_DEBUG_KMS("buf_cnt = %d\n", exynos_fb->buf_cnt); 198 DRM_DEBUG_KMS("buf_cnt = %d\n", exynos_fb->buf_cnt);
236 199
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
index 9819fa6a9e2a..a0edab833148 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
@@ -33,7 +33,6 @@
33#include "exynos_drm_crtc.h" 33#include "exynos_drm_crtc.h"
34#include "exynos_drm_plane.h" 34#include "exynos_drm_plane.h"
35#include "exynos_drm_iommu.h" 35#include "exynos_drm_iommu.h"
36#include "exynos_drm_fimd.h"
37 36
38/* 37/*
39 * FIMD stands for Fully Interactive Mobile Display and 38 * FIMD stands for Fully Interactive Mobile Display and
@@ -216,7 +215,7 @@ static void fimd_wait_for_vblank(struct exynos_drm_crtc *crtc)
216 DRM_DEBUG_KMS("vblank wait timed out.\n"); 215 DRM_DEBUG_KMS("vblank wait timed out.\n");
217} 216}
218 217
219static void fimd_enable_video_output(struct fimd_context *ctx, int win, 218static void fimd_enable_video_output(struct fimd_context *ctx, unsigned int win,
220 bool enable) 219 bool enable)
221{ 220{
222 u32 val = readl(ctx->regs + WINCON(win)); 221 u32 val = readl(ctx->regs + WINCON(win));
@@ -229,7 +228,8 @@ static void fimd_enable_video_output(struct fimd_context *ctx, int win,
229 writel(val, ctx->regs + WINCON(win)); 228 writel(val, ctx->regs + WINCON(win));
230} 229}
231 230
232static void fimd_enable_shadow_channel_path(struct fimd_context *ctx, int win, 231static void fimd_enable_shadow_channel_path(struct fimd_context *ctx,
232 unsigned int win,
233 bool enable) 233 bool enable)
234{ 234{
235 u32 val = readl(ctx->regs + SHADOWCON); 235 u32 val = readl(ctx->regs + SHADOWCON);
@@ -244,7 +244,7 @@ static void fimd_enable_shadow_channel_path(struct fimd_context *ctx, int win,
244 244
245static void fimd_clear_channel(struct fimd_context *ctx) 245static void fimd_clear_channel(struct fimd_context *ctx)
246{ 246{
247 int win, ch_enabled = 0; 247 unsigned int win, ch_enabled = 0;
248 248
249 DRM_DEBUG_KMS("%s\n", __FILE__); 249 DRM_DEBUG_KMS("%s\n", __FILE__);
250 250
@@ -946,7 +946,24 @@ static void fimd_te_handler(struct exynos_drm_crtc *crtc)
946 drm_handle_vblank(ctx->drm_dev, ctx->pipe); 946 drm_handle_vblank(ctx->drm_dev, ctx->pipe);
947} 947}
948 948
949static struct exynos_drm_crtc_ops fimd_crtc_ops = { 949static void fimd_dp_clock_enable(struct exynos_drm_crtc *crtc, bool enable)
950{
951 struct fimd_context *ctx = crtc->ctx;
952 u32 val;
953
954 /*
955 * Only Exynos 5250, 5260, 5410 and 542x requires enabling DP/MIE
956 * clock. On these SoCs the bootloader may enable it but any
957 * power domain off/on will reset it to disable state.
958 */
959 if (ctx->driver_data != &exynos5_fimd_driver_data)
960 return;
961
962 val = enable ? DP_MIE_CLK_DP_ENABLE : DP_MIE_CLK_DISABLE;
963 writel(DP_MIE_CLK_DP_ENABLE, ctx->regs + DP_MIE_CLKCON);
964}
965
966static const struct exynos_drm_crtc_ops fimd_crtc_ops = {
950 .dpms = fimd_dpms, 967 .dpms = fimd_dpms,
951 .mode_fixup = fimd_mode_fixup, 968 .mode_fixup = fimd_mode_fixup,
952 .commit = fimd_commit, 969 .commit = fimd_commit,
@@ -956,6 +973,7 @@ static struct exynos_drm_crtc_ops fimd_crtc_ops = {
956 .win_commit = fimd_win_commit, 973 .win_commit = fimd_win_commit,
957 .win_disable = fimd_win_disable, 974 .win_disable = fimd_win_disable,
958 .te_handler = fimd_te_handler, 975 .te_handler = fimd_te_handler,
976 .clock_enable = fimd_dp_clock_enable,
959}; 977};
960 978
961static irqreturn_t fimd_irq_handler(int irq, void *dev_id) 979static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
@@ -1025,12 +1043,7 @@ static int fimd_bind(struct device *dev, struct device *master, void *data)
1025 if (ctx->display) 1043 if (ctx->display)
1026 exynos_drm_create_enc_conn(drm_dev, ctx->display); 1044 exynos_drm_create_enc_conn(drm_dev, ctx->display);
1027 1045
1028 ret = fimd_iommu_attach_devices(ctx, drm_dev); 1046 return fimd_iommu_attach_devices(ctx, drm_dev);
1029 if (ret)
1030 return ret;
1031
1032 return 0;
1033
1034} 1047}
1035 1048
1036static void fimd_unbind(struct device *dev, struct device *master, 1049static void fimd_unbind(struct device *dev, struct device *master,
@@ -1192,24 +1205,6 @@ static int fimd_remove(struct platform_device *pdev)
1192 return 0; 1205 return 0;
1193} 1206}
1194 1207
1195void fimd_dp_clock_enable(struct exynos_drm_crtc *crtc, bool enable)
1196{
1197 struct fimd_context *ctx = crtc->ctx;
1198 u32 val;
1199
1200 /*
1201 * Only Exynos 5250, 5260, 5410 and 542x requires enabling DP/MIE
1202 * clock. On these SoCs the bootloader may enable it but any
1203 * power domain off/on will reset it to disable state.
1204 */
1205 if (ctx->driver_data != &exynos5_fimd_driver_data)
1206 return;
1207
1208 val = enable ? DP_MIE_CLK_DP_ENABLE : DP_MIE_CLK_DISABLE;
1209 writel(DP_MIE_CLK_DP_ENABLE, ctx->regs + DP_MIE_CLKCON);
1210}
1211EXPORT_SYMBOL_GPL(fimd_dp_clock_enable);
1212
1213struct platform_driver fimd_driver = { 1208struct platform_driver fimd_driver = {
1214 .probe = fimd_probe, 1209 .probe = fimd_probe,
1215 .remove = fimd_remove, 1210 .remove = fimd_remove,
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.h b/drivers/gpu/drm/exynos/exynos_drm_fimd.h
deleted file mode 100644
index b4fcaa568456..000000000000
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.h
+++ /dev/null
@@ -1,15 +0,0 @@
1/*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 */
9
10#ifndef _EXYNOS_DRM_FIMD_H_
11#define _EXYNOS_DRM_FIMD_H_
12
13extern void fimd_dp_clock_enable(struct exynos_drm_crtc *crtc, bool enable);
14
15#endif /* _EXYNOS_DRM_FIMD_H_ */
diff --git a/drivers/gpu/drm/exynos/exynos_drm_plane.c b/drivers/gpu/drm/exynos/exynos_drm_plane.c
index 13ea3349363b..b1180fbe7546 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_plane.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_plane.c
@@ -76,7 +76,7 @@ int exynos_check_plane(struct drm_plane *plane, struct drm_framebuffer *fb)
76 return -EFAULT; 76 return -EFAULT;
77 } 77 }
78 78
79 exynos_plane->dma_addr[i] = buffer->dma_addr; 79 exynos_plane->dma_addr[i] = buffer->dma_addr + fb->offsets[i];
80 80
81 DRM_DEBUG_KMS("buffer: %d, dma_addr = 0x%lx\n", 81 DRM_DEBUG_KMS("buffer: %d, dma_addr = 0x%lx\n",
82 i, (unsigned long)exynos_plane->dma_addr[i]); 82 i, (unsigned long)exynos_plane->dma_addr[i]);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
index 27e84ec21694..1b3479a8db5f 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
@@ -217,7 +217,7 @@ static int vidi_ctx_initialize(struct vidi_context *ctx,
217 return 0; 217 return 0;
218} 218}
219 219
220static struct exynos_drm_crtc_ops vidi_crtc_ops = { 220static const struct exynos_drm_crtc_ops vidi_crtc_ops = {
221 .dpms = vidi_dpms, 221 .dpms = vidi_dpms,
222 .enable_vblank = vidi_enable_vblank, 222 .enable_vblank = vidi_enable_vblank,
223 .disable_vblank = vidi_disable_vblank, 223 .disable_vblank = vidi_disable_vblank,
diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c
index fbec750574e6..8874c1fcb3ab 100644
--- a/drivers/gpu/drm/exynos/exynos_mixer.c
+++ b/drivers/gpu/drm/exynos/exynos_mixer.c
@@ -44,6 +44,12 @@
44#define MIXER_WIN_NR 3 44#define MIXER_WIN_NR 3
45#define MIXER_DEFAULT_WIN 0 45#define MIXER_DEFAULT_WIN 0
46 46
47/* The pixelformats that are natively supported by the mixer. */
48#define MXR_FORMAT_RGB565 4
49#define MXR_FORMAT_ARGB1555 5
50#define MXR_FORMAT_ARGB4444 6
51#define MXR_FORMAT_ARGB8888 7
52
47struct mixer_resources { 53struct mixer_resources {
48 int irq; 54 int irq;
49 void __iomem *mixer_regs; 55 void __iomem *mixer_regs;
@@ -327,7 +333,8 @@ static void mixer_cfg_rgb_fmt(struct mixer_context *ctx, unsigned int height)
327 mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK); 333 mixer_reg_writemask(res, MXR_CFG, val, MXR_CFG_RGB_FMT_MASK);
328} 334}
329 335
330static void mixer_cfg_layer(struct mixer_context *ctx, int win, bool enable) 336static void mixer_cfg_layer(struct mixer_context *ctx, unsigned int win,
337 bool enable)
331{ 338{
332 struct mixer_resources *res = &ctx->mixer_res; 339 struct mixer_resources *res = &ctx->mixer_res;
333 u32 val = enable ? ~0 : 0; 340 u32 val = enable ? ~0 : 0;
@@ -359,8 +366,6 @@ static void mixer_run(struct mixer_context *ctx)
359 struct mixer_resources *res = &ctx->mixer_res; 366 struct mixer_resources *res = &ctx->mixer_res;
360 367
361 mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN); 368 mixer_reg_writemask(res, MXR_STATUS, ~0, MXR_STATUS_REG_RUN);
362
363 mixer_regs_dump(ctx);
364} 369}
365 370
366static void mixer_stop(struct mixer_context *ctx) 371static void mixer_stop(struct mixer_context *ctx)
@@ -373,16 +378,13 @@ static void mixer_stop(struct mixer_context *ctx)
373 while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) && 378 while (!(mixer_reg_read(res, MXR_STATUS) & MXR_STATUS_REG_IDLE) &&
374 --timeout) 379 --timeout)
375 usleep_range(10000, 12000); 380 usleep_range(10000, 12000);
376
377 mixer_regs_dump(ctx);
378} 381}
379 382
380static void vp_video_buffer(struct mixer_context *ctx, int win) 383static void vp_video_buffer(struct mixer_context *ctx, unsigned int win)
381{ 384{
382 struct mixer_resources *res = &ctx->mixer_res; 385 struct mixer_resources *res = &ctx->mixer_res;
383 unsigned long flags; 386 unsigned long flags;
384 struct exynos_drm_plane *plane; 387 struct exynos_drm_plane *plane;
385 unsigned int buf_num = 1;
386 dma_addr_t luma_addr[2], chroma_addr[2]; 388 dma_addr_t luma_addr[2], chroma_addr[2];
387 bool tiled_mode = false; 389 bool tiled_mode = false;
388 bool crcb_mode = false; 390 bool crcb_mode = false;
@@ -393,27 +395,18 @@ static void vp_video_buffer(struct mixer_context *ctx, int win)
393 switch (plane->pixel_format) { 395 switch (plane->pixel_format) {
394 case DRM_FORMAT_NV12: 396 case DRM_FORMAT_NV12:
395 crcb_mode = false; 397 crcb_mode = false;
396 buf_num = 2;
397 break; 398 break;
398 /* TODO: single buffer format NV12, NV21 */ 399 case DRM_FORMAT_NV21:
400 crcb_mode = true;
401 break;
399 default: 402 default:
400 /* ignore pixel format at disable time */
401 if (!plane->dma_addr[0])
402 break;
403
404 DRM_ERROR("pixel format for vp is wrong [%d].\n", 403 DRM_ERROR("pixel format for vp is wrong [%d].\n",
405 plane->pixel_format); 404 plane->pixel_format);
406 return; 405 return;
407 } 406 }
408 407
409 if (buf_num == 2) { 408 luma_addr[0] = plane->dma_addr[0];
410 luma_addr[0] = plane->dma_addr[0]; 409 chroma_addr[0] = plane->dma_addr[1];
411 chroma_addr[0] = plane->dma_addr[1];
412 } else {
413 luma_addr[0] = plane->dma_addr[0];
414 chroma_addr[0] = plane->dma_addr[0]
415 + (plane->pitch * plane->fb_height);
416 }
417 410
418 if (plane->scan_flag & DRM_MODE_FLAG_INTERLACE) { 411 if (plane->scan_flag & DRM_MODE_FLAG_INTERLACE) {
419 ctx->interlace = true; 412 ctx->interlace = true;
@@ -484,6 +477,7 @@ static void vp_video_buffer(struct mixer_context *ctx, int win)
484 mixer_vsync_set_update(ctx, true); 477 mixer_vsync_set_update(ctx, true);
485 spin_unlock_irqrestore(&res->reg_slock, flags); 478 spin_unlock_irqrestore(&res->reg_slock, flags);
486 479
480 mixer_regs_dump(ctx);
487 vp_regs_dump(ctx); 481 vp_regs_dump(ctx);
488} 482}
489 483
@@ -518,7 +512,7 @@ fail:
518 return -ENOTSUPP; 512 return -ENOTSUPP;
519} 513}
520 514
521static void mixer_graph_buffer(struct mixer_context *ctx, int win) 515static void mixer_graph_buffer(struct mixer_context *ctx, unsigned int win)
522{ 516{
523 struct mixer_resources *res = &ctx->mixer_res; 517 struct mixer_resources *res = &ctx->mixer_res;
524 unsigned long flags; 518 unsigned long flags;
@@ -531,20 +525,27 @@ static void mixer_graph_buffer(struct mixer_context *ctx, int win)
531 525
532 plane = &ctx->planes[win]; 526 plane = &ctx->planes[win];
533 527
534 #define RGB565 4 528 switch (plane->pixel_format) {
535 #define ARGB1555 5 529 case DRM_FORMAT_XRGB4444:
536 #define ARGB4444 6 530 fmt = MXR_FORMAT_ARGB4444;
537 #define ARGB8888 7 531 break;
538 532
539 switch (plane->bpp) { 533 case DRM_FORMAT_XRGB1555:
540 case 16: 534 fmt = MXR_FORMAT_ARGB1555;
541 fmt = ARGB4444;
542 break; 535 break;
543 case 32: 536
544 fmt = ARGB8888; 537 case DRM_FORMAT_RGB565:
538 fmt = MXR_FORMAT_RGB565;
539 break;
540
541 case DRM_FORMAT_XRGB8888:
542 case DRM_FORMAT_ARGB8888:
543 fmt = MXR_FORMAT_ARGB8888;
545 break; 544 break;
545
546 default: 546 default:
547 fmt = ARGB8888; 547 DRM_DEBUG_KMS("pixelformat unsupported by mixer\n");
548 return;
548 } 549 }
549 550
550 /* check if mixer supports requested scaling setup */ 551 /* check if mixer supports requested scaling setup */
@@ -617,6 +618,8 @@ static void mixer_graph_buffer(struct mixer_context *ctx, int win)
617 618
618 mixer_vsync_set_update(ctx, true); 619 mixer_vsync_set_update(ctx, true);
619 spin_unlock_irqrestore(&res->reg_slock, flags); 620 spin_unlock_irqrestore(&res->reg_slock, flags);
621
622 mixer_regs_dump(ctx);
620} 623}
621 624
622static void vp_win_reset(struct mixer_context *ctx) 625static void vp_win_reset(struct mixer_context *ctx)
@@ -1070,6 +1073,7 @@ static void mixer_poweroff(struct mixer_context *ctx)
1070 mutex_unlock(&ctx->mixer_mutex); 1073 mutex_unlock(&ctx->mixer_mutex);
1071 1074
1072 mixer_stop(ctx); 1075 mixer_stop(ctx);
1076 mixer_regs_dump(ctx);
1073 mixer_window_suspend(ctx); 1077 mixer_window_suspend(ctx);
1074 1078
1075 ctx->int_en = mixer_reg_read(res, MXR_INT_EN); 1079 ctx->int_en = mixer_reg_read(res, MXR_INT_EN);
@@ -1126,7 +1130,7 @@ int mixer_check_mode(struct drm_display_mode *mode)
1126 return -EINVAL; 1130 return -EINVAL;
1127} 1131}
1128 1132
1129static struct exynos_drm_crtc_ops mixer_crtc_ops = { 1133static const struct exynos_drm_crtc_ops mixer_crtc_ops = {
1130 .dpms = mixer_dpms, 1134 .dpms = mixer_dpms,
1131 .enable_vblank = mixer_enable_vblank, 1135 .enable_vblank = mixer_enable_vblank,
1132 .disable_vblank = mixer_disable_vblank, 1136 .disable_vblank = mixer_disable_vblank,
@@ -1156,7 +1160,7 @@ static struct mixer_drv_data exynos4210_mxr_drv_data = {
1156 .has_sclk = 1, 1160 .has_sclk = 1,
1157}; 1161};
1158 1162
1159static struct platform_device_id mixer_driver_types[] = { 1163static const struct platform_device_id mixer_driver_types[] = {
1160 { 1164 {
1161 .name = "s5p-mixer", 1165 .name = "s5p-mixer",
1162 .driver_data = (unsigned long)&exynos4210_mxr_drv_data, 1166 .driver_data = (unsigned long)&exynos4210_mxr_drv_data,
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index c302ffb5a168..a19d2c71e205 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -699,6 +699,16 @@ static int i915_drm_resume(struct drm_device *dev)
699 intel_init_pch_refclk(dev); 699 intel_init_pch_refclk(dev);
700 drm_mode_config_reset(dev); 700 drm_mode_config_reset(dev);
701 701
702 /*
703 * Interrupts have to be enabled before any batches are run. If not the
704 * GPU will hang. i915_gem_init_hw() will initiate batches to
705 * update/restore the context.
706 *
707 * Modeset enabling in intel_modeset_init_hw() also needs working
708 * interrupts.
709 */
710 intel_runtime_pm_enable_interrupts(dev_priv);
711
702 mutex_lock(&dev->struct_mutex); 712 mutex_lock(&dev->struct_mutex);
703 if (i915_gem_init_hw(dev)) { 713 if (i915_gem_init_hw(dev)) {
704 DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n"); 714 DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
@@ -706,9 +716,6 @@ static int i915_drm_resume(struct drm_device *dev)
706 } 716 }
707 mutex_unlock(&dev->struct_mutex); 717 mutex_unlock(&dev->struct_mutex);
708 718
709 /* We need working interrupts for modeset enabling ... */
710 intel_runtime_pm_enable_interrupts(dev_priv);
711
712 intel_modeset_init_hw(dev); 719 intel_modeset_init_hw(dev);
713 720
714 spin_lock_irq(&dev_priv->irq_lock); 721 spin_lock_irq(&dev_priv->irq_lock);
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 3da1af46625c..773d1d24e604 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -6074,6 +6074,8 @@ enum skl_disp_power_wells {
6074#define GTFIFOCTL 0x120008 6074#define GTFIFOCTL 0x120008
6075#define GT_FIFO_FREE_ENTRIES_MASK 0x7f 6075#define GT_FIFO_FREE_ENTRIES_MASK 0x7f
6076#define GT_FIFO_NUM_RESERVED_ENTRIES 20 6076#define GT_FIFO_NUM_RESERVED_ENTRIES 20
6077#define GT_FIFO_CTL_BLOCK_ALL_POLICY_STALL (1 << 12)
6078#define GT_FIFO_CTL_RC6_POLICY_STALL (1 << 11)
6077 6079
6078#define HSW_IDICR 0x9008 6080#define HSW_IDICR 0x9008
6079#define IDIHASHMSK(x) (((x) & 0x3f) << 16) 6081#define IDIHASHMSK(x) (((x) & 0x3f) << 16)
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index d547d9c8dda2..d0f3cbc87474 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -13635,9 +13635,6 @@ static const struct intel_dmi_quirk intel_dmi_quirks[] = {
13635}; 13635};
13636 13636
13637static struct intel_quirk intel_quirks[] = { 13637static struct intel_quirk intel_quirks[] = {
13638 /* HP Mini needs pipe A force quirk (LP: #322104) */
13639 { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
13640
13641 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ 13638 /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
13642 { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, 13639 { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
13643 13640
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index d0237102c27e..f27346e907b1 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1348,7 +1348,7 @@ intel_dp_compute_config(struct intel_encoder *encoder,
1348 1348
1349 pipe_config->has_dp_encoder = true; 1349 pipe_config->has_dp_encoder = true;
1350 pipe_config->has_drrs = false; 1350 pipe_config->has_drrs = false;
1351 pipe_config->has_audio = intel_dp->has_audio; 1351 pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
1352 1352
1353 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) { 1353 if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1354 intel_fixed_panel_mode(intel_connector->panel.fixed_mode, 1354 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
@@ -2211,8 +2211,8 @@ static void intel_dp_get_config(struct intel_encoder *encoder,
2211 int dotclock; 2211 int dotclock;
2212 2212
2213 tmp = I915_READ(intel_dp->output_reg); 2213 tmp = I915_READ(intel_dp->output_reg);
2214 if (tmp & DP_AUDIO_OUTPUT_ENABLE) 2214
2215 pipe_config->has_audio = true; 2215 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
2216 2216
2217 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) { 2217 if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
2218 if (tmp & DP_SYNC_HS_HIGH) 2218 if (tmp & DP_SYNC_HS_HIGH)
@@ -3812,7 +3812,8 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp)
3812 if (val == 0) 3812 if (val == 0)
3813 break; 3813 break;
3814 3814
3815 intel_dp->sink_rates[i] = val * 200; 3815 /* Value read is in kHz while drm clock is saved in deca-kHz */
3816 intel_dp->sink_rates[i] = (val * 200) / 10;
3816 } 3817 }
3817 intel_dp->num_sink_rates = i; 3818 intel_dp->num_sink_rates = i;
3818 } 3819 }
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index 5abda1d2c018..fbcc7dff0d63 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -813,12 +813,28 @@ static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
813static const struct dmi_system_id intel_dual_link_lvds[] = { 813static const struct dmi_system_id intel_dual_link_lvds[] = {
814 { 814 {
815 .callback = intel_dual_link_lvds_callback, 815 .callback = intel_dual_link_lvds_callback,
816 .ident = "Apple MacBook Pro (Core i5/i7 Series)", 816 .ident = "Apple MacBook Pro 15\" (2010)",
817 .matches = {
818 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
819 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
820 },
821 },
822 {
823 .callback = intel_dual_link_lvds_callback,
824 .ident = "Apple MacBook Pro 15\" (2011)",
817 .matches = { 825 .matches = {
818 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 826 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
819 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"), 827 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
820 }, 828 },
821 }, 829 },
830 {
831 .callback = intel_dual_link_lvds_callback,
832 .ident = "Apple MacBook Pro 15\" (2012)",
833 .matches = {
834 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
835 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
836 },
837 },
822 { } /* terminating entry */ 838 { } /* terminating entry */
823}; 839};
824 840
@@ -848,6 +864,11 @@ static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
848 if (i915.lvds_channel_mode > 0) 864 if (i915.lvds_channel_mode > 0)
849 return i915.lvds_channel_mode == 2; 865 return i915.lvds_channel_mode == 2;
850 866
867 /* single channel LVDS is limited to 112 MHz */
868 if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
869 > 112999)
870 return true;
871
851 if (dmi_check_system(intel_dual_link_lvds)) 872 if (dmi_check_system(intel_dual_link_lvds))
852 return true; 873 return true;
853 874
@@ -1111,6 +1132,8 @@ void intel_lvds_init(struct drm_device *dev)
1111out: 1132out:
1112 mutex_unlock(&dev->mode_config.mutex); 1133 mutex_unlock(&dev->mode_config.mutex);
1113 1134
1135 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
1136
1114 lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder); 1137 lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1115 DRM_DEBUG_KMS("detected %s-link lvds configuration\n", 1138 DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1116 lvds_encoder->is_dual_link ? "dual" : "single"); 1139 lvds_encoder->is_dual_link ? "dual" : "single");
@@ -1125,7 +1148,6 @@ out:
1125 } 1148 }
1126 drm_connector_register(connector); 1149 drm_connector_register(connector);
1127 1150
1128 intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
1129 intel_panel_setup_backlight(connector, INVALID_PIPE); 1151 intel_panel_setup_backlight(connector, INVALID_PIPE);
1130 1152
1131 return; 1153 return;
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index fa4ccb346389..555b896d2bda 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -2045,22 +2045,20 @@ static void ilk_compute_wm_parameters(struct drm_crtc *crtc,
2045 p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; 2045 p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal;
2046 p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); 2046 p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc);
2047 2047
2048 if (crtc->primary->state->fb) { 2048 if (crtc->primary->state->fb)
2049 p->pri.enabled = true;
2050 p->pri.bytes_per_pixel = 2049 p->pri.bytes_per_pixel =
2051 crtc->primary->state->fb->bits_per_pixel / 8; 2050 crtc->primary->state->fb->bits_per_pixel / 8;
2052 } else { 2051 else
2053 p->pri.enabled = false; 2052 p->pri.bytes_per_pixel = 4;
2054 p->pri.bytes_per_pixel = 0; 2053
2055 } 2054 p->cur.bytes_per_pixel = 4;
2055 /*
2056 * TODO: for now, assume primary and cursor planes are always enabled.
2057 * Setting them to false makes the screen flicker.
2058 */
2059 p->pri.enabled = true;
2060 p->cur.enabled = true;
2056 2061
2057 if (crtc->cursor->state->fb) {
2058 p->cur.enabled = true;
2059 p->cur.bytes_per_pixel = 4;
2060 } else {
2061 p->cur.enabled = false;
2062 p->cur.bytes_per_pixel = 0;
2063 }
2064 p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; 2062 p->pri.horiz_pixels = intel_crtc->config->pipe_src_w;
2065 p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w; 2063 p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w;
2066 2064
diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
index ab5cc94588e1..ff2a74651dd4 100644
--- a/drivers/gpu/drm/i915/intel_uncore.c
+++ b/drivers/gpu/drm/i915/intel_uncore.c
@@ -360,6 +360,14 @@ static void __intel_uncore_early_sanitize(struct drm_device *dev,
360 __raw_i915_write32(dev_priv, GTFIFODBG, 360 __raw_i915_write32(dev_priv, GTFIFODBG,
361 __raw_i915_read32(dev_priv, GTFIFODBG)); 361 __raw_i915_read32(dev_priv, GTFIFODBG));
362 362
363 /* WaDisableShadowRegForCpd:chv */
364 if (IS_CHERRYVIEW(dev)) {
365 __raw_i915_write32(dev_priv, GTFIFOCTL,
366 __raw_i915_read32(dev_priv, GTFIFOCTL) |
367 GT_FIFO_CTL_BLOCK_ALL_POLICY_STALL |
368 GT_FIFO_CTL_RC6_POLICY_STALL);
369 }
370
363 intel_uncore_forcewake_reset(dev, restore_forcewake); 371 intel_uncore_forcewake_reset(dev, restore_forcewake);
364} 372}
365 373
diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
index 94a5bee69fe7..bbdcab0a56c1 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
@@ -384,7 +384,7 @@ void adreno_gpu_cleanup(struct adreno_gpu *gpu)
384 if (gpu->memptrs_bo) { 384 if (gpu->memptrs_bo) {
385 if (gpu->memptrs_iova) 385 if (gpu->memptrs_iova)
386 msm_gem_put_iova(gpu->memptrs_bo, gpu->base.id); 386 msm_gem_put_iova(gpu->memptrs_bo, gpu->base.id);
387 drm_gem_object_unreference(gpu->memptrs_bo); 387 drm_gem_object_unreference_unlocked(gpu->memptrs_bo);
388 } 388 }
389 release_firmware(gpu->pm4); 389 release_firmware(gpu->pm4);
390 release_firmware(gpu->pfp); 390 release_firmware(gpu->pfp);
diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c
index 28d1f95a90cc..ad50b80225f5 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.c
+++ b/drivers/gpu/drm/msm/dsi/dsi.c
@@ -177,6 +177,11 @@ int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
177 goto fail; 177 goto fail;
178 } 178 }
179 179
180 for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
181 encoders[i]->bridge = msm_dsi->bridge;
182 msm_dsi->encoders[i] = encoders[i];
183 }
184
180 msm_dsi->connector = msm_dsi_manager_connector_init(msm_dsi->id); 185 msm_dsi->connector = msm_dsi_manager_connector_init(msm_dsi->id);
181 if (IS_ERR(msm_dsi->connector)) { 186 if (IS_ERR(msm_dsi->connector)) {
182 ret = PTR_ERR(msm_dsi->connector); 187 ret = PTR_ERR(msm_dsi->connector);
@@ -185,11 +190,6 @@ int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
185 goto fail; 190 goto fail;
186 } 191 }
187 192
188 for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
189 encoders[i]->bridge = msm_dsi->bridge;
190 msm_dsi->encoders[i] = encoders[i];
191 }
192
193 priv->bridges[priv->num_bridges++] = msm_dsi->bridge; 193 priv->bridges[priv->num_bridges++] = msm_dsi->bridge;
194 priv->connectors[priv->num_connectors++] = msm_dsi->connector; 194 priv->connectors[priv->num_connectors++] = msm_dsi->connector;
195 195
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 956b22492c9a..649d20d29f92 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1023,7 +1023,7 @@ static int dsi_short_read1_resp(u8 *buf, const struct mipi_dsi_msg *msg)
1023 *data = buf[1]; /* strip out dcs type */ 1023 *data = buf[1]; /* strip out dcs type */
1024 return 1; 1024 return 1;
1025 } else { 1025 } else {
1026 pr_err("%s: read data does not match with rx_buf len %d\n", 1026 pr_err("%s: read data does not match with rx_buf len %zu\n",
1027 __func__, msg->rx_len); 1027 __func__, msg->rx_len);
1028 return -EINVAL; 1028 return -EINVAL;
1029 } 1029 }
@@ -1040,7 +1040,7 @@ static int dsi_short_read2_resp(u8 *buf, const struct mipi_dsi_msg *msg)
1040 data[1] = buf[2]; 1040 data[1] = buf[2];
1041 return 2; 1041 return 2;
1042 } else { 1042 } else {
1043 pr_err("%s: read data does not match with rx_buf len %d\n", 1043 pr_err("%s: read data does not match with rx_buf len %zu\n",
1044 __func__, msg->rx_len); 1044 __func__, msg->rx_len);
1045 return -EINVAL; 1045 return -EINVAL;
1046 } 1046 }
@@ -1093,7 +1093,6 @@ static int dsi_cmd_dma_rx(struct msm_dsi_host *msm_host,
1093{ 1093{
1094 u32 *lp, *temp, data; 1094 u32 *lp, *temp, data;
1095 int i, j = 0, cnt; 1095 int i, j = 0, cnt;
1096 bool ack_error = false;
1097 u32 read_cnt; 1096 u32 read_cnt;
1098 u8 reg[16]; 1097 u8 reg[16];
1099 int repeated_bytes = 0; 1098 int repeated_bytes = 0;
@@ -1105,15 +1104,10 @@ static int dsi_cmd_dma_rx(struct msm_dsi_host *msm_host,
1105 if (cnt > 4) 1104 if (cnt > 4)
1106 cnt = 4; /* 4 x 32 bits registers only */ 1105 cnt = 4; /* 4 x 32 bits registers only */
1107 1106
1108 /* Calculate real read data count */ 1107 if (rx_byte == 4)
1109 read_cnt = dsi_read(msm_host, 0x1d4) >> 16; 1108 read_cnt = 4;
1110 1109 else
1111 ack_error = (rx_byte == 4) ? 1110 read_cnt = pkt_size + 6;
1112 (read_cnt == 8) : /* short pkt + 4-byte error pkt */
1113 (read_cnt == (pkt_size + 6 + 4)); /* long pkt+4-byte error pkt*/
1114
1115 if (ack_error)
1116 read_cnt -= 4; /* Remove 4 byte error pkt */
1117 1111
1118 /* 1112 /*
1119 * In case of multiple reads from the panel, after the first read, there 1113 * In case of multiple reads from the panel, after the first read, there
@@ -1215,7 +1209,7 @@ static void dsi_err_worker(struct work_struct *work)
1215 container_of(work, struct msm_dsi_host, err_work); 1209 container_of(work, struct msm_dsi_host, err_work);
1216 u32 status = msm_host->err_work_state; 1210 u32 status = msm_host->err_work_state;
1217 1211
1218 pr_err("%s: status=%x\n", __func__, status); 1212 pr_err_ratelimited("%s: status=%x\n", __func__, status);
1219 if (status & DSI_ERR_STATE_MDP_FIFO_UNDERFLOW) 1213 if (status & DSI_ERR_STATE_MDP_FIFO_UNDERFLOW)
1220 dsi_sw_reset_restore(msm_host); 1214 dsi_sw_reset_restore(msm_host);
1221 1215
@@ -1797,6 +1791,7 @@ int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
1797 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT: 1791 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
1798 pr_err("%s: rx ACK_ERR_PACLAGE\n", __func__); 1792 pr_err("%s: rx ACK_ERR_PACLAGE\n", __func__);
1799 ret = 0; 1793 ret = 0;
1794 break;
1800 case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE: 1795 case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
1801 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE: 1796 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
1802 ret = dsi_short_read1_resp(buf, msg); 1797 ret = dsi_short_read1_resp(buf, msg);
diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c b/drivers/gpu/drm/msm/dsi/dsi_manager.c
index ee3ebcaa33f5..0a40f3c64e8b 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_manager.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c
@@ -462,7 +462,7 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id)
462 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); 462 struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
463 struct drm_connector *connector = NULL; 463 struct drm_connector *connector = NULL;
464 struct dsi_connector *dsi_connector; 464 struct dsi_connector *dsi_connector;
465 int ret; 465 int ret, i;
466 466
467 dsi_connector = devm_kzalloc(msm_dsi->dev->dev, 467 dsi_connector = devm_kzalloc(msm_dsi->dev->dev,
468 sizeof(*dsi_connector), GFP_KERNEL); 468 sizeof(*dsi_connector), GFP_KERNEL);
@@ -495,6 +495,10 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id)
495 if (ret) 495 if (ret)
496 goto fail; 496 goto fail;
497 497
498 for (i = 0; i < MSM_DSI_ENCODER_NUM; i++)
499 drm_mode_connector_attach_encoder(connector,
500 msm_dsi->encoders[i]);
501
498 return connector; 502 return connector;
499 503
500fail: 504fail:
diff --git a/drivers/gpu/drm/msm/edp/edp_aux.c b/drivers/gpu/drm/msm/edp/edp_aux.c
index 5f5a84f6074c..208f9d47f82e 100644
--- a/drivers/gpu/drm/msm/edp/edp_aux.c
+++ b/drivers/gpu/drm/msm/edp/edp_aux.c
@@ -132,7 +132,7 @@ ssize_t edp_aux_transfer(struct drm_dp_aux *drm_aux, struct drm_dp_aux_msg *msg)
132 /* msg sanity check */ 132 /* msg sanity check */
133 if ((native && (msg->size > AUX_CMD_NATIVE_MAX)) || 133 if ((native && (msg->size > AUX_CMD_NATIVE_MAX)) ||
134 (msg->size > AUX_CMD_I2C_MAX)) { 134 (msg->size > AUX_CMD_I2C_MAX)) {
135 pr_err("%s: invalid msg: size(%d), request(%x)\n", 135 pr_err("%s: invalid msg: size(%zu), request(%x)\n",
136 __func__, msg->size, msg->request); 136 __func__, msg->size, msg->request);
137 return -EINVAL; 137 return -EINVAL;
138 } 138 }
@@ -155,7 +155,7 @@ ssize_t edp_aux_transfer(struct drm_dp_aux *drm_aux, struct drm_dp_aux_msg *msg)
155 */ 155 */
156 edp_write(aux->base + REG_EDP_AUX_TRANS_CTRL, 0); 156 edp_write(aux->base + REG_EDP_AUX_TRANS_CTRL, 0);
157 msm_edp_aux_ctrl(aux, 1); 157 msm_edp_aux_ctrl(aux, 1);
158 pr_err("%s: aux timeout, %d\n", __func__, ret); 158 pr_err("%s: aux timeout, %zd\n", __func__, ret);
159 goto unlock_exit; 159 goto unlock_exit;
160 } 160 }
161 DBG("completion"); 161 DBG("completion");
diff --git a/drivers/gpu/drm/msm/edp/edp_connector.c b/drivers/gpu/drm/msm/edp/edp_connector.c
index d8812e84da54..b4d1b469862a 100644
--- a/drivers/gpu/drm/msm/edp/edp_connector.c
+++ b/drivers/gpu/drm/msm/edp/edp_connector.c
@@ -151,6 +151,8 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp)
151 if (ret) 151 if (ret)
152 goto fail; 152 goto fail;
153 153
154 drm_mode_connector_attach_encoder(connector, edp->encoder);
155
154 return connector; 156 return connector;
155 157
156fail: 158fail:
diff --git a/drivers/gpu/drm/msm/edp/edp_ctrl.c b/drivers/gpu/drm/msm/edp/edp_ctrl.c
index 0ec5abdba5c4..29e52d7c61c0 100644
--- a/drivers/gpu/drm/msm/edp/edp_ctrl.c
+++ b/drivers/gpu/drm/msm/edp/edp_ctrl.c
@@ -1149,12 +1149,13 @@ int msm_edp_ctrl_init(struct msm_edp *edp)
1149 ctrl->aux = msm_edp_aux_init(dev, ctrl->base, &ctrl->drm_aux); 1149 ctrl->aux = msm_edp_aux_init(dev, ctrl->base, &ctrl->drm_aux);
1150 if (!ctrl->aux || !ctrl->drm_aux) { 1150 if (!ctrl->aux || !ctrl->drm_aux) {
1151 pr_err("%s:failed to init aux\n", __func__); 1151 pr_err("%s:failed to init aux\n", __func__);
1152 return ret; 1152 return -ENOMEM;
1153 } 1153 }
1154 1154
1155 ctrl->phy = msm_edp_phy_init(dev, ctrl->base); 1155 ctrl->phy = msm_edp_phy_init(dev, ctrl->base);
1156 if (!ctrl->phy) { 1156 if (!ctrl->phy) {
1157 pr_err("%s:failed to init phy\n", __func__); 1157 pr_err("%s:failed to init phy\n", __func__);
1158 ret = -ENOMEM;
1158 goto err_destory_aux; 1159 goto err_destory_aux;
1159 } 1160 }
1160 1161
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c
index e001e6b2296a..8b9a7931b162 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c
@@ -72,14 +72,13 @@ const struct mdp5_cfg_hw msm8x74_config = {
72 .base = { 0x12d00, 0x12e00, 0x12f00 }, 72 .base = { 0x12d00, 0x12e00, 0x12f00 },
73 }, 73 },
74 .intf = { 74 .intf = {
75 .count = 4,
76 .base = { 0x12500, 0x12700, 0x12900, 0x12b00 }, 75 .base = { 0x12500, 0x12700, 0x12900, 0x12b00 },
77 }, 76 .connect = {
78 .intfs = { 77 [0] = INTF_eDP,
79 [0] = INTF_eDP, 78 [1] = INTF_DSI,
80 [1] = INTF_DSI, 79 [2] = INTF_DSI,
81 [2] = INTF_DSI, 80 [3] = INTF_HDMI,
82 [3] = INTF_HDMI, 81 },
83 }, 82 },
84 .max_clk = 200000000, 83 .max_clk = 200000000,
85}; 84};
@@ -142,14 +141,13 @@ const struct mdp5_cfg_hw apq8084_config = {
142 .base = { 0x12f00, 0x13000, 0x13100, 0x13200 }, 141 .base = { 0x12f00, 0x13000, 0x13100, 0x13200 },
143 }, 142 },
144 .intf = { 143 .intf = {
145 .count = 5,
146 .base = { 0x12500, 0x12700, 0x12900, 0x12b00, 0x12d00 }, 144 .base = { 0x12500, 0x12700, 0x12900, 0x12b00, 0x12d00 },
147 }, 145 .connect = {
148 .intfs = { 146 [0] = INTF_eDP,
149 [0] = INTF_eDP, 147 [1] = INTF_DSI,
150 [1] = INTF_DSI, 148 [2] = INTF_DSI,
151 [2] = INTF_DSI, 149 [3] = INTF_HDMI,
152 [3] = INTF_HDMI, 150 },
153 }, 151 },
154 .max_clk = 320000000, 152 .max_clk = 320000000,
155}; 153};
@@ -196,10 +194,12 @@ const struct mdp5_cfg_hw msm8x16_config = {
196 194
197 }, 195 },
198 .intf = { 196 .intf = {
199 .count = 1, /* INTF_1 */ 197 .base = { 0x00000, 0x6b800 },
200 .base = { 0x6B800 }, 198 .connect = {
199 [0] = INTF_DISABLED,
200 [1] = INTF_DSI,
201 },
201 }, 202 },
202 /* TODO enable .intfs[] with [1] = INTF_DSI, once DSI is implemented */
203 .max_clk = 320000000, 203 .max_clk = 320000000,
204}; 204};
205 205
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.h b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.h
index 3a551b0892d8..69349abe59f2 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.h
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.h
@@ -59,6 +59,11 @@ struct mdp5_smp_block {
59 59
60#define MDP5_INTF_NUM_MAX 5 60#define MDP5_INTF_NUM_MAX 5
61 61
62struct mdp5_intf_block {
63 uint32_t base[MAX_BASES];
64 u32 connect[MDP5_INTF_NUM_MAX]; /* array of enum mdp5_intf_type */
65};
66
62struct mdp5_cfg_hw { 67struct mdp5_cfg_hw {
63 char *name; 68 char *name;
64 69
@@ -72,9 +77,7 @@ struct mdp5_cfg_hw {
72 struct mdp5_sub_block dspp; 77 struct mdp5_sub_block dspp;
73 struct mdp5_sub_block ad; 78 struct mdp5_sub_block ad;
74 struct mdp5_sub_block pp; 79 struct mdp5_sub_block pp;
75 struct mdp5_sub_block intf; 80 struct mdp5_intf_block intf;
76
77 u32 intfs[MDP5_INTF_NUM_MAX]; /* array of enum mdp5_intf_type */
78 81
79 uint32_t max_clk; 82 uint32_t max_clk;
80}; 83};
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c
index dfa8beb9343a..bbacf9d2b738 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c
@@ -206,8 +206,8 @@ static struct drm_encoder *construct_encoder(struct mdp5_kms *mdp5_kms,
206 206
207static int get_dsi_id_from_intf(const struct mdp5_cfg_hw *hw_cfg, int intf_num) 207static int get_dsi_id_from_intf(const struct mdp5_cfg_hw *hw_cfg, int intf_num)
208{ 208{
209 const int intf_cnt = hw_cfg->intf.count; 209 const enum mdp5_intf_type *intfs = hw_cfg->intf.connect;
210 const u32 *intfs = hw_cfg->intfs; 210 const int intf_cnt = ARRAY_SIZE(hw_cfg->intf.connect);
211 int id = 0, i; 211 int id = 0, i;
212 212
213 for (i = 0; i < intf_cnt; i++) { 213 for (i = 0; i < intf_cnt; i++) {
@@ -228,7 +228,7 @@ static int modeset_init_intf(struct mdp5_kms *mdp5_kms, int intf_num)
228 struct msm_drm_private *priv = dev->dev_private; 228 struct msm_drm_private *priv = dev->dev_private;
229 const struct mdp5_cfg_hw *hw_cfg = 229 const struct mdp5_cfg_hw *hw_cfg =
230 mdp5_cfg_get_hw_config(mdp5_kms->cfg); 230 mdp5_cfg_get_hw_config(mdp5_kms->cfg);
231 enum mdp5_intf_type intf_type = hw_cfg->intfs[intf_num]; 231 enum mdp5_intf_type intf_type = hw_cfg->intf.connect[intf_num];
232 struct drm_encoder *encoder; 232 struct drm_encoder *encoder;
233 int ret = 0; 233 int ret = 0;
234 234
@@ -365,7 +365,7 @@ static int modeset_init(struct mdp5_kms *mdp5_kms)
365 /* Construct encoders and modeset initialize connector devices 365 /* Construct encoders and modeset initialize connector devices
366 * for each external display interface. 366 * for each external display interface.
367 */ 367 */
368 for (i = 0; i < ARRAY_SIZE(hw_cfg->intfs); i++) { 368 for (i = 0; i < ARRAY_SIZE(hw_cfg->intf.connect); i++) {
369 ret = modeset_init_intf(mdp5_kms, i); 369 ret = modeset_init_intf(mdp5_kms, i);
370 if (ret) 370 if (ret)
371 goto fail; 371 goto fail;
@@ -514,8 +514,8 @@ struct msm_kms *mdp5_kms_init(struct drm_device *dev)
514 */ 514 */
515 mdp5_enable(mdp5_kms); 515 mdp5_enable(mdp5_kms);
516 for (i = 0; i < MDP5_INTF_NUM_MAX; i++) { 516 for (i = 0; i < MDP5_INTF_NUM_MAX; i++) {
517 if (!config->hw->intf.base[i] || 517 if (mdp5_cfg_intf_is_virtual(config->hw->intf.connect[i]) ||
518 mdp5_cfg_intf_is_virtual(config->hw->intfs[i])) 518 !config->hw->intf.base[i])
519 continue; 519 continue;
520 mdp5_write(mdp5_kms, REG_MDP5_INTF_TIMING_ENGINE_EN(i), 0); 520 mdp5_write(mdp5_kms, REG_MDP5_INTF_TIMING_ENGINE_EN(i), 0);
521 } 521 }
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
index 18a3d203b174..57b8f56ae9d0 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
@@ -273,7 +273,7 @@ static void set_scanout_locked(struct drm_plane *plane,
273 mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC2_ADDR(pipe), 273 mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC2_ADDR(pipe),
274 msm_framebuffer_iova(fb, mdp5_kms->id, 2)); 274 msm_framebuffer_iova(fb, mdp5_kms->id, 2));
275 mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC3_ADDR(pipe), 275 mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC3_ADDR(pipe),
276 msm_framebuffer_iova(fb, mdp5_kms->id, 4)); 276 msm_framebuffer_iova(fb, mdp5_kms->id, 3));
277 277
278 plane->fb = fb; 278 plane->fb = fb;
279} 279}
diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 47f4dd407671..c80a6bee2b18 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -21,9 +21,11 @@
21 21
22static void msm_fb_output_poll_changed(struct drm_device *dev) 22static void msm_fb_output_poll_changed(struct drm_device *dev)
23{ 23{
24#ifdef CONFIG_DRM_MSM_FBDEV
24 struct msm_drm_private *priv = dev->dev_private; 25 struct msm_drm_private *priv = dev->dev_private;
25 if (priv->fbdev) 26 if (priv->fbdev)
26 drm_fb_helper_hotplug_event(priv->fbdev); 27 drm_fb_helper_hotplug_event(priv->fbdev);
28#endif
27} 29}
28 30
29static const struct drm_mode_config_funcs mode_config_funcs = { 31static const struct drm_mode_config_funcs mode_config_funcs = {
@@ -94,7 +96,7 @@ void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
94 } 96 }
95 97
96 if (reglog) 98 if (reglog)
97 printk(KERN_DEBUG "IO:region %s %08x %08lx\n", dbgname, (u32)ptr, size); 99 printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size);
98 100
99 return ptr; 101 return ptr;
100} 102}
@@ -102,7 +104,7 @@ void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
102void msm_writel(u32 data, void __iomem *addr) 104void msm_writel(u32 data, void __iomem *addr)
103{ 105{
104 if (reglog) 106 if (reglog)
105 printk(KERN_DEBUG "IO:W %08x %08x\n", (u32)addr, data); 107 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
106 writel(data, addr); 108 writel(data, addr);
107} 109}
108 110
@@ -110,7 +112,7 @@ u32 msm_readl(const void __iomem *addr)
110{ 112{
111 u32 val = readl(addr); 113 u32 val = readl(addr);
112 if (reglog) 114 if (reglog)
113 printk(KERN_ERR "IO:R %08x %08x\n", (u32)addr, val); 115 printk(KERN_ERR "IO:R %p %08x\n", addr, val);
114 return val; 116 return val;
115} 117}
116 118
@@ -143,8 +145,8 @@ static int msm_unload(struct drm_device *dev)
143 if (gpu) { 145 if (gpu) {
144 mutex_lock(&dev->struct_mutex); 146 mutex_lock(&dev->struct_mutex);
145 gpu->funcs->pm_suspend(gpu); 147 gpu->funcs->pm_suspend(gpu);
146 gpu->funcs->destroy(gpu);
147 mutex_unlock(&dev->struct_mutex); 148 mutex_unlock(&dev->struct_mutex);
149 gpu->funcs->destroy(gpu);
148 } 150 }
149 151
150 if (priv->vram.paddr) { 152 if (priv->vram.paddr) {
@@ -177,7 +179,7 @@ static int get_mdp_ver(struct platform_device *pdev)
177 const struct of_device_id *match; 179 const struct of_device_id *match;
178 match = of_match_node(match_types, dev->of_node); 180 match = of_match_node(match_types, dev->of_node);
179 if (match) 181 if (match)
180 return (int)match->data; 182 return (int)(unsigned long)match->data;
181#endif 183#endif
182 return 4; 184 return 4;
183} 185}
@@ -216,7 +218,7 @@ static int msm_init_vram(struct drm_device *dev)
216 if (ret) 218 if (ret)
217 return ret; 219 return ret;
218 size = r.end - r.start; 220 size = r.end - r.start;
219 DRM_INFO("using VRAM carveout: %lx@%08x\n", size, r.start); 221 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
220 } else 222 } else
221#endif 223#endif
222 224
@@ -283,10 +285,6 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
283 285
284 drm_mode_config_init(dev); 286 drm_mode_config_init(dev);
285 287
286 ret = msm_init_vram(dev);
287 if (ret)
288 goto fail;
289
290 platform_set_drvdata(pdev, dev); 288 platform_set_drvdata(pdev, dev);
291 289
292 /* Bind all our sub-components: */ 290 /* Bind all our sub-components: */
@@ -294,6 +292,10 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
294 if (ret) 292 if (ret)
295 return ret; 293 return ret;
296 294
295 ret = msm_init_vram(dev);
296 if (ret)
297 goto fail;
298
297 switch (get_mdp_ver(pdev)) { 299 switch (get_mdp_ver(pdev)) {
298 case 4: 300 case 4:
299 kms = mdp4_kms_init(dev); 301 kms = mdp4_kms_init(dev);
@@ -419,9 +421,11 @@ static void msm_preclose(struct drm_device *dev, struct drm_file *file)
419 421
420static void msm_lastclose(struct drm_device *dev) 422static void msm_lastclose(struct drm_device *dev)
421{ 423{
424#ifdef CONFIG_DRM_MSM_FBDEV
422 struct msm_drm_private *priv = dev->dev_private; 425 struct msm_drm_private *priv = dev->dev_private;
423 if (priv->fbdev) 426 if (priv->fbdev)
424 drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev); 427 drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
428#endif
425} 429}
426 430
427static irqreturn_t msm_irq(int irq, void *arg) 431static irqreturn_t msm_irq(int irq, void *arg)
diff --git a/drivers/gpu/drm/msm/msm_fb.c b/drivers/gpu/drm/msm/msm_fb.c
index 6b573e612f27..121713281417 100644
--- a/drivers/gpu/drm/msm/msm_fb.c
+++ b/drivers/gpu/drm/msm/msm_fb.c
@@ -172,8 +172,8 @@ struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
172{ 172{
173 struct msm_drm_private *priv = dev->dev_private; 173 struct msm_drm_private *priv = dev->dev_private;
174 struct msm_kms *kms = priv->kms; 174 struct msm_kms *kms = priv->kms;
175 struct msm_framebuffer *msm_fb; 175 struct msm_framebuffer *msm_fb = NULL;
176 struct drm_framebuffer *fb = NULL; 176 struct drm_framebuffer *fb;
177 const struct msm_format *format; 177 const struct msm_format *format;
178 int ret, i, n; 178 int ret, i, n;
179 unsigned int hsub, vsub; 179 unsigned int hsub, vsub;
@@ -239,8 +239,7 @@ struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
239 return fb; 239 return fb;
240 240
241fail: 241fail:
242 if (fb) 242 kfree(msm_fb);
243 msm_framebuffer_destroy(fb);
244 243
245 return ERR_PTR(ret); 244 return ERR_PTR(ret);
246} 245}
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 479d8af72bcb..52839769eb6c 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -483,7 +483,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
483 uint64_t off = drm_vma_node_start(&obj->vma_node); 483 uint64_t off = drm_vma_node_start(&obj->vma_node);
484 484
485 WARN_ON(!mutex_is_locked(&dev->struct_mutex)); 485 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
486 seq_printf(m, "%08x: %c(r=%u,w=%u) %2d (%2d) %08llx %p %d\n", 486 seq_printf(m, "%08x: %c(r=%u,w=%u) %2d (%2d) %08llx %p %zu\n",
487 msm_obj->flags, is_active(msm_obj) ? 'A' : 'I', 487 msm_obj->flags, is_active(msm_obj) ? 'A' : 'I',
488 msm_obj->read_fence, msm_obj->write_fence, 488 msm_obj->read_fence, msm_obj->write_fence,
489 obj->name, obj->refcount.refcount.counter, 489 obj->name, obj->refcount.refcount.counter,
diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c
index 7acdaa5688b7..7ac2f1997e4a 100644
--- a/drivers/gpu/drm/msm/msm_iommu.c
+++ b/drivers/gpu/drm/msm/msm_iommu.c
@@ -60,7 +60,7 @@ static int msm_iommu_map(struct msm_mmu *mmu, uint32_t iova,
60 u32 pa = sg_phys(sg) - sg->offset; 60 u32 pa = sg_phys(sg) - sg->offset;
61 size_t bytes = sg->length + sg->offset; 61 size_t bytes = sg->length + sg->offset;
62 62
63 VERB("map[%d]: %08x %08x(%x)", i, iova, pa, bytes); 63 VERB("map[%d]: %08x %08x(%zx)", i, iova, pa, bytes);
64 64
65 ret = iommu_map(domain, da, pa, bytes, prot); 65 ret = iommu_map(domain, da, pa, bytes, prot);
66 if (ret) 66 if (ret)
@@ -99,7 +99,7 @@ static int msm_iommu_unmap(struct msm_mmu *mmu, uint32_t iova,
99 if (unmapped < bytes) 99 if (unmapped < bytes)
100 return unmapped; 100 return unmapped;
101 101
102 VERB("unmap[%d]: %08x(%x)", i, iova, bytes); 102 VERB("unmap[%d]: %08x(%zx)", i, iova, bytes);
103 103
104 BUG_ON(!PAGE_ALIGNED(bytes)); 104 BUG_ON(!PAGE_ALIGNED(bytes));
105 105
diff --git a/drivers/gpu/drm/msm/msm_ringbuffer.c b/drivers/gpu/drm/msm/msm_ringbuffer.c
index 8171537dd7d1..1f14b908b221 100644
--- a/drivers/gpu/drm/msm/msm_ringbuffer.c
+++ b/drivers/gpu/drm/msm/msm_ringbuffer.c
@@ -56,6 +56,6 @@ fail:
56void msm_ringbuffer_destroy(struct msm_ringbuffer *ring) 56void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
57{ 57{
58 if (ring->bo) 58 if (ring->bo)
59 drm_gem_object_unreference(ring->bo); 59 drm_gem_object_unreference_unlocked(ring->bo);
60 kfree(ring); 60 kfree(ring);
61} 61}
diff --git a/drivers/gpu/drm/nouveau/include/nvif/class.h b/drivers/gpu/drm/nouveau/include/nvif/class.h
index 0b5af0fe8659..64f8b2f687d2 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/class.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/class.h
@@ -14,7 +14,7 @@
14 14
15#define FERMI_TWOD_A 0x0000902d 15#define FERMI_TWOD_A 0x0000902d
16 16
17#define FERMI_MEMORY_TO_MEMORY_FORMAT_A 0x0000903d 17#define FERMI_MEMORY_TO_MEMORY_FORMAT_A 0x00009039
18 18
19#define KEPLER_INLINE_TO_MEMORY_A 0x0000a040 19#define KEPLER_INLINE_TO_MEMORY_A 0x0000a040
20#define KEPLER_INLINE_TO_MEMORY_B 0x0000a140 20#define KEPLER_INLINE_TO_MEMORY_B 0x0000a140
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm204.c b/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm204.c
index 2f5eadd12a9b..fdb1dcf16a59 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm204.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/gr/gm204.c
@@ -329,7 +329,6 @@ gm204_gr_init(struct nvkm_object *object)
329 nv_mask(priv, 0x419cc0, 0x00000008, 0x00000008); 329 nv_mask(priv, 0x419cc0, 0x00000008, 0x00000008);
330 330
331 for (gpc = 0; gpc < priv->gpc_nr; gpc++) { 331 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
332 printk(KERN_ERR "ppc %d %d\n", gpc, priv->ppc_nr[gpc]);
333 for (ppc = 0; ppc < priv->ppc_nr[gpc]; ppc++) 332 for (ppc = 0; ppc < priv->ppc_nr[gpc]; ppc++)
334 nv_wr32(priv, PPC_UNIT(gpc, ppc, 0x038), 0xc0000000); 333 nv_wr32(priv, PPC_UNIT(gpc, ppc, 0x038), 0xc0000000);
335 nv_wr32(priv, GPC_UNIT(gpc, 0x0420), 0xc0000000); 334 nv_wr32(priv, GPC_UNIT(gpc, 0x0420), 0xc0000000);
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c
index e8778c67578e..c61102f70805 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gf100.c
@@ -90,12 +90,14 @@ gf100_devinit_disable(struct nvkm_devinit *devinit)
90 return disable; 90 return disable;
91} 91}
92 92
93static int 93int
94gf100_devinit_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 94gf100_devinit_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
95 struct nvkm_oclass *oclass, void *data, u32 size, 95 struct nvkm_oclass *oclass, void *data, u32 size,
96 struct nvkm_object **pobject) 96 struct nvkm_object **pobject)
97{ 97{
98 struct nvkm_devinit_impl *impl = (void *)oclass;
98 struct nv50_devinit_priv *priv; 99 struct nv50_devinit_priv *priv;
100 u64 disable;
99 int ret; 101 int ret;
100 102
101 ret = nvkm_devinit_create(parent, engine, oclass, &priv); 103 ret = nvkm_devinit_create(parent, engine, oclass, &priv);
@@ -103,7 +105,8 @@ gf100_devinit_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
103 if (ret) 105 if (ret)
104 return ret; 106 return ret;
105 107
106 if (nv_rd32(priv, 0x022500) & 0x00000001) 108 disable = impl->disable(&priv->base);
109 if (disable & (1ULL << NVDEV_ENGINE_DISP))
107 priv->base.post = true; 110 priv->base.post = true;
108 111
109 return 0; 112 return 0;
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm107.c b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm107.c
index b345a53e881d..87ca0ece37b4 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm107.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm107.c
@@ -48,7 +48,7 @@ struct nvkm_oclass *
48gm107_devinit_oclass = &(struct nvkm_devinit_impl) { 48gm107_devinit_oclass = &(struct nvkm_devinit_impl) {
49 .base.handle = NV_SUBDEV(DEVINIT, 0x07), 49 .base.handle = NV_SUBDEV(DEVINIT, 0x07),
50 .base.ofuncs = &(struct nvkm_ofuncs) { 50 .base.ofuncs = &(struct nvkm_ofuncs) {
51 .ctor = nv50_devinit_ctor, 51 .ctor = gf100_devinit_ctor,
52 .dtor = _nvkm_devinit_dtor, 52 .dtor = _nvkm_devinit_dtor,
53 .init = nv50_devinit_init, 53 .init = nv50_devinit_init,
54 .fini = _nvkm_devinit_fini, 54 .fini = _nvkm_devinit_fini,
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm204.c b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm204.c
index 535172c5f1ad..1076fcf0d716 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm204.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/gm204.c
@@ -161,7 +161,7 @@ struct nvkm_oclass *
161gm204_devinit_oclass = &(struct nvkm_devinit_impl) { 161gm204_devinit_oclass = &(struct nvkm_devinit_impl) {
162 .base.handle = NV_SUBDEV(DEVINIT, 0x07), 162 .base.handle = NV_SUBDEV(DEVINIT, 0x07),
163 .base.ofuncs = &(struct nvkm_ofuncs) { 163 .base.ofuncs = &(struct nvkm_ofuncs) {
164 .ctor = nv50_devinit_ctor, 164 .ctor = gf100_devinit_ctor,
165 .dtor = _nvkm_devinit_dtor, 165 .dtor = _nvkm_devinit_dtor,
166 .init = nv50_devinit_init, 166 .init = nv50_devinit_init,
167 .fini = _nvkm_devinit_fini, 167 .fini = _nvkm_devinit_fini,
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/nv50.h b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/nv50.h
index b882b65ff3cd..9243521c80ac 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/nv50.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/devinit/nv50.h
@@ -15,6 +15,9 @@ int nv50_devinit_pll_set(struct nvkm_devinit *, u32, u32);
15 15
16int gt215_devinit_pll_set(struct nvkm_devinit *, u32, u32); 16int gt215_devinit_pll_set(struct nvkm_devinit *, u32, u32);
17 17
18int gf100_devinit_ctor(struct nvkm_object *, struct nvkm_object *,
19 struct nvkm_oclass *, void *, u32,
20 struct nvkm_object **);
18int gf100_devinit_pll_set(struct nvkm_devinit *, u32, u32); 21int gf100_devinit_pll_set(struct nvkm_devinit *, u32, u32);
19 22
20u64 gm107_devinit_disable(struct nvkm_devinit *); 23u64 gm107_devinit_disable(struct nvkm_devinit *);
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index dac78ad24b31..e597ffc26563 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -580,6 +580,9 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
580 else 580 else
581 radeon_crtc->pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV; 581 radeon_crtc->pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV;
582 582
583 /* if there is no audio, set MINM_OVER_MAXP */
584 if (!drm_detect_monitor_audio(radeon_connector_edid(connector)))
585 radeon_crtc->pll_flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP;
583 if (rdev->family < CHIP_RV770) 586 if (rdev->family < CHIP_RV770)
584 radeon_crtc->pll_flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP; 587 radeon_crtc->pll_flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP;
585 /* use frac fb div on APUs */ 588 /* use frac fb div on APUs */
@@ -1795,7 +1798,9 @@ static int radeon_get_shared_nondp_ppll(struct drm_crtc *crtc)
1795 if ((crtc->mode.clock == test_crtc->mode.clock) && 1798 if ((crtc->mode.clock == test_crtc->mode.clock) &&
1796 (adjusted_clock == test_adjusted_clock) && 1799 (adjusted_clock == test_adjusted_clock) &&
1797 (radeon_crtc->ss_enabled == test_radeon_crtc->ss_enabled) && 1800 (radeon_crtc->ss_enabled == test_radeon_crtc->ss_enabled) &&
1798 (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID)) 1801 (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) &&
1802 (drm_detect_monitor_audio(radeon_connector_edid(test_radeon_crtc->connector)) ==
1803 drm_detect_monitor_audio(radeon_connector_edid(radeon_crtc->connector))))
1799 return test_radeon_crtc->pll_id; 1804 return test_radeon_crtc->pll_id;
1800 } 1805 }
1801 } 1806 }
diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c
index 3e3290c203c6..b435c859dcbc 100644
--- a/drivers/gpu/drm/radeon/atombios_dp.c
+++ b/drivers/gpu/drm/radeon/atombios_dp.c
@@ -421,19 +421,21 @@ bool radeon_dp_getdpcd(struct radeon_connector *radeon_connector)
421{ 421{
422 struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv; 422 struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
423 u8 msg[DP_DPCD_SIZE]; 423 u8 msg[DP_DPCD_SIZE];
424 int ret; 424 int ret, i;
425 425
426 ret = drm_dp_dpcd_read(&radeon_connector->ddc_bus->aux, DP_DPCD_REV, msg, 426 for (i = 0; i < 7; i++) {
427 DP_DPCD_SIZE); 427 ret = drm_dp_dpcd_read(&radeon_connector->ddc_bus->aux, DP_DPCD_REV, msg,
428 if (ret > 0) { 428 DP_DPCD_SIZE);
429 memcpy(dig_connector->dpcd, msg, DP_DPCD_SIZE); 429 if (ret == DP_DPCD_SIZE) {
430 memcpy(dig_connector->dpcd, msg, DP_DPCD_SIZE);
430 431
431 DRM_DEBUG_KMS("DPCD: %*ph\n", (int)sizeof(dig_connector->dpcd), 432 DRM_DEBUG_KMS("DPCD: %*ph\n", (int)sizeof(dig_connector->dpcd),
432 dig_connector->dpcd); 433 dig_connector->dpcd);
433 434
434 radeon_dp_probe_oui(radeon_connector); 435 radeon_dp_probe_oui(radeon_connector);
435 436
436 return true; 437 return true;
438 }
437 } 439 }
438 dig_connector->dpcd[0] = 0; 440 dig_connector->dpcd[0] = 0;
439 return false; 441 return false;
diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
index f57c1ab617bc..dd39f434b4a7 100644
--- a/drivers/gpu/drm/radeon/atombios_encoders.c
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -1761,17 +1761,15 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1761 struct drm_device *dev = encoder->dev; 1761 struct drm_device *dev = encoder->dev;
1762 struct radeon_device *rdev = dev->dev_private; 1762 struct radeon_device *rdev = dev->dev_private;
1763 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1763 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1764 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1765 int encoder_mode = atombios_get_encoder_mode(encoder); 1764 int encoder_mode = atombios_get_encoder_mode(encoder);
1766 1765
1767 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n", 1766 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
1768 radeon_encoder->encoder_id, mode, radeon_encoder->devices, 1767 radeon_encoder->encoder_id, mode, radeon_encoder->devices,
1769 radeon_encoder->active_device); 1768 radeon_encoder->active_device);
1770 1769
1771 if (connector && (radeon_audio != 0) && 1770 if ((radeon_audio != 0) &&
1772 ((encoder_mode == ATOM_ENCODER_MODE_HDMI) || 1771 ((encoder_mode == ATOM_ENCODER_MODE_HDMI) ||
1773 (ENCODER_MODE_IS_DP(encoder_mode) && 1772 ENCODER_MODE_IS_DP(encoder_mode)))
1774 drm_detect_monitor_audio(radeon_connector_edid(connector)))))
1775 radeon_audio_dpms(encoder, mode); 1773 radeon_audio_dpms(encoder, mode);
1776 1774
1777 switch (radeon_encoder->encoder_id) { 1775 switch (radeon_encoder->encoder_id) {
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index 28faea9996f9..ba50f3c1c2e0 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -5837,7 +5837,7 @@ static int cik_pcie_gart_enable(struct radeon_device *rdev)
5837 /* restore context1-15 */ 5837 /* restore context1-15 */
5838 /* set vm size, must be a multiple of 4 */ 5838 /* set vm size, must be a multiple of 4 */
5839 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0); 5839 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
5840 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn); 5840 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn - 1);
5841 for (i = 1; i < 16; i++) { 5841 for (i = 1; i < 16; i++) {
5842 if (i < 8) 5842 if (i < 8)
5843 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2), 5843 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index 3adc2afe32aa..68fd9fc677e3 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -295,28 +295,3 @@ void dce6_dp_audio_set_dto(struct radeon_device *rdev,
295 WREG32(DCCG_AUDIO_DTO1_MODULE, clock); 295 WREG32(DCCG_AUDIO_DTO1_MODULE, clock);
296 } 296 }
297} 297}
298
299void dce6_dp_enable(struct drm_encoder *encoder, bool enable)
300{
301 struct drm_device *dev = encoder->dev;
302 struct radeon_device *rdev = dev->dev_private;
303 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
304 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
305
306 if (!dig || !dig->afmt)
307 return;
308
309 if (enable) {
310 WREG32(EVERGREEN_DP_SEC_TIMESTAMP + dig->afmt->offset,
311 EVERGREEN_DP_SEC_TIMESTAMP_MODE(1));
312 WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset,
313 EVERGREEN_DP_SEC_ASP_ENABLE | /* Audio packet transmission */
314 EVERGREEN_DP_SEC_ATP_ENABLE | /* Audio timestamp packet transmission */
315 EVERGREEN_DP_SEC_AIP_ENABLE | /* Audio infoframe packet transmission */
316 EVERGREEN_DP_SEC_STREAM_ENABLE); /* Master enable for secondary stream engine */
317 } else {
318 WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, 0);
319 }
320
321 dig->afmt->enabled = enable;
322}
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index c18d4ecbd95d..9953356fe263 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -219,13 +219,9 @@ void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset,
219 WREG32(AFMT_AVI_INFO3 + offset, 219 WREG32(AFMT_AVI_INFO3 + offset,
220 frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24)); 220 frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24));
221 221
222 WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset,
223 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
224 HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */
225
226 WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, 222 WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset,
227 HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ 223 HDMI_AVI_INFO_LINE(2), /* anything other than 0 */
228 ~HDMI_AVI_INFO_LINE_MASK); 224 ~HDMI_AVI_INFO_LINE_MASK);
229} 225}
230 226
231void dce4_hdmi_audio_set_dto(struct radeon_device *rdev, 227void dce4_hdmi_audio_set_dto(struct radeon_device *rdev,
@@ -370,9 +366,13 @@ void dce4_set_audio_packet(struct drm_encoder *encoder, u32 offset)
370 WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, 366 WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset,
371 AFMT_AUDIO_CHANNEL_ENABLE(0xff)); 367 AFMT_AUDIO_CHANNEL_ENABLE(0xff));
372 368
369 WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
370 HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
371 HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
372
373 /* allow 60958 channel status and send audio packets fields to be updated */ 373 /* allow 60958 channel status and send audio packets fields to be updated */
374 WREG32(AFMT_AUDIO_PACKET_CONTROL + offset, 374 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset,
375 AFMT_AUDIO_SAMPLE_SEND | AFMT_RESET_FIFO_WHEN_AUDIO_DIS | AFMT_60958_CS_UPDATE); 375 AFMT_RESET_FIFO_WHEN_AUDIO_DIS | AFMT_60958_CS_UPDATE);
376} 376}
377 377
378 378
@@ -398,17 +398,26 @@ void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
398 return; 398 return;
399 399
400 if (enable) { 400 if (enable) {
401 WREG32(HDMI_INFOFRAME_CONTROL1 + dig->afmt->offset, 401 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
402 HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
403
404 WREG32(HDMI_AUDIO_PACKET_CONTROL + dig->afmt->offset,
405 HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
406 HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
407 402
408 WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 403 if (connector && drm_detect_monitor_audio(radeon_connector_edid(connector))) {
409 HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ 404 WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset,
410 HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ 405 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
406 HDMI_AVI_INFO_CONT | /* required for audio info values to be updated */
407 HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
408 HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
409 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset,
410 AFMT_AUDIO_SAMPLE_SEND);
411 } else {
412 WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset,
413 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
414 HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */
415 WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset,
416 ~AFMT_AUDIO_SAMPLE_SEND);
417 }
411 } else { 418 } else {
419 WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset,
420 ~AFMT_AUDIO_SAMPLE_SEND);
412 WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 0); 421 WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 0);
413 } 422 }
414 423
@@ -424,20 +433,25 @@ void evergreen_dp_enable(struct drm_encoder *encoder, bool enable)
424 struct radeon_device *rdev = dev->dev_private; 433 struct radeon_device *rdev = dev->dev_private;
425 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 434 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
426 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 435 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
436 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
427 437
428 if (!dig || !dig->afmt) 438 if (!dig || !dig->afmt)
429 return; 439 return;
430 440
431 if (enable) { 441 if (enable && connector &&
442 drm_detect_monitor_audio(radeon_connector_edid(connector))) {
432 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 443 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
433 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 444 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
434 struct radeon_connector_atom_dig *dig_connector; 445 struct radeon_connector_atom_dig *dig_connector;
435 uint32_t val; 446 uint32_t val;
436 447
448 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset,
449 AFMT_AUDIO_SAMPLE_SEND);
450
437 WREG32(EVERGREEN_DP_SEC_TIMESTAMP + dig->afmt->offset, 451 WREG32(EVERGREEN_DP_SEC_TIMESTAMP + dig->afmt->offset,
438 EVERGREEN_DP_SEC_TIMESTAMP_MODE(1)); 452 EVERGREEN_DP_SEC_TIMESTAMP_MODE(1));
439 453
440 if (radeon_connector->con_priv) { 454 if (!ASIC_IS_DCE6(rdev) && radeon_connector->con_priv) {
441 dig_connector = radeon_connector->con_priv; 455 dig_connector = radeon_connector->con_priv;
442 val = RREG32(EVERGREEN_DP_SEC_AUD_N + dig->afmt->offset); 456 val = RREG32(EVERGREEN_DP_SEC_AUD_N + dig->afmt->offset);
443 val &= ~EVERGREEN_DP_SEC_N_BASE_MULTIPLE(0xf); 457 val &= ~EVERGREEN_DP_SEC_N_BASE_MULTIPLE(0xf);
@@ -457,6 +471,8 @@ void evergreen_dp_enable(struct drm_encoder *encoder, bool enable)
457 EVERGREEN_DP_SEC_STREAM_ENABLE); /* Master enable for secondary stream engine */ 471 EVERGREEN_DP_SEC_STREAM_ENABLE); /* Master enable for secondary stream engine */
458 } else { 472 } else {
459 WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, 0); 473 WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, 0);
474 WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset,
475 ~AFMT_AUDIO_SAMPLE_SEND);
460 } 476 }
461 477
462 dig->afmt->enabled = enable; 478 dig->afmt->enabled = enable;
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index e8a496ff007e..64d3a771920d 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -1301,7 +1301,8 @@ static int cayman_pcie_gart_enable(struct radeon_device *rdev)
1301 */ 1301 */
1302 for (i = 1; i < 8; i++) { 1302 for (i = 1; i < 8; i++) {
1303 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0); 1303 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
1304 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), rdev->vm_manager.max_pfn); 1304 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2),
1305 rdev->vm_manager.max_pfn - 1);
1305 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2), 1306 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
1306 rdev->vm_manager.saved_table_addr[i]); 1307 rdev->vm_manager.saved_table_addr[i]);
1307 } 1308 }
diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c
index dd6606b8e23c..e85894ade95c 100644
--- a/drivers/gpu/drm/radeon/r600_hdmi.c
+++ b/drivers/gpu/drm/radeon/r600_hdmi.c
@@ -228,12 +228,13 @@ void r600_set_avi_packet(struct radeon_device *rdev, u32 offset,
228 WREG32(HDMI0_AVI_INFO3 + offset, 228 WREG32(HDMI0_AVI_INFO3 + offset,
229 frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24)); 229 frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24));
230 230
231 WREG32_OR(HDMI0_INFOFRAME_CONTROL1 + offset,
232 HDMI0_AVI_INFO_LINE(2)); /* anything other than 0 */
233
231 WREG32_OR(HDMI0_INFOFRAME_CONTROL0 + offset, 234 WREG32_OR(HDMI0_INFOFRAME_CONTROL0 + offset,
232 HDMI0_AVI_INFO_SEND | /* enable AVI info frames */ 235 HDMI0_AVI_INFO_SEND | /* enable AVI info frames */
233 HDMI0_AVI_INFO_CONT); /* send AVI info frames every frame/field */ 236 HDMI0_AVI_INFO_CONT); /* send AVI info frames every frame/field */
234 237
235 WREG32_OR(HDMI0_INFOFRAME_CONTROL1 + offset,
236 HDMI0_AVI_INFO_LINE(2)); /* anything other than 0 */
237} 238}
238 239
239/* 240/*
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index d2abe481954f..46eb0fa75a61 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1673,7 +1673,6 @@ struct radeon_uvd {
1673 struct radeon_bo *vcpu_bo; 1673 struct radeon_bo *vcpu_bo;
1674 void *cpu_addr; 1674 void *cpu_addr;
1675 uint64_t gpu_addr; 1675 uint64_t gpu_addr;
1676 void *saved_bo;
1677 atomic_t handles[RADEON_MAX_UVD_HANDLES]; 1676 atomic_t handles[RADEON_MAX_UVD_HANDLES];
1678 struct drm_file *filp[RADEON_MAX_UVD_HANDLES]; 1677 struct drm_file *filp[RADEON_MAX_UVD_HANDLES];
1679 unsigned img_size[RADEON_MAX_UVD_HANDLES]; 1678 unsigned img_size[RADEON_MAX_UVD_HANDLES];
diff --git a/drivers/gpu/drm/radeon/radeon_asic.c b/drivers/gpu/drm/radeon/radeon_asic.c
index fafd8ce4d58f..8dbf5083c4ff 100644
--- a/drivers/gpu/drm/radeon/radeon_asic.c
+++ b/drivers/gpu/drm/radeon/radeon_asic.c
@@ -1202,7 +1202,7 @@ static struct radeon_asic rs780_asic = {
1202static struct radeon_asic_ring rv770_uvd_ring = { 1202static struct radeon_asic_ring rv770_uvd_ring = {
1203 .ib_execute = &uvd_v1_0_ib_execute, 1203 .ib_execute = &uvd_v1_0_ib_execute,
1204 .emit_fence = &uvd_v2_2_fence_emit, 1204 .emit_fence = &uvd_v2_2_fence_emit,
1205 .emit_semaphore = &uvd_v1_0_semaphore_emit, 1205 .emit_semaphore = &uvd_v2_2_semaphore_emit,
1206 .cs_parse = &radeon_uvd_cs_parse, 1206 .cs_parse = &radeon_uvd_cs_parse,
1207 .ring_test = &uvd_v1_0_ring_test, 1207 .ring_test = &uvd_v1_0_ring_test,
1208 .ib_test = &uvd_v1_0_ib_test, 1208 .ib_test = &uvd_v1_0_ib_test,
diff --git a/drivers/gpu/drm/radeon/radeon_asic.h b/drivers/gpu/drm/radeon/radeon_asic.h
index cf0a90bb61ca..a3ca8cd305c5 100644
--- a/drivers/gpu/drm/radeon/radeon_asic.h
+++ b/drivers/gpu/drm/radeon/radeon_asic.h
@@ -949,6 +949,10 @@ void uvd_v1_0_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib);
949int uvd_v2_2_resume(struct radeon_device *rdev); 949int uvd_v2_2_resume(struct radeon_device *rdev);
950void uvd_v2_2_fence_emit(struct radeon_device *rdev, 950void uvd_v2_2_fence_emit(struct radeon_device *rdev,
951 struct radeon_fence *fence); 951 struct radeon_fence *fence);
952bool uvd_v2_2_semaphore_emit(struct radeon_device *rdev,
953 struct radeon_ring *ring,
954 struct radeon_semaphore *semaphore,
955 bool emit_wait);
952 956
953/* uvd v3.1 */ 957/* uvd v3.1 */
954bool uvd_v3_1_semaphore_emit(struct radeon_device *rdev, 958bool uvd_v3_1_semaphore_emit(struct radeon_device *rdev,
diff --git a/drivers/gpu/drm/radeon/radeon_audio.c b/drivers/gpu/drm/radeon/radeon_audio.c
index 48d49e651a30..25191f126f3b 100644
--- a/drivers/gpu/drm/radeon/radeon_audio.c
+++ b/drivers/gpu/drm/radeon/radeon_audio.c
@@ -102,7 +102,6 @@ static void radeon_audio_dp_mode_set(struct drm_encoder *encoder,
102void r600_hdmi_enable(struct drm_encoder *encoder, bool enable); 102void r600_hdmi_enable(struct drm_encoder *encoder, bool enable);
103void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable); 103void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable);
104void evergreen_dp_enable(struct drm_encoder *encoder, bool enable); 104void evergreen_dp_enable(struct drm_encoder *encoder, bool enable);
105void dce6_dp_enable(struct drm_encoder *encoder, bool enable);
106 105
107static const u32 pin_offsets[7] = 106static const u32 pin_offsets[7] =
108{ 107{
@@ -240,7 +239,7 @@ static struct radeon_audio_funcs dce6_dp_funcs = {
240 .set_avi_packet = evergreen_set_avi_packet, 239 .set_avi_packet = evergreen_set_avi_packet,
241 .set_audio_packet = dce4_set_audio_packet, 240 .set_audio_packet = dce4_set_audio_packet,
242 .mode_set = radeon_audio_dp_mode_set, 241 .mode_set = radeon_audio_dp_mode_set,
243 .dpms = dce6_dp_enable, 242 .dpms = evergreen_dp_enable,
244}; 243};
245 244
246static void radeon_audio_interface_init(struct radeon_device *rdev) 245static void radeon_audio_interface_init(struct radeon_device *rdev)
@@ -462,6 +461,10 @@ void radeon_audio_detect(struct drm_connector *connector,
462 return; 461 return;
463 462
464 rdev = connector->encoder->dev->dev_private; 463 rdev = connector->encoder->dev->dev_private;
464
465 if (!radeon_audio_chipset_supported(rdev))
466 return;
467
465 radeon_encoder = to_radeon_encoder(connector->encoder); 468 radeon_encoder = to_radeon_encoder(connector->encoder);
466 dig = radeon_encoder->enc_priv; 469 dig = radeon_encoder->enc_priv;
467 470
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 4d0f96cc3da4..ab39b85e0f76 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -88,7 +88,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
88 p->dma_reloc_idx = 0; 88 p->dma_reloc_idx = 0;
89 /* FIXME: we assume that each relocs use 4 dwords */ 89 /* FIXME: we assume that each relocs use 4 dwords */
90 p->nrelocs = chunk->length_dw / 4; 90 p->nrelocs = chunk->length_dw / 4;
91 p->relocs = kcalloc(p->nrelocs, sizeof(struct radeon_bo_list), GFP_KERNEL); 91 p->relocs = drm_calloc_large(p->nrelocs, sizeof(struct radeon_bo_list));
92 if (p->relocs == NULL) { 92 if (p->relocs == NULL) {
93 return -ENOMEM; 93 return -ENOMEM;
94 } 94 }
@@ -428,7 +428,7 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error, bo
428 } 428 }
429 } 429 }
430 kfree(parser->track); 430 kfree(parser->track);
431 kfree(parser->relocs); 431 drm_free_large(parser->relocs);
432 drm_free_large(parser->vm_bos); 432 drm_free_large(parser->vm_bos);
433 for (i = 0; i < parser->nchunks; i++) 433 for (i = 0; i < parser->nchunks; i++)
434 drm_free_large(parser->chunks[i].kdata); 434 drm_free_large(parser->chunks[i].kdata);
diff --git a/drivers/gpu/drm/radeon/radeon_dp_auxch.c b/drivers/gpu/drm/radeon/radeon_dp_auxch.c
index bf1fecc6cceb..fcbd60bb0349 100644
--- a/drivers/gpu/drm/radeon/radeon_dp_auxch.c
+++ b/drivers/gpu/drm/radeon/radeon_dp_auxch.c
@@ -30,8 +30,6 @@
30 AUX_SW_RX_HPD_DISCON | \ 30 AUX_SW_RX_HPD_DISCON | \
31 AUX_SW_RX_PARTIAL_BYTE | \ 31 AUX_SW_RX_PARTIAL_BYTE | \
32 AUX_SW_NON_AUX_MODE | \ 32 AUX_SW_NON_AUX_MODE | \
33 AUX_SW_RX_MIN_COUNT_VIOL | \
34 AUX_SW_RX_INVALID_STOP | \
35 AUX_SW_RX_SYNC_INVALID_L | \ 33 AUX_SW_RX_SYNC_INVALID_L | \
36 AUX_SW_RX_SYNC_INVALID_H | \ 34 AUX_SW_RX_SYNC_INVALID_H | \
37 AUX_SW_RX_INVALID_START | \ 35 AUX_SW_RX_INVALID_START | \
diff --git a/drivers/gpu/drm/radeon/radeon_dp_mst.c b/drivers/gpu/drm/radeon/radeon_dp_mst.c
index 1017338a49d9..2b98ed3e684d 100644
--- a/drivers/gpu/drm/radeon/radeon_dp_mst.c
+++ b/drivers/gpu/drm/radeon/radeon_dp_mst.c
@@ -666,6 +666,9 @@ radeon_dp_mst_probe(struct radeon_connector *radeon_connector)
666 int ret; 666 int ret;
667 u8 msg[1]; 667 u8 msg[1];
668 668
669 if (!radeon_mst)
670 return 0;
671
669 if (dig_connector->dpcd[DP_DPCD_REV] < 0x12) 672 if (dig_connector->dpcd[DP_DPCD_REV] < 0x12)
670 return 0; 673 return 0;
671 674
diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index 01701376b239..eef006c48584 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -135,28 +135,31 @@ static void radeon_mn_invalidate_range_start(struct mmu_notifier *mn,
135 while (it) { 135 while (it) {
136 struct radeon_mn_node *node; 136 struct radeon_mn_node *node;
137 struct radeon_bo *bo; 137 struct radeon_bo *bo;
138 int r; 138 long r;
139 139
140 node = container_of(it, struct radeon_mn_node, it); 140 node = container_of(it, struct radeon_mn_node, it);
141 it = interval_tree_iter_next(it, start, end); 141 it = interval_tree_iter_next(it, start, end);
142 142
143 list_for_each_entry(bo, &node->bos, mn_list) { 143 list_for_each_entry(bo, &node->bos, mn_list) {
144 144
145 if (!bo->tbo.ttm || bo->tbo.ttm->state != tt_bound)
146 continue;
147
145 r = radeon_bo_reserve(bo, true); 148 r = radeon_bo_reserve(bo, true);
146 if (r) { 149 if (r) {
147 DRM_ERROR("(%d) failed to reserve user bo\n", r); 150 DRM_ERROR("(%ld) failed to reserve user bo\n", r);
148 continue; 151 continue;
149 } 152 }
150 153
151 r = reservation_object_wait_timeout_rcu(bo->tbo.resv, 154 r = reservation_object_wait_timeout_rcu(bo->tbo.resv,
152 true, false, MAX_SCHEDULE_TIMEOUT); 155 true, false, MAX_SCHEDULE_TIMEOUT);
153 if (r) 156 if (r <= 0)
154 DRM_ERROR("(%d) failed to wait for user bo\n", r); 157 DRM_ERROR("(%ld) failed to wait for user bo\n", r);
155 158
156 radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_CPU); 159 radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_CPU);
157 r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); 160 r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
158 if (r) 161 if (r)
159 DRM_ERROR("(%d) failed to validate user bo\n", r); 162 DRM_ERROR("(%ld) failed to validate user bo\n", r);
160 163
161 radeon_bo_unreserve(bo); 164 radeon_bo_unreserve(bo);
162 } 165 }
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index b292aca0f342..edafd3c2b170 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -591,8 +591,7 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
591{ 591{
592 struct radeon_device *rdev = radeon_get_rdev(ttm->bdev); 592 struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
593 struct radeon_ttm_tt *gtt = (void *)ttm; 593 struct radeon_ttm_tt *gtt = (void *)ttm;
594 struct scatterlist *sg; 594 struct sg_page_iter sg_iter;
595 int i;
596 595
597 int write = !(gtt->userflags & RADEON_GEM_USERPTR_READONLY); 596 int write = !(gtt->userflags & RADEON_GEM_USERPTR_READONLY);
598 enum dma_data_direction direction = write ? 597 enum dma_data_direction direction = write ?
@@ -605,9 +604,8 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
605 /* free the sg table and pages again */ 604 /* free the sg table and pages again */
606 dma_unmap_sg(rdev->dev, ttm->sg->sgl, ttm->sg->nents, direction); 605 dma_unmap_sg(rdev->dev, ttm->sg->sgl, ttm->sg->nents, direction);
607 606
608 for_each_sg(ttm->sg->sgl, sg, ttm->sg->nents, i) { 607 for_each_sg_page(ttm->sg->sgl, &sg_iter, ttm->sg->nents, 0) {
609 struct page *page = sg_page(sg); 608 struct page *page = sg_page_iter_page(&sg_iter);
610
611 if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY)) 609 if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
612 set_page_dirty(page); 610 set_page_dirty(page);
613 611
diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
index c10b2aec6450..6edcb5485092 100644
--- a/drivers/gpu/drm/radeon/radeon_uvd.c
+++ b/drivers/gpu/drm/radeon/radeon_uvd.c
@@ -204,28 +204,32 @@ void radeon_uvd_fini(struct radeon_device *rdev)
204 204
205int radeon_uvd_suspend(struct radeon_device *rdev) 205int radeon_uvd_suspend(struct radeon_device *rdev)
206{ 206{
207 unsigned size; 207 int i, r;
208 void *ptr;
209 int i;
210 208
211 if (rdev->uvd.vcpu_bo == NULL) 209 if (rdev->uvd.vcpu_bo == NULL)
212 return 0; 210 return 0;
213 211
214 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) 212 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
215 if (atomic_read(&rdev->uvd.handles[i])) 213 uint32_t handle = atomic_read(&rdev->uvd.handles[i]);
216 break; 214 if (handle != 0) {
215 struct radeon_fence *fence;
217 216
218 if (i == RADEON_MAX_UVD_HANDLES) 217 radeon_uvd_note_usage(rdev);
219 return 0;
220 218
221 size = radeon_bo_size(rdev->uvd.vcpu_bo); 219 r = radeon_uvd_get_destroy_msg(rdev,
222 size -= rdev->uvd_fw->size; 220 R600_RING_TYPE_UVD_INDEX, handle, &fence);
221 if (r) {
222 DRM_ERROR("Error destroying UVD (%d)!\n", r);
223 continue;
224 }
223 225
224 ptr = rdev->uvd.cpu_addr; 226 radeon_fence_wait(fence, false);
225 ptr += rdev->uvd_fw->size; 227 radeon_fence_unref(&fence);
226 228
227 rdev->uvd.saved_bo = kmalloc(size, GFP_KERNEL); 229 rdev->uvd.filp[i] = NULL;
228 memcpy(rdev->uvd.saved_bo, ptr, size); 230 atomic_set(&rdev->uvd.handles[i], 0);
231 }
232 }
229 233
230 return 0; 234 return 0;
231} 235}
@@ -246,12 +250,7 @@ int radeon_uvd_resume(struct radeon_device *rdev)
246 ptr = rdev->uvd.cpu_addr; 250 ptr = rdev->uvd.cpu_addr;
247 ptr += rdev->uvd_fw->size; 251 ptr += rdev->uvd_fw->size;
248 252
249 if (rdev->uvd.saved_bo != NULL) { 253 memset(ptr, 0, size);
250 memcpy(ptr, rdev->uvd.saved_bo, size);
251 kfree(rdev->uvd.saved_bo);
252 rdev->uvd.saved_bo = NULL;
253 } else
254 memset(ptr, 0, size);
255 254
256 return 0; 255 return 0;
257} 256}
@@ -396,6 +395,29 @@ static int radeon_uvd_cs_msg_decode(uint32_t *msg, unsigned buf_sizes[])
396 return 0; 395 return 0;
397} 396}
398 397
398static int radeon_uvd_validate_codec(struct radeon_cs_parser *p,
399 unsigned stream_type)
400{
401 switch (stream_type) {
402 case 0: /* H264 */
403 case 1: /* VC1 */
404 /* always supported */
405 return 0;
406
407 case 3: /* MPEG2 */
408 case 4: /* MPEG4 */
409 /* only since UVD 3 */
410 if (p->rdev->family >= CHIP_PALM)
411 return 0;
412
413 /* fall through */
414 default:
415 DRM_ERROR("UVD codec not supported by hardware %d!\n",
416 stream_type);
417 return -EINVAL;
418 }
419}
420
399static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo, 421static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,
400 unsigned offset, unsigned buf_sizes[]) 422 unsigned offset, unsigned buf_sizes[])
401{ 423{
@@ -436,50 +458,70 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,
436 return -EINVAL; 458 return -EINVAL;
437 } 459 }
438 460
439 if (msg_type == 1) { 461 switch (msg_type) {
440 /* it's a decode msg, calc buffer sizes */ 462 case 0:
441 r = radeon_uvd_cs_msg_decode(msg, buf_sizes); 463 /* it's a create msg, calc image size (width * height) */
442 /* calc image size (width * height) */ 464 img_size = msg[7] * msg[8];
443 img_size = msg[6] * msg[7]; 465
466 r = radeon_uvd_validate_codec(p, msg[4]);
444 radeon_bo_kunmap(bo); 467 radeon_bo_kunmap(bo);
445 if (r) 468 if (r)
446 return r; 469 return r;
447 470
448 } else if (msg_type == 2) { 471 /* try to alloc a new handle */
472 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
473 if (atomic_read(&p->rdev->uvd.handles[i]) == handle) {
474 DRM_ERROR("Handle 0x%x already in use!\n", handle);
475 return -EINVAL;
476 }
477
478 if (!atomic_cmpxchg(&p->rdev->uvd.handles[i], 0, handle)) {
479 p->rdev->uvd.filp[i] = p->filp;
480 p->rdev->uvd.img_size[i] = img_size;
481 return 0;
482 }
483 }
484
485 DRM_ERROR("No more free UVD handles!\n");
486 return -EINVAL;
487
488 case 1:
489 /* it's a decode msg, validate codec and calc buffer sizes */
490 r = radeon_uvd_validate_codec(p, msg[4]);
491 if (!r)
492 r = radeon_uvd_cs_msg_decode(msg, buf_sizes);
493 radeon_bo_kunmap(bo);
494 if (r)
495 return r;
496
497 /* validate the handle */
498 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
499 if (atomic_read(&p->rdev->uvd.handles[i]) == handle) {
500 if (p->rdev->uvd.filp[i] != p->filp) {
501 DRM_ERROR("UVD handle collision detected!\n");
502 return -EINVAL;
503 }
504 return 0;
505 }
506 }
507
508 DRM_ERROR("Invalid UVD handle 0x%x!\n", handle);
509 return -ENOENT;
510
511 case 2:
449 /* it's a destroy msg, free the handle */ 512 /* it's a destroy msg, free the handle */
450 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) 513 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i)
451 atomic_cmpxchg(&p->rdev->uvd.handles[i], handle, 0); 514 atomic_cmpxchg(&p->rdev->uvd.handles[i], handle, 0);
452 radeon_bo_kunmap(bo); 515 radeon_bo_kunmap(bo);
453 return 0; 516 return 0;
454 } else {
455 /* it's a create msg, calc image size (width * height) */
456 img_size = msg[7] * msg[8];
457 radeon_bo_kunmap(bo);
458 517
459 if (msg_type != 0) { 518 default:
460 DRM_ERROR("Illegal UVD message type (%d)!\n", msg_type);
461 return -EINVAL;
462 }
463
464 /* it's a create msg, no special handling needed */
465 }
466
467 /* create or decode, validate the handle */
468 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
469 if (atomic_read(&p->rdev->uvd.handles[i]) == handle)
470 return 0;
471 }
472 519
473 /* handle not found try to alloc a new one */ 520 DRM_ERROR("Illegal UVD message type (%d)!\n", msg_type);
474 for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) { 521 return -EINVAL;
475 if (!atomic_cmpxchg(&p->rdev->uvd.handles[i], 0, handle)) {
476 p->rdev->uvd.filp[i] = p->filp;
477 p->rdev->uvd.img_size[i] = img_size;
478 return 0;
479 }
480 } 522 }
481 523
482 DRM_ERROR("No more free UVD handles!\n"); 524 BUG();
483 return -EINVAL; 525 return -EINVAL;
484} 526}
485 527
diff --git a/drivers/gpu/drm/radeon/radeon_vce.c b/drivers/gpu/drm/radeon/radeon_vce.c
index 24f849f888bb..0de5711ac508 100644
--- a/drivers/gpu/drm/radeon/radeon_vce.c
+++ b/drivers/gpu/drm/radeon/radeon_vce.c
@@ -493,18 +493,27 @@ int radeon_vce_cs_reloc(struct radeon_cs_parser *p, int lo, int hi,
493 * 493 *
494 * @p: parser context 494 * @p: parser context
495 * @handle: handle to validate 495 * @handle: handle to validate
496 * @allocated: allocated a new handle?
496 * 497 *
497 * Validates the handle and return the found session index or -EINVAL 498 * Validates the handle and return the found session index or -EINVAL
498 * we we don't have another free session index. 499 * we we don't have another free session index.
499 */ 500 */
500int radeon_vce_validate_handle(struct radeon_cs_parser *p, uint32_t handle) 501static int radeon_vce_validate_handle(struct radeon_cs_parser *p,
502 uint32_t handle, bool *allocated)
501{ 503{
502 unsigned i; 504 unsigned i;
503 505
506 *allocated = false;
507
504 /* validate the handle */ 508 /* validate the handle */
505 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) { 509 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) {
506 if (atomic_read(&p->rdev->vce.handles[i]) == handle) 510 if (atomic_read(&p->rdev->vce.handles[i]) == handle) {
511 if (p->rdev->vce.filp[i] != p->filp) {
512 DRM_ERROR("VCE handle collision detected!\n");
513 return -EINVAL;
514 }
507 return i; 515 return i;
516 }
508 } 517 }
509 518
510 /* handle not found try to alloc a new one */ 519 /* handle not found try to alloc a new one */
@@ -512,6 +521,7 @@ int radeon_vce_validate_handle(struct radeon_cs_parser *p, uint32_t handle)
512 if (!atomic_cmpxchg(&p->rdev->vce.handles[i], 0, handle)) { 521 if (!atomic_cmpxchg(&p->rdev->vce.handles[i], 0, handle)) {
513 p->rdev->vce.filp[i] = p->filp; 522 p->rdev->vce.filp[i] = p->filp;
514 p->rdev->vce.img_size[i] = 0; 523 p->rdev->vce.img_size[i] = 0;
524 *allocated = true;
515 return i; 525 return i;
516 } 526 }
517 } 527 }
@@ -529,10 +539,10 @@ int radeon_vce_validate_handle(struct radeon_cs_parser *p, uint32_t handle)
529int radeon_vce_cs_parse(struct radeon_cs_parser *p) 539int radeon_vce_cs_parse(struct radeon_cs_parser *p)
530{ 540{
531 int session_idx = -1; 541 int session_idx = -1;
532 bool destroyed = false; 542 bool destroyed = false, created = false, allocated = false;
533 uint32_t tmp, handle = 0; 543 uint32_t tmp, handle = 0;
534 uint32_t *size = &tmp; 544 uint32_t *size = &tmp;
535 int i, r; 545 int i, r = 0;
536 546
537 while (p->idx < p->chunk_ib->length_dw) { 547 while (p->idx < p->chunk_ib->length_dw) {
538 uint32_t len = radeon_get_ib_value(p, p->idx); 548 uint32_t len = radeon_get_ib_value(p, p->idx);
@@ -540,18 +550,21 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
540 550
541 if ((len < 8) || (len & 3)) { 551 if ((len < 8) || (len & 3)) {
542 DRM_ERROR("invalid VCE command length (%d)!\n", len); 552 DRM_ERROR("invalid VCE command length (%d)!\n", len);
543 return -EINVAL; 553 r = -EINVAL;
554 goto out;
544 } 555 }
545 556
546 if (destroyed) { 557 if (destroyed) {
547 DRM_ERROR("No other command allowed after destroy!\n"); 558 DRM_ERROR("No other command allowed after destroy!\n");
548 return -EINVAL; 559 r = -EINVAL;
560 goto out;
549 } 561 }
550 562
551 switch (cmd) { 563 switch (cmd) {
552 case 0x00000001: // session 564 case 0x00000001: // session
553 handle = radeon_get_ib_value(p, p->idx + 2); 565 handle = radeon_get_ib_value(p, p->idx + 2);
554 session_idx = radeon_vce_validate_handle(p, handle); 566 session_idx = radeon_vce_validate_handle(p, handle,
567 &allocated);
555 if (session_idx < 0) 568 if (session_idx < 0)
556 return session_idx; 569 return session_idx;
557 size = &p->rdev->vce.img_size[session_idx]; 570 size = &p->rdev->vce.img_size[session_idx];
@@ -561,6 +574,13 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
561 break; 574 break;
562 575
563 case 0x01000001: // create 576 case 0x01000001: // create
577 created = true;
578 if (!allocated) {
579 DRM_ERROR("Handle already in use!\n");
580 r = -EINVAL;
581 goto out;
582 }
583
564 *size = radeon_get_ib_value(p, p->idx + 8) * 584 *size = radeon_get_ib_value(p, p->idx + 8) *
565 radeon_get_ib_value(p, p->idx + 10) * 585 radeon_get_ib_value(p, p->idx + 10) *
566 8 * 3 / 2; 586 8 * 3 / 2;
@@ -578,12 +598,12 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
578 r = radeon_vce_cs_reloc(p, p->idx + 10, p->idx + 9, 598 r = radeon_vce_cs_reloc(p, p->idx + 10, p->idx + 9,
579 *size); 599 *size);
580 if (r) 600 if (r)
581 return r; 601 goto out;
582 602
583 r = radeon_vce_cs_reloc(p, p->idx + 12, p->idx + 11, 603 r = radeon_vce_cs_reloc(p, p->idx + 12, p->idx + 11,
584 *size / 3); 604 *size / 3);
585 if (r) 605 if (r)
586 return r; 606 goto out;
587 break; 607 break;
588 608
589 case 0x02000001: // destroy 609 case 0x02000001: // destroy
@@ -594,7 +614,7 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
594 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2, 614 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2,
595 *size * 2); 615 *size * 2);
596 if (r) 616 if (r)
597 return r; 617 goto out;
598 break; 618 break;
599 619
600 case 0x05000004: // video bitstream buffer 620 case 0x05000004: // video bitstream buffer
@@ -602,36 +622,47 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
602 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2, 622 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2,
603 tmp); 623 tmp);
604 if (r) 624 if (r)
605 return r; 625 goto out;
606 break; 626 break;
607 627
608 case 0x05000005: // feedback buffer 628 case 0x05000005: // feedback buffer
609 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2, 629 r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2,
610 4096); 630 4096);
611 if (r) 631 if (r)
612 return r; 632 goto out;
613 break; 633 break;
614 634
615 default: 635 default:
616 DRM_ERROR("invalid VCE command (0x%x)!\n", cmd); 636 DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
617 return -EINVAL; 637 r = -EINVAL;
638 goto out;
618 } 639 }
619 640
620 if (session_idx == -1) { 641 if (session_idx == -1) {
621 DRM_ERROR("no session command at start of IB\n"); 642 DRM_ERROR("no session command at start of IB\n");
622 return -EINVAL; 643 r = -EINVAL;
644 goto out;
623 } 645 }
624 646
625 p->idx += len / 4; 647 p->idx += len / 4;
626 } 648 }
627 649
628 if (destroyed) { 650 if (allocated && !created) {
629 /* IB contains a destroy msg, free the handle */ 651 DRM_ERROR("New session without create command!\n");
652 r = -ENOENT;
653 }
654
655out:
656 if ((!r && destroyed) || (r && allocated)) {
657 /*
658 * IB contains a destroy msg or we have allocated an
659 * handle and got an error, anyway free the handle
660 */
630 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) 661 for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i)
631 atomic_cmpxchg(&p->rdev->vce.handles[i], handle, 0); 662 atomic_cmpxchg(&p->rdev->vce.handles[i], handle, 0);
632 } 663 }
633 664
634 return 0; 665 return r;
635} 666}
636 667
637/** 668/**
diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
index 2a5a4a9e772d..de42fc4a22b8 100644
--- a/drivers/gpu/drm/radeon/radeon_vm.c
+++ b/drivers/gpu/drm/radeon/radeon_vm.c
@@ -473,6 +473,23 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
473 } 473 }
474 474
475 mutex_lock(&vm->mutex); 475 mutex_lock(&vm->mutex);
476 soffset /= RADEON_GPU_PAGE_SIZE;
477 eoffset /= RADEON_GPU_PAGE_SIZE;
478 if (soffset || eoffset) {
479 struct interval_tree_node *it;
480 it = interval_tree_iter_first(&vm->va, soffset, eoffset - 1);
481 if (it && it != &bo_va->it) {
482 struct radeon_bo_va *tmp;
483 tmp = container_of(it, struct radeon_bo_va, it);
484 /* bo and tmp overlap, invalid offset */
485 dev_err(rdev->dev, "bo %p va 0x%010Lx conflict with "
486 "(bo %p 0x%010lx 0x%010lx)\n", bo_va->bo,
487 soffset, tmp->bo, tmp->it.start, tmp->it.last);
488 mutex_unlock(&vm->mutex);
489 return -EINVAL;
490 }
491 }
492
476 if (bo_va->it.start || bo_va->it.last) { 493 if (bo_va->it.start || bo_va->it.last) {
477 if (bo_va->addr) { 494 if (bo_va->addr) {
478 /* add a clone of the bo_va to clear the old address */ 495 /* add a clone of the bo_va to clear the old address */
@@ -490,6 +507,8 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
490 spin_lock(&vm->status_lock); 507 spin_lock(&vm->status_lock);
491 list_add(&tmp->vm_status, &vm->freed); 508 list_add(&tmp->vm_status, &vm->freed);
492 spin_unlock(&vm->status_lock); 509 spin_unlock(&vm->status_lock);
510
511 bo_va->addr = 0;
493 } 512 }
494 513
495 interval_tree_remove(&bo_va->it, &vm->va); 514 interval_tree_remove(&bo_va->it, &vm->va);
@@ -497,21 +516,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
497 bo_va->it.last = 0; 516 bo_va->it.last = 0;
498 } 517 }
499 518
500 soffset /= RADEON_GPU_PAGE_SIZE;
501 eoffset /= RADEON_GPU_PAGE_SIZE;
502 if (soffset || eoffset) { 519 if (soffset || eoffset) {
503 struct interval_tree_node *it;
504 it = interval_tree_iter_first(&vm->va, soffset, eoffset - 1);
505 if (it) {
506 struct radeon_bo_va *tmp;
507 tmp = container_of(it, struct radeon_bo_va, it);
508 /* bo and tmp overlap, invalid offset */
509 dev_err(rdev->dev, "bo %p va 0x%010Lx conflict with "
510 "(bo %p 0x%010lx 0x%010lx)\n", bo_va->bo,
511 soffset, tmp->bo, tmp->it.start, tmp->it.last);
512 mutex_unlock(&vm->mutex);
513 return -EINVAL;
514 }
515 bo_va->it.start = soffset; 520 bo_va->it.start = soffset;
516 bo_va->it.last = eoffset - 1; 521 bo_va->it.last = eoffset - 1;
517 interval_tree_insert(&bo_va->it, &vm->va); 522 interval_tree_insert(&bo_va->it, &vm->va);
@@ -1107,7 +1112,8 @@ void radeon_vm_bo_rmv(struct radeon_device *rdev,
1107 list_del(&bo_va->bo_list); 1112 list_del(&bo_va->bo_list);
1108 1113
1109 mutex_lock(&vm->mutex); 1114 mutex_lock(&vm->mutex);
1110 interval_tree_remove(&bo_va->it, &vm->va); 1115 if (bo_va->it.start || bo_va->it.last)
1116 interval_tree_remove(&bo_va->it, &vm->va);
1111 spin_lock(&vm->status_lock); 1117 spin_lock(&vm->status_lock);
1112 list_del(&bo_va->vm_status); 1118 list_del(&bo_va->vm_status);
1113 1119
diff --git a/drivers/gpu/drm/radeon/rv770d.h b/drivers/gpu/drm/radeon/rv770d.h
index 3cf1e2921545..9ef2064b1c9c 100644
--- a/drivers/gpu/drm/radeon/rv770d.h
+++ b/drivers/gpu/drm/radeon/rv770d.h
@@ -989,6 +989,9 @@
989 ((n) & 0x3FFF) << 16) 989 ((n) & 0x3FFF) << 16)
990 990
991/* UVD */ 991/* UVD */
992#define UVD_SEMA_ADDR_LOW 0xef00
993#define UVD_SEMA_ADDR_HIGH 0xef04
994#define UVD_SEMA_CMD 0xef08
992#define UVD_GPCOM_VCPU_CMD 0xef0c 995#define UVD_GPCOM_VCPU_CMD 0xef0c
993#define UVD_GPCOM_VCPU_DATA0 0xef10 996#define UVD_GPCOM_VCPU_DATA0 0xef10
994#define UVD_GPCOM_VCPU_DATA1 0xef14 997#define UVD_GPCOM_VCPU_DATA1 0xef14
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index b1d74bc375d8..4c679b802bc8 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -4318,7 +4318,7 @@ static int si_pcie_gart_enable(struct radeon_device *rdev)
4318 /* empty context1-15 */ 4318 /* empty context1-15 */
4319 /* set vm size, must be a multiple of 4 */ 4319 /* set vm size, must be a multiple of 4 */
4320 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0); 4320 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
4321 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn); 4321 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn - 1);
4322 /* Assign the pt base to something valid for now; the pts used for 4322 /* Assign the pt base to something valid for now; the pts used for
4323 * the VMs are determined by the application and setup and assigned 4323 * the VMs are determined by the application and setup and assigned
4324 * on the fly in the vm part of radeon_gart.c 4324 * on the fly in the vm part of radeon_gart.c
diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
index b35bccfeef79..ff8b83f5e929 100644
--- a/drivers/gpu/drm/radeon/si_dpm.c
+++ b/drivers/gpu/drm/radeon/si_dpm.c
@@ -2924,6 +2924,7 @@ struct si_dpm_quirk {
2924static struct si_dpm_quirk si_dpm_quirk_list[] = { 2924static struct si_dpm_quirk si_dpm_quirk_list[] = {
2925 /* PITCAIRN - https://bugs.freedesktop.org/show_bug.cgi?id=76490 */ 2925 /* PITCAIRN - https://bugs.freedesktop.org/show_bug.cgi?id=76490 */
2926 { PCI_VENDOR_ID_ATI, 0x6810, 0x1462, 0x3036, 0, 120000 }, 2926 { PCI_VENDOR_ID_ATI, 0x6810, 0x1462, 0x3036, 0, 120000 },
2927 { PCI_VENDOR_ID_ATI, 0x6811, 0x174b, 0xe271, 0, 120000 },
2927 { 0, 0, 0, 0 }, 2928 { 0, 0, 0, 0 },
2928}; 2929};
2929 2930
diff --git a/drivers/gpu/drm/radeon/uvd_v1_0.c b/drivers/gpu/drm/radeon/uvd_v1_0.c
index e72b3cb59358..c6b1cbca47fc 100644
--- a/drivers/gpu/drm/radeon/uvd_v1_0.c
+++ b/drivers/gpu/drm/radeon/uvd_v1_0.c
@@ -466,18 +466,8 @@ bool uvd_v1_0_semaphore_emit(struct radeon_device *rdev,
466 struct radeon_semaphore *semaphore, 466 struct radeon_semaphore *semaphore,
467 bool emit_wait) 467 bool emit_wait)
468{ 468{
469 uint64_t addr = semaphore->gpu_addr; 469 /* disable semaphores for UVD V1 hardware */
470 470 return false;
471 radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_LOW, 0));
472 radeon_ring_write(ring, (addr >> 3) & 0x000FFFFF);
473
474 radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_HIGH, 0));
475 radeon_ring_write(ring, (addr >> 23) & 0x000FFFFF);
476
477 radeon_ring_write(ring, PACKET0(UVD_SEMA_CMD, 0));
478 radeon_ring_write(ring, emit_wait ? 1 : 0);
479
480 return true;
481} 471}
482 472
483/** 473/**
diff --git a/drivers/gpu/drm/radeon/uvd_v2_2.c b/drivers/gpu/drm/radeon/uvd_v2_2.c
index 89193519f8a1..7ed778cec7c6 100644
--- a/drivers/gpu/drm/radeon/uvd_v2_2.c
+++ b/drivers/gpu/drm/radeon/uvd_v2_2.c
@@ -60,6 +60,35 @@ void uvd_v2_2_fence_emit(struct radeon_device *rdev,
60} 60}
61 61
62/** 62/**
63 * uvd_v2_2_semaphore_emit - emit semaphore command
64 *
65 * @rdev: radeon_device pointer
66 * @ring: radeon_ring pointer
67 * @semaphore: semaphore to emit commands for
68 * @emit_wait: true if we should emit a wait command
69 *
70 * Emit a semaphore command (either wait or signal) to the UVD ring.
71 */
72bool uvd_v2_2_semaphore_emit(struct radeon_device *rdev,
73 struct radeon_ring *ring,
74 struct radeon_semaphore *semaphore,
75 bool emit_wait)
76{
77 uint64_t addr = semaphore->gpu_addr;
78
79 radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_LOW, 0));
80 radeon_ring_write(ring, (addr >> 3) & 0x000FFFFF);
81
82 radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_HIGH, 0));
83 radeon_ring_write(ring, (addr >> 23) & 0x000FFFFF);
84
85 radeon_ring_write(ring, PACKET0(UVD_SEMA_CMD, 0));
86 radeon_ring_write(ring, emit_wait ? 1 : 0);
87
88 return true;
89}
90
91/**
63 * uvd_v2_2_resume - memory controller programming 92 * uvd_v2_2_resume - memory controller programming
64 * 93 *
65 * @rdev: radeon_device pointer 94 * @rdev: radeon_device pointer
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index ccb0ce073ef2..4557f335a8a5 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -1409,7 +1409,7 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
1409 struct vop *vop; 1409 struct vop *vop;
1410 struct resource *res; 1410 struct resource *res;
1411 size_t alloc_size; 1411 size_t alloc_size;
1412 int ret; 1412 int ret, irq;
1413 1413
1414 of_id = of_match_device(vop_driver_dt_match, dev); 1414 of_id = of_match_device(vop_driver_dt_match, dev);
1415 vop_data = of_id->data; 1415 vop_data = of_id->data;
@@ -1445,11 +1445,12 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
1445 return ret; 1445 return ret;
1446 } 1446 }
1447 1447
1448 vop->irq = platform_get_irq(pdev, 0); 1448 irq = platform_get_irq(pdev, 0);
1449 if (vop->irq < 0) { 1449 if (irq < 0) {
1450 dev_err(dev, "cannot find irq for vop\n"); 1450 dev_err(dev, "cannot find irq for vop\n");
1451 return vop->irq; 1451 return irq;
1452 } 1452 }
1453 vop->irq = (unsigned int)irq;
1453 1454
1454 spin_lock_init(&vop->reg_lock); 1455 spin_lock_init(&vop->reg_lock);
1455 spin_lock_init(&vop->irq_lock); 1456 spin_lock_init(&vop->irq_lock);
diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index 1833abd7d3aa..bfad15a913a0 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -173,7 +173,6 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
173 drm->irq_enabled = true; 173 drm->irq_enabled = true;
174 174
175 /* syncpoints are used for full 32-bit hardware VBLANK counters */ 175 /* syncpoints are used for full 32-bit hardware VBLANK counters */
176 drm->vblank_disable_immediate = true;
177 drm->max_vblank_count = 0xffffffff; 176 drm->max_vblank_count = 0xffffffff;
178 177
179 err = drm_vblank_init(drm, drm->mode_config.num_crtc); 178 err = drm_vblank_init(drm, drm->mode_config.num_crtc);
diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
index 1055cb79096c..3f4c7b842028 100644
--- a/drivers/gpu/drm/vgem/Makefile
+++ b/drivers/gpu/drm/vgem/Makefile
@@ -1,4 +1,4 @@
1ccflags-y := -Iinclude/drm 1ccflags-y := -Iinclude/drm
2vgem-y := vgem_drv.o vgem_dma_buf.o 2vgem-y := vgem_drv.o
3 3
4obj-$(CONFIG_DRM_VGEM) += vgem.o 4obj-$(CONFIG_DRM_VGEM) += vgem.o
diff --git a/drivers/gpu/drm/vgem/vgem_dma_buf.c b/drivers/gpu/drm/vgem/vgem_dma_buf.c
deleted file mode 100644
index 0254438ad1a6..000000000000
--- a/drivers/gpu/drm/vgem/vgem_dma_buf.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/*
2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2014 The Chromium OS Authors
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * Authors:
25 * Ben Widawsky <ben@bwidawsk.net>
26 *
27 */
28
29#include <linux/dma-buf.h>
30#include "vgem_drv.h"
31
32struct sg_table *vgem_gem_prime_get_sg_table(struct drm_gem_object *gobj)
33{
34 struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
35 BUG_ON(obj->pages == NULL);
36
37 return drm_prime_pages_to_sg(obj->pages, obj->base.size / PAGE_SIZE);
38}
39
40int vgem_gem_prime_pin(struct drm_gem_object *gobj)
41{
42 struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
43 return vgem_gem_get_pages(obj);
44}
45
46void vgem_gem_prime_unpin(struct drm_gem_object *gobj)
47{
48 struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
49 vgem_gem_put_pages(obj);
50}
51
52void *vgem_gem_prime_vmap(struct drm_gem_object *gobj)
53{
54 struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
55 BUG_ON(obj->pages == NULL);
56
57 return vmap(obj->pages, obj->base.size / PAGE_SIZE, 0, PAGE_KERNEL);
58}
59
60void vgem_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
61{
62 vunmap(vaddr);
63}
64
65struct drm_gem_object *vgem_gem_prime_import(struct drm_device *dev,
66 struct dma_buf *dma_buf)
67{
68 struct drm_vgem_gem_object *obj = NULL;
69 int ret;
70
71 obj = kzalloc(sizeof(*obj), GFP_KERNEL);
72 if (obj == NULL) {
73 ret = -ENOMEM;
74 goto fail;
75 }
76
77 ret = drm_gem_object_init(dev, &obj->base, dma_buf->size);
78 if (ret) {
79 ret = -ENOMEM;
80 goto fail_free;
81 }
82
83 get_dma_buf(dma_buf);
84
85 obj->base.dma_buf = dma_buf;
86 obj->use_dma_buf = true;
87
88 return &obj->base;
89
90fail_free:
91 kfree(obj);
92fail:
93 return ERR_PTR(ret);
94}
diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
index cb3b43525b2d..7a207ca547be 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.c
+++ b/drivers/gpu/drm/vgem/vgem_drv.c
@@ -302,22 +302,13 @@ static const struct file_operations vgem_driver_fops = {
302}; 302};
303 303
304static struct drm_driver vgem_driver = { 304static struct drm_driver vgem_driver = {
305 .driver_features = DRIVER_GEM | DRIVER_PRIME, 305 .driver_features = DRIVER_GEM,
306 .gem_free_object = vgem_gem_free_object, 306 .gem_free_object = vgem_gem_free_object,
307 .gem_vm_ops = &vgem_gem_vm_ops, 307 .gem_vm_ops = &vgem_gem_vm_ops,
308 .ioctls = vgem_ioctls, 308 .ioctls = vgem_ioctls,
309 .fops = &vgem_driver_fops, 309 .fops = &vgem_driver_fops,
310 .dumb_create = vgem_gem_dumb_create, 310 .dumb_create = vgem_gem_dumb_create,
311 .dumb_map_offset = vgem_gem_dumb_map, 311 .dumb_map_offset = vgem_gem_dumb_map,
312 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
313 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
314 .gem_prime_export = drm_gem_prime_export,
315 .gem_prime_import = vgem_gem_prime_import,
316 .gem_prime_pin = vgem_gem_prime_pin,
317 .gem_prime_unpin = vgem_gem_prime_unpin,
318 .gem_prime_get_sg_table = vgem_gem_prime_get_sg_table,
319 .gem_prime_vmap = vgem_gem_prime_vmap,
320 .gem_prime_vunmap = vgem_gem_prime_vunmap,
321 .name = DRIVER_NAME, 312 .name = DRIVER_NAME,
322 .desc = DRIVER_DESC, 313 .desc = DRIVER_DESC,
323 .date = DRIVER_DATE, 314 .date = DRIVER_DATE,
diff --git a/drivers/gpu/drm/vgem/vgem_drv.h b/drivers/gpu/drm/vgem/vgem_drv.h
index 57ab4d8f41f9..e9f92f7ee275 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.h
+++ b/drivers/gpu/drm/vgem/vgem_drv.h
@@ -43,15 +43,4 @@ struct drm_vgem_gem_object {
43extern void vgem_gem_put_pages(struct drm_vgem_gem_object *obj); 43extern void vgem_gem_put_pages(struct drm_vgem_gem_object *obj);
44extern int vgem_gem_get_pages(struct drm_vgem_gem_object *obj); 44extern int vgem_gem_get_pages(struct drm_vgem_gem_object *obj);
45 45
46/* vgem_dma_buf.c */
47extern struct sg_table *vgem_gem_prime_get_sg_table(
48 struct drm_gem_object *gobj);
49extern int vgem_gem_prime_pin(struct drm_gem_object *gobj);
50extern void vgem_gem_prime_unpin(struct drm_gem_object *gobj);
51extern void *vgem_gem_prime_vmap(struct drm_gem_object *gobj);
52extern void vgem_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
53extern struct drm_gem_object *vgem_gem_prime_import(struct drm_device *dev,
54 struct dma_buf *dma_buf);
55
56
57#endif 46#endif
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 41f167e4d75f..7ce93d927f62 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -164,6 +164,7 @@
164#define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204 164#define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204
165#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 165#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
166#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 166#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
167#define USB_DEVICE_ID_ATEN_CS682 0x2213
167 168
168#define USB_VENDOR_ID_ATMEL 0x03eb 169#define USB_VENDOR_ID_ATMEL 0x03eb
169#define USB_DEVICE_ID_ATMEL_MULTITOUCH 0x211c 170#define USB_DEVICE_ID_ATMEL_MULTITOUCH 0x211c
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index b3cf6fd4be96..5fd530acf747 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -44,7 +44,6 @@ MODULE_PARM_DESC(disable_raw_mode,
44/* bits 1..20 are reserved for classes */ 44/* bits 1..20 are reserved for classes */
45#define HIDPP_QUIRK_DELAYED_INIT BIT(21) 45#define HIDPP_QUIRK_DELAYED_INIT BIT(21)
46#define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22) 46#define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
47#define HIDPP_QUIRK_MULTI_INPUT BIT(23)
48 47
49/* 48/*
50 * There are two hidpp protocols in use, the first version hidpp10 is known 49 * There are two hidpp protocols in use, the first version hidpp10 is known
@@ -706,12 +705,6 @@ static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
706 struct hid_field *field, struct hid_usage *usage, 705 struct hid_field *field, struct hid_usage *usage,
707 unsigned long **bit, int *max) 706 unsigned long **bit, int *max)
708{ 707{
709 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
710
711 if ((hidpp->quirks & HIDPP_QUIRK_MULTI_INPUT) &&
712 (field->application == HID_GD_KEYBOARD))
713 return 0;
714
715 return -1; 708 return -1;
716} 709}
717 710
@@ -720,10 +713,6 @@ static void wtp_populate_input(struct hidpp_device *hidpp,
720{ 713{
721 struct wtp_data *wd = hidpp->private_data; 714 struct wtp_data *wd = hidpp->private_data;
722 715
723 if ((hidpp->quirks & HIDPP_QUIRK_MULTI_INPUT) && origin_is_hid_core)
724 /* this is the generic hid-input call */
725 return;
726
727 __set_bit(EV_ABS, input_dev->evbit); 716 __set_bit(EV_ABS, input_dev->evbit);
728 __set_bit(EV_KEY, input_dev->evbit); 717 __set_bit(EV_KEY, input_dev->evbit);
729 __clear_bit(EV_REL, input_dev->evbit); 718 __clear_bit(EV_REL, input_dev->evbit);
@@ -1245,10 +1234,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
1245 if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) 1234 if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT)
1246 connect_mask &= ~HID_CONNECT_HIDINPUT; 1235 connect_mask &= ~HID_CONNECT_HIDINPUT;
1247 1236
1248 /* Re-enable hidinput for multi-input devices */
1249 if (hidpp->quirks & HIDPP_QUIRK_MULTI_INPUT)
1250 connect_mask |= HID_CONNECT_HIDINPUT;
1251
1252 ret = hid_hw_start(hdev, connect_mask); 1237 ret = hid_hw_start(hdev, connect_mask);
1253 if (ret) { 1238 if (ret) {
1254 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); 1239 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
@@ -1296,11 +1281,6 @@ static const struct hid_device_id hidpp_devices[] = {
1296 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 1281 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
1297 USB_DEVICE_ID_LOGITECH_T651), 1282 USB_DEVICE_ID_LOGITECH_T651),
1298 .driver_data = HIDPP_QUIRK_CLASS_WTP }, 1283 .driver_data = HIDPP_QUIRK_CLASS_WTP },
1299 { /* Keyboard TK820 */
1300 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
1301 USB_VENDOR_ID_LOGITECH, 0x4102),
1302 .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_MULTI_INPUT |
1303 HIDPP_QUIRK_CLASS_WTP },
1304 1284
1305 { HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, 1285 { HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
1306 USB_VENDOR_ID_LOGITECH, HID_ANY_ID)}, 1286 USB_VENDOR_ID_LOGITECH, HID_ANY_ID)},
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index c3f6f1e311ea..090a1ba0abb6 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -294,7 +294,7 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
294 if (!report) 294 if (!report)
295 return -EINVAL; 295 return -EINVAL;
296 296
297 mutex_lock(&hsdev->mutex); 297 mutex_lock(hsdev->mutex_ptr);
298 if (flag == SENSOR_HUB_SYNC) { 298 if (flag == SENSOR_HUB_SYNC) {
299 memset(&hsdev->pending, 0, sizeof(hsdev->pending)); 299 memset(&hsdev->pending, 0, sizeof(hsdev->pending));
300 init_completion(&hsdev->pending.ready); 300 init_completion(&hsdev->pending.ready);
@@ -328,7 +328,7 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
328 kfree(hsdev->pending.raw_data); 328 kfree(hsdev->pending.raw_data);
329 hsdev->pending.status = false; 329 hsdev->pending.status = false;
330 } 330 }
331 mutex_unlock(&hsdev->mutex); 331 mutex_unlock(hsdev->mutex_ptr);
332 332
333 return ret_val; 333 return ret_val;
334} 334}
@@ -667,7 +667,14 @@ static int sensor_hub_probe(struct hid_device *hdev,
667 hsdev->vendor_id = hdev->vendor; 667 hsdev->vendor_id = hdev->vendor;
668 hsdev->product_id = hdev->product; 668 hsdev->product_id = hdev->product;
669 hsdev->usage = collection->usage; 669 hsdev->usage = collection->usage;
670 mutex_init(&hsdev->mutex); 670 hsdev->mutex_ptr = devm_kzalloc(&hdev->dev,
671 sizeof(struct mutex),
672 GFP_KERNEL);
673 if (!hsdev->mutex_ptr) {
674 ret = -ENOMEM;
675 goto err_stop_hw;
676 }
677 mutex_init(hsdev->mutex_ptr);
671 hsdev->start_collection_index = i; 678 hsdev->start_collection_index = i;
672 if (last_hsdev) 679 if (last_hsdev)
673 last_hsdev->end_collection_index = i; 680 last_hsdev->end_collection_index = i;
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index ab4dd952b6ba..92d6cdf02460 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -862,6 +862,7 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client,
862 union acpi_object *obj; 862 union acpi_object *obj;
863 struct acpi_device *adev; 863 struct acpi_device *adev;
864 acpi_handle handle; 864 acpi_handle handle;
865 int ret;
865 866
866 handle = ACPI_HANDLE(&client->dev); 867 handle = ACPI_HANDLE(&client->dev);
867 if (!handle || acpi_bus_get_device(handle, &adev)) 868 if (!handle || acpi_bus_get_device(handle, &adev))
@@ -877,7 +878,9 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client,
877 pdata->hid_descriptor_address = obj->integer.value; 878 pdata->hid_descriptor_address = obj->integer.value;
878 ACPI_FREE(obj); 879 ACPI_FREE(obj);
879 880
880 return acpi_dev_add_driver_gpios(adev, i2c_hid_acpi_gpios); 881 /* GPIOs are optional */
882 ret = acpi_dev_add_driver_gpios(adev, i2c_hid_acpi_gpios);
883 return ret < 0 && ret != -ENXIO ? ret : 0;
881} 884}
882 885
883static const struct acpi_device_id i2c_hid_acpi_match[] = { 886static const struct acpi_device_id i2c_hid_acpi_match[] = {
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index a775143e6265..4696895eb708 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -61,6 +61,7 @@ static const struct hid_blacklist {
61 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 61 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
62 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 62 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
63 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 63 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
64 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS682, HID_QUIRK_NOGET },
64 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FIGHTERSTICK, HID_QUIRK_NOGET }, 65 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FIGHTERSTICK, HID_QUIRK_NOGET },
65 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_COMBATSTICK, HID_QUIRK_NOGET }, 66 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_COMBATSTICK, HID_QUIRK_NOGET },
66 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FLIGHT_SIM_ECLIPSE_YOKE, HID_QUIRK_NOGET }, 67 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FLIGHT_SIM_ECLIPSE_YOKE, HID_QUIRK_NOGET },
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index fa54d3290659..adf959dcfa5d 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1072,6 +1072,9 @@ static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1072 int count = 0; 1072 int count = 0;
1073 int i; 1073 int i;
1074 1074
1075 if (!touch_max)
1076 return 0;
1077
1075 /* non-HID_GENERIC single touch input doesn't call this routine */ 1078 /* non-HID_GENERIC single touch input doesn't call this routine */
1076 if ((touch_max == 1) && (wacom->features.type == HID_GENERIC)) 1079 if ((touch_max == 1) && (wacom->features.type == HID_GENERIC))
1077 return wacom->hid_data.tipswitch && 1080 return wacom->hid_data.tipswitch &&
diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
index f3830db02d46..37f01702d081 100644
--- a/drivers/hwmon/nct6683.c
+++ b/drivers/hwmon/nct6683.c
@@ -439,6 +439,7 @@ nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
439 (*t)->dev_attr.attr.name, tg->base + i); 439 (*t)->dev_attr.attr.name, tg->base + i);
440 if ((*t)->s2) { 440 if ((*t)->s2) {
441 a2 = &su->u.a2; 441 a2 = &su->u.a2;
442 sysfs_attr_init(&a2->dev_attr.attr);
442 a2->dev_attr.attr.name = su->name; 443 a2->dev_attr.attr.name = su->name;
443 a2->nr = (*t)->u.s.nr + i; 444 a2->nr = (*t)->u.s.nr + i;
444 a2->index = (*t)->u.s.index; 445 a2->index = (*t)->u.s.index;
@@ -449,6 +450,7 @@ nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
449 *attrs = &a2->dev_attr.attr; 450 *attrs = &a2->dev_attr.attr;
450 } else { 451 } else {
451 a = &su->u.a1; 452 a = &su->u.a1;
453 sysfs_attr_init(&a->dev_attr.attr);
452 a->dev_attr.attr.name = su->name; 454 a->dev_attr.attr.name = su->name;
453 a->index = (*t)->u.index + i; 455 a->index = (*t)->u.index + i;
454 a->dev_attr.attr.mode = 456 a->dev_attr.attr.mode =
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 4fcb48103299..bd1c99deac71 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -995,6 +995,7 @@ nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
995 (*t)->dev_attr.attr.name, tg->base + i); 995 (*t)->dev_attr.attr.name, tg->base + i);
996 if ((*t)->s2) { 996 if ((*t)->s2) {
997 a2 = &su->u.a2; 997 a2 = &su->u.a2;
998 sysfs_attr_init(&a2->dev_attr.attr);
998 a2->dev_attr.attr.name = su->name; 999 a2->dev_attr.attr.name = su->name;
999 a2->nr = (*t)->u.s.nr + i; 1000 a2->nr = (*t)->u.s.nr + i;
1000 a2->index = (*t)->u.s.index; 1001 a2->index = (*t)->u.s.index;
@@ -1005,6 +1006,7 @@ nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
1005 *attrs = &a2->dev_attr.attr; 1006 *attrs = &a2->dev_attr.attr;
1006 } else { 1007 } else {
1007 a = &su->u.a1; 1008 a = &su->u.a1;
1009 sysfs_attr_init(&a->dev_attr.attr);
1008 a->dev_attr.attr.name = su->name; 1010 a->dev_attr.attr.name = su->name;
1009 a->index = (*t)->u.index + i; 1011 a->index = (*t)->u.index + i;
1010 a->dev_attr.attr.mode = 1012 a->dev_attr.attr.mode =
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 112e4d45e4a0..68800115876b 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -239,8 +239,10 @@ static struct ntc_thermistor_platform_data *
239ntc_thermistor_parse_dt(struct platform_device *pdev) 239ntc_thermistor_parse_dt(struct platform_device *pdev)
240{ 240{
241 struct iio_channel *chan; 241 struct iio_channel *chan;
242 enum iio_chan_type type;
242 struct device_node *np = pdev->dev.of_node; 243 struct device_node *np = pdev->dev.of_node;
243 struct ntc_thermistor_platform_data *pdata; 244 struct ntc_thermistor_platform_data *pdata;
245 int ret;
244 246
245 if (!np) 247 if (!np)
246 return NULL; 248 return NULL;
@@ -253,6 +255,13 @@ ntc_thermistor_parse_dt(struct platform_device *pdev)
253 if (IS_ERR(chan)) 255 if (IS_ERR(chan))
254 return ERR_CAST(chan); 256 return ERR_CAST(chan);
255 257
258 ret = iio_get_channel_type(chan, &type);
259 if (ret < 0)
260 return ERR_PTR(ret);
261
262 if (type != IIO_VOLTAGE)
263 return ERR_PTR(-EINVAL);
264
256 if (of_property_read_u32(np, "pullup-uv", &pdata->pullup_uv)) 265 if (of_property_read_u32(np, "pullup-uv", &pdata->pullup_uv))
257 return ERR_PTR(-ENODEV); 266 return ERR_PTR(-ENODEV);
258 if (of_property_read_u32(np, "pullup-ohm", &pdata->pullup_ohm)) 267 if (of_property_read_u32(np, "pullup-ohm", &pdata->pullup_ohm))
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index 99664ebc738d..ccf4cffe0ee1 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -44,7 +44,7 @@
44#include <linux/sysfs.h> 44#include <linux/sysfs.h>
45 45
46/* Addresses to scan */ 46/* Addresses to scan */
47static const unsigned short normal_i2c[] = { 0x37, 0x48, 0x49, 0x4a, 0x4c, 0x4d, 47static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c, 0x4d,
48 0x4e, 0x4f, I2C_CLIENT_END }; 48 0x4e, 0x4f, I2C_CLIENT_END };
49 49
50enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 }; 50enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index a04c49f2a011..39ea67f9b066 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -643,15 +643,6 @@ config BLK_DEV_TC86C001
643 help 643 help
644 This driver adds support for Toshiba TC86C001 GOKU-S chip. 644 This driver adds support for Toshiba TC86C001 GOKU-S chip.
645 645
646config BLK_DEV_CELLEB
647 tristate "Toshiba's Cell Reference Set IDE support"
648 depends on PPC_CELLEB
649 select BLK_DEV_IDEDMA_PCI
650 help
651 This driver provides support for the on-board IDE controller on
652 Toshiba Cell Reference Board.
653 If unsure, say Y.
654
655endif 646endif
656 647
657# TODO: BLK_DEV_IDEDMA_PCI -> BLK_DEV_IDEDMA_SFF 648# TODO: BLK_DEV_IDEDMA_PCI -> BLK_DEV_IDEDMA_SFF
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index a04ee82f1c8f..2a8c417d4081 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -38,7 +38,6 @@ obj-$(CONFIG_BLK_DEV_AEC62XX) += aec62xx.o
38obj-$(CONFIG_BLK_DEV_ALI15X3) += alim15x3.o 38obj-$(CONFIG_BLK_DEV_ALI15X3) += alim15x3.o
39obj-$(CONFIG_BLK_DEV_AMD74XX) += amd74xx.o 39obj-$(CONFIG_BLK_DEV_AMD74XX) += amd74xx.o
40obj-$(CONFIG_BLK_DEV_ATIIXP) += atiixp.o 40obj-$(CONFIG_BLK_DEV_ATIIXP) += atiixp.o
41obj-$(CONFIG_BLK_DEV_CELLEB) += scc_pata.o
42obj-$(CONFIG_BLK_DEV_CMD64X) += cmd64x.o 41obj-$(CONFIG_BLK_DEV_CMD64X) += cmd64x.o
43obj-$(CONFIG_BLK_DEV_CS5520) += cs5520.o 42obj-$(CONFIG_BLK_DEV_CS5520) += cs5520.o
44obj-$(CONFIG_BLK_DEV_CS5530) += cs5530.o 43obj-$(CONFIG_BLK_DEV_CS5530) += cs5530.o
diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
deleted file mode 100644
index 2a2d188b5d5b..000000000000
--- a/drivers/ide/scc_pata.c
+++ /dev/null
@@ -1,887 +0,0 @@
1/*
2 * Support for IDE interfaces on Celleb platform
3 *
4 * (C) Copyright 2006 TOSHIBA CORPORATION
5 *
6 * This code is based on drivers/ide/pci/siimage.c:
7 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
8 * Copyright (C) 2003 Red Hat
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25#include <linux/types.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28#include <linux/delay.h>
29#include <linux/ide.h>
30#include <linux/init.h>
31
32#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
33
34#define SCC_PATA_NAME "scc IDE"
35
36#define TDVHSEL_MASTER 0x00000001
37#define TDVHSEL_SLAVE 0x00000004
38
39#define MODE_JCUSFEN 0x00000080
40
41#define CCKCTRL_ATARESET 0x00040000
42#define CCKCTRL_BUFCNT 0x00020000
43#define CCKCTRL_CRST 0x00010000
44#define CCKCTRL_OCLKEN 0x00000100
45#define CCKCTRL_ATACLKOEN 0x00000002
46#define CCKCTRL_LCLKEN 0x00000001
47
48#define QCHCD_IOS_SS 0x00000001
49
50#define QCHSD_STPDIAG 0x00020000
51
52#define INTMASK_MSK 0xD1000012
53#define INTSTS_SERROR 0x80000000
54#define INTSTS_PRERR 0x40000000
55#define INTSTS_RERR 0x10000000
56#define INTSTS_ICERR 0x01000000
57#define INTSTS_BMSINT 0x00000010
58#define INTSTS_BMHE 0x00000008
59#define INTSTS_IOIRQS 0x00000004
60#define INTSTS_INTRQ 0x00000002
61#define INTSTS_ACTEINT 0x00000001
62
63#define ECMODE_VALUE 0x01
64
65static struct scc_ports {
66 unsigned long ctl, dma;
67 struct ide_host *host; /* for removing port from system */
68} scc_ports[MAX_HWIFS];
69
70/* PIO transfer mode table */
71/* JCHST */
72static unsigned long JCHSTtbl[2][7] = {
73 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
74 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
75};
76
77/* JCHHT */
78static unsigned long JCHHTtbl[2][7] = {
79 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
80 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
81};
82
83/* JCHCT */
84static unsigned long JCHCTtbl[2][7] = {
85 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
86 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
87};
88
89
90/* DMA transfer mode table */
91/* JCHDCTM/JCHDCTS */
92static unsigned long JCHDCTxtbl[2][7] = {
93 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
94 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
95};
96
97/* JCSTWTM/JCSTWTS */
98static unsigned long JCSTWTxtbl[2][7] = {
99 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
100 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
101};
102
103/* JCTSS */
104static unsigned long JCTSStbl[2][7] = {
105 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
106 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
107};
108
109/* JCENVT */
110static unsigned long JCENVTtbl[2][7] = {
111 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
112 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
113};
114
115/* JCACTSELS/JCACTSELM */
116static unsigned long JCACTSELtbl[2][7] = {
117 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
118 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
119};
120
121
122static u8 scc_ide_inb(unsigned long port)
123{
124 u32 data = in_be32((void*)port);
125 return (u8)data;
126}
127
128static void scc_exec_command(ide_hwif_t *hwif, u8 cmd)
129{
130 out_be32((void *)hwif->io_ports.command_addr, cmd);
131 eieio();
132 in_be32((void *)(hwif->dma_base + 0x01c));
133 eieio();
134}
135
136static u8 scc_read_status(ide_hwif_t *hwif)
137{
138 return (u8)in_be32((void *)hwif->io_ports.status_addr);
139}
140
141static u8 scc_read_altstatus(ide_hwif_t *hwif)
142{
143 return (u8)in_be32((void *)hwif->io_ports.ctl_addr);
144}
145
146static u8 scc_dma_sff_read_status(ide_hwif_t *hwif)
147{
148 return (u8)in_be32((void *)(hwif->dma_base + 4));
149}
150
151static void scc_write_devctl(ide_hwif_t *hwif, u8 ctl)
152{
153 out_be32((void *)hwif->io_ports.ctl_addr, ctl);
154 eieio();
155 in_be32((void *)(hwif->dma_base + 0x01c));
156 eieio();
157}
158
159static void scc_ide_insw(unsigned long port, void *addr, u32 count)
160{
161 u16 *ptr = (u16 *)addr;
162 while (count--) {
163 *ptr++ = le16_to_cpu(in_be32((void*)port));
164 }
165}
166
167static void scc_ide_insl(unsigned long port, void *addr, u32 count)
168{
169 u16 *ptr = (u16 *)addr;
170 while (count--) {
171 *ptr++ = le16_to_cpu(in_be32((void*)port));
172 *ptr++ = le16_to_cpu(in_be32((void*)port));
173 }
174}
175
176static void scc_ide_outb(u8 addr, unsigned long port)
177{
178 out_be32((void*)port, addr);
179}
180
181static void
182scc_ide_outsw(unsigned long port, void *addr, u32 count)
183{
184 u16 *ptr = (u16 *)addr;
185 while (count--) {
186 out_be32((void*)port, cpu_to_le16(*ptr++));
187 }
188}
189
190static void
191scc_ide_outsl(unsigned long port, void *addr, u32 count)
192{
193 u16 *ptr = (u16 *)addr;
194 while (count--) {
195 out_be32((void*)port, cpu_to_le16(*ptr++));
196 out_be32((void*)port, cpu_to_le16(*ptr++));
197 }
198}
199
200/**
201 * scc_set_pio_mode - set host controller for PIO mode
202 * @hwif: port
203 * @drive: drive
204 *
205 * Load the timing settings for this device mode into the
206 * controller.
207 */
208
209static void scc_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
210{
211 struct scc_ports *ports = ide_get_hwifdata(hwif);
212 unsigned long ctl_base = ports->ctl;
213 unsigned long cckctrl_port = ctl_base + 0xff0;
214 unsigned long piosht_port = ctl_base + 0x000;
215 unsigned long pioct_port = ctl_base + 0x004;
216 unsigned long reg;
217 int offset;
218 const u8 pio = drive->pio_mode - XFER_PIO_0;
219
220 reg = in_be32((void __iomem *)cckctrl_port);
221 if (reg & CCKCTRL_ATACLKOEN) {
222 offset = 1; /* 133MHz */
223 } else {
224 offset = 0; /* 100MHz */
225 }
226 reg = JCHSTtbl[offset][pio] << 16 | JCHHTtbl[offset][pio];
227 out_be32((void __iomem *)piosht_port, reg);
228 reg = JCHCTtbl[offset][pio];
229 out_be32((void __iomem *)pioct_port, reg);
230}
231
232/**
233 * scc_set_dma_mode - set host controller for DMA mode
234 * @hwif: port
235 * @drive: drive
236 *
237 * Load the timing settings for this device mode into the
238 * controller.
239 */
240
241static void scc_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
242{
243 struct scc_ports *ports = ide_get_hwifdata(hwif);
244 unsigned long ctl_base = ports->ctl;
245 unsigned long cckctrl_port = ctl_base + 0xff0;
246 unsigned long mdmact_port = ctl_base + 0x008;
247 unsigned long mcrcst_port = ctl_base + 0x00c;
248 unsigned long sdmact_port = ctl_base + 0x010;
249 unsigned long scrcst_port = ctl_base + 0x014;
250 unsigned long udenvt_port = ctl_base + 0x018;
251 unsigned long tdvhsel_port = ctl_base + 0x020;
252 int is_slave = drive->dn & 1;
253 int offset, idx;
254 unsigned long reg;
255 unsigned long jcactsel;
256 const u8 speed = drive->dma_mode;
257
258 reg = in_be32((void __iomem *)cckctrl_port);
259 if (reg & CCKCTRL_ATACLKOEN) {
260 offset = 1; /* 133MHz */
261 } else {
262 offset = 0; /* 100MHz */
263 }
264
265 idx = speed - XFER_UDMA_0;
266
267 jcactsel = JCACTSELtbl[offset][idx];
268 if (is_slave) {
269 out_be32((void __iomem *)sdmact_port, JCHDCTxtbl[offset][idx]);
270 out_be32((void __iomem *)scrcst_port, JCSTWTxtbl[offset][idx]);
271 jcactsel = jcactsel << 2;
272 out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_SLAVE) | jcactsel);
273 } else {
274 out_be32((void __iomem *)mdmact_port, JCHDCTxtbl[offset][idx]);
275 out_be32((void __iomem *)mcrcst_port, JCSTWTxtbl[offset][idx]);
276 out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_MASTER) | jcactsel);
277 }
278 reg = JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx];
279 out_be32((void __iomem *)udenvt_port, reg);
280}
281
282static void scc_dma_host_set(ide_drive_t *drive, int on)
283{
284 ide_hwif_t *hwif = drive->hwif;
285 u8 unit = drive->dn & 1;
286 u8 dma_stat = scc_dma_sff_read_status(hwif);
287
288 if (on)
289 dma_stat |= (1 << (5 + unit));
290 else
291 dma_stat &= ~(1 << (5 + unit));
292
293 scc_ide_outb(dma_stat, hwif->dma_base + 4);
294}
295
296/**
297 * scc_dma_setup - begin a DMA phase
298 * @drive: target device
299 * @cmd: command
300 *
301 * Build an IDE DMA PRD (IDE speak for scatter gather table)
302 * and then set up the DMA transfer registers.
303 *
304 * Returns 0 on success. If a PIO fallback is required then 1
305 * is returned.
306 */
307
308static int scc_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
309{
310 ide_hwif_t *hwif = drive->hwif;
311 u32 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR;
312 u8 dma_stat;
313
314 /* fall back to pio! */
315 if (ide_build_dmatable(drive, cmd) == 0)
316 return 1;
317
318 /* PRD table */
319 out_be32((void __iomem *)(hwif->dma_base + 8), hwif->dmatable_dma);
320
321 /* specify r/w */
322 out_be32((void __iomem *)hwif->dma_base, rw);
323
324 /* read DMA status for INTR & ERROR flags */
325 dma_stat = scc_dma_sff_read_status(hwif);
326
327 /* clear INTR & ERROR flags */
328 out_be32((void __iomem *)(hwif->dma_base + 4), dma_stat | 6);
329
330 return 0;
331}
332
333static void scc_dma_start(ide_drive_t *drive)
334{
335 ide_hwif_t *hwif = drive->hwif;
336 u8 dma_cmd = scc_ide_inb(hwif->dma_base);
337
338 /* start DMA */
339 scc_ide_outb(dma_cmd | 1, hwif->dma_base);
340}
341
342static int __scc_dma_end(ide_drive_t *drive)
343{
344 ide_hwif_t *hwif = drive->hwif;
345 u8 dma_stat, dma_cmd;
346
347 /* get DMA command mode */
348 dma_cmd = scc_ide_inb(hwif->dma_base);
349 /* stop DMA */
350 scc_ide_outb(dma_cmd & ~1, hwif->dma_base);
351 /* get DMA status */
352 dma_stat = scc_dma_sff_read_status(hwif);
353 /* clear the INTR & ERROR bits */
354 scc_ide_outb(dma_stat | 6, hwif->dma_base + 4);
355 /* verify good DMA status */
356 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
357}
358
359/**
360 * scc_dma_end - Stop DMA
361 * @drive: IDE drive
362 *
363 * Check and clear INT Status register.
364 * Then call __scc_dma_end().
365 */
366
367static int scc_dma_end(ide_drive_t *drive)
368{
369 ide_hwif_t *hwif = drive->hwif;
370 void __iomem *dma_base = (void __iomem *)hwif->dma_base;
371 unsigned long intsts_port = hwif->dma_base + 0x014;
372 u32 reg;
373 int dma_stat, data_loss = 0;
374 static int retry = 0;
375
376 /* errata A308 workaround: Step5 (check data loss) */
377 /* We don't check non ide_disk because it is limited to UDMA4 */
378 if (!(in_be32((void __iomem *)hwif->io_ports.ctl_addr)
379 & ATA_ERR) &&
380 drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) {
381 reg = in_be32((void __iomem *)intsts_port);
382 if (!(reg & INTSTS_ACTEINT)) {
383 printk(KERN_WARNING "%s: operation failed (transfer data loss)\n",
384 drive->name);
385 data_loss = 1;
386 if (retry++) {
387 struct request *rq = hwif->rq;
388 ide_drive_t *drive;
389 int i;
390
391 /* ERROR_RESET and drive->crc_count are needed
392 * to reduce DMA transfer mode in retry process.
393 */
394 if (rq)
395 rq->errors |= ERROR_RESET;
396
397 ide_port_for_each_dev(i, drive, hwif)
398 drive->crc_count++;
399 }
400 }
401 }
402
403 while (1) {
404 reg = in_be32((void __iomem *)intsts_port);
405
406 if (reg & INTSTS_SERROR) {
407 printk(KERN_WARNING "%s: SERROR\n", SCC_PATA_NAME);
408 out_be32((void __iomem *)intsts_port, INTSTS_SERROR|INTSTS_BMSINT);
409
410 out_be32(dma_base, in_be32(dma_base) & ~QCHCD_IOS_SS);
411 continue;
412 }
413
414 if (reg & INTSTS_PRERR) {
415 u32 maea0, maec0;
416 unsigned long ctl_base = hwif->config_data;
417
418 maea0 = in_be32((void __iomem *)(ctl_base + 0xF50));
419 maec0 = in_be32((void __iomem *)(ctl_base + 0xF54));
420
421 printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", SCC_PATA_NAME, maea0, maec0);
422
423 out_be32((void __iomem *)intsts_port, INTSTS_PRERR|INTSTS_BMSINT);
424
425 out_be32(dma_base, in_be32(dma_base) & ~QCHCD_IOS_SS);
426 continue;
427 }
428
429 if (reg & INTSTS_RERR) {
430 printk(KERN_WARNING "%s: Response Error\n", SCC_PATA_NAME);
431 out_be32((void __iomem *)intsts_port, INTSTS_RERR|INTSTS_BMSINT);
432
433 out_be32(dma_base, in_be32(dma_base) & ~QCHCD_IOS_SS);
434 continue;
435 }
436
437 if (reg & INTSTS_ICERR) {
438 out_be32(dma_base, in_be32(dma_base) & ~QCHCD_IOS_SS);
439
440 printk(KERN_WARNING "%s: Illegal Configuration\n", SCC_PATA_NAME);
441 out_be32((void __iomem *)intsts_port, INTSTS_ICERR|INTSTS_BMSINT);
442 continue;
443 }
444
445 if (reg & INTSTS_BMSINT) {
446 printk(KERN_WARNING "%s: Internal Bus Error\n", SCC_PATA_NAME);
447 out_be32((void __iomem *)intsts_port, INTSTS_BMSINT);
448
449 ide_do_reset(drive);
450 continue;
451 }
452
453 if (reg & INTSTS_BMHE) {
454 out_be32((void __iomem *)intsts_port, INTSTS_BMHE);
455 continue;
456 }
457
458 if (reg & INTSTS_ACTEINT) {
459 out_be32((void __iomem *)intsts_port, INTSTS_ACTEINT);
460 continue;
461 }
462
463 if (reg & INTSTS_IOIRQS) {
464 out_be32((void __iomem *)intsts_port, INTSTS_IOIRQS);
465 continue;
466 }
467 break;
468 }
469
470 dma_stat = __scc_dma_end(drive);
471 if (data_loss)
472 dma_stat |= 2; /* emulate DMA error (to retry command) */
473 return dma_stat;
474}
475
476/* returns 1 if dma irq issued, 0 otherwise */
477static int scc_dma_test_irq(ide_drive_t *drive)
478{
479 ide_hwif_t *hwif = drive->hwif;
480 u32 int_stat = in_be32((void __iomem *)hwif->dma_base + 0x014);
481
482 /* SCC errata A252,A308 workaround: Step4 */
483 if ((in_be32((void __iomem *)hwif->io_ports.ctl_addr)
484 & ATA_ERR) &&
485 (int_stat & INTSTS_INTRQ))
486 return 1;
487
488 /* SCC errata A308 workaround: Step5 (polling IOIRQS) */
489 if (int_stat & INTSTS_IOIRQS)
490 return 1;
491
492 return 0;
493}
494
495static u8 scc_udma_filter(ide_drive_t *drive)
496{
497 ide_hwif_t *hwif = drive->hwif;
498 u8 mask = hwif->ultra_mask;
499
500 /* errata A308 workaround: limit non ide_disk drive to UDMA4 */
501 if ((drive->media != ide_disk) && (mask & 0xE0)) {
502 printk(KERN_INFO "%s: limit %s to UDMA4\n",
503 SCC_PATA_NAME, drive->name);
504 mask = ATA_UDMA4;
505 }
506
507 return mask;
508}
509
510/**
511 * setup_mmio_scc - map CTRL/BMID region
512 * @dev: PCI device we are configuring
513 * @name: device name
514 *
515 */
516
517static int setup_mmio_scc (struct pci_dev *dev, const char *name)
518{
519 void __iomem *ctl_addr;
520 void __iomem *dma_addr;
521 int i, ret;
522
523 for (i = 0; i < MAX_HWIFS; i++) {
524 if (scc_ports[i].ctl == 0)
525 break;
526 }
527 if (i >= MAX_HWIFS)
528 return -ENOMEM;
529
530 ret = pci_request_selected_regions(dev, (1 << 2) - 1, name);
531 if (ret < 0) {
532 printk(KERN_ERR "%s: can't reserve resources\n", name);
533 return ret;
534 }
535
536 ctl_addr = pci_ioremap_bar(dev, 0);
537 if (!ctl_addr)
538 goto fail_0;
539
540 dma_addr = pci_ioremap_bar(dev, 1);
541 if (!dma_addr)
542 goto fail_1;
543
544 pci_set_master(dev);
545 scc_ports[i].ctl = (unsigned long)ctl_addr;
546 scc_ports[i].dma = (unsigned long)dma_addr;
547 pci_set_drvdata(dev, (void *) &scc_ports[i]);
548
549 return 1;
550
551 fail_1:
552 iounmap(ctl_addr);
553 fail_0:
554 return -ENOMEM;
555}
556
557static int scc_ide_setup_pci_device(struct pci_dev *dev,
558 const struct ide_port_info *d)
559{
560 struct scc_ports *ports = pci_get_drvdata(dev);
561 struct ide_host *host;
562 struct ide_hw hw, *hws[] = { &hw };
563 int i, rc;
564
565 memset(&hw, 0, sizeof(hw));
566 for (i = 0; i <= 8; i++)
567 hw.io_ports_array[i] = ports->dma + 0x20 + i * 4;
568 hw.irq = dev->irq;
569 hw.dev = &dev->dev;
570
571 rc = ide_host_add(d, hws, 1, &host);
572 if (rc)
573 return rc;
574
575 ports->host = host;
576
577 return 0;
578}
579
580/**
581 * init_setup_scc - set up an SCC PATA Controller
582 * @dev: PCI device
583 * @d: IDE port info
584 *
585 * Perform the initial set up for this device.
586 */
587
588static int init_setup_scc(struct pci_dev *dev, const struct ide_port_info *d)
589{
590 unsigned long ctl_base;
591 unsigned long dma_base;
592 unsigned long cckctrl_port;
593 unsigned long intmask_port;
594 unsigned long mode_port;
595 unsigned long ecmode_port;
596 u32 reg = 0;
597 struct scc_ports *ports;
598 int rc;
599
600 rc = pci_enable_device(dev);
601 if (rc)
602 goto end;
603
604 rc = setup_mmio_scc(dev, d->name);
605 if (rc < 0)
606 goto end;
607
608 ports = pci_get_drvdata(dev);
609 ctl_base = ports->ctl;
610 dma_base = ports->dma;
611 cckctrl_port = ctl_base + 0xff0;
612 intmask_port = dma_base + 0x010;
613 mode_port = ctl_base + 0x024;
614 ecmode_port = ctl_base + 0xf00;
615
616 /* controller initialization */
617 reg = 0;
618 out_be32((void*)cckctrl_port, reg);
619 reg |= CCKCTRL_ATACLKOEN;
620 out_be32((void*)cckctrl_port, reg);
621 reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
622 out_be32((void*)cckctrl_port, reg);
623 reg |= CCKCTRL_CRST;
624 out_be32((void*)cckctrl_port, reg);
625
626 for (;;) {
627 reg = in_be32((void*)cckctrl_port);
628 if (reg & CCKCTRL_CRST)
629 break;
630 udelay(5000);
631 }
632
633 reg |= CCKCTRL_ATARESET;
634 out_be32((void*)cckctrl_port, reg);
635
636 out_be32((void*)ecmode_port, ECMODE_VALUE);
637 out_be32((void*)mode_port, MODE_JCUSFEN);
638 out_be32((void*)intmask_port, INTMASK_MSK);
639
640 rc = scc_ide_setup_pci_device(dev, d);
641
642 end:
643 return rc;
644}
645
646static void scc_tf_load(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid)
647{
648 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
649
650 if (valid & IDE_VALID_FEATURE)
651 scc_ide_outb(tf->feature, io_ports->feature_addr);
652 if (valid & IDE_VALID_NSECT)
653 scc_ide_outb(tf->nsect, io_ports->nsect_addr);
654 if (valid & IDE_VALID_LBAL)
655 scc_ide_outb(tf->lbal, io_ports->lbal_addr);
656 if (valid & IDE_VALID_LBAM)
657 scc_ide_outb(tf->lbam, io_ports->lbam_addr);
658 if (valid & IDE_VALID_LBAH)
659 scc_ide_outb(tf->lbah, io_ports->lbah_addr);
660 if (valid & IDE_VALID_DEVICE)
661 scc_ide_outb(tf->device, io_ports->device_addr);
662}
663
664static void scc_tf_read(ide_drive_t *drive, struct ide_taskfile *tf, u8 valid)
665{
666 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
667
668 if (valid & IDE_VALID_ERROR)
669 tf->error = scc_ide_inb(io_ports->feature_addr);
670 if (valid & IDE_VALID_NSECT)
671 tf->nsect = scc_ide_inb(io_ports->nsect_addr);
672 if (valid & IDE_VALID_LBAL)
673 tf->lbal = scc_ide_inb(io_ports->lbal_addr);
674 if (valid & IDE_VALID_LBAM)
675 tf->lbam = scc_ide_inb(io_ports->lbam_addr);
676 if (valid & IDE_VALID_LBAH)
677 tf->lbah = scc_ide_inb(io_ports->lbah_addr);
678 if (valid & IDE_VALID_DEVICE)
679 tf->device = scc_ide_inb(io_ports->device_addr);
680}
681
682static void scc_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
683 void *buf, unsigned int len)
684{
685 unsigned long data_addr = drive->hwif->io_ports.data_addr;
686
687 len++;
688
689 if (drive->io_32bit) {
690 scc_ide_insl(data_addr, buf, len / 4);
691
692 if ((len & 3) >= 2)
693 scc_ide_insw(data_addr, (u8 *)buf + (len & ~3), 1);
694 } else
695 scc_ide_insw(data_addr, buf, len / 2);
696}
697
698static void scc_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
699 void *buf, unsigned int len)
700{
701 unsigned long data_addr = drive->hwif->io_ports.data_addr;
702
703 len++;
704
705 if (drive->io_32bit) {
706 scc_ide_outsl(data_addr, buf, len / 4);
707
708 if ((len & 3) >= 2)
709 scc_ide_outsw(data_addr, (u8 *)buf + (len & ~3), 1);
710 } else
711 scc_ide_outsw(data_addr, buf, len / 2);
712}
713
714/**
715 * init_mmio_iops_scc - set up the iops for MMIO
716 * @hwif: interface to set up
717 *
718 */
719
720static void init_mmio_iops_scc(ide_hwif_t *hwif)
721{
722 struct pci_dev *dev = to_pci_dev(hwif->dev);
723 struct scc_ports *ports = pci_get_drvdata(dev);
724 unsigned long dma_base = ports->dma;
725
726 ide_set_hwifdata(hwif, ports);
727
728 hwif->dma_base = dma_base;
729 hwif->config_data = ports->ctl;
730}
731
732/**
733 * init_iops_scc - set up iops
734 * @hwif: interface to set up
735 *
736 * Do the basic setup for the SCC hardware interface
737 * and then do the MMIO setup.
738 */
739
740static void init_iops_scc(ide_hwif_t *hwif)
741{
742 struct pci_dev *dev = to_pci_dev(hwif->dev);
743
744 hwif->hwif_data = NULL;
745 if (pci_get_drvdata(dev) == NULL)
746 return;
747 init_mmio_iops_scc(hwif);
748}
749
750static int scc_init_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
751{
752 return ide_allocate_dma_engine(hwif);
753}
754
755static u8 scc_cable_detect(ide_hwif_t *hwif)
756{
757 return ATA_CBL_PATA80;
758}
759
760/**
761 * init_hwif_scc - set up hwif
762 * @hwif: interface to set up
763 *
764 * We do the basic set up of the interface structure. The SCC
765 * requires several custom handlers so we override the default
766 * ide DMA handlers appropriately.
767 */
768
769static void init_hwif_scc(ide_hwif_t *hwif)
770{
771 /* PTERADD */
772 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma);
773
774 if (in_be32((void __iomem *)(hwif->config_data + 0xff0)) & CCKCTRL_ATACLKOEN)
775 hwif->ultra_mask = ATA_UDMA6; /* 133MHz */
776 else
777 hwif->ultra_mask = ATA_UDMA5; /* 100MHz */
778}
779
780static const struct ide_tp_ops scc_tp_ops = {
781 .exec_command = scc_exec_command,
782 .read_status = scc_read_status,
783 .read_altstatus = scc_read_altstatus,
784 .write_devctl = scc_write_devctl,
785
786 .dev_select = ide_dev_select,
787 .tf_load = scc_tf_load,
788 .tf_read = scc_tf_read,
789
790 .input_data = scc_input_data,
791 .output_data = scc_output_data,
792};
793
794static const struct ide_port_ops scc_port_ops = {
795 .set_pio_mode = scc_set_pio_mode,
796 .set_dma_mode = scc_set_dma_mode,
797 .udma_filter = scc_udma_filter,
798 .cable_detect = scc_cable_detect,
799};
800
801static const struct ide_dma_ops scc_dma_ops = {
802 .dma_host_set = scc_dma_host_set,
803 .dma_setup = scc_dma_setup,
804 .dma_start = scc_dma_start,
805 .dma_end = scc_dma_end,
806 .dma_test_irq = scc_dma_test_irq,
807 .dma_lost_irq = ide_dma_lost_irq,
808 .dma_timer_expiry = ide_dma_sff_timer_expiry,
809 .dma_sff_read_status = scc_dma_sff_read_status,
810};
811
812static const struct ide_port_info scc_chipset = {
813 .name = "sccIDE",
814 .init_iops = init_iops_scc,
815 .init_dma = scc_init_dma,
816 .init_hwif = init_hwif_scc,
817 .tp_ops = &scc_tp_ops,
818 .port_ops = &scc_port_ops,
819 .dma_ops = &scc_dma_ops,
820 .host_flags = IDE_HFLAG_SINGLE,
821 .irq_flags = IRQF_SHARED,
822 .pio_mask = ATA_PIO4,
823 .chipset = ide_pci,
824};
825
826/**
827 * scc_init_one - pci layer discovery entry
828 * @dev: PCI device
829 * @id: ident table entry
830 *
831 * Called by the PCI code when it finds an SCC PATA controller.
832 * We then use the IDE PCI generic helper to do most of the work.
833 */
834
835static int scc_init_one(struct pci_dev *dev, const struct pci_device_id *id)
836{
837 return init_setup_scc(dev, &scc_chipset);
838}
839
840/**
841 * scc_remove - pci layer remove entry
842 * @dev: PCI device
843 *
844 * Called by the PCI code when it removes an SCC PATA controller.
845 */
846
847static void scc_remove(struct pci_dev *dev)
848{
849 struct scc_ports *ports = pci_get_drvdata(dev);
850 struct ide_host *host = ports->host;
851
852 ide_host_remove(host);
853
854 iounmap((void*)ports->dma);
855 iounmap((void*)ports->ctl);
856 pci_release_selected_regions(dev, (1 << 2) - 1);
857 memset(ports, 0, sizeof(*ports));
858}
859
860static const struct pci_device_id scc_pci_tbl[] = {
861 { PCI_VDEVICE(TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA), 0 },
862 { 0, },
863};
864MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
865
866static struct pci_driver scc_pci_driver = {
867 .name = "SCC IDE",
868 .id_table = scc_pci_tbl,
869 .probe = scc_init_one,
870 .remove = scc_remove,
871};
872
873static int __init scc_ide_init(void)
874{
875 return ide_pci_register_driver(&scc_pci_driver);
876}
877
878static void __exit scc_ide_exit(void)
879{
880 pci_unregister_driver(&scc_pci_driver);
881}
882
883module_init(scc_ide_init);
884module_exit(scc_ide_exit);
885
886MODULE_DESCRIPTION("PCI driver module for Toshiba SCC IDE");
887MODULE_LICENSE("GPL");
diff --git a/drivers/iio/accel/mma9551_core.c b/drivers/iio/accel/mma9551_core.c
index 7f55a6d7cd03..c6d5a3a40b60 100644
--- a/drivers/iio/accel/mma9551_core.c
+++ b/drivers/iio/accel/mma9551_core.c
@@ -389,7 +389,12 @@ int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
389{ 389{
390 int ret, i; 390 int ret, i;
391 int len_words = len / sizeof(u16); 391 int len_words = len / sizeof(u16);
392 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS]; 392 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
393
394 if (len_words > ARRAY_SIZE(be_buf)) {
395 dev_err(&client->dev, "Invalid buffer size %d\n", len);
396 return -EINVAL;
397 }
393 398
394 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, 399 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
395 reg, NULL, 0, (u8 *) be_buf, len); 400 reg, NULL, 0, (u8 *) be_buf, len);
@@ -424,7 +429,12 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
424{ 429{
425 int ret, i; 430 int ret, i;
426 int len_words = len / sizeof(u16); 431 int len_words = len / sizeof(u16);
427 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS]; 432 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];
433
434 if (len_words > ARRAY_SIZE(be_buf)) {
435 dev_err(&client->dev, "Invalid buffer size %d\n", len);
436 return -EINVAL;
437 }
428 438
429 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, 439 ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
430 reg, NULL, 0, (u8 *) be_buf, len); 440 reg, NULL, 0, (u8 *) be_buf, len);
@@ -459,7 +469,12 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
459{ 469{
460 int i; 470 int i;
461 int len_words = len / sizeof(u16); 471 int len_words = len / sizeof(u16);
462 __be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS]; 472 __be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2];
473
474 if (len_words > ARRAY_SIZE(be_buf)) {
475 dev_err(&client->dev, "Invalid buffer size %d\n", len);
476 return -EINVAL;
477 }
463 478
464 for (i = 0; i < len_words; i++) 479 for (i = 0; i < len_words; i++)
465 be_buf[i] = cpu_to_be16(buf[i]); 480 be_buf[i] = cpu_to_be16(buf[i]);
diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c
index 2df1af7d43fc..365a109aaaef 100644
--- a/drivers/iio/accel/mma9553.c
+++ b/drivers/iio/accel/mma9553.c
@@ -54,6 +54,7 @@
54#define MMA9553_MASK_CONF_STEPCOALESCE GENMASK(7, 0) 54#define MMA9553_MASK_CONF_STEPCOALESCE GENMASK(7, 0)
55 55
56#define MMA9553_REG_CONF_ACTTHD 0x0E 56#define MMA9553_REG_CONF_ACTTHD 0x0E
57#define MMA9553_MAX_ACTTHD GENMASK(15, 0)
57 58
58/* Pedometer status registers (R-only) */ 59/* Pedometer status registers (R-only) */
59#define MMA9553_REG_STATUS 0x00 60#define MMA9553_REG_STATUS 0x00
@@ -316,22 +317,19 @@ static int mma9553_set_config(struct mma9553_data *data, u16 reg,
316static int mma9553_read_activity_stepcnt(struct mma9553_data *data, 317static int mma9553_read_activity_stepcnt(struct mma9553_data *data,
317 u8 *activity, u16 *stepcnt) 318 u8 *activity, u16 *stepcnt)
318{ 319{
319 u32 status_stepcnt; 320 u16 buf[2];
320 u16 status;
321 int ret; 321 int ret;
322 322
323 ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, 323 ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
324 MMA9553_REG_STATUS, sizeof(u32), 324 MMA9553_REG_STATUS, sizeof(u32), buf);
325 (u16 *) &status_stepcnt);
326 if (ret < 0) { 325 if (ret < 0) {
327 dev_err(&data->client->dev, 326 dev_err(&data->client->dev,
328 "error reading status and stepcnt\n"); 327 "error reading status and stepcnt\n");
329 return ret; 328 return ret;
330 } 329 }
331 330
332 status = status_stepcnt & MMA9553_MASK_CONF_WORD; 331 *activity = mma9553_get_bits(buf[0], MMA9553_MASK_STATUS_ACTIVITY);
333 *activity = mma9553_get_bits(status, MMA9553_MASK_STATUS_ACTIVITY); 332 *stepcnt = buf[1];
334 *stepcnt = status_stepcnt >> 16;
335 333
336 return 0; 334 return 0;
337} 335}
@@ -872,6 +870,9 @@ static int mma9553_write_event_value(struct iio_dev *indio_dev,
872 case IIO_EV_INFO_PERIOD: 870 case IIO_EV_INFO_PERIOD:
873 switch (chan->type) { 871 switch (chan->type) {
874 case IIO_ACTIVITY: 872 case IIO_ACTIVITY:
873 if (val < 0 || val > MMA9553_ACTIVITY_THD_TO_SEC(
874 MMA9553_MAX_ACTTHD))
875 return -EINVAL;
875 mutex_lock(&data->mutex); 876 mutex_lock(&data->mutex);
876 ret = mma9553_set_config(data, MMA9553_REG_CONF_ACTTHD, 877 ret = mma9553_set_config(data, MMA9553_REG_CONF_ACTTHD,
877 &data->conf.actthd, 878 &data->conf.actthd,
@@ -971,7 +972,8 @@ static const struct iio_chan_spec_ext_info mma9553_ext_info[] = {
971 .modified = 1, \ 972 .modified = 1, \
972 .channel2 = _chan2, \ 973 .channel2 = _chan2, \
973 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ 974 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
974 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBHEIGHT), \ 975 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBHEIGHT) | \
976 BIT(IIO_CHAN_INFO_ENABLE), \
975 .event_spec = mma9553_activity_events, \ 977 .event_spec = mma9553_activity_events, \
976 .num_event_specs = ARRAY_SIZE(mma9553_activity_events), \ 978 .num_event_specs = ARRAY_SIZE(mma9553_activity_events), \
977 .ext_info = mma9553_ext_info, \ 979 .ext_info = mma9553_ext_info, \
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 58d1d13d552a..211b13271c61 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -546,6 +546,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
546 546
547 indio_dev->modes = INDIO_DIRECT_MODE; 547 indio_dev->modes = INDIO_DIRECT_MODE;
548 indio_dev->info = &accel_info; 548 indio_dev->info = &accel_info;
549 mutex_init(&adata->tb.buf_lock);
549 550
550 st_sensors_power_enable(indio_dev); 551 st_sensors_power_enable(indio_dev);
551 552
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
index 08bcfb061ca5..56008a86b78f 100644
--- a/drivers/iio/adc/axp288_adc.c
+++ b/drivers/iio/adc/axp288_adc.c
@@ -53,39 +53,42 @@ static const struct iio_chan_spec const axp288_adc_channels[] = {
53 .channel = 0, 53 .channel = 0,
54 .address = AXP288_TS_ADC_H, 54 .address = AXP288_TS_ADC_H,
55 .datasheet_name = "TS_PIN", 55 .datasheet_name = "TS_PIN",
56 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
56 }, { 57 }, {
57 .indexed = 1, 58 .indexed = 1,
58 .type = IIO_TEMP, 59 .type = IIO_TEMP,
59 .channel = 1, 60 .channel = 1,
60 .address = AXP288_PMIC_ADC_H, 61 .address = AXP288_PMIC_ADC_H,
61 .datasheet_name = "PMIC_TEMP", 62 .datasheet_name = "PMIC_TEMP",
63 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
62 }, { 64 }, {
63 .indexed = 1, 65 .indexed = 1,
64 .type = IIO_TEMP, 66 .type = IIO_TEMP,
65 .channel = 2, 67 .channel = 2,
66 .address = AXP288_GP_ADC_H, 68 .address = AXP288_GP_ADC_H,
67 .datasheet_name = "GPADC", 69 .datasheet_name = "GPADC",
70 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
68 }, { 71 }, {
69 .indexed = 1, 72 .indexed = 1,
70 .type = IIO_CURRENT, 73 .type = IIO_CURRENT,
71 .channel = 3, 74 .channel = 3,
72 .address = AXP20X_BATT_CHRG_I_H, 75 .address = AXP20X_BATT_CHRG_I_H,
73 .datasheet_name = "BATT_CHG_I", 76 .datasheet_name = "BATT_CHG_I",
74 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 77 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
75 }, { 78 }, {
76 .indexed = 1, 79 .indexed = 1,
77 .type = IIO_CURRENT, 80 .type = IIO_CURRENT,
78 .channel = 4, 81 .channel = 4,
79 .address = AXP20X_BATT_DISCHRG_I_H, 82 .address = AXP20X_BATT_DISCHRG_I_H,
80 .datasheet_name = "BATT_DISCHRG_I", 83 .datasheet_name = "BATT_DISCHRG_I",
81 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 84 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
82 }, { 85 }, {
83 .indexed = 1, 86 .indexed = 1,
84 .type = IIO_VOLTAGE, 87 .type = IIO_VOLTAGE,
85 .channel = 5, 88 .channel = 5,
86 .address = AXP20X_BATT_V_H, 89 .address = AXP20X_BATT_V_H,
87 .datasheet_name = "BATT_V", 90 .datasheet_name = "BATT_V",
88 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 91 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
89 }, 92 },
90}; 93};
91 94
@@ -151,9 +154,6 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
151 chan->address)) 154 chan->address))
152 dev_err(&indio_dev->dev, "TS pin restore\n"); 155 dev_err(&indio_dev->dev, "TS pin restore\n");
153 break; 156 break;
154 case IIO_CHAN_INFO_PROCESSED:
155 ret = axp288_adc_read_channel(val, chan->address, info->regmap);
156 break;
157 default: 157 default:
158 ret = -EINVAL; 158 ret = -EINVAL;
159 } 159 }
diff --git a/drivers/iio/adc/cc10001_adc.c b/drivers/iio/adc/cc10001_adc.c
index 51e2a83c9404..115f6e99a7fa 100644
--- a/drivers/iio/adc/cc10001_adc.c
+++ b/drivers/iio/adc/cc10001_adc.c
@@ -35,8 +35,9 @@
35#define CC10001_ADC_EOC_SET BIT(0) 35#define CC10001_ADC_EOC_SET BIT(0)
36 36
37#define CC10001_ADC_CHSEL_SAMPLED 0x0c 37#define CC10001_ADC_CHSEL_SAMPLED 0x0c
38#define CC10001_ADC_POWER_UP 0x10 38#define CC10001_ADC_POWER_DOWN 0x10
39#define CC10001_ADC_POWER_UP_SET BIT(0) 39#define CC10001_ADC_POWER_DOWN_SET BIT(0)
40
40#define CC10001_ADC_DEBUG 0x14 41#define CC10001_ADC_DEBUG 0x14
41#define CC10001_ADC_DATA_COUNT 0x20 42#define CC10001_ADC_DATA_COUNT 0x20
42 43
@@ -62,7 +63,6 @@ struct cc10001_adc_device {
62 u16 *buf; 63 u16 *buf;
63 64
64 struct mutex lock; 65 struct mutex lock;
65 unsigned long channel_map;
66 unsigned int start_delay_ns; 66 unsigned int start_delay_ns;
67 unsigned int eoc_delay_ns; 67 unsigned int eoc_delay_ns;
68}; 68};
@@ -79,6 +79,18 @@ static inline u32 cc10001_adc_read_reg(struct cc10001_adc_device *adc_dev,
79 return readl(adc_dev->reg_base + reg); 79 return readl(adc_dev->reg_base + reg);
80} 80}
81 81
82static void cc10001_adc_power_up(struct cc10001_adc_device *adc_dev)
83{
84 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_DOWN, 0);
85 ndelay(adc_dev->start_delay_ns);
86}
87
88static void cc10001_adc_power_down(struct cc10001_adc_device *adc_dev)
89{
90 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_DOWN,
91 CC10001_ADC_POWER_DOWN_SET);
92}
93
82static void cc10001_adc_start(struct cc10001_adc_device *adc_dev, 94static void cc10001_adc_start(struct cc10001_adc_device *adc_dev,
83 unsigned int channel) 95 unsigned int channel)
84{ 96{
@@ -88,6 +100,7 @@ static void cc10001_adc_start(struct cc10001_adc_device *adc_dev,
88 val = (channel & CC10001_ADC_CH_MASK) | CC10001_ADC_MODE_SINGLE_CONV; 100 val = (channel & CC10001_ADC_CH_MASK) | CC10001_ADC_MODE_SINGLE_CONV;
89 cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val); 101 cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val);
90 102
103 udelay(1);
91 val = cc10001_adc_read_reg(adc_dev, CC10001_ADC_CONFIG); 104 val = cc10001_adc_read_reg(adc_dev, CC10001_ADC_CONFIG);
92 val = val | CC10001_ADC_START_CONV; 105 val = val | CC10001_ADC_START_CONV;
93 cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val); 106 cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val);
@@ -129,6 +142,7 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
129 struct iio_dev *indio_dev; 142 struct iio_dev *indio_dev;
130 unsigned int delay_ns; 143 unsigned int delay_ns;
131 unsigned int channel; 144 unsigned int channel;
145 unsigned int scan_idx;
132 bool sample_invalid; 146 bool sample_invalid;
133 u16 *data; 147 u16 *data;
134 int i; 148 int i;
@@ -139,20 +153,17 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
139 153
140 mutex_lock(&adc_dev->lock); 154 mutex_lock(&adc_dev->lock);
141 155
142 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP, 156 cc10001_adc_power_up(adc_dev);
143 CC10001_ADC_POWER_UP_SET);
144
145 /* Wait for 8 (6+2) clock cycles before activating START */
146 ndelay(adc_dev->start_delay_ns);
147 157
148 /* Calculate delay step for eoc and sampled data */ 158 /* Calculate delay step for eoc and sampled data */
149 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; 159 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT;
150 160
151 i = 0; 161 i = 0;
152 sample_invalid = false; 162 sample_invalid = false;
153 for_each_set_bit(channel, indio_dev->active_scan_mask, 163 for_each_set_bit(scan_idx, indio_dev->active_scan_mask,
154 indio_dev->masklength) { 164 indio_dev->masklength) {
155 165
166 channel = indio_dev->channels[scan_idx].channel;
156 cc10001_adc_start(adc_dev, channel); 167 cc10001_adc_start(adc_dev, channel);
157 168
158 data[i] = cc10001_adc_poll_done(indio_dev, channel, delay_ns); 169 data[i] = cc10001_adc_poll_done(indio_dev, channel, delay_ns);
@@ -166,7 +177,7 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
166 } 177 }
167 178
168done: 179done:
169 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP, 0); 180 cc10001_adc_power_down(adc_dev);
170 181
171 mutex_unlock(&adc_dev->lock); 182 mutex_unlock(&adc_dev->lock);
172 183
@@ -185,11 +196,7 @@ static u16 cc10001_adc_read_raw_voltage(struct iio_dev *indio_dev,
185 unsigned int delay_ns; 196 unsigned int delay_ns;
186 u16 val; 197 u16 val;
187 198
188 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP, 199 cc10001_adc_power_up(adc_dev);
189 CC10001_ADC_POWER_UP_SET);
190
191 /* Wait for 8 (6+2) clock cycles before activating START */
192 ndelay(adc_dev->start_delay_ns);
193 200
194 /* Calculate delay step for eoc and sampled data */ 201 /* Calculate delay step for eoc and sampled data */
195 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; 202 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT;
@@ -198,7 +205,7 @@ static u16 cc10001_adc_read_raw_voltage(struct iio_dev *indio_dev,
198 205
199 val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns); 206 val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns);
200 207
201 cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP, 0); 208 cc10001_adc_power_down(adc_dev);
202 209
203 return val; 210 return val;
204} 211}
@@ -224,7 +231,7 @@ static int cc10001_adc_read_raw(struct iio_dev *indio_dev,
224 231
225 case IIO_CHAN_INFO_SCALE: 232 case IIO_CHAN_INFO_SCALE:
226 ret = regulator_get_voltage(adc_dev->reg); 233 ret = regulator_get_voltage(adc_dev->reg);
227 if (ret) 234 if (ret < 0)
228 return ret; 235 return ret;
229 236
230 *val = ret / 1000; 237 *val = ret / 1000;
@@ -255,22 +262,22 @@ static const struct iio_info cc10001_adc_info = {
255 .update_scan_mode = &cc10001_update_scan_mode, 262 .update_scan_mode = &cc10001_update_scan_mode,
256}; 263};
257 264
258static int cc10001_adc_channel_init(struct iio_dev *indio_dev) 265static int cc10001_adc_channel_init(struct iio_dev *indio_dev,
266 unsigned long channel_map)
259{ 267{
260 struct cc10001_adc_device *adc_dev = iio_priv(indio_dev);
261 struct iio_chan_spec *chan_array, *timestamp; 268 struct iio_chan_spec *chan_array, *timestamp;
262 unsigned int bit, idx = 0; 269 unsigned int bit, idx = 0;
263 270
264 indio_dev->num_channels = bitmap_weight(&adc_dev->channel_map, 271 indio_dev->num_channels = bitmap_weight(&channel_map,
265 CC10001_ADC_NUM_CHANNELS); 272 CC10001_ADC_NUM_CHANNELS) + 1;
266 273
267 chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels + 1, 274 chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels,
268 sizeof(struct iio_chan_spec), 275 sizeof(struct iio_chan_spec),
269 GFP_KERNEL); 276 GFP_KERNEL);
270 if (!chan_array) 277 if (!chan_array)
271 return -ENOMEM; 278 return -ENOMEM;
272 279
273 for_each_set_bit(bit, &adc_dev->channel_map, CC10001_ADC_NUM_CHANNELS) { 280 for_each_set_bit(bit, &channel_map, CC10001_ADC_NUM_CHANNELS) {
274 struct iio_chan_spec *chan = &chan_array[idx]; 281 struct iio_chan_spec *chan = &chan_array[idx];
275 282
276 chan->type = IIO_VOLTAGE; 283 chan->type = IIO_VOLTAGE;
@@ -305,6 +312,7 @@ static int cc10001_adc_probe(struct platform_device *pdev)
305 unsigned long adc_clk_rate; 312 unsigned long adc_clk_rate;
306 struct resource *res; 313 struct resource *res;
307 struct iio_dev *indio_dev; 314 struct iio_dev *indio_dev;
315 unsigned long channel_map;
308 int ret; 316 int ret;
309 317
310 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev)); 318 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev));
@@ -313,9 +321,9 @@ static int cc10001_adc_probe(struct platform_device *pdev)
313 321
314 adc_dev = iio_priv(indio_dev); 322 adc_dev = iio_priv(indio_dev);
315 323
316 adc_dev->channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0); 324 channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0);
317 if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) 325 if (!of_property_read_u32(node, "adc-reserved-channels", &ret))
318 adc_dev->channel_map &= ~ret; 326 channel_map &= ~ret;
319 327
320 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref"); 328 adc_dev->reg = devm_regulator_get(&pdev->dev, "vref");
321 if (IS_ERR(adc_dev->reg)) 329 if (IS_ERR(adc_dev->reg))
@@ -361,7 +369,7 @@ static int cc10001_adc_probe(struct platform_device *pdev)
361 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES; 369 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES;
362 370
363 /* Setup the ADC channels available on the device */ 371 /* Setup the ADC channels available on the device */
364 ret = cc10001_adc_channel_init(indio_dev); 372 ret = cc10001_adc_channel_init(indio_dev, channel_map);
365 if (ret < 0) 373 if (ret < 0)
366 goto err_disable_clk; 374 goto err_disable_clk;
367 375
diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index efbfd12a4bfd..8d9c9b9215dd 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -60,12 +60,12 @@ struct mcp320x {
60 struct spi_message msg; 60 struct spi_message msg;
61 struct spi_transfer transfer[2]; 61 struct spi_transfer transfer[2];
62 62
63 u8 tx_buf;
64 u8 rx_buf[2];
65
66 struct regulator *reg; 63 struct regulator *reg;
67 struct mutex lock; 64 struct mutex lock;
68 const struct mcp320x_chip_info *chip_info; 65 const struct mcp320x_chip_info *chip_info;
66
67 u8 tx_buf ____cacheline_aligned;
68 u8 rx_buf[2];
69}; 69};
70 70
71static int mcp320x_channel_to_tx_data(int device_index, 71static int mcp320x_channel_to_tx_data(int device_index,
diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
index 3211729bcb0b..0c4618b4d515 100644
--- a/drivers/iio/adc/qcom-spmi-vadc.c
+++ b/drivers/iio/adc/qcom-spmi-vadc.c
@@ -18,6 +18,7 @@
18#include <linux/iio/iio.h> 18#include <linux/iio/iio.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/math64.h>
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/of.h> 23#include <linux/of.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
@@ -471,11 +472,11 @@ static s32 vadc_calibrate(struct vadc_priv *vadc,
471 const struct vadc_channel_prop *prop, u16 adc_code) 472 const struct vadc_channel_prop *prop, u16 adc_code)
472{ 473{
473 const struct vadc_prescale_ratio *prescale; 474 const struct vadc_prescale_ratio *prescale;
474 s32 voltage; 475 s64 voltage;
475 476
476 voltage = adc_code - vadc->graph[prop->calibration].gnd; 477 voltage = adc_code - vadc->graph[prop->calibration].gnd;
477 voltage *= vadc->graph[prop->calibration].dx; 478 voltage *= vadc->graph[prop->calibration].dx;
478 voltage = voltage / vadc->graph[prop->calibration].dy; 479 voltage = div64_s64(voltage, vadc->graph[prop->calibration].dy);
479 480
480 if (prop->calibration == VADC_CALIB_ABSOLUTE) 481 if (prop->calibration == VADC_CALIB_ABSOLUTE)
481 voltage += vadc->graph[prop->calibration].dx; 482 voltage += vadc->graph[prop->calibration].dx;
@@ -487,7 +488,7 @@ static s32 vadc_calibrate(struct vadc_priv *vadc,
487 488
488 voltage = voltage * prescale->den; 489 voltage = voltage * prescale->den;
489 490
490 return voltage / prescale->num; 491 return div64_s64(voltage, prescale->num);
491} 492}
492 493
493static int vadc_decimation_from_dt(u32 value) 494static int vadc_decimation_from_dt(u32 value)
diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
index a221f7329b79..ce93bd8e3f68 100644
--- a/drivers/iio/adc/xilinx-xadc-core.c
+++ b/drivers/iio/adc/xilinx-xadc-core.c
@@ -856,6 +856,7 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
856 switch (chan->address) { 856 switch (chan->address) {
857 case XADC_REG_VCCINT: 857 case XADC_REG_VCCINT:
858 case XADC_REG_VCCAUX: 858 case XADC_REG_VCCAUX:
859 case XADC_REG_VREFP:
859 case XADC_REG_VCCBRAM: 860 case XADC_REG_VCCBRAM:
860 case XADC_REG_VCCPINT: 861 case XADC_REG_VCCPINT:
861 case XADC_REG_VCCPAUX: 862 case XADC_REG_VCCPAUX:
@@ -996,7 +997,7 @@ static const struct iio_event_spec xadc_voltage_events[] = {
996 .num_event_specs = (_alarm) ? ARRAY_SIZE(xadc_voltage_events) : 0, \ 997 .num_event_specs = (_alarm) ? ARRAY_SIZE(xadc_voltage_events) : 0, \
997 .scan_index = (_scan_index), \ 998 .scan_index = (_scan_index), \
998 .scan_type = { \ 999 .scan_type = { \
999 .sign = 'u', \ 1000 .sign = ((_addr) == XADC_REG_VREFN) ? 's' : 'u', \
1000 .realbits = 12, \ 1001 .realbits = 12, \
1001 .storagebits = 16, \ 1002 .storagebits = 16, \
1002 .shift = 4, \ 1003 .shift = 4, \
@@ -1008,7 +1009,7 @@ static const struct iio_event_spec xadc_voltage_events[] = {
1008static const struct iio_chan_spec xadc_channels[] = { 1009static const struct iio_chan_spec xadc_channels[] = {
1009 XADC_CHAN_TEMP(0, 8, XADC_REG_TEMP), 1010 XADC_CHAN_TEMP(0, 8, XADC_REG_TEMP),
1010 XADC_CHAN_VOLTAGE(0, 9, XADC_REG_VCCINT, "vccint", true), 1011 XADC_CHAN_VOLTAGE(0, 9, XADC_REG_VCCINT, "vccint", true),
1011 XADC_CHAN_VOLTAGE(1, 10, XADC_REG_VCCINT, "vccaux", true), 1012 XADC_CHAN_VOLTAGE(1, 10, XADC_REG_VCCAUX, "vccaux", true),
1012 XADC_CHAN_VOLTAGE(2, 14, XADC_REG_VCCBRAM, "vccbram", true), 1013 XADC_CHAN_VOLTAGE(2, 14, XADC_REG_VCCBRAM, "vccbram", true),
1013 XADC_CHAN_VOLTAGE(3, 5, XADC_REG_VCCPINT, "vccpint", true), 1014 XADC_CHAN_VOLTAGE(3, 5, XADC_REG_VCCPINT, "vccpint", true),
1014 XADC_CHAN_VOLTAGE(4, 6, XADC_REG_VCCPAUX, "vccpaux", true), 1015 XADC_CHAN_VOLTAGE(4, 6, XADC_REG_VCCPAUX, "vccpaux", true),
diff --git a/drivers/iio/adc/xilinx-xadc.h b/drivers/iio/adc/xilinx-xadc.h
index c7487e8d7f80..54adc5087210 100644
--- a/drivers/iio/adc/xilinx-xadc.h
+++ b/drivers/iio/adc/xilinx-xadc.h
@@ -145,9 +145,9 @@ static inline int xadc_write_adc_reg(struct xadc *xadc, unsigned int reg,
145#define XADC_REG_MAX_VCCPINT 0x28 145#define XADC_REG_MAX_VCCPINT 0x28
146#define XADC_REG_MAX_VCCPAUX 0x29 146#define XADC_REG_MAX_VCCPAUX 0x29
147#define XADC_REG_MAX_VCCO_DDR 0x2a 147#define XADC_REG_MAX_VCCO_DDR 0x2a
148#define XADC_REG_MIN_VCCPINT 0x2b 148#define XADC_REG_MIN_VCCPINT 0x2c
149#define XADC_REG_MIN_VCCPAUX 0x2c 149#define XADC_REG_MIN_VCCPAUX 0x2d
150#define XADC_REG_MIN_VCCO_DDR 0x2d 150#define XADC_REG_MIN_VCCO_DDR 0x2e
151 151
152#define XADC_REG_CONF0 0x40 152#define XADC_REG_CONF0 0x40
153#define XADC_REG_CONF1 0x41 153#define XADC_REG_CONF1 0x41
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index edd13d2b4121..8dd0477e201c 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -304,8 +304,6 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev,
304 struct st_sensors_platform_data *of_pdata; 304 struct st_sensors_platform_data *of_pdata;
305 int err = 0; 305 int err = 0;
306 306
307 mutex_init(&sdata->tb.buf_lock);
308
309 /* If OF/DT pdata exists, it will take precedence of anything else */ 307 /* If OF/DT pdata exists, it will take precedence of anything else */
310 of_pdata = st_sensors_of_probe(indio_dev->dev.parent, pdata); 308 of_pdata = st_sensors_of_probe(indio_dev->dev.parent, pdata);
311 if (of_pdata) 309 if (of_pdata)
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index 21395f26d227..ffe96642b6d0 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -400,6 +400,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
400 400
401 indio_dev->modes = INDIO_DIRECT_MODE; 401 indio_dev->modes = INDIO_DIRECT_MODE;
402 indio_dev->info = &gyro_info; 402 indio_dev->info = &gyro_info;
403 mutex_init(&gdata->tb.buf_lock);
403 404
404 st_sensors_power_enable(indio_dev); 405 st_sensors_power_enable(indio_dev);
405 406
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
index 847ca561afe0..55c267bbfd2f 100644
--- a/drivers/iio/kfifo_buf.c
+++ b/drivers/iio/kfifo_buf.c
@@ -38,7 +38,8 @@ static int iio_request_update_kfifo(struct iio_buffer *r)
38 kfifo_free(&buf->kf); 38 kfifo_free(&buf->kf);
39 ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum, 39 ret = __iio_allocate_kfifo(buf, buf->buffer.bytes_per_datum,
40 buf->buffer.length); 40 buf->buffer.length);
41 buf->update_needed = false; 41 if (ret >= 0)
42 buf->update_needed = false;
42 } else { 43 } else {
43 kfifo_reset_out(&buf->kf); 44 kfifo_reset_out(&buf->kf);
44 } 45 }
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 91ecc46ffeaa..ef60bae738e3 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -43,8 +43,6 @@ struct prox_state {
43static const struct iio_chan_spec prox_channels[] = { 43static const struct iio_chan_spec prox_channels[] = {
44 { 44 {
45 .type = IIO_PROXIMITY, 45 .type = IIO_PROXIMITY,
46 .modified = 1,
47 .channel2 = IIO_NO_MOD,
48 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 46 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
49 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 47 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
50 BIT(IIO_CHAN_INFO_SCALE) | 48 BIT(IIO_CHAN_INFO_SCALE) |
@@ -253,7 +251,6 @@ static int hid_prox_probe(struct platform_device *pdev)
253 struct iio_dev *indio_dev; 251 struct iio_dev *indio_dev;
254 struct prox_state *prox_state; 252 struct prox_state *prox_state;
255 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 253 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
256 struct iio_chan_spec *channels;
257 254
258 indio_dev = devm_iio_device_alloc(&pdev->dev, 255 indio_dev = devm_iio_device_alloc(&pdev->dev,
259 sizeof(struct prox_state)); 256 sizeof(struct prox_state));
@@ -272,20 +269,21 @@ static int hid_prox_probe(struct platform_device *pdev)
272 return ret; 269 return ret;
273 } 270 }
274 271
275 channels = kmemdup(prox_channels, sizeof(prox_channels), GFP_KERNEL); 272 indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels),
276 if (!channels) { 273 GFP_KERNEL);
274 if (!indio_dev->channels) {
277 dev_err(&pdev->dev, "failed to duplicate channels\n"); 275 dev_err(&pdev->dev, "failed to duplicate channels\n");
278 return -ENOMEM; 276 return -ENOMEM;
279 } 277 }
280 278
281 ret = prox_parse_report(pdev, hsdev, channels, 279 ret = prox_parse_report(pdev, hsdev,
280 (struct iio_chan_spec *)indio_dev->channels,
282 HID_USAGE_SENSOR_PROX, prox_state); 281 HID_USAGE_SENSOR_PROX, prox_state);
283 if (ret) { 282 if (ret) {
284 dev_err(&pdev->dev, "failed to setup attributes\n"); 283 dev_err(&pdev->dev, "failed to setup attributes\n");
285 goto error_free_dev_mem; 284 goto error_free_dev_mem;
286 } 285 }
287 286
288 indio_dev->channels = channels;
289 indio_dev->num_channels = 287 indio_dev->num_channels =
290 ARRAY_SIZE(prox_channels); 288 ARRAY_SIZE(prox_channels);
291 indio_dev->dev.parent = &pdev->dev; 289 indio_dev->dev.parent = &pdev->dev;
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 8ade473f99fe..2e56f812a644 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -369,6 +369,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
369 369
370 indio_dev->modes = INDIO_DIRECT_MODE; 370 indio_dev->modes = INDIO_DIRECT_MODE;
371 indio_dev->info = &magn_info; 371 indio_dev->info = &magn_info;
372 mutex_init(&mdata->tb.buf_lock);
372 373
373 st_sensors_power_enable(indio_dev); 374 st_sensors_power_enable(indio_dev);
374 375
diff --git a/drivers/iio/pressure/bmp280.c b/drivers/iio/pressure/bmp280.c
index 7c623e2bd633..a2602d8dd6d5 100644
--- a/drivers/iio/pressure/bmp280.c
+++ b/drivers/iio/pressure/bmp280.c
@@ -172,6 +172,7 @@ static s32 bmp280_compensate_temp(struct bmp280_data *data,
172 var2 = (((((adc_temp >> 4) - ((s32)le16_to_cpu(buf[T1]))) * 172 var2 = (((((adc_temp >> 4) - ((s32)le16_to_cpu(buf[T1]))) *
173 ((adc_temp >> 4) - ((s32)le16_to_cpu(buf[T1])))) >> 12) * 173 ((adc_temp >> 4) - ((s32)le16_to_cpu(buf[T1])))) >> 12) *
174 ((s32)(s16)le16_to_cpu(buf[T3]))) >> 14; 174 ((s32)(s16)le16_to_cpu(buf[T3]))) >> 14;
175 data->t_fine = var1 + var2;
175 176
176 return (data->t_fine * 5 + 128) >> 8; 177 return (data->t_fine * 5 + 128) >> 8;
177} 178}
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index 7bb8d4c1f7df..3cf0bd67d24c 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -47,8 +47,6 @@ struct press_state {
47static const struct iio_chan_spec press_channels[] = { 47static const struct iio_chan_spec press_channels[] = {
48 { 48 {
49 .type = IIO_PRESSURE, 49 .type = IIO_PRESSURE,
50 .modified = 1,
51 .channel2 = IIO_NO_MOD,
52 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 50 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
53 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | 51 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
54 BIT(IIO_CHAN_INFO_SCALE) | 52 BIT(IIO_CHAN_INFO_SCALE) |
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 97baf40d424b..e881fa6291e9 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -417,6 +417,7 @@ int st_press_common_probe(struct iio_dev *indio_dev)
417 417
418 indio_dev->modes = INDIO_DIRECT_MODE; 418 indio_dev->modes = INDIO_DIRECT_MODE;
419 indio_dev->info = &press_info; 419 indio_dev->info = &press_info;
420 mutex_init(&press_data->tb.buf_lock);
420 421
421 st_sensors_power_enable(indio_dev); 422 st_sensors_power_enable(indio_dev);
422 423
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index f80da50d84a5..38339d220d7f 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -472,13 +472,8 @@ int rdma_addr_find_dmac_by_grh(union ib_gid *sgid, union ib_gid *dgid, u8 *dmac,
472 } sgid_addr, dgid_addr; 472 } sgid_addr, dgid_addr;
473 473
474 474
475 ret = rdma_gid2ip(&sgid_addr._sockaddr, sgid); 475 rdma_gid2ip(&sgid_addr._sockaddr, sgid);
476 if (ret) 476 rdma_gid2ip(&dgid_addr._sockaddr, dgid);
477 return ret;
478
479 ret = rdma_gid2ip(&dgid_addr._sockaddr, dgid);
480 if (ret)
481 return ret;
482 477
483 memset(&dev_addr, 0, sizeof(dev_addr)); 478 memset(&dev_addr, 0, sizeof(dev_addr));
484 479
@@ -512,10 +507,8 @@ int rdma_addr_find_smac_by_sgid(union ib_gid *sgid, u8 *smac, u16 *vlan_id)
512 struct sockaddr_in6 _sockaddr_in6; 507 struct sockaddr_in6 _sockaddr_in6;
513 } gid_addr; 508 } gid_addr;
514 509
515 ret = rdma_gid2ip(&gid_addr._sockaddr, sgid); 510 rdma_gid2ip(&gid_addr._sockaddr, sgid);
516 511
517 if (ret)
518 return ret;
519 memset(&dev_addr, 0, sizeof(dev_addr)); 512 memset(&dev_addr, 0, sizeof(dev_addr));
520 ret = rdma_translate_ip(&gid_addr._sockaddr, &dev_addr, vlan_id); 513 ret = rdma_translate_ip(&gid_addr._sockaddr, &dev_addr, vlan_id);
521 if (ret) 514 if (ret)
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index e28a494e2a3a..0271608a51c4 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -437,39 +437,38 @@ static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id)
437 return cm_id_priv; 437 return cm_id_priv;
438} 438}
439 439
440static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask) 440static void cm_mask_copy(u32 *dst, const u32 *src, const u32 *mask)
441{ 441{
442 int i; 442 int i;
443 443
444 for (i = 0; i < IB_CM_COMPARE_SIZE / sizeof(unsigned long); i++) 444 for (i = 0; i < IB_CM_COMPARE_SIZE; i++)
445 ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & 445 dst[i] = src[i] & mask[i];
446 ((unsigned long *) mask)[i];
447} 446}
448 447
449static int cm_compare_data(struct ib_cm_compare_data *src_data, 448static int cm_compare_data(struct ib_cm_compare_data *src_data,
450 struct ib_cm_compare_data *dst_data) 449 struct ib_cm_compare_data *dst_data)
451{ 450{
452 u8 src[IB_CM_COMPARE_SIZE]; 451 u32 src[IB_CM_COMPARE_SIZE];
453 u8 dst[IB_CM_COMPARE_SIZE]; 452 u32 dst[IB_CM_COMPARE_SIZE];
454 453
455 if (!src_data || !dst_data) 454 if (!src_data || !dst_data)
456 return 0; 455 return 0;
457 456
458 cm_mask_copy(src, src_data->data, dst_data->mask); 457 cm_mask_copy(src, src_data->data, dst_data->mask);
459 cm_mask_copy(dst, dst_data->data, src_data->mask); 458 cm_mask_copy(dst, dst_data->data, src_data->mask);
460 return memcmp(src, dst, IB_CM_COMPARE_SIZE); 459 return memcmp(src, dst, sizeof(src));
461} 460}
462 461
463static int cm_compare_private_data(u8 *private_data, 462static int cm_compare_private_data(u32 *private_data,
464 struct ib_cm_compare_data *dst_data) 463 struct ib_cm_compare_data *dst_data)
465{ 464{
466 u8 src[IB_CM_COMPARE_SIZE]; 465 u32 src[IB_CM_COMPARE_SIZE];
467 466
468 if (!dst_data) 467 if (!dst_data)
469 return 0; 468 return 0;
470 469
471 cm_mask_copy(src, private_data, dst_data->mask); 470 cm_mask_copy(src, private_data, dst_data->mask);
472 return memcmp(src, dst_data->data, IB_CM_COMPARE_SIZE); 471 return memcmp(src, dst_data->data, sizeof(src));
473} 472}
474 473
475/* 474/*
@@ -538,7 +537,7 @@ static struct cm_id_private * cm_insert_listen(struct cm_id_private *cm_id_priv)
538 537
539static struct cm_id_private * cm_find_listen(struct ib_device *device, 538static struct cm_id_private * cm_find_listen(struct ib_device *device,
540 __be64 service_id, 539 __be64 service_id,
541 u8 *private_data) 540 u32 *private_data)
542{ 541{
543 struct rb_node *node = cm.listen_service_table.rb_node; 542 struct rb_node *node = cm.listen_service_table.rb_node;
544 struct cm_id_private *cm_id_priv; 543 struct cm_id_private *cm_id_priv;
@@ -862,6 +861,7 @@ retest:
862 cm_reject_sidr_req(cm_id_priv, IB_SIDR_REJECT); 861 cm_reject_sidr_req(cm_id_priv, IB_SIDR_REJECT);
863 break; 862 break;
864 case IB_CM_REQ_SENT: 863 case IB_CM_REQ_SENT:
864 case IB_CM_MRA_REQ_RCVD:
865 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 865 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
866 spin_unlock_irq(&cm_id_priv->lock); 866 spin_unlock_irq(&cm_id_priv->lock);
867 ib_send_cm_rej(cm_id, IB_CM_REJ_TIMEOUT, 867 ib_send_cm_rej(cm_id, IB_CM_REJ_TIMEOUT,
@@ -880,7 +880,6 @@ retest:
880 NULL, 0, NULL, 0); 880 NULL, 0, NULL, 0);
881 } 881 }
882 break; 882 break;
883 case IB_CM_MRA_REQ_RCVD:
884 case IB_CM_REP_SENT: 883 case IB_CM_REP_SENT:
885 case IB_CM_MRA_REP_RCVD: 884 case IB_CM_MRA_REP_RCVD:
886 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg); 885 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
@@ -953,7 +952,7 @@ int ib_cm_listen(struct ib_cm_id *cm_id, __be64 service_id, __be64 service_mask,
953 cm_mask_copy(cm_id_priv->compare_data->data, 952 cm_mask_copy(cm_id_priv->compare_data->data,
954 compare_data->data, compare_data->mask); 953 compare_data->data, compare_data->mask);
955 memcpy(cm_id_priv->compare_data->mask, compare_data->mask, 954 memcpy(cm_id_priv->compare_data->mask, compare_data->mask,
956 IB_CM_COMPARE_SIZE); 955 sizeof(compare_data->mask));
957 } 956 }
958 957
959 cm_id->state = IB_CM_LISTEN; 958 cm_id->state = IB_CM_LISTEN;
diff --git a/drivers/infiniband/core/cm_msgs.h b/drivers/infiniband/core/cm_msgs.h
index be068f47e47e..8b76f0ef965e 100644
--- a/drivers/infiniband/core/cm_msgs.h
+++ b/drivers/infiniband/core/cm_msgs.h
@@ -103,7 +103,7 @@ struct cm_req_msg {
103 /* local ACK timeout:5, rsvd:3 */ 103 /* local ACK timeout:5, rsvd:3 */
104 u8 alt_offset139; 104 u8 alt_offset139;
105 105
106 u8 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE]; 106 u32 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE / sizeof(u32)];
107 107
108} __attribute__ ((packed)); 108} __attribute__ ((packed));
109 109
@@ -801,7 +801,7 @@ struct cm_sidr_req_msg {
801 __be16 rsvd; 801 __be16 rsvd;
802 __be64 service_id; 802 __be64 service_id;
803 803
804 u8 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE]; 804 u32 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE / sizeof(u32)];
805} __attribute__ ((packed)); 805} __attribute__ ((packed));
806 806
807struct cm_sidr_rep_msg { 807struct cm_sidr_rep_msg {
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index d570030d899c..38ffe0981503 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -845,33 +845,49 @@ static void cma_save_ib_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id
845 listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; 845 listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr;
846 ib = (struct sockaddr_ib *) &id->route.addr.src_addr; 846 ib = (struct sockaddr_ib *) &id->route.addr.src_addr;
847 ib->sib_family = listen_ib->sib_family; 847 ib->sib_family = listen_ib->sib_family;
848 ib->sib_pkey = path->pkey; 848 if (path) {
849 ib->sib_flowinfo = path->flow_label; 849 ib->sib_pkey = path->pkey;
850 memcpy(&ib->sib_addr, &path->sgid, 16); 850 ib->sib_flowinfo = path->flow_label;
851 memcpy(&ib->sib_addr, &path->sgid, 16);
852 } else {
853 ib->sib_pkey = listen_ib->sib_pkey;
854 ib->sib_flowinfo = listen_ib->sib_flowinfo;
855 ib->sib_addr = listen_ib->sib_addr;
856 }
851 ib->sib_sid = listen_ib->sib_sid; 857 ib->sib_sid = listen_ib->sib_sid;
852 ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); 858 ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL);
853 ib->sib_scope_id = listen_ib->sib_scope_id; 859 ib->sib_scope_id = listen_ib->sib_scope_id;
854 860
855 ib = (struct sockaddr_ib *) &id->route.addr.dst_addr; 861 if (path) {
856 ib->sib_family = listen_ib->sib_family; 862 ib = (struct sockaddr_ib *) &id->route.addr.dst_addr;
857 ib->sib_pkey = path->pkey; 863 ib->sib_family = listen_ib->sib_family;
858 ib->sib_flowinfo = path->flow_label; 864 ib->sib_pkey = path->pkey;
859 memcpy(&ib->sib_addr, &path->dgid, 16); 865 ib->sib_flowinfo = path->flow_label;
866 memcpy(&ib->sib_addr, &path->dgid, 16);
867 }
868}
869
870static __be16 ss_get_port(const struct sockaddr_storage *ss)
871{
872 if (ss->ss_family == AF_INET)
873 return ((struct sockaddr_in *)ss)->sin_port;
874 else if (ss->ss_family == AF_INET6)
875 return ((struct sockaddr_in6 *)ss)->sin6_port;
876 BUG();
860} 877}
861 878
862static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, 879static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id,
863 struct cma_hdr *hdr) 880 struct cma_hdr *hdr)
864{ 881{
865 struct sockaddr_in *listen4, *ip4; 882 struct sockaddr_in *ip4;
866 883
867 listen4 = (struct sockaddr_in *) &listen_id->route.addr.src_addr;
868 ip4 = (struct sockaddr_in *) &id->route.addr.src_addr; 884 ip4 = (struct sockaddr_in *) &id->route.addr.src_addr;
869 ip4->sin_family = listen4->sin_family; 885 ip4->sin_family = AF_INET;
870 ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr; 886 ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr;
871 ip4->sin_port = listen4->sin_port; 887 ip4->sin_port = ss_get_port(&listen_id->route.addr.src_addr);
872 888
873 ip4 = (struct sockaddr_in *) &id->route.addr.dst_addr; 889 ip4 = (struct sockaddr_in *) &id->route.addr.dst_addr;
874 ip4->sin_family = listen4->sin_family; 890 ip4->sin_family = AF_INET;
875 ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr; 891 ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr;
876 ip4->sin_port = hdr->port; 892 ip4->sin_port = hdr->port;
877} 893}
@@ -879,16 +895,15 @@ static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_i
879static void cma_save_ip6_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, 895static void cma_save_ip6_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id,
880 struct cma_hdr *hdr) 896 struct cma_hdr *hdr)
881{ 897{
882 struct sockaddr_in6 *listen6, *ip6; 898 struct sockaddr_in6 *ip6;
883 899
884 listen6 = (struct sockaddr_in6 *) &listen_id->route.addr.src_addr;
885 ip6 = (struct sockaddr_in6 *) &id->route.addr.src_addr; 900 ip6 = (struct sockaddr_in6 *) &id->route.addr.src_addr;
886 ip6->sin6_family = listen6->sin6_family; 901 ip6->sin6_family = AF_INET6;
887 ip6->sin6_addr = hdr->dst_addr.ip6; 902 ip6->sin6_addr = hdr->dst_addr.ip6;
888 ip6->sin6_port = listen6->sin6_port; 903 ip6->sin6_port = ss_get_port(&listen_id->route.addr.src_addr);
889 904
890 ip6 = (struct sockaddr_in6 *) &id->route.addr.dst_addr; 905 ip6 = (struct sockaddr_in6 *) &id->route.addr.dst_addr;
891 ip6->sin6_family = listen6->sin6_family; 906 ip6->sin6_family = AF_INET6;
892 ip6->sin6_addr = hdr->src_addr.ip6; 907 ip6->sin6_addr = hdr->src_addr.ip6;
893 ip6->sin6_port = hdr->port; 908 ip6->sin6_port = hdr->port;
894} 909}
@@ -898,9 +913,11 @@ static int cma_save_net_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id
898{ 913{
899 struct cma_hdr *hdr; 914 struct cma_hdr *hdr;
900 915
901 if ((listen_id->route.addr.src_addr.ss_family == AF_IB) && 916 if (listen_id->route.addr.src_addr.ss_family == AF_IB) {
902 (ib_event->event == IB_CM_REQ_RECEIVED)) { 917 if (ib_event->event == IB_CM_REQ_RECEIVED)
903 cma_save_ib_info(id, listen_id, ib_event->param.req_rcvd.primary_path); 918 cma_save_ib_info(id, listen_id, ib_event->param.req_rcvd.primary_path);
919 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED)
920 cma_save_ib_info(id, listen_id, NULL);
904 return 0; 921 return 0;
905 } 922 }
906 923
diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c
index b85ddbc979e0..e6ffa2e66c1a 100644
--- a/drivers/infiniband/core/iwpm_msg.c
+++ b/drivers/infiniband/core/iwpm_msg.c
@@ -33,7 +33,7 @@
33 33
34#include "iwpm_util.h" 34#include "iwpm_util.h"
35 35
36static const char iwpm_ulib_name[] = "iWarpPortMapperUser"; 36static const char iwpm_ulib_name[IWPM_ULIBNAME_SIZE] = "iWarpPortMapperUser";
37static int iwpm_ulib_version = 3; 37static int iwpm_ulib_version = 3;
38static int iwpm_user_pid = IWPM_PID_UNDEFINED; 38static int iwpm_user_pid = IWPM_PID_UNDEFINED;
39static atomic_t echo_nlmsg_seq; 39static atomic_t echo_nlmsg_seq;
@@ -468,7 +468,8 @@ add_mapping_response_exit:
468} 468}
469EXPORT_SYMBOL(iwpm_add_mapping_cb); 469EXPORT_SYMBOL(iwpm_add_mapping_cb);
470 470
471/* netlink attribute policy for the response to add and query mapping request */ 471/* netlink attribute policy for the response to add and query mapping request
472 * and response with remote address info */
472static const struct nla_policy resp_query_policy[IWPM_NLA_RQUERY_MAPPING_MAX] = { 473static const struct nla_policy resp_query_policy[IWPM_NLA_RQUERY_MAPPING_MAX] = {
473 [IWPM_NLA_QUERY_MAPPING_SEQ] = { .type = NLA_U32 }, 474 [IWPM_NLA_QUERY_MAPPING_SEQ] = { .type = NLA_U32 },
474 [IWPM_NLA_QUERY_LOCAL_ADDR] = { .len = sizeof(struct sockaddr_storage) }, 475 [IWPM_NLA_QUERY_LOCAL_ADDR] = { .len = sizeof(struct sockaddr_storage) },
@@ -559,6 +560,76 @@ query_mapping_response_exit:
559} 560}
560EXPORT_SYMBOL(iwpm_add_and_query_mapping_cb); 561EXPORT_SYMBOL(iwpm_add_and_query_mapping_cb);
561 562
563/*
564 * iwpm_remote_info_cb - Process a port mapper message, containing
565 * the remote connecting peer address info
566 */
567int iwpm_remote_info_cb(struct sk_buff *skb, struct netlink_callback *cb)
568{
569 struct nlattr *nltb[IWPM_NLA_RQUERY_MAPPING_MAX];
570 struct sockaddr_storage *local_sockaddr, *remote_sockaddr;
571 struct sockaddr_storage *mapped_loc_sockaddr, *mapped_rem_sockaddr;
572 struct iwpm_remote_info *rem_info;
573 const char *msg_type;
574 u8 nl_client;
575 int ret = -EINVAL;
576
577 msg_type = "Remote Mapping info";
578 if (iwpm_parse_nlmsg(cb, IWPM_NLA_RQUERY_MAPPING_MAX,
579 resp_query_policy, nltb, msg_type))
580 return ret;
581
582 nl_client = RDMA_NL_GET_CLIENT(cb->nlh->nlmsg_type);
583 if (!iwpm_valid_client(nl_client)) {
584 pr_info("%s: Invalid port mapper client = %d\n",
585 __func__, nl_client);
586 return ret;
587 }
588 atomic_set(&echo_nlmsg_seq, cb->nlh->nlmsg_seq);
589
590 local_sockaddr = (struct sockaddr_storage *)
591 nla_data(nltb[IWPM_NLA_QUERY_LOCAL_ADDR]);
592 remote_sockaddr = (struct sockaddr_storage *)
593 nla_data(nltb[IWPM_NLA_QUERY_REMOTE_ADDR]);
594 mapped_loc_sockaddr = (struct sockaddr_storage *)
595 nla_data(nltb[IWPM_NLA_RQUERY_MAPPED_LOC_ADDR]);
596 mapped_rem_sockaddr = (struct sockaddr_storage *)
597 nla_data(nltb[IWPM_NLA_RQUERY_MAPPED_REM_ADDR]);
598
599 if (mapped_loc_sockaddr->ss_family != local_sockaddr->ss_family ||
600 mapped_rem_sockaddr->ss_family != remote_sockaddr->ss_family) {
601 pr_info("%s: Sockaddr family doesn't match the requested one\n",
602 __func__);
603 return ret;
604 }
605 rem_info = kzalloc(sizeof(struct iwpm_remote_info), GFP_ATOMIC);
606 if (!rem_info) {
607 pr_err("%s: Unable to allocate a remote info\n", __func__);
608 ret = -ENOMEM;
609 return ret;
610 }
611 memcpy(&rem_info->mapped_loc_sockaddr, mapped_loc_sockaddr,
612 sizeof(struct sockaddr_storage));
613 memcpy(&rem_info->remote_sockaddr, remote_sockaddr,
614 sizeof(struct sockaddr_storage));
615 memcpy(&rem_info->mapped_rem_sockaddr, mapped_rem_sockaddr,
616 sizeof(struct sockaddr_storage));
617 rem_info->nl_client = nl_client;
618
619 iwpm_add_remote_info(rem_info);
620
621 iwpm_print_sockaddr(local_sockaddr,
622 "remote_info: Local sockaddr:");
623 iwpm_print_sockaddr(mapped_loc_sockaddr,
624 "remote_info: Mapped local sockaddr:");
625 iwpm_print_sockaddr(remote_sockaddr,
626 "remote_info: Remote sockaddr:");
627 iwpm_print_sockaddr(mapped_rem_sockaddr,
628 "remote_info: Mapped remote sockaddr:");
629 return ret;
630}
631EXPORT_SYMBOL(iwpm_remote_info_cb);
632
562/* netlink attribute policy for the received request for mapping info */ 633/* netlink attribute policy for the received request for mapping info */
563static const struct nla_policy resp_mapinfo_policy[IWPM_NLA_MAPINFO_REQ_MAX] = { 634static const struct nla_policy resp_mapinfo_policy[IWPM_NLA_MAPINFO_REQ_MAX] = {
564 [IWPM_NLA_MAPINFO_ULIB_NAME] = { .type = NLA_STRING, 635 [IWPM_NLA_MAPINFO_ULIB_NAME] = { .type = NLA_STRING,
diff --git a/drivers/infiniband/core/iwpm_util.c b/drivers/infiniband/core/iwpm_util.c
index 69e9f84c1605..a626795bf9c7 100644
--- a/drivers/infiniband/core/iwpm_util.c
+++ b/drivers/infiniband/core/iwpm_util.c
@@ -33,8 +33,10 @@
33 33
34#include "iwpm_util.h" 34#include "iwpm_util.h"
35 35
36#define IWPM_HASH_BUCKET_SIZE 512 36#define IWPM_MAPINFO_HASH_SIZE 512
37#define IWPM_HASH_BUCKET_MASK (IWPM_HASH_BUCKET_SIZE - 1) 37#define IWPM_MAPINFO_HASH_MASK (IWPM_MAPINFO_HASH_SIZE - 1)
38#define IWPM_REMINFO_HASH_SIZE 64
39#define IWPM_REMINFO_HASH_MASK (IWPM_REMINFO_HASH_SIZE - 1)
38 40
39static LIST_HEAD(iwpm_nlmsg_req_list); 41static LIST_HEAD(iwpm_nlmsg_req_list);
40static DEFINE_SPINLOCK(iwpm_nlmsg_req_lock); 42static DEFINE_SPINLOCK(iwpm_nlmsg_req_lock);
@@ -42,31 +44,49 @@ static DEFINE_SPINLOCK(iwpm_nlmsg_req_lock);
42static struct hlist_head *iwpm_hash_bucket; 44static struct hlist_head *iwpm_hash_bucket;
43static DEFINE_SPINLOCK(iwpm_mapinfo_lock); 45static DEFINE_SPINLOCK(iwpm_mapinfo_lock);
44 46
47static struct hlist_head *iwpm_reminfo_bucket;
48static DEFINE_SPINLOCK(iwpm_reminfo_lock);
49
45static DEFINE_MUTEX(iwpm_admin_lock); 50static DEFINE_MUTEX(iwpm_admin_lock);
46static struct iwpm_admin_data iwpm_admin; 51static struct iwpm_admin_data iwpm_admin;
47 52
48int iwpm_init(u8 nl_client) 53int iwpm_init(u8 nl_client)
49{ 54{
55 int ret = 0;
50 if (iwpm_valid_client(nl_client)) 56 if (iwpm_valid_client(nl_client))
51 return -EINVAL; 57 return -EINVAL;
52 mutex_lock(&iwpm_admin_lock); 58 mutex_lock(&iwpm_admin_lock);
53 if (atomic_read(&iwpm_admin.refcount) == 0) { 59 if (atomic_read(&iwpm_admin.refcount) == 0) {
54 iwpm_hash_bucket = kzalloc(IWPM_HASH_BUCKET_SIZE * 60 iwpm_hash_bucket = kzalloc(IWPM_MAPINFO_HASH_SIZE *
55 sizeof(struct hlist_head), GFP_KERNEL); 61 sizeof(struct hlist_head), GFP_KERNEL);
56 if (!iwpm_hash_bucket) { 62 if (!iwpm_hash_bucket) {
57 mutex_unlock(&iwpm_admin_lock); 63 ret = -ENOMEM;
58 pr_err("%s Unable to create mapinfo hash table\n", __func__); 64 pr_err("%s Unable to create mapinfo hash table\n", __func__);
59 return -ENOMEM; 65 goto init_exit;
66 }
67 iwpm_reminfo_bucket = kzalloc(IWPM_REMINFO_HASH_SIZE *
68 sizeof(struct hlist_head), GFP_KERNEL);
69 if (!iwpm_reminfo_bucket) {
70 kfree(iwpm_hash_bucket);
71 ret = -ENOMEM;
72 pr_err("%s Unable to create reminfo hash table\n", __func__);
73 goto init_exit;
60 } 74 }
61 } 75 }
62 atomic_inc(&iwpm_admin.refcount); 76 atomic_inc(&iwpm_admin.refcount);
77init_exit:
63 mutex_unlock(&iwpm_admin_lock); 78 mutex_unlock(&iwpm_admin_lock);
64 iwpm_set_valid(nl_client, 1); 79 if (!ret) {
65 return 0; 80 iwpm_set_valid(nl_client, 1);
81 pr_debug("%s: Mapinfo and reminfo tables are created\n",
82 __func__);
83 }
84 return ret;
66} 85}
67EXPORT_SYMBOL(iwpm_init); 86EXPORT_SYMBOL(iwpm_init);
68 87
69static void free_hash_bucket(void); 88static void free_hash_bucket(void);
89static void free_reminfo_bucket(void);
70 90
71int iwpm_exit(u8 nl_client) 91int iwpm_exit(u8 nl_client)
72{ 92{
@@ -81,7 +101,8 @@ int iwpm_exit(u8 nl_client)
81 } 101 }
82 if (atomic_dec_and_test(&iwpm_admin.refcount)) { 102 if (atomic_dec_and_test(&iwpm_admin.refcount)) {
83 free_hash_bucket(); 103 free_hash_bucket();
84 pr_debug("%s: Mapinfo hash table is destroyed\n", __func__); 104 free_reminfo_bucket();
105 pr_debug("%s: Resources are destroyed\n", __func__);
85 } 106 }
86 mutex_unlock(&iwpm_admin_lock); 107 mutex_unlock(&iwpm_admin_lock);
87 iwpm_set_valid(nl_client, 0); 108 iwpm_set_valid(nl_client, 0);
@@ -89,7 +110,7 @@ int iwpm_exit(u8 nl_client)
89} 110}
90EXPORT_SYMBOL(iwpm_exit); 111EXPORT_SYMBOL(iwpm_exit);
91 112
92static struct hlist_head *get_hash_bucket_head(struct sockaddr_storage *, 113static struct hlist_head *get_mapinfo_hash_bucket(struct sockaddr_storage *,
93 struct sockaddr_storage *); 114 struct sockaddr_storage *);
94 115
95int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr, 116int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr,
@@ -99,9 +120,10 @@ int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr,
99 struct hlist_head *hash_bucket_head; 120 struct hlist_head *hash_bucket_head;
100 struct iwpm_mapping_info *map_info; 121 struct iwpm_mapping_info *map_info;
101 unsigned long flags; 122 unsigned long flags;
123 int ret = -EINVAL;
102 124
103 if (!iwpm_valid_client(nl_client)) 125 if (!iwpm_valid_client(nl_client))
104 return -EINVAL; 126 return ret;
105 map_info = kzalloc(sizeof(struct iwpm_mapping_info), GFP_KERNEL); 127 map_info = kzalloc(sizeof(struct iwpm_mapping_info), GFP_KERNEL);
106 if (!map_info) { 128 if (!map_info) {
107 pr_err("%s: Unable to allocate a mapping info\n", __func__); 129 pr_err("%s: Unable to allocate a mapping info\n", __func__);
@@ -115,13 +137,16 @@ int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr,
115 137
116 spin_lock_irqsave(&iwpm_mapinfo_lock, flags); 138 spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
117 if (iwpm_hash_bucket) { 139 if (iwpm_hash_bucket) {
118 hash_bucket_head = get_hash_bucket_head( 140 hash_bucket_head = get_mapinfo_hash_bucket(
119 &map_info->local_sockaddr, 141 &map_info->local_sockaddr,
120 &map_info->mapped_sockaddr); 142 &map_info->mapped_sockaddr);
121 hlist_add_head(&map_info->hlist_node, hash_bucket_head); 143 if (hash_bucket_head) {
144 hlist_add_head(&map_info->hlist_node, hash_bucket_head);
145 ret = 0;
146 }
122 } 147 }
123 spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags); 148 spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
124 return 0; 149 return ret;
125} 150}
126EXPORT_SYMBOL(iwpm_create_mapinfo); 151EXPORT_SYMBOL(iwpm_create_mapinfo);
127 152
@@ -136,9 +161,12 @@ int iwpm_remove_mapinfo(struct sockaddr_storage *local_sockaddr,
136 161
137 spin_lock_irqsave(&iwpm_mapinfo_lock, flags); 162 spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
138 if (iwpm_hash_bucket) { 163 if (iwpm_hash_bucket) {
139 hash_bucket_head = get_hash_bucket_head( 164 hash_bucket_head = get_mapinfo_hash_bucket(
140 local_sockaddr, 165 local_sockaddr,
141 mapped_local_addr); 166 mapped_local_addr);
167 if (!hash_bucket_head)
168 goto remove_mapinfo_exit;
169
142 hlist_for_each_entry_safe(map_info, tmp_hlist_node, 170 hlist_for_each_entry_safe(map_info, tmp_hlist_node,
143 hash_bucket_head, hlist_node) { 171 hash_bucket_head, hlist_node) {
144 172
@@ -152,6 +180,7 @@ int iwpm_remove_mapinfo(struct sockaddr_storage *local_sockaddr,
152 } 180 }
153 } 181 }
154 } 182 }
183remove_mapinfo_exit:
155 spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags); 184 spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
156 return ret; 185 return ret;
157} 186}
@@ -166,7 +195,7 @@ static void free_hash_bucket(void)
166 195
167 /* remove all the mapinfo data from the list */ 196 /* remove all the mapinfo data from the list */
168 spin_lock_irqsave(&iwpm_mapinfo_lock, flags); 197 spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
169 for (i = 0; i < IWPM_HASH_BUCKET_SIZE; i++) { 198 for (i = 0; i < IWPM_MAPINFO_HASH_SIZE; i++) {
170 hlist_for_each_entry_safe(map_info, tmp_hlist_node, 199 hlist_for_each_entry_safe(map_info, tmp_hlist_node,
171 &iwpm_hash_bucket[i], hlist_node) { 200 &iwpm_hash_bucket[i], hlist_node) {
172 201
@@ -180,6 +209,96 @@ static void free_hash_bucket(void)
180 spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags); 209 spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
181} 210}
182 211
212static void free_reminfo_bucket(void)
213{
214 struct hlist_node *tmp_hlist_node;
215 struct iwpm_remote_info *rem_info;
216 unsigned long flags;
217 int i;
218
219 /* remove all the remote info from the list */
220 spin_lock_irqsave(&iwpm_reminfo_lock, flags);
221 for (i = 0; i < IWPM_REMINFO_HASH_SIZE; i++) {
222 hlist_for_each_entry_safe(rem_info, tmp_hlist_node,
223 &iwpm_reminfo_bucket[i], hlist_node) {
224
225 hlist_del_init(&rem_info->hlist_node);
226 kfree(rem_info);
227 }
228 }
229 /* free the hash list */
230 kfree(iwpm_reminfo_bucket);
231 iwpm_reminfo_bucket = NULL;
232 spin_unlock_irqrestore(&iwpm_reminfo_lock, flags);
233}
234
235static struct hlist_head *get_reminfo_hash_bucket(struct sockaddr_storage *,
236 struct sockaddr_storage *);
237
238void iwpm_add_remote_info(struct iwpm_remote_info *rem_info)
239{
240 struct hlist_head *hash_bucket_head;
241 unsigned long flags;
242
243 spin_lock_irqsave(&iwpm_reminfo_lock, flags);
244 if (iwpm_reminfo_bucket) {
245 hash_bucket_head = get_reminfo_hash_bucket(
246 &rem_info->mapped_loc_sockaddr,
247 &rem_info->mapped_rem_sockaddr);
248 if (hash_bucket_head)
249 hlist_add_head(&rem_info->hlist_node, hash_bucket_head);
250 }
251 spin_unlock_irqrestore(&iwpm_reminfo_lock, flags);
252}
253
254int iwpm_get_remote_info(struct sockaddr_storage *mapped_loc_addr,
255 struct sockaddr_storage *mapped_rem_addr,
256 struct sockaddr_storage *remote_addr,
257 u8 nl_client)
258{
259 struct hlist_node *tmp_hlist_node;
260 struct hlist_head *hash_bucket_head;
261 struct iwpm_remote_info *rem_info = NULL;
262 unsigned long flags;
263 int ret = -EINVAL;
264
265 if (!iwpm_valid_client(nl_client)) {
266 pr_info("%s: Invalid client = %d\n", __func__, nl_client);
267 return ret;
268 }
269 spin_lock_irqsave(&iwpm_reminfo_lock, flags);
270 if (iwpm_reminfo_bucket) {
271 hash_bucket_head = get_reminfo_hash_bucket(
272 mapped_loc_addr,
273 mapped_rem_addr);
274 if (!hash_bucket_head)
275 goto get_remote_info_exit;
276 hlist_for_each_entry_safe(rem_info, tmp_hlist_node,
277 hash_bucket_head, hlist_node) {
278
279 if (!iwpm_compare_sockaddr(&rem_info->mapped_loc_sockaddr,
280 mapped_loc_addr) &&
281 !iwpm_compare_sockaddr(&rem_info->mapped_rem_sockaddr,
282 mapped_rem_addr)) {
283
284 memcpy(remote_addr, &rem_info->remote_sockaddr,
285 sizeof(struct sockaddr_storage));
286 iwpm_print_sockaddr(remote_addr,
287 "get_remote_info: Remote sockaddr:");
288
289 hlist_del_init(&rem_info->hlist_node);
290 kfree(rem_info);
291 ret = 0;
292 break;
293 }
294 }
295 }
296get_remote_info_exit:
297 spin_unlock_irqrestore(&iwpm_reminfo_lock, flags);
298 return ret;
299}
300EXPORT_SYMBOL(iwpm_get_remote_info);
301
183struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq, 302struct iwpm_nlmsg_request *iwpm_get_nlmsg_request(__u32 nlmsg_seq,
184 u8 nl_client, gfp_t gfp) 303 u8 nl_client, gfp_t gfp)
185{ 304{
@@ -409,31 +528,54 @@ static u32 iwpm_ipv4_jhash(struct sockaddr_in *ipv4_sockaddr)
409 return hash; 528 return hash;
410} 529}
411 530
412static struct hlist_head *get_hash_bucket_head(struct sockaddr_storage 531static int get_hash_bucket(struct sockaddr_storage *a_sockaddr,
413 *local_sockaddr, 532 struct sockaddr_storage *b_sockaddr, u32 *hash)
414 struct sockaddr_storage
415 *mapped_sockaddr)
416{ 533{
417 u32 local_hash, mapped_hash, hash; 534 u32 a_hash, b_hash;
418 535
419 if (local_sockaddr->ss_family == AF_INET) { 536 if (a_sockaddr->ss_family == AF_INET) {
420 local_hash = iwpm_ipv4_jhash((struct sockaddr_in *) local_sockaddr); 537 a_hash = iwpm_ipv4_jhash((struct sockaddr_in *) a_sockaddr);
421 mapped_hash = iwpm_ipv4_jhash((struct sockaddr_in *) mapped_sockaddr); 538 b_hash = iwpm_ipv4_jhash((struct sockaddr_in *) b_sockaddr);
422 539
423 } else if (local_sockaddr->ss_family == AF_INET6) { 540 } else if (a_sockaddr->ss_family == AF_INET6) {
424 local_hash = iwpm_ipv6_jhash((struct sockaddr_in6 *) local_sockaddr); 541 a_hash = iwpm_ipv6_jhash((struct sockaddr_in6 *) a_sockaddr);
425 mapped_hash = iwpm_ipv6_jhash((struct sockaddr_in6 *) mapped_sockaddr); 542 b_hash = iwpm_ipv6_jhash((struct sockaddr_in6 *) b_sockaddr);
426 } else { 543 } else {
427 pr_err("%s: Invalid sockaddr family\n", __func__); 544 pr_err("%s: Invalid sockaddr family\n", __func__);
428 return NULL; 545 return -EINVAL;
429 } 546 }
430 547
431 if (local_hash == mapped_hash) /* if port mapper isn't available */ 548 if (a_hash == b_hash) /* if port mapper isn't available */
432 hash = local_hash; 549 *hash = a_hash;
433 else 550 else
434 hash = jhash_2words(local_hash, mapped_hash, 0); 551 *hash = jhash_2words(a_hash, b_hash, 0);
552 return 0;
553}
554
555static struct hlist_head *get_mapinfo_hash_bucket(struct sockaddr_storage
556 *local_sockaddr, struct sockaddr_storage
557 *mapped_sockaddr)
558{
559 u32 hash;
560 int ret;
435 561
436 return &iwpm_hash_bucket[hash & IWPM_HASH_BUCKET_MASK]; 562 ret = get_hash_bucket(local_sockaddr, mapped_sockaddr, &hash);
563 if (ret)
564 return NULL;
565 return &iwpm_hash_bucket[hash & IWPM_MAPINFO_HASH_MASK];
566}
567
568static struct hlist_head *get_reminfo_hash_bucket(struct sockaddr_storage
569 *mapped_loc_sockaddr, struct sockaddr_storage
570 *mapped_rem_sockaddr)
571{
572 u32 hash;
573 int ret;
574
575 ret = get_hash_bucket(mapped_loc_sockaddr, mapped_rem_sockaddr, &hash);
576 if (ret)
577 return NULL;
578 return &iwpm_reminfo_bucket[hash & IWPM_REMINFO_HASH_MASK];
437} 579}
438 580
439static int send_mapinfo_num(u32 mapping_num, u8 nl_client, int iwpm_pid) 581static int send_mapinfo_num(u32 mapping_num, u8 nl_client, int iwpm_pid)
@@ -512,7 +654,7 @@ int iwpm_send_mapinfo(u8 nl_client, int iwpm_pid)
512 } 654 }
513 skb_num++; 655 skb_num++;
514 spin_lock_irqsave(&iwpm_mapinfo_lock, flags); 656 spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
515 for (i = 0; i < IWPM_HASH_BUCKET_SIZE; i++) { 657 for (i = 0; i < IWPM_MAPINFO_HASH_SIZE; i++) {
516 hlist_for_each_entry(map_info, &iwpm_hash_bucket[i], 658 hlist_for_each_entry(map_info, &iwpm_hash_bucket[i],
517 hlist_node) { 659 hlist_node) {
518 if (map_info->nl_client != nl_client) 660 if (map_info->nl_client != nl_client)
@@ -595,7 +737,7 @@ int iwpm_mapinfo_available(void)
595 737
596 spin_lock_irqsave(&iwpm_mapinfo_lock, flags); 738 spin_lock_irqsave(&iwpm_mapinfo_lock, flags);
597 if (iwpm_hash_bucket) { 739 if (iwpm_hash_bucket) {
598 for (i = 0; i < IWPM_HASH_BUCKET_SIZE; i++) { 740 for (i = 0; i < IWPM_MAPINFO_HASH_SIZE; i++) {
599 if (!hlist_empty(&iwpm_hash_bucket[i])) { 741 if (!hlist_empty(&iwpm_hash_bucket[i])) {
600 full_bucket = 1; 742 full_bucket = 1;
601 break; 743 break;
diff --git a/drivers/infiniband/core/iwpm_util.h b/drivers/infiniband/core/iwpm_util.h
index 9777c869a140..ee2d9ff095be 100644
--- a/drivers/infiniband/core/iwpm_util.h
+++ b/drivers/infiniband/core/iwpm_util.h
@@ -76,6 +76,14 @@ struct iwpm_mapping_info {
76 u8 nl_client; 76 u8 nl_client;
77}; 77};
78 78
79struct iwpm_remote_info {
80 struct hlist_node hlist_node;
81 struct sockaddr_storage remote_sockaddr;
82 struct sockaddr_storage mapped_loc_sockaddr;
83 struct sockaddr_storage mapped_rem_sockaddr;
84 u8 nl_client;
85};
86
79struct iwpm_admin_data { 87struct iwpm_admin_data {
80 atomic_t refcount; 88 atomic_t refcount;
81 atomic_t nlmsg_seq; 89 atomic_t nlmsg_seq;
@@ -128,6 +136,13 @@ int iwpm_wait_complete_req(struct iwpm_nlmsg_request *nlmsg_request);
128int iwpm_get_nlmsg_seq(void); 136int iwpm_get_nlmsg_seq(void);
129 137
130/** 138/**
139 * iwpm_add_reminfo - Add remote address info of the connecting peer
140 * to the remote info hash table
141 * @reminfo: The remote info to be added
142 */
143void iwpm_add_remote_info(struct iwpm_remote_info *reminfo);
144
145/**
131 * iwpm_valid_client - Check if the port mapper client is valid 146 * iwpm_valid_client - Check if the port mapper client is valid
132 * @nl_client: The index of the netlink client 147 * @nl_client: The index of the netlink client
133 * 148 *
diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c
index 8b8cc6fa0ab0..40becdb3196e 100644
--- a/drivers/infiniband/core/umem_odp.c
+++ b/drivers/infiniband/core/umem_odp.c
@@ -446,7 +446,6 @@ static int ib_umem_odp_map_dma_single_page(
446 int remove_existing_mapping = 0; 446 int remove_existing_mapping = 0;
447 int ret = 0; 447 int ret = 0;
448 448
449 mutex_lock(&umem->odp_data->umem_mutex);
450 /* 449 /*
451 * Note: we avoid writing if seq is different from the initial seq, to 450 * Note: we avoid writing if seq is different from the initial seq, to
452 * handle case of a racing notifier. This check also allows us to bail 451 * handle case of a racing notifier. This check also allows us to bail
@@ -479,8 +478,6 @@ static int ib_umem_odp_map_dma_single_page(
479 } 478 }
480 479
481out: 480out:
482 mutex_unlock(&umem->odp_data->umem_mutex);
483
484 /* On Demand Paging - avoid pinning the page */ 481 /* On Demand Paging - avoid pinning the page */
485 if (umem->context->invalidate_range || !stored_page) 482 if (umem->context->invalidate_range || !stored_page)
486 put_page(page); 483 put_page(page);
@@ -586,6 +583,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
586 583
587 bcnt -= min_t(size_t, npages << PAGE_SHIFT, bcnt); 584 bcnt -= min_t(size_t, npages << PAGE_SHIFT, bcnt);
588 user_virt += npages << PAGE_SHIFT; 585 user_virt += npages << PAGE_SHIFT;
586 mutex_lock(&umem->odp_data->umem_mutex);
589 for (j = 0; j < npages; ++j) { 587 for (j = 0; j < npages; ++j) {
590 ret = ib_umem_odp_map_dma_single_page( 588 ret = ib_umem_odp_map_dma_single_page(
591 umem, k, base_virt_addr, local_page_list[j], 589 umem, k, base_virt_addr, local_page_list[j],
@@ -594,6 +592,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
594 break; 592 break;
595 k++; 593 k++;
596 } 594 }
595 mutex_unlock(&umem->odp_data->umem_mutex);
597 596
598 if (ret < 0) { 597 if (ret < 0) {
599 /* Release left over pages when handling errors. */ 598 /* Release left over pages when handling errors. */
@@ -633,12 +632,11 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt,
633 * faults from completion. We might be racing with other 632 * faults from completion. We might be racing with other
634 * invalidations, so we must make sure we free each page only 633 * invalidations, so we must make sure we free each page only
635 * once. */ 634 * once. */
635 mutex_lock(&umem->odp_data->umem_mutex);
636 for (addr = virt; addr < bound; addr += (u64)umem->page_size) { 636 for (addr = virt; addr < bound; addr += (u64)umem->page_size) {
637 idx = (addr - ib_umem_start(umem)) / PAGE_SIZE; 637 idx = (addr - ib_umem_start(umem)) / PAGE_SIZE;
638 mutex_lock(&umem->odp_data->umem_mutex);
639 if (umem->odp_data->page_list[idx]) { 638 if (umem->odp_data->page_list[idx]) {
640 struct page *page = umem->odp_data->page_list[idx]; 639 struct page *page = umem->odp_data->page_list[idx];
641 struct page *head_page = compound_head(page);
642 dma_addr_t dma = umem->odp_data->dma_list[idx]; 640 dma_addr_t dma = umem->odp_data->dma_list[idx];
643 dma_addr_t dma_addr = dma & ODP_DMA_ADDR_MASK; 641 dma_addr_t dma_addr = dma & ODP_DMA_ADDR_MASK;
644 642
@@ -646,7 +644,8 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt,
646 644
647 ib_dma_unmap_page(dev, dma_addr, PAGE_SIZE, 645 ib_dma_unmap_page(dev, dma_addr, PAGE_SIZE,
648 DMA_BIDIRECTIONAL); 646 DMA_BIDIRECTIONAL);
649 if (dma & ODP_WRITE_ALLOWED_BIT) 647 if (dma & ODP_WRITE_ALLOWED_BIT) {
648 struct page *head_page = compound_head(page);
650 /* 649 /*
651 * set_page_dirty prefers being called with 650 * set_page_dirty prefers being called with
652 * the page lock. However, MMU notifiers are 651 * the page lock. However, MMU notifiers are
@@ -657,13 +656,14 @@ void ib_umem_odp_unmap_dma_pages(struct ib_umem *umem, u64 virt,
657 * be removed. 656 * be removed.
658 */ 657 */
659 set_page_dirty(head_page); 658 set_page_dirty(head_page);
659 }
660 /* on demand pinning support */ 660 /* on demand pinning support */
661 if (!umem->context->invalidate_range) 661 if (!umem->context->invalidate_range)
662 put_page(page); 662 put_page(page);
663 umem->odp_data->page_list[idx] = NULL; 663 umem->odp_data->page_list[idx] = NULL;
664 umem->odp_data->dma_list[idx] = 0; 664 umem->odp_data->dma_list[idx] = 0;
665 } 665 }
666 mutex_unlock(&umem->odp_data->umem_mutex);
667 } 666 }
667 mutex_unlock(&umem->odp_data->umem_mutex);
668} 668}
669EXPORT_SYMBOL(ib_umem_odp_unmap_dma_pages); 669EXPORT_SYMBOL(ib_umem_odp_unmap_dma_pages);
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 57176ddd4c50..3ad8dc798f52 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -583,6 +583,22 @@ static void c4iw_record_pm_msg(struct c4iw_ep *ep,
583 sizeof(ep->com.mapped_remote_addr)); 583 sizeof(ep->com.mapped_remote_addr));
584} 584}
585 585
586static int get_remote_addr(struct c4iw_ep *parent_ep, struct c4iw_ep *child_ep)
587{
588 int ret;
589
590 print_addr(&parent_ep->com, __func__, "get_remote_addr parent_ep ");
591 print_addr(&child_ep->com, __func__, "get_remote_addr child_ep ");
592
593 ret = iwpm_get_remote_info(&parent_ep->com.mapped_local_addr,
594 &child_ep->com.mapped_remote_addr,
595 &child_ep->com.remote_addr, RDMA_NL_C4IW);
596 if (ret)
597 PDBG("Unable to find remote peer addr info - err %d\n", ret);
598
599 return ret;
600}
601
586static void best_mtu(const unsigned short *mtus, unsigned short mtu, 602static void best_mtu(const unsigned short *mtus, unsigned short mtu,
587 unsigned int *idx, int use_ts, int ipv6) 603 unsigned int *idx, int use_ts, int ipv6)
588{ 604{
@@ -675,7 +691,7 @@ static int send_connect(struct c4iw_ep *ep)
675 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) { 691 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
676 opt2 |= T5_OPT_2_VALID_F; 692 opt2 |= T5_OPT_2_VALID_F;
677 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE); 693 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
678 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */ 694 opt2 |= T5_ISS_F;
679 } 695 }
680 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure); 696 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
681 697
@@ -2042,9 +2058,12 @@ static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2042 status, status2errno(status)); 2058 status, status2errno(status));
2043 2059
2044 if (is_neg_adv(status)) { 2060 if (is_neg_adv(status)) {
2045 dev_warn(&dev->rdev.lldi.pdev->dev, 2061 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2046 "Connection problems for atid %u status %u (%s)\n", 2062 __func__, atid, status, neg_adv_str(status));
2047 atid, status, neg_adv_str(status)); 2063 ep->stats.connect_neg_adv++;
2064 mutex_lock(&dev->rdev.stats.lock);
2065 dev->rdev.stats.neg_adv++;
2066 mutex_unlock(&dev->rdev.stats.lock);
2048 return 0; 2067 return 0;
2049 } 2068 }
2050 2069
@@ -2214,7 +2233,7 @@ static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2214 u32 isn = (prandom_u32() & ~7UL) - 1; 2233 u32 isn = (prandom_u32() & ~7UL) - 1;
2215 opt2 |= T5_OPT_2_VALID_F; 2234 opt2 |= T5_OPT_2_VALID_F;
2216 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE); 2235 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
2217 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */ 2236 opt2 |= T5_ISS_F;
2218 rpl5 = (void *)rpl; 2237 rpl5 = (void *)rpl;
2219 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16)); 2238 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2220 if (peer2peer) 2239 if (peer2peer)
@@ -2352,27 +2371,57 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2352 state_set(&child_ep->com, CONNECTING); 2371 state_set(&child_ep->com, CONNECTING);
2353 child_ep->com.dev = dev; 2372 child_ep->com.dev = dev;
2354 child_ep->com.cm_id = NULL; 2373 child_ep->com.cm_id = NULL;
2374
2375 /*
2376 * The mapped_local and mapped_remote addresses get setup with
2377 * the actual 4-tuple. The local address will be based on the
2378 * actual local address of the connection, but on the port number
2379 * of the parent listening endpoint. The remote address is
2380 * setup based on a query to the IWPM since we don't know what it
2381 * originally was before mapping. If no mapping was done, then
2382 * mapped_remote == remote, and mapped_local == local.
2383 */
2355 if (iptype == 4) { 2384 if (iptype == 4) {
2356 struct sockaddr_in *sin = (struct sockaddr_in *) 2385 struct sockaddr_in *sin = (struct sockaddr_in *)
2357 &child_ep->com.local_addr; 2386 &child_ep->com.mapped_local_addr;
2387
2358 sin->sin_family = PF_INET; 2388 sin->sin_family = PF_INET;
2359 sin->sin_port = local_port; 2389 sin->sin_port = local_port;
2360 sin->sin_addr.s_addr = *(__be32 *)local_ip; 2390 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2361 sin = (struct sockaddr_in *)&child_ep->com.remote_addr; 2391
2392 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2393 sin->sin_family = PF_INET;
2394 sin->sin_port = ((struct sockaddr_in *)
2395 &parent_ep->com.local_addr)->sin_port;
2396 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2397
2398 sin = (struct sockaddr_in *)&child_ep->com.mapped_remote_addr;
2362 sin->sin_family = PF_INET; 2399 sin->sin_family = PF_INET;
2363 sin->sin_port = peer_port; 2400 sin->sin_port = peer_port;
2364 sin->sin_addr.s_addr = *(__be32 *)peer_ip; 2401 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2365 } else { 2402 } else {
2366 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) 2403 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2367 &child_ep->com.local_addr; 2404 &child_ep->com.mapped_local_addr;
2405
2368 sin6->sin6_family = PF_INET6; 2406 sin6->sin6_family = PF_INET6;
2369 sin6->sin6_port = local_port; 2407 sin6->sin6_port = local_port;
2370 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16); 2408 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2371 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr; 2409
2410 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2411 sin6->sin6_family = PF_INET6;
2412 sin6->sin6_port = ((struct sockaddr_in6 *)
2413 &parent_ep->com.local_addr)->sin6_port;
2414 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2415
2416 sin6 = (struct sockaddr_in6 *)&child_ep->com.mapped_remote_addr;
2372 sin6->sin6_family = PF_INET6; 2417 sin6->sin6_family = PF_INET6;
2373 sin6->sin6_port = peer_port; 2418 sin6->sin6_port = peer_port;
2374 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16); 2419 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2375 } 2420 }
2421 memcpy(&child_ep->com.remote_addr, &child_ep->com.mapped_remote_addr,
2422 sizeof(child_ep->com.remote_addr));
2423 get_remote_addr(parent_ep, child_ep);
2424
2376 c4iw_get_ep(&parent_ep->com); 2425 c4iw_get_ep(&parent_ep->com);
2377 child_ep->parent_ep = parent_ep; 2426 child_ep->parent_ep = parent_ep;
2378 child_ep->tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid)); 2427 child_ep->tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
@@ -2520,9 +2569,13 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2520 2569
2521 ep = lookup_tid(t, tid); 2570 ep = lookup_tid(t, tid);
2522 if (is_neg_adv(req->status)) { 2571 if (is_neg_adv(req->status)) {
2523 dev_warn(&dev->rdev.lldi.pdev->dev, 2572 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2524 "Negative advice on abort - tid %u status %d (%s)\n", 2573 __func__, ep->hwtid, req->status,
2525 ep->hwtid, req->status, neg_adv_str(req->status)); 2574 neg_adv_str(req->status));
2575 ep->stats.abort_neg_adv++;
2576 mutex_lock(&dev->rdev.stats.lock);
2577 dev->rdev.stats.neg_adv++;
2578 mutex_unlock(&dev->rdev.stats.lock);
2526 return 0; 2579 return 0;
2527 } 2580 }
2528 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid, 2581 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
@@ -3571,7 +3624,7 @@ static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3571 * TP will ignore any value > 0 for MSS index. 3624 * TP will ignore any value > 0 for MSS index.
3572 */ 3625 */
3573 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF)); 3626 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
3574 req->cookie = (unsigned long)skb; 3627 req->cookie = (uintptr_t)skb;
3575 3628
3576 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id); 3629 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3577 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb); 3630 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
@@ -3931,9 +3984,11 @@ static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3931 return 0; 3984 return 0;
3932 } 3985 }
3933 if (is_neg_adv(req->status)) { 3986 if (is_neg_adv(req->status)) {
3934 dev_warn(&dev->rdev.lldi.pdev->dev, 3987 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
3935 "Negative advice on abort - tid %u status %d (%s)\n", 3988 __func__, ep->hwtid, req->status,
3936 ep->hwtid, req->status, neg_adv_str(req->status)); 3989 neg_adv_str(req->status));
3990 ep->stats.abort_neg_adv++;
3991 dev->rdev.stats.neg_adv++;
3937 kfree_skb(skb); 3992 kfree_skb(skb);
3938 return 0; 3993 return 0;
3939 } 3994 }
diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
index ab7692ac2044..68ddb3710215 100644
--- a/drivers/infiniband/hw/cxgb4/cq.c
+++ b/drivers/infiniband/hw/cxgb4/cq.c
@@ -55,7 +55,7 @@ static int destroy_cq(struct c4iw_rdev *rdev, struct t4_cq *cq,
55 FW_RI_RES_WR_NRES_V(1) | 55 FW_RI_RES_WR_NRES_V(1) |
56 FW_WR_COMPL_F); 56 FW_WR_COMPL_F);
57 res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16)); 57 res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16));
58 res_wr->cookie = (unsigned long) &wr_wait; 58 res_wr->cookie = (uintptr_t)&wr_wait;
59 res = res_wr->res; 59 res = res_wr->res;
60 res->u.cq.restype = FW_RI_RES_TYPE_CQ; 60 res->u.cq.restype = FW_RI_RES_TYPE_CQ;
61 res->u.cq.op = FW_RI_RES_OP_RESET; 61 res->u.cq.op = FW_RI_RES_OP_RESET;
@@ -125,7 +125,7 @@ static int create_cq(struct c4iw_rdev *rdev, struct t4_cq *cq,
125 FW_RI_RES_WR_NRES_V(1) | 125 FW_RI_RES_WR_NRES_V(1) |
126 FW_WR_COMPL_F); 126 FW_WR_COMPL_F);
127 res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16)); 127 res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16));
128 res_wr->cookie = (unsigned long) &wr_wait; 128 res_wr->cookie = (uintptr_t)&wr_wait;
129 res = res_wr->res; 129 res = res_wr->res;
130 res->u.cq.restype = FW_RI_RES_TYPE_CQ; 130 res->u.cq.restype = FW_RI_RES_TYPE_CQ;
131 res->u.cq.op = FW_RI_RES_OP_WRITE; 131 res->u.cq.op = FW_RI_RES_OP_WRITE;
@@ -156,12 +156,19 @@ static int create_cq(struct c4iw_rdev *rdev, struct t4_cq *cq,
156 goto err4; 156 goto err4;
157 157
158 cq->gen = 1; 158 cq->gen = 1;
159 cq->gts = rdev->lldi.gts_reg;
160 cq->rdev = rdev; 159 cq->rdev = rdev;
161 if (user) { 160 if (user) {
162 cq->ugts = (u64)pci_resource_start(rdev->lldi.pdev, 2) + 161 u32 off = (cq->cqid << rdev->cqshift) & PAGE_MASK;
163 (cq->cqid << rdev->cqshift); 162
164 cq->ugts &= PAGE_MASK; 163 cq->ugts = (u64)rdev->bar2_pa + off;
164 } else if (is_t4(rdev->lldi.adapter_type)) {
165 cq->gts = rdev->lldi.gts_reg;
166 cq->qid_mask = -1U;
167 } else {
168 u32 off = ((cq->cqid << rdev->cqshift) & PAGE_MASK) + 12;
169
170 cq->gts = rdev->bar2_kva + off;
171 cq->qid_mask = rdev->qpmask;
165 } 172 }
166 return 0; 173 return 0;
167err4: 174err4:
@@ -970,8 +977,7 @@ struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
970 } 977 }
971 PDBG("%s cqid 0x%0x chp %p size %u memsize %zu, dma_addr 0x%0llx\n", 978 PDBG("%s cqid 0x%0x chp %p size %u memsize %zu, dma_addr 0x%0llx\n",
972 __func__, chp->cq.cqid, chp, chp->cq.size, 979 __func__, chp->cq.cqid, chp, chp->cq.size,
973 chp->cq.memsize, 980 chp->cq.memsize, (unsigned long long) chp->cq.dma_addr);
974 (unsigned long long) chp->cq.dma_addr);
975 return &chp->ibcq; 981 return &chp->ibcq;
976err5: 982err5:
977 kfree(mm2); 983 kfree(mm2);
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index 8fb295e4a9ab..7e895d714b19 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -93,6 +93,7 @@ static struct ibnl_client_cbs c4iw_nl_cb_table[] = {
93 [RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb}, 93 [RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb},
94 [RDMA_NL_IWPM_QUERY_MAPPING] = {.dump = iwpm_add_and_query_mapping_cb}, 94 [RDMA_NL_IWPM_QUERY_MAPPING] = {.dump = iwpm_add_and_query_mapping_cb},
95 [RDMA_NL_IWPM_HANDLE_ERR] = {.dump = iwpm_mapping_error_cb}, 95 [RDMA_NL_IWPM_HANDLE_ERR] = {.dump = iwpm_mapping_error_cb},
96 [RDMA_NL_IWPM_REMOTE_INFO] = {.dump = iwpm_remote_info_cb},
96 [RDMA_NL_IWPM_MAPINFO] = {.dump = iwpm_mapping_info_cb}, 97 [RDMA_NL_IWPM_MAPINFO] = {.dump = iwpm_mapping_info_cb},
97 [RDMA_NL_IWPM_MAPINFO_NUM] = {.dump = iwpm_ack_mapping_info_cb} 98 [RDMA_NL_IWPM_MAPINFO_NUM] = {.dump = iwpm_ack_mapping_info_cb}
98}; 99};
@@ -151,7 +152,7 @@ static int wr_log_show(struct seq_file *seq, void *v)
151 int prev_ts_set = 0; 152 int prev_ts_set = 0;
152 int idx, end; 153 int idx, end;
153 154
154#define ts2ns(ts) div64_ul((ts) * dev->rdev.lldi.cclk_ps, 1000) 155#define ts2ns(ts) div64_u64((ts) * dev->rdev.lldi.cclk_ps, 1000)
155 156
156 idx = atomic_read(&dev->rdev.wr_log_idx) & 157 idx = atomic_read(&dev->rdev.wr_log_idx) &
157 (dev->rdev.wr_log_size - 1); 158 (dev->rdev.wr_log_size - 1);
@@ -489,6 +490,7 @@ static int stats_show(struct seq_file *seq, void *v)
489 dev->rdev.stats.act_ofld_conn_fails); 490 dev->rdev.stats.act_ofld_conn_fails);
490 seq_printf(seq, "PAS_OFLD_CONN_FAILS: %10llu\n", 491 seq_printf(seq, "PAS_OFLD_CONN_FAILS: %10llu\n",
491 dev->rdev.stats.pas_ofld_conn_fails); 492 dev->rdev.stats.pas_ofld_conn_fails);
493 seq_printf(seq, "NEG_ADV_RCVD: %10llu\n", dev->rdev.stats.neg_adv);
492 seq_printf(seq, "AVAILABLE IRD: %10u\n", dev->avail_ird); 494 seq_printf(seq, "AVAILABLE IRD: %10u\n", dev->avail_ird);
493 return 0; 495 return 0;
494} 496}
@@ -560,10 +562,13 @@ static int dump_ep(int id, void *p, void *data)
560 cc = snprintf(epd->buf + epd->pos, space, 562 cc = snprintf(epd->buf + epd->pos, space,
561 "ep %p cm_id %p qp %p state %d flags 0x%lx " 563 "ep %p cm_id %p qp %p state %d flags 0x%lx "
562 "history 0x%lx hwtid %d atid %d " 564 "history 0x%lx hwtid %d atid %d "
565 "conn_na %u abort_na %u "
563 "%pI4:%d/%d <-> %pI4:%d/%d\n", 566 "%pI4:%d/%d <-> %pI4:%d/%d\n",
564 ep, ep->com.cm_id, ep->com.qp, 567 ep, ep->com.cm_id, ep->com.qp,
565 (int)ep->com.state, ep->com.flags, 568 (int)ep->com.state, ep->com.flags,
566 ep->com.history, ep->hwtid, ep->atid, 569 ep->com.history, ep->hwtid, ep->atid,
570 ep->stats.connect_neg_adv,
571 ep->stats.abort_neg_adv,
567 &lsin->sin_addr, ntohs(lsin->sin_port), 572 &lsin->sin_addr, ntohs(lsin->sin_port),
568 ntohs(mapped_lsin->sin_port), 573 ntohs(mapped_lsin->sin_port),
569 &rsin->sin_addr, ntohs(rsin->sin_port), 574 &rsin->sin_addr, ntohs(rsin->sin_port),
@@ -581,10 +586,13 @@ static int dump_ep(int id, void *p, void *data)
581 cc = snprintf(epd->buf + epd->pos, space, 586 cc = snprintf(epd->buf + epd->pos, space,
582 "ep %p cm_id %p qp %p state %d flags 0x%lx " 587 "ep %p cm_id %p qp %p state %d flags 0x%lx "
583 "history 0x%lx hwtid %d atid %d " 588 "history 0x%lx hwtid %d atid %d "
589 "conn_na %u abort_na %u "
584 "%pI6:%d/%d <-> %pI6:%d/%d\n", 590 "%pI6:%d/%d <-> %pI6:%d/%d\n",
585 ep, ep->com.cm_id, ep->com.qp, 591 ep, ep->com.cm_id, ep->com.qp,
586 (int)ep->com.state, ep->com.flags, 592 (int)ep->com.state, ep->com.flags,
587 ep->com.history, ep->hwtid, ep->atid, 593 ep->com.history, ep->hwtid, ep->atid,
594 ep->stats.connect_neg_adv,
595 ep->stats.abort_neg_adv,
588 &lsin6->sin6_addr, ntohs(lsin6->sin6_port), 596 &lsin6->sin6_addr, ntohs(lsin6->sin6_port),
589 ntohs(mapped_lsin6->sin6_port), 597 ntohs(mapped_lsin6->sin6_port),
590 &rsin6->sin6_addr, ntohs(rsin6->sin6_port), 598 &rsin6->sin6_addr, ntohs(rsin6->sin6_port),
@@ -765,6 +773,29 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev)
765 c4iw_init_dev_ucontext(rdev, &rdev->uctx); 773 c4iw_init_dev_ucontext(rdev, &rdev->uctx);
766 774
767 /* 775 /*
776 * This implementation assumes udb_density == ucq_density! Eventually
777 * we might need to support this but for now fail the open. Also the
778 * cqid and qpid range must match for now.
779 */
780 if (rdev->lldi.udb_density != rdev->lldi.ucq_density) {
781 pr_err(MOD "%s: unsupported udb/ucq densities %u/%u\n",
782 pci_name(rdev->lldi.pdev), rdev->lldi.udb_density,
783 rdev->lldi.ucq_density);
784 err = -EINVAL;
785 goto err1;
786 }
787 if (rdev->lldi.vr->qp.start != rdev->lldi.vr->cq.start ||
788 rdev->lldi.vr->qp.size != rdev->lldi.vr->cq.size) {
789 pr_err(MOD "%s: unsupported qp and cq id ranges "
790 "qp start %u size %u cq start %u size %u\n",
791 pci_name(rdev->lldi.pdev), rdev->lldi.vr->qp.start,
792 rdev->lldi.vr->qp.size, rdev->lldi.vr->cq.size,
793 rdev->lldi.vr->cq.size);
794 err = -EINVAL;
795 goto err1;
796 }
797
798 /*
768 * qpshift is the number of bits to shift the qpid left in order 799 * qpshift is the number of bits to shift the qpid left in order
769 * to get the correct address of the doorbell for that qp. 800 * to get the correct address of the doorbell for that qp.
770 */ 801 */
@@ -784,10 +815,10 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev)
784 rdev->lldi.vr->qp.size, 815 rdev->lldi.vr->qp.size,
785 rdev->lldi.vr->cq.start, 816 rdev->lldi.vr->cq.start,
786 rdev->lldi.vr->cq.size); 817 rdev->lldi.vr->cq.size);
787 PDBG("udb len 0x%x udb base %llx db_reg %p gts_reg %p qpshift %lu " 818 PDBG("udb len 0x%x udb base %p db_reg %p gts_reg %p qpshift %lu "
788 "qpmask 0x%x cqshift %lu cqmask 0x%x\n", 819 "qpmask 0x%x cqshift %lu cqmask 0x%x\n",
789 (unsigned)pci_resource_len(rdev->lldi.pdev, 2), 820 (unsigned)pci_resource_len(rdev->lldi.pdev, 2),
790 (u64)pci_resource_start(rdev->lldi.pdev, 2), 821 (void *)pci_resource_start(rdev->lldi.pdev, 2),
791 rdev->lldi.db_reg, 822 rdev->lldi.db_reg,
792 rdev->lldi.gts_reg, 823 rdev->lldi.gts_reg,
793 rdev->qpshift, rdev->qpmask, 824 rdev->qpshift, rdev->qpmask,
@@ -1355,7 +1386,7 @@ static void recover_lost_dbs(struct uld_ctx *ctx, struct qp_list *qp_list)
1355 t4_sq_host_wq_pidx(&qp->wq), 1386 t4_sq_host_wq_pidx(&qp->wq),
1356 t4_sq_wq_size(&qp->wq)); 1387 t4_sq_wq_size(&qp->wq));
1357 if (ret) { 1388 if (ret) {
1358 pr_err(KERN_ERR MOD "%s: Fatal error - " 1389 pr_err(MOD "%s: Fatal error - "
1359 "DB overflow recovery failed - " 1390 "DB overflow recovery failed - "
1360 "error syncing SQ qid %u\n", 1391 "error syncing SQ qid %u\n",
1361 pci_name(ctx->lldi.pdev), qp->wq.sq.qid); 1392 pci_name(ctx->lldi.pdev), qp->wq.sq.qid);
@@ -1371,7 +1402,7 @@ static void recover_lost_dbs(struct uld_ctx *ctx, struct qp_list *qp_list)
1371 t4_rq_wq_size(&qp->wq)); 1402 t4_rq_wq_size(&qp->wq));
1372 1403
1373 if (ret) { 1404 if (ret) {
1374 pr_err(KERN_ERR MOD "%s: Fatal error - " 1405 pr_err(MOD "%s: Fatal error - "
1375 "DB overflow recovery failed - " 1406 "DB overflow recovery failed - "
1376 "error syncing RQ qid %u\n", 1407 "error syncing RQ qid %u\n",
1377 pci_name(ctx->lldi.pdev), qp->wq.rq.qid); 1408 pci_name(ctx->lldi.pdev), qp->wq.rq.qid);
diff --git a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
index d87e1650f643..97bb5550a6cf 100644
--- a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
+++ b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
@@ -137,6 +137,7 @@ struct c4iw_stats {
137 u64 tcam_full; 137 u64 tcam_full;
138 u64 act_ofld_conn_fails; 138 u64 act_ofld_conn_fails;
139 u64 pas_ofld_conn_fails; 139 u64 pas_ofld_conn_fails;
140 u64 neg_adv;
140}; 141};
141 142
142struct c4iw_hw_queue { 143struct c4iw_hw_queue {
@@ -814,6 +815,11 @@ struct c4iw_listen_ep {
814 int backlog; 815 int backlog;
815}; 816};
816 817
818struct c4iw_ep_stats {
819 unsigned connect_neg_adv;
820 unsigned abort_neg_adv;
821};
822
817struct c4iw_ep { 823struct c4iw_ep {
818 struct c4iw_ep_common com; 824 struct c4iw_ep_common com;
819 struct c4iw_ep *parent_ep; 825 struct c4iw_ep *parent_ep;
@@ -846,6 +852,7 @@ struct c4iw_ep {
846 unsigned int retry_count; 852 unsigned int retry_count;
847 int snd_win; 853 int snd_win;
848 int rcv_win; 854 int rcv_win;
855 struct c4iw_ep_stats stats;
849}; 856};
850 857
851static inline void print_addr(struct c4iw_ep_common *epc, const char *func, 858static inline void print_addr(struct c4iw_ep_common *epc, const char *func,
diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index 3ef0cf9f5c44..cff815b91707 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -144,7 +144,7 @@ static int _c4iw_write_mem_inline(struct c4iw_rdev *rdev, u32 addr, u32 len,
144 if (i == (num_wqe-1)) { 144 if (i == (num_wqe-1)) {
145 req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR) | 145 req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR) |
146 FW_WR_COMPL_F); 146 FW_WR_COMPL_F);
147 req->wr.wr_lo = (__force __be64)(unsigned long) &wr_wait; 147 req->wr.wr_lo = (__force __be64)&wr_wait;
148 } else 148 } else
149 req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR)); 149 req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR));
150 req->wr.wr_mid = cpu_to_be32( 150 req->wr.wr_mid = cpu_to_be32(
@@ -676,12 +676,12 @@ struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc)
676 mhp->attr.zbva = 0; 676 mhp->attr.zbva = 0;
677 mhp->attr.va_fbo = 0; 677 mhp->attr.va_fbo = 0;
678 mhp->attr.page_size = 0; 678 mhp->attr.page_size = 0;
679 mhp->attr.len = ~0UL; 679 mhp->attr.len = ~0ULL;
680 mhp->attr.pbl_size = 0; 680 mhp->attr.pbl_size = 0;
681 681
682 ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, php->pdid, 682 ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, php->pdid,
683 FW_RI_STAG_NSMR, mhp->attr.perms, 683 FW_RI_STAG_NSMR, mhp->attr.perms,
684 mhp->attr.mw_bind_enable, 0, 0, ~0UL, 0, 0, 0); 684 mhp->attr.mw_bind_enable, 0, 0, ~0ULL, 0, 0, 0);
685 if (ret) 685 if (ret)
686 goto err1; 686 goto err1;
687 687
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index 15cae5a31018..389ced335bc5 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -275,7 +275,7 @@ static int create_qp(struct c4iw_rdev *rdev, struct t4_wq *wq,
275 FW_RI_RES_WR_NRES_V(2) | 275 FW_RI_RES_WR_NRES_V(2) |
276 FW_WR_COMPL_F); 276 FW_WR_COMPL_F);
277 res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16)); 277 res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16));
278 res_wr->cookie = (unsigned long) &wr_wait; 278 res_wr->cookie = (uintptr_t)&wr_wait;
279 res = res_wr->res; 279 res = res_wr->res;
280 res->u.sqrq.restype = FW_RI_RES_TYPE_SQ; 280 res->u.sqrq.restype = FW_RI_RES_TYPE_SQ;
281 res->u.sqrq.op = FW_RI_RES_OP_WRITE; 281 res->u.sqrq.op = FW_RI_RES_OP_WRITE;
@@ -1209,7 +1209,7 @@ static int rdma_fini(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
1209 wqe->flowid_len16 = cpu_to_be32( 1209 wqe->flowid_len16 = cpu_to_be32(
1210 FW_WR_FLOWID_V(ep->hwtid) | 1210 FW_WR_FLOWID_V(ep->hwtid) |
1211 FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16))); 1211 FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16)));
1212 wqe->cookie = (unsigned long) &ep->com.wr_wait; 1212 wqe->cookie = (uintptr_t)&ep->com.wr_wait;
1213 1213
1214 wqe->u.fini.type = FW_RI_TYPE_FINI; 1214 wqe->u.fini.type = FW_RI_TYPE_FINI;
1215 ret = c4iw_ofld_send(&rhp->rdev, skb); 1215 ret = c4iw_ofld_send(&rhp->rdev, skb);
@@ -1279,7 +1279,7 @@ static int rdma_init(struct c4iw_dev *rhp, struct c4iw_qp *qhp)
1279 FW_WR_FLOWID_V(qhp->ep->hwtid) | 1279 FW_WR_FLOWID_V(qhp->ep->hwtid) |
1280 FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16))); 1280 FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16)));
1281 1281
1282 wqe->cookie = (unsigned long) &qhp->ep->com.wr_wait; 1282 wqe->cookie = (uintptr_t)&qhp->ep->com.wr_wait;
1283 1283
1284 wqe->u.init.type = FW_RI_TYPE_INIT; 1284 wqe->u.init.type = FW_RI_TYPE_INIT;
1285 wqe->u.init.mpareqbit_p2ptype = 1285 wqe->u.init.mpareqbit_p2ptype =
@@ -1766,11 +1766,11 @@ struct ib_qp *c4iw_create_qp(struct ib_pd *pd, struct ib_qp_init_attr *attrs,
1766 mm2->len = PAGE_ALIGN(qhp->wq.rq.memsize); 1766 mm2->len = PAGE_ALIGN(qhp->wq.rq.memsize);
1767 insert_mmap(ucontext, mm2); 1767 insert_mmap(ucontext, mm2);
1768 mm3->key = uresp.sq_db_gts_key; 1768 mm3->key = uresp.sq_db_gts_key;
1769 mm3->addr = (__force unsigned long) qhp->wq.sq.udb; 1769 mm3->addr = (__force unsigned long)qhp->wq.sq.udb;
1770 mm3->len = PAGE_SIZE; 1770 mm3->len = PAGE_SIZE;
1771 insert_mmap(ucontext, mm3); 1771 insert_mmap(ucontext, mm3);
1772 mm4->key = uresp.rq_db_gts_key; 1772 mm4->key = uresp.rq_db_gts_key;
1773 mm4->addr = (__force unsigned long) qhp->wq.rq.udb; 1773 mm4->addr = (__force unsigned long)qhp->wq.rq.udb;
1774 mm4->len = PAGE_SIZE; 1774 mm4->len = PAGE_SIZE;
1775 insert_mmap(ucontext, mm4); 1775 insert_mmap(ucontext, mm4);
1776 if (mm5) { 1776 if (mm5) {
diff --git a/drivers/infiniband/hw/cxgb4/t4.h b/drivers/infiniband/hw/cxgb4/t4.h
index 871cdcac7be2..7f2a6c244d25 100644
--- a/drivers/infiniband/hw/cxgb4/t4.h
+++ b/drivers/infiniband/hw/cxgb4/t4.h
@@ -539,6 +539,7 @@ struct t4_cq {
539 size_t memsize; 539 size_t memsize;
540 __be64 bits_type_ts; 540 __be64 bits_type_ts;
541 u32 cqid; 541 u32 cqid;
542 u32 qid_mask;
542 int vector; 543 int vector;
543 u16 size; /* including status page */ 544 u16 size; /* including status page */
544 u16 cidx; 545 u16 cidx;
@@ -563,12 +564,12 @@ static inline int t4_arm_cq(struct t4_cq *cq, int se)
563 set_bit(CQ_ARMED, &cq->flags); 564 set_bit(CQ_ARMED, &cq->flags);
564 while (cq->cidx_inc > CIDXINC_M) { 565 while (cq->cidx_inc > CIDXINC_M) {
565 val = SEINTARM_V(0) | CIDXINC_V(CIDXINC_M) | TIMERREG_V(7) | 566 val = SEINTARM_V(0) | CIDXINC_V(CIDXINC_M) | TIMERREG_V(7) |
566 INGRESSQID_V(cq->cqid); 567 INGRESSQID_V(cq->cqid & cq->qid_mask);
567 writel(val, cq->gts); 568 writel(val, cq->gts);
568 cq->cidx_inc -= CIDXINC_M; 569 cq->cidx_inc -= CIDXINC_M;
569 } 570 }
570 val = SEINTARM_V(se) | CIDXINC_V(cq->cidx_inc) | TIMERREG_V(6) | 571 val = SEINTARM_V(se) | CIDXINC_V(cq->cidx_inc) | TIMERREG_V(6) |
571 INGRESSQID_V(cq->cqid); 572 INGRESSQID_V(cq->cqid & cq->qid_mask);
572 writel(val, cq->gts); 573 writel(val, cq->gts);
573 cq->cidx_inc = 0; 574 cq->cidx_inc = 0;
574 return 0; 575 return 0;
@@ -601,7 +602,7 @@ static inline void t4_hwcq_consume(struct t4_cq *cq)
601 u32 val; 602 u32 val;
602 603
603 val = SEINTARM_V(0) | CIDXINC_V(cq->cidx_inc) | TIMERREG_V(7) | 604 val = SEINTARM_V(0) | CIDXINC_V(cq->cidx_inc) | TIMERREG_V(7) |
604 INGRESSQID_V(cq->cqid); 605 INGRESSQID_V(cq->cqid & cq->qid_mask);
605 writel(val, cq->gts); 606 writel(val, cq->gts);
606 cq->cidx_inc = 0; 607 cq->cidx_inc = 0;
607 } 608 }
diff --git a/drivers/infiniband/hw/cxgb4/t4fw_ri_api.h b/drivers/infiniband/hw/cxgb4/t4fw_ri_api.h
index 5e53327fc647..343e8daf2270 100644
--- a/drivers/infiniband/hw/cxgb4/t4fw_ri_api.h
+++ b/drivers/infiniband/hw/cxgb4/t4fw_ri_api.h
@@ -848,6 +848,8 @@ enum { /* TCP congestion control algorithms */
848#define CONG_CNTRL_V(x) ((x) << CONG_CNTRL_S) 848#define CONG_CNTRL_V(x) ((x) << CONG_CNTRL_S)
849#define CONG_CNTRL_G(x) (((x) >> CONG_CNTRL_S) & CONG_CNTRL_M) 849#define CONG_CNTRL_G(x) (((x) >> CONG_CNTRL_S) & CONG_CNTRL_M)
850 850
851#define CONG_CNTRL_VALID (1 << 18) 851#define T5_ISS_S 18
852#define T5_ISS_V(x) ((x) << T5_ISS_S)
853#define T5_ISS_F T5_ISS_V(1U)
852 854
853#endif /* _T4FW_RI_API_H_ */ 855#endif /* _T4FW_RI_API_H_ */
diff --git a/drivers/infiniband/hw/ehca/ehca_mcast.c b/drivers/infiniband/hw/ehca/ehca_mcast.c
index 120aedf9f989..cec181532924 100644
--- a/drivers/infiniband/hw/ehca/ehca_mcast.c
+++ b/drivers/infiniband/hw/ehca/ehca_mcast.c
@@ -77,7 +77,7 @@ int ehca_attach_mcast(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
77 return -EINVAL; 77 return -EINVAL;
78 } 78 }
79 79
80 memcpy(&my_gid.raw, gid->raw, sizeof(union ib_gid)); 80 memcpy(&my_gid, gid->raw, sizeof(union ib_gid));
81 81
82 subnet_prefix = be64_to_cpu(my_gid.global.subnet_prefix); 82 subnet_prefix = be64_to_cpu(my_gid.global.subnet_prefix);
83 interface_id = be64_to_cpu(my_gid.global.interface_id); 83 interface_id = be64_to_cpu(my_gid.global.interface_id);
@@ -114,7 +114,7 @@ int ehca_detach_mcast(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
114 return -EINVAL; 114 return -EINVAL;
115 } 115 }
116 116
117 memcpy(&my_gid.raw, gid->raw, sizeof(union ib_gid)); 117 memcpy(&my_gid, gid->raw, sizeof(union ib_gid));
118 118
119 subnet_prefix = be64_to_cpu(my_gid.global.subnet_prefix); 119 subnet_prefix = be64_to_cpu(my_gid.global.subnet_prefix);
120 interface_id = be64_to_cpu(my_gid.global.interface_id); 120 interface_id = be64_to_cpu(my_gid.global.interface_id);
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 57070c529dfb..cc64400d41ac 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -1569,8 +1569,7 @@ static void reset_gids_task(struct work_struct *work)
1569 MLX4_CMD_TIME_CLASS_B, 1569 MLX4_CMD_TIME_CLASS_B,
1570 MLX4_CMD_WRAPPED); 1570 MLX4_CMD_WRAPPED);
1571 if (err) 1571 if (err)
1572 pr_warn(KERN_WARNING 1572 pr_warn("set port %d command failed\n", gw->port);
1573 "set port %d command failed\n", gw->port);
1574 } 1573 }
1575 1574
1576 mlx4_free_cmd_mailbox(dev, mailbox); 1575 mlx4_free_cmd_mailbox(dev, mailbox);
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 4d7024b899cb..d35f62d4f4c5 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -1392,7 +1392,7 @@ static int mlx5_set_path(struct mlx5_ib_dev *dev, const struct ib_ah_attr *ah,
1392 1392
1393 if (ah->ah_flags & IB_AH_GRH) { 1393 if (ah->ah_flags & IB_AH_GRH) {
1394 if (ah->grh.sgid_index >= gen->port[port - 1].gid_table_len) { 1394 if (ah->grh.sgid_index >= gen->port[port - 1].gid_table_len) {
1395 pr_err(KERN_ERR "sgid_index (%u) too large. max is %d\n", 1395 pr_err("sgid_index (%u) too large. max is %d\n",
1396 ah->grh.sgid_index, gen->port[port - 1].gid_table_len); 1396 ah->grh.sgid_index, gen->port[port - 1].gid_table_len);
1397 return -EINVAL; 1397 return -EINVAL;
1398 } 1398 }
diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
index 3b2a6dc8ea99..9f9d5c563a61 100644
--- a/drivers/infiniband/hw/nes/nes.c
+++ b/drivers/infiniband/hw/nes/nes.c
@@ -116,6 +116,7 @@ static struct ibnl_client_cbs nes_nl_cb_table[] = {
116 [RDMA_NL_IWPM_REG_PID] = {.dump = iwpm_register_pid_cb}, 116 [RDMA_NL_IWPM_REG_PID] = {.dump = iwpm_register_pid_cb},
117 [RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb}, 117 [RDMA_NL_IWPM_ADD_MAPPING] = {.dump = iwpm_add_mapping_cb},
118 [RDMA_NL_IWPM_QUERY_MAPPING] = {.dump = iwpm_add_and_query_mapping_cb}, 118 [RDMA_NL_IWPM_QUERY_MAPPING] = {.dump = iwpm_add_and_query_mapping_cb},
119 [RDMA_NL_IWPM_REMOTE_INFO] = {.dump = iwpm_remote_info_cb},
119 [RDMA_NL_IWPM_HANDLE_ERR] = {.dump = iwpm_mapping_error_cb}, 120 [RDMA_NL_IWPM_HANDLE_ERR] = {.dump = iwpm_mapping_error_cb},
120 [RDMA_NL_IWPM_MAPINFO] = {.dump = iwpm_mapping_info_cb}, 121 [RDMA_NL_IWPM_MAPINFO] = {.dump = iwpm_mapping_info_cb},
121 [RDMA_NL_IWPM_MAPINFO_NUM] = {.dump = iwpm_ack_mapping_info_cb} 122 [RDMA_NL_IWPM_MAPINFO_NUM] = {.dump = iwpm_ack_mapping_info_cb}
diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
index 6f09a72e78d7..72b43417cbe3 100644
--- a/drivers/infiniband/hw/nes/nes_cm.c
+++ b/drivers/infiniband/hw/nes/nes_cm.c
@@ -596,27 +596,52 @@ static void nes_form_reg_msg(struct nes_vnic *nesvnic,
596 memcpy(pm_msg->if_name, nesvnic->netdev->name, IWPM_IFNAME_SIZE); 596 memcpy(pm_msg->if_name, nesvnic->netdev->name, IWPM_IFNAME_SIZE);
597} 597}
598 598
599static void record_sockaddr_info(struct sockaddr_storage *addr_info,
600 nes_addr_t *ip_addr, u16 *port_num)
601{
602 struct sockaddr_in *in_addr = (struct sockaddr_in *)addr_info;
603
604 if (in_addr->sin_family == AF_INET) {
605 *ip_addr = ntohl(in_addr->sin_addr.s_addr);
606 *port_num = ntohs(in_addr->sin_port);
607 }
608}
609
599/* 610/*
600 * nes_record_pm_msg - Save the received mapping info 611 * nes_record_pm_msg - Save the received mapping info
601 */ 612 */
602static void nes_record_pm_msg(struct nes_cm_info *cm_info, 613static void nes_record_pm_msg(struct nes_cm_info *cm_info,
603 struct iwpm_sa_data *pm_msg) 614 struct iwpm_sa_data *pm_msg)
604{ 615{
605 struct sockaddr_in *mapped_loc_addr = 616 record_sockaddr_info(&pm_msg->mapped_loc_addr,
606 (struct sockaddr_in *)&pm_msg->mapped_loc_addr; 617 &cm_info->mapped_loc_addr, &cm_info->mapped_loc_port);
607 struct sockaddr_in *mapped_rem_addr = 618
608 (struct sockaddr_in *)&pm_msg->mapped_rem_addr; 619 record_sockaddr_info(&pm_msg->mapped_rem_addr,
609 620 &cm_info->mapped_rem_addr, &cm_info->mapped_rem_port);
610 if (mapped_loc_addr->sin_family == AF_INET) { 621}
611 cm_info->mapped_loc_addr = 622
612 ntohl(mapped_loc_addr->sin_addr.s_addr); 623/*
613 cm_info->mapped_loc_port = ntohs(mapped_loc_addr->sin_port); 624 * nes_get_reminfo - Get the address info of the remote connecting peer
614 } 625 */
615 if (mapped_rem_addr->sin_family == AF_INET) { 626static int nes_get_remote_addr(struct nes_cm_node *cm_node)
616 cm_info->mapped_rem_addr = 627{
617 ntohl(mapped_rem_addr->sin_addr.s_addr); 628 struct sockaddr_storage mapped_loc_addr, mapped_rem_addr;
618 cm_info->mapped_rem_port = ntohs(mapped_rem_addr->sin_port); 629 struct sockaddr_storage remote_addr;
619 } 630 int ret;
631
632 nes_create_sockaddr(htonl(cm_node->mapped_loc_addr),
633 htons(cm_node->mapped_loc_port), &mapped_loc_addr);
634 nes_create_sockaddr(htonl(cm_node->mapped_rem_addr),
635 htons(cm_node->mapped_rem_port), &mapped_rem_addr);
636
637 ret = iwpm_get_remote_info(&mapped_loc_addr, &mapped_rem_addr,
638 &remote_addr, RDMA_NL_NES);
639 if (ret)
640 nes_debug(NES_DBG_CM, "Unable to find remote peer address info\n");
641 else
642 record_sockaddr_info(&remote_addr, &cm_node->rem_addr,
643 &cm_node->rem_port);
644 return ret;
620} 645}
621 646
622/** 647/**
@@ -1566,9 +1591,14 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
1566 return NULL; 1591 return NULL;
1567 1592
1568 /* set our node specific transport info */ 1593 /* set our node specific transport info */
1569 cm_node->loc_addr = cm_info->loc_addr; 1594 if (listener) {
1595 cm_node->loc_addr = listener->loc_addr;
1596 cm_node->loc_port = listener->loc_port;
1597 } else {
1598 cm_node->loc_addr = cm_info->loc_addr;
1599 cm_node->loc_port = cm_info->loc_port;
1600 }
1570 cm_node->rem_addr = cm_info->rem_addr; 1601 cm_node->rem_addr = cm_info->rem_addr;
1571 cm_node->loc_port = cm_info->loc_port;
1572 cm_node->rem_port = cm_info->rem_port; 1602 cm_node->rem_port = cm_info->rem_port;
1573 1603
1574 cm_node->mapped_loc_addr = cm_info->mapped_loc_addr; 1604 cm_node->mapped_loc_addr = cm_info->mapped_loc_addr;
@@ -2151,6 +2181,7 @@ static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
2151 cm_node->state = NES_CM_STATE_ESTABLISHED; 2181 cm_node->state = NES_CM_STATE_ESTABLISHED;
2152 if (datasize) { 2182 if (datasize) {
2153 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize; 2183 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2184 nes_get_remote_addr(cm_node);
2154 handle_rcv_mpa(cm_node, skb); 2185 handle_rcv_mpa(cm_node, skb);
2155 } else { /* rcvd ACK only */ 2186 } else { /* rcvd ACK only */
2156 dev_kfree_skb_any(skb); 2187 dev_kfree_skb_any(skb);
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma.h b/drivers/infiniband/hw/ocrdma/ocrdma.h
index c9780d919769..b396344fae16 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma.h
+++ b/drivers/infiniband/hw/ocrdma/ocrdma.h
@@ -40,7 +40,7 @@
40#include <be_roce.h> 40#include <be_roce.h>
41#include "ocrdma_sli.h" 41#include "ocrdma_sli.h"
42 42
43#define OCRDMA_ROCE_DRV_VERSION "10.4.205.0u" 43#define OCRDMA_ROCE_DRV_VERSION "10.6.0.0"
44 44
45#define OCRDMA_ROCE_DRV_DESC "Emulex OneConnect RoCE Driver" 45#define OCRDMA_ROCE_DRV_DESC "Emulex OneConnect RoCE Driver"
46#define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA" 46#define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
@@ -515,6 +515,8 @@ static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
515 memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6)); 515 memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
516 if (rdma_is_multicast_addr(&in6)) 516 if (rdma_is_multicast_addr(&in6))
517 rdma_get_mcast_mac(&in6, mac_addr); 517 rdma_get_mcast_mac(&in6, mac_addr);
518 else if (rdma_link_local_addr(&in6))
519 rdma_get_ll_mac(&in6, mac_addr);
518 else 520 else
519 memcpy(mac_addr, ah_attr->dmac, ETH_ALEN); 521 memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
520 return 0; 522 return 0;
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_ah.c b/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
index d812904f3984..f5a5ea836dbd 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_ah.c
@@ -56,7 +56,13 @@ static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
56 vlan_tag = attr->vlan_id; 56 vlan_tag = attr->vlan_id;
57 if (!vlan_tag || (vlan_tag > 0xFFF)) 57 if (!vlan_tag || (vlan_tag > 0xFFF))
58 vlan_tag = dev->pvid; 58 vlan_tag = dev->pvid;
59 if (vlan_tag && (vlan_tag < 0x1000)) { 59 if (vlan_tag || dev->pfc_state) {
60 if (!vlan_tag) {
61 pr_err("ocrdma%d:Using VLAN with PFC is recommended\n",
62 dev->id);
63 pr_err("ocrdma%d:Using VLAN 0 for this connection\n",
64 dev->id);
65 }
60 eth.eth_type = cpu_to_be16(0x8100); 66 eth.eth_type = cpu_to_be16(0x8100);
61 eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE); 67 eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
62 vlan_tag |= (dev->sl & 0x07) << OCRDMA_VID_PCP_SHIFT; 68 vlan_tag |= (dev->sl & 0x07) << OCRDMA_VID_PCP_SHIFT;
@@ -121,7 +127,9 @@ struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
121 goto av_conf_err; 127 goto av_conf_err;
122 } 128 }
123 129
124 if (pd->uctx) { 130 if ((pd->uctx) &&
131 (!rdma_is_multicast_addr((struct in6_addr *)attr->grh.dgid.raw)) &&
132 (!rdma_link_local_addr((struct in6_addr *)attr->grh.dgid.raw))) {
125 status = rdma_addr_find_dmac_by_grh(&sgid, &attr->grh.dgid, 133 status = rdma_addr_find_dmac_by_grh(&sgid, &attr->grh.dgid,
126 attr->dmac, &attr->vlan_id); 134 attr->dmac, &attr->vlan_id);
127 if (status) { 135 if (status) {
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 0c9e95909a64..47615ff33bc6 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -933,12 +933,18 @@ static irqreturn_t ocrdma_irq_handler(int irq, void *handle)
933 struct ocrdma_eqe eqe; 933 struct ocrdma_eqe eqe;
934 struct ocrdma_eqe *ptr; 934 struct ocrdma_eqe *ptr;
935 u16 cq_id; 935 u16 cq_id;
936 u8 mcode;
936 int budget = eq->cq_cnt; 937 int budget = eq->cq_cnt;
937 938
938 do { 939 do {
939 ptr = ocrdma_get_eqe(eq); 940 ptr = ocrdma_get_eqe(eq);
940 eqe = *ptr; 941 eqe = *ptr;
941 ocrdma_le32_to_cpu(&eqe, sizeof(eqe)); 942 ocrdma_le32_to_cpu(&eqe, sizeof(eqe));
943 mcode = (eqe.id_valid & OCRDMA_EQE_MAJOR_CODE_MASK)
944 >> OCRDMA_EQE_MAJOR_CODE_SHIFT;
945 if (mcode == OCRDMA_MAJOR_CODE_SENTINAL)
946 pr_err("EQ full on eqid = 0x%x, eqe = 0x%x\n",
947 eq->q.id, eqe.id_valid);
942 if ((eqe.id_valid & OCRDMA_EQE_VALID_MASK) == 0) 948 if ((eqe.id_valid & OCRDMA_EQE_VALID_MASK) == 0)
943 break; 949 break;
944 950
@@ -1434,27 +1440,30 @@ static int ocrdma_mbx_alloc_pd_range(struct ocrdma_dev *dev)
1434 struct ocrdma_alloc_pd_range_rsp *rsp; 1440 struct ocrdma_alloc_pd_range_rsp *rsp;
1435 1441
1436 /* Pre allocate the DPP PDs */ 1442 /* Pre allocate the DPP PDs */
1437 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_ALLOC_PD_RANGE, sizeof(*cmd)); 1443 if (dev->attr.max_dpp_pds) {
1438 if (!cmd) 1444 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_ALLOC_PD_RANGE,
1439 return -ENOMEM; 1445 sizeof(*cmd));
1440 cmd->pd_count = dev->attr.max_dpp_pds; 1446 if (!cmd)
1441 cmd->enable_dpp_rsvd |= OCRDMA_ALLOC_PD_ENABLE_DPP; 1447 return -ENOMEM;
1442 status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd); 1448 cmd->pd_count = dev->attr.max_dpp_pds;
1443 if (status) 1449 cmd->enable_dpp_rsvd |= OCRDMA_ALLOC_PD_ENABLE_DPP;
1444 goto mbx_err; 1450 status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd);
1445 rsp = (struct ocrdma_alloc_pd_range_rsp *)cmd; 1451 rsp = (struct ocrdma_alloc_pd_range_rsp *)cmd;
1446 1452
1447 if ((rsp->dpp_page_pdid & OCRDMA_ALLOC_PD_RSP_DPP) && rsp->pd_count) { 1453 if (!status && (rsp->dpp_page_pdid & OCRDMA_ALLOC_PD_RSP_DPP) &&
1448 dev->pd_mgr->dpp_page_index = rsp->dpp_page_pdid >> 1454 rsp->pd_count) {
1449 OCRDMA_ALLOC_PD_RSP_DPP_PAGE_SHIFT; 1455 dev->pd_mgr->dpp_page_index = rsp->dpp_page_pdid >>
1450 dev->pd_mgr->pd_dpp_start = rsp->dpp_page_pdid & 1456 OCRDMA_ALLOC_PD_RSP_DPP_PAGE_SHIFT;
1451 OCRDMA_ALLOC_PD_RNG_RSP_START_PDID_MASK; 1457 dev->pd_mgr->pd_dpp_start = rsp->dpp_page_pdid &
1452 dev->pd_mgr->max_dpp_pd = rsp->pd_count; 1458 OCRDMA_ALLOC_PD_RNG_RSP_START_PDID_MASK;
1453 pd_bitmap_size = BITS_TO_LONGS(rsp->pd_count) * sizeof(long); 1459 dev->pd_mgr->max_dpp_pd = rsp->pd_count;
1454 dev->pd_mgr->pd_dpp_bitmap = kzalloc(pd_bitmap_size, 1460 pd_bitmap_size =
1455 GFP_KERNEL); 1461 BITS_TO_LONGS(rsp->pd_count) * sizeof(long);
1462 dev->pd_mgr->pd_dpp_bitmap = kzalloc(pd_bitmap_size,
1463 GFP_KERNEL);
1464 }
1465 kfree(cmd);
1456 } 1466 }
1457 kfree(cmd);
1458 1467
1459 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_ALLOC_PD_RANGE, sizeof(*cmd)); 1468 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_ALLOC_PD_RANGE, sizeof(*cmd));
1460 if (!cmd) 1469 if (!cmd)
@@ -1462,10 +1471,8 @@ static int ocrdma_mbx_alloc_pd_range(struct ocrdma_dev *dev)
1462 1471
1463 cmd->pd_count = dev->attr.max_pd - dev->attr.max_dpp_pds; 1472 cmd->pd_count = dev->attr.max_pd - dev->attr.max_dpp_pds;
1464 status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd); 1473 status = ocrdma_mbx_cmd(dev, (struct ocrdma_mqe *)cmd);
1465 if (status)
1466 goto mbx_err;
1467 rsp = (struct ocrdma_alloc_pd_range_rsp *)cmd; 1474 rsp = (struct ocrdma_alloc_pd_range_rsp *)cmd;
1468 if (rsp->pd_count) { 1475 if (!status && rsp->pd_count) {
1469 dev->pd_mgr->pd_norm_start = rsp->dpp_page_pdid & 1476 dev->pd_mgr->pd_norm_start = rsp->dpp_page_pdid &
1470 OCRDMA_ALLOC_PD_RNG_RSP_START_PDID_MASK; 1477 OCRDMA_ALLOC_PD_RNG_RSP_START_PDID_MASK;
1471 dev->pd_mgr->max_normal_pd = rsp->pd_count; 1478 dev->pd_mgr->max_normal_pd = rsp->pd_count;
@@ -1473,15 +1480,13 @@ static int ocrdma_mbx_alloc_pd_range(struct ocrdma_dev *dev)
1473 dev->pd_mgr->pd_norm_bitmap = kzalloc(pd_bitmap_size, 1480 dev->pd_mgr->pd_norm_bitmap = kzalloc(pd_bitmap_size,
1474 GFP_KERNEL); 1481 GFP_KERNEL);
1475 } 1482 }
1483 kfree(cmd);
1476 1484
1477 if (dev->pd_mgr->pd_norm_bitmap || dev->pd_mgr->pd_dpp_bitmap) { 1485 if (dev->pd_mgr->pd_norm_bitmap || dev->pd_mgr->pd_dpp_bitmap) {
1478 /* Enable PD resource manager */ 1486 /* Enable PD resource manager */
1479 dev->pd_mgr->pd_prealloc_valid = true; 1487 dev->pd_mgr->pd_prealloc_valid = true;
1480 } else { 1488 return 0;
1481 return -ENOMEM;
1482 } 1489 }
1483mbx_err:
1484 kfree(cmd);
1485 return status; 1490 return status;
1486} 1491}
1487 1492
@@ -2406,7 +2411,7 @@ int ocrdma_mbx_query_qp(struct ocrdma_dev *dev, struct ocrdma_qp *qp,
2406 struct ocrdma_query_qp *cmd; 2411 struct ocrdma_query_qp *cmd;
2407 struct ocrdma_query_qp_rsp *rsp; 2412 struct ocrdma_query_qp_rsp *rsp;
2408 2413
2409 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_QUERY_QP, sizeof(*cmd)); 2414 cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_QUERY_QP, sizeof(*rsp));
2410 if (!cmd) 2415 if (!cmd)
2411 return status; 2416 return status;
2412 cmd->qp_id = qp->id; 2417 cmd->qp_id = qp->id;
@@ -2428,7 +2433,7 @@ static int ocrdma_set_av_params(struct ocrdma_qp *qp,
2428 int status; 2433 int status;
2429 struct ib_ah_attr *ah_attr = &attrs->ah_attr; 2434 struct ib_ah_attr *ah_attr = &attrs->ah_attr;
2430 union ib_gid sgid, zgid; 2435 union ib_gid sgid, zgid;
2431 u32 vlan_id; 2436 u32 vlan_id = 0xFFFF;
2432 u8 mac_addr[6]; 2437 u8 mac_addr[6];
2433 struct ocrdma_dev *dev = get_ocrdma_dev(qp->ibqp.device); 2438 struct ocrdma_dev *dev = get_ocrdma_dev(qp->ibqp.device);
2434 2439
@@ -2468,12 +2473,22 @@ static int ocrdma_set_av_params(struct ocrdma_qp *qp,
2468 cmd->params.vlan_dmac_b4_to_b5 = mac_addr[4] | (mac_addr[5] << 8); 2473 cmd->params.vlan_dmac_b4_to_b5 = mac_addr[4] | (mac_addr[5] << 8);
2469 if (attr_mask & IB_QP_VID) { 2474 if (attr_mask & IB_QP_VID) {
2470 vlan_id = attrs->vlan_id; 2475 vlan_id = attrs->vlan_id;
2476 } else if (dev->pfc_state) {
2477 vlan_id = 0;
2478 pr_err("ocrdma%d:Using VLAN with PFC is recommended\n",
2479 dev->id);
2480 pr_err("ocrdma%d:Using VLAN 0 for this connection\n",
2481 dev->id);
2482 }
2483
2484 if (vlan_id < 0x1000) {
2471 cmd->params.vlan_dmac_b4_to_b5 |= 2485 cmd->params.vlan_dmac_b4_to_b5 |=
2472 vlan_id << OCRDMA_QP_PARAMS_VLAN_SHIFT; 2486 vlan_id << OCRDMA_QP_PARAMS_VLAN_SHIFT;
2473 cmd->flags |= OCRDMA_QP_PARA_VLAN_EN_VALID; 2487 cmd->flags |= OCRDMA_QP_PARA_VLAN_EN_VALID;
2474 cmd->params.rnt_rc_sl_fl |= 2488 cmd->params.rnt_rc_sl_fl |=
2475 (dev->sl & 0x07) << OCRDMA_QP_PARAMS_SL_SHIFT; 2489 (dev->sl & 0x07) << OCRDMA_QP_PARAMS_SL_SHIFT;
2476 } 2490 }
2491
2477 return 0; 2492 return 0;
2478} 2493}
2479 2494
@@ -2519,8 +2534,10 @@ static int ocrdma_set_qp_params(struct ocrdma_qp *qp,
2519 cmd->flags |= OCRDMA_QP_PARA_DST_QPN_VALID; 2534 cmd->flags |= OCRDMA_QP_PARA_DST_QPN_VALID;
2520 } 2535 }
2521 if (attr_mask & IB_QP_PATH_MTU) { 2536 if (attr_mask & IB_QP_PATH_MTU) {
2522 if (attrs->path_mtu < IB_MTU_256 || 2537 if (attrs->path_mtu < IB_MTU_512 ||
2523 attrs->path_mtu > IB_MTU_4096) { 2538 attrs->path_mtu > IB_MTU_4096) {
2539 pr_err("ocrdma%d: IB MTU %d is not supported\n",
2540 dev->id, ib_mtu_enum_to_int(attrs->path_mtu));
2524 status = -EINVAL; 2541 status = -EINVAL;
2525 goto pmtu_err; 2542 goto pmtu_err;
2526 } 2543 }
@@ -3147,9 +3164,9 @@ void ocrdma_cleanup_hw(struct ocrdma_dev *dev)
3147 ocrdma_free_pd_pool(dev); 3164 ocrdma_free_pd_pool(dev);
3148 ocrdma_mbx_delete_ah_tbl(dev); 3165 ocrdma_mbx_delete_ah_tbl(dev);
3149 3166
3150 /* cleanup the eqs */
3151 ocrdma_destroy_eqs(dev);
3152
3153 /* cleanup the control path */ 3167 /* cleanup the control path */
3154 ocrdma_destroy_mq(dev); 3168 ocrdma_destroy_mq(dev);
3169
3170 /* cleanup the eqs */
3171 ocrdma_destroy_eqs(dev);
3155} 3172}
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_sli.h b/drivers/infiniband/hw/ocrdma/ocrdma_sli.h
index 243c87c8bd65..02ad0aee99af 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_sli.h
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_sli.h
@@ -1176,6 +1176,8 @@ struct ocrdma_query_qp_rsp {
1176 struct ocrdma_mqe_hdr hdr; 1176 struct ocrdma_mqe_hdr hdr;
1177 struct ocrdma_mbx_rsp rsp; 1177 struct ocrdma_mbx_rsp rsp;
1178 struct ocrdma_qp_params params; 1178 struct ocrdma_qp_params params;
1179 u32 dpp_credits_cqid;
1180 u32 rbq_id;
1179}; 1181};
1180 1182
1181enum { 1183enum {
@@ -1624,12 +1626,19 @@ struct ocrdma_delete_ah_tbl_rsp {
1624enum { 1626enum {
1625 OCRDMA_EQE_VALID_SHIFT = 0, 1627 OCRDMA_EQE_VALID_SHIFT = 0,
1626 OCRDMA_EQE_VALID_MASK = BIT(0), 1628 OCRDMA_EQE_VALID_MASK = BIT(0),
1629 OCRDMA_EQE_MAJOR_CODE_MASK = 0x0E,
1630 OCRDMA_EQE_MAJOR_CODE_SHIFT = 0x01,
1627 OCRDMA_EQE_FOR_CQE_MASK = 0xFFFE, 1631 OCRDMA_EQE_FOR_CQE_MASK = 0xFFFE,
1628 OCRDMA_EQE_RESOURCE_ID_SHIFT = 16, 1632 OCRDMA_EQE_RESOURCE_ID_SHIFT = 16,
1629 OCRDMA_EQE_RESOURCE_ID_MASK = 0xFFFF << 1633 OCRDMA_EQE_RESOURCE_ID_MASK = 0xFFFF <<
1630 OCRDMA_EQE_RESOURCE_ID_SHIFT, 1634 OCRDMA_EQE_RESOURCE_ID_SHIFT,
1631}; 1635};
1632 1636
1637enum major_code {
1638 OCRDMA_MAJOR_CODE_COMPLETION = 0x00,
1639 OCRDMA_MAJOR_CODE_SENTINAL = 0x01
1640};
1641
1633struct ocrdma_eqe { 1642struct ocrdma_eqe {
1634 u32 id_valid; 1643 u32 id_valid;
1635}; 1644};
diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
index 877175563634..9dcb66077d6c 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
@@ -365,7 +365,7 @@ static struct ocrdma_pd *_ocrdma_alloc_pd(struct ocrdma_dev *dev,
365 if (!pd) 365 if (!pd)
366 return ERR_PTR(-ENOMEM); 366 return ERR_PTR(-ENOMEM);
367 367
368 if (udata && uctx) { 368 if (udata && uctx && dev->attr.max_dpp_pds) {
369 pd->dpp_enabled = 369 pd->dpp_enabled =
370 ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R; 370 ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R;
371 pd->num_dpp_qp = 371 pd->num_dpp_qp =
@@ -1721,18 +1721,20 @@ int ocrdma_destroy_qp(struct ib_qp *ibqp)
1721 struct ocrdma_qp *qp; 1721 struct ocrdma_qp *qp;
1722 struct ocrdma_dev *dev; 1722 struct ocrdma_dev *dev;
1723 struct ib_qp_attr attrs; 1723 struct ib_qp_attr attrs;
1724 int attr_mask = IB_QP_STATE; 1724 int attr_mask;
1725 unsigned long flags; 1725 unsigned long flags;
1726 1726
1727 qp = get_ocrdma_qp(ibqp); 1727 qp = get_ocrdma_qp(ibqp);
1728 dev = get_ocrdma_dev(ibqp->device); 1728 dev = get_ocrdma_dev(ibqp->device);
1729 1729
1730 attrs.qp_state = IB_QPS_ERR;
1731 pd = qp->pd; 1730 pd = qp->pd;
1732 1731
1733 /* change the QP state to ERROR */ 1732 /* change the QP state to ERROR */
1734 _ocrdma_modify_qp(ibqp, &attrs, attr_mask); 1733 if (qp->state != OCRDMA_QPS_RST) {
1735 1734 attrs.qp_state = IB_QPS_ERR;
1735 attr_mask = IB_QP_STATE;
1736 _ocrdma_modify_qp(ibqp, &attrs, attr_mask);
1737 }
1736 /* ensure that CQEs for newly created QP (whose id may be same with 1738 /* ensure that CQEs for newly created QP (whose id may be same with
1737 * one which just getting destroyed are same), dont get 1739 * one which just getting destroyed are same), dont get
1738 * discarded until the old CQEs are discarded. 1740 * discarded until the old CQEs are discarded.
diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
index ffd48bfc4923..7df16f74bb45 100644
--- a/drivers/infiniband/hw/qib/qib.h
+++ b/drivers/infiniband/hw/qib/qib.h
@@ -903,7 +903,7 @@ struct qib_devdata {
903 /* PCI Device ID (here for NodeInfo) */ 903 /* PCI Device ID (here for NodeInfo) */
904 u16 deviceid; 904 u16 deviceid;
905 /* for write combining settings */ 905 /* for write combining settings */
906 unsigned long wc_cookie; 906 int wc_cookie;
907 unsigned long wc_base; 907 unsigned long wc_base;
908 unsigned long wc_len; 908 unsigned long wc_len;
909 909
@@ -1136,7 +1136,6 @@ extern struct qib_devdata *qib_lookup(int unit);
1136extern u32 qib_cpulist_count; 1136extern u32 qib_cpulist_count;
1137extern unsigned long *qib_cpulist; 1137extern unsigned long *qib_cpulist;
1138 1138
1139extern unsigned qib_wc_pat;
1140extern unsigned qib_cc_table_size; 1139extern unsigned qib_cc_table_size;
1141int qib_init(struct qib_devdata *, int); 1140int qib_init(struct qib_devdata *, int);
1142int init_chip_wc_pat(struct qib_devdata *dd, u32); 1141int init_chip_wc_pat(struct qib_devdata *dd, u32);
diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c
index 9ea6c440a00c..725881890c4a 100644
--- a/drivers/infiniband/hw/qib/qib_file_ops.c
+++ b/drivers/infiniband/hw/qib/qib_file_ops.c
@@ -835,7 +835,8 @@ static int mmap_piobufs(struct vm_area_struct *vma,
835 vma->vm_flags &= ~VM_MAYREAD; 835 vma->vm_flags &= ~VM_MAYREAD;
836 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND; 836 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
837 837
838 if (qib_wc_pat) 838 /* We used PAT if wc_cookie == 0 */
839 if (!dd->wc_cookie)
839 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 840 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
840 841
841 ret = io_remap_pfn_range(vma, vma->vm_start, phys >> PAGE_SHIFT, 842 ret = io_remap_pfn_range(vma, vma->vm_start, phys >> PAGE_SHIFT,
diff --git a/drivers/infiniband/hw/qib/qib_iba6120.c b/drivers/infiniband/hw/qib/qib_iba6120.c
index 0d2ba59af30a..4b927809d1a1 100644
--- a/drivers/infiniband/hw/qib/qib_iba6120.c
+++ b/drivers/infiniband/hw/qib/qib_iba6120.c
@@ -3315,11 +3315,9 @@ static int init_6120_variables(struct qib_devdata *dd)
3315 qib_6120_config_ctxts(dd); 3315 qib_6120_config_ctxts(dd);
3316 qib_set_ctxtcnt(dd); 3316 qib_set_ctxtcnt(dd);
3317 3317
3318 if (qib_wc_pat) { 3318 ret = init_chip_wc_pat(dd, 0);
3319 ret = init_chip_wc_pat(dd, 0); 3319 if (ret)
3320 if (ret) 3320 goto bail;
3321 goto bail;
3322 }
3323 set_6120_baseaddrs(dd); /* set chip access pointers now */ 3321 set_6120_baseaddrs(dd); /* set chip access pointers now */
3324 3322
3325 ret = 0; 3323 ret = 0;
diff --git a/drivers/infiniband/hw/qib/qib_iba7220.c b/drivers/infiniband/hw/qib/qib_iba7220.c
index 22affda8af88..00b2af211157 100644
--- a/drivers/infiniband/hw/qib/qib_iba7220.c
+++ b/drivers/infiniband/hw/qib/qib_iba7220.c
@@ -4126,11 +4126,9 @@ static int qib_init_7220_variables(struct qib_devdata *dd)
4126 qib_7220_config_ctxts(dd); 4126 qib_7220_config_ctxts(dd);
4127 qib_set_ctxtcnt(dd); /* needed for PAT setup */ 4127 qib_set_ctxtcnt(dd); /* needed for PAT setup */
4128 4128
4129 if (qib_wc_pat) { 4129 ret = init_chip_wc_pat(dd, 0);
4130 ret = init_chip_wc_pat(dd, 0); 4130 if (ret)
4131 if (ret) 4131 goto bail;
4132 goto bail;
4133 }
4134 set_7220_baseaddrs(dd); /* set chip access pointers now */ 4132 set_7220_baseaddrs(dd); /* set chip access pointers now */
4135 4133
4136 ret = 0; 4134 ret = 0;
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index ef97b71c8f7d..f32b4628e991 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -6429,6 +6429,7 @@ static int qib_init_7322_variables(struct qib_devdata *dd)
6429 unsigned features, pidx, sbufcnt; 6429 unsigned features, pidx, sbufcnt;
6430 int ret, mtu; 6430 int ret, mtu;
6431 u32 sbufs, updthresh; 6431 u32 sbufs, updthresh;
6432 resource_size_t vl15off;
6432 6433
6433 /* pport structs are contiguous, allocated after devdata */ 6434 /* pport structs are contiguous, allocated after devdata */
6434 ppd = (struct qib_pportdata *)(dd + 1); 6435 ppd = (struct qib_pportdata *)(dd + 1);
@@ -6677,29 +6678,27 @@ static int qib_init_7322_variables(struct qib_devdata *dd)
6677 qib_7322_config_ctxts(dd); 6678 qib_7322_config_ctxts(dd);
6678 qib_set_ctxtcnt(dd); 6679 qib_set_ctxtcnt(dd);
6679 6680
6680 if (qib_wc_pat) { 6681 /*
6681 resource_size_t vl15off; 6682 * We do not set WC on the VL15 buffers to avoid
6682 /* 6683 * a rare problem with unaligned writes from
6683 * We do not set WC on the VL15 buffers to avoid 6684 * interrupt-flushed store buffers, so we need
6684 * a rare problem with unaligned writes from 6685 * to map those separately here. We can't solve
6685 * interrupt-flushed store buffers, so we need 6686 * this for the rarely used mtrr case.
6686 * to map those separately here. We can't solve 6687 */
6687 * this for the rarely used mtrr case. 6688 ret = init_chip_wc_pat(dd, 0);
6688 */ 6689 if (ret)
6689 ret = init_chip_wc_pat(dd, 0); 6690 goto bail;
6690 if (ret)
6691 goto bail;
6692 6691
6693 /* vl15 buffers start just after the 4k buffers */ 6692 /* vl15 buffers start just after the 4k buffers */
6694 vl15off = dd->physaddr + (dd->piobufbase >> 32) + 6693 vl15off = dd->physaddr + (dd->piobufbase >> 32) +
6695 dd->piobcnt4k * dd->align4k; 6694 dd->piobcnt4k * dd->align4k;
6696 dd->piovl15base = ioremap_nocache(vl15off, 6695 dd->piovl15base = ioremap_nocache(vl15off,
6697 NUM_VL15_BUFS * dd->align4k); 6696 NUM_VL15_BUFS * dd->align4k);
6698 if (!dd->piovl15base) { 6697 if (!dd->piovl15base) {
6699 ret = -ENOMEM; 6698 ret = -ENOMEM;
6700 goto bail; 6699 goto bail;
6701 }
6702 } 6700 }
6701
6703 qib_7322_set_baseaddrs(dd); /* set chip access pointers now */ 6702 qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
6704 6703
6705 ret = 0; 6704 ret = 0;
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index 2ee36953e234..7e00470adc30 100644
--- a/drivers/infiniband/hw/qib/qib_init.c
+++ b/drivers/infiniband/hw/qib/qib_init.c
@@ -91,15 +91,6 @@ MODULE_PARM_DESC(krcvqs, "number of kernel receive queues per IB port");
91unsigned qib_cc_table_size; 91unsigned qib_cc_table_size;
92module_param_named(cc_table_size, qib_cc_table_size, uint, S_IRUGO); 92module_param_named(cc_table_size, qib_cc_table_size, uint, S_IRUGO);
93MODULE_PARM_DESC(cc_table_size, "Congestion control table entries 0 (CCA disabled - default), min = 128, max = 1984"); 93MODULE_PARM_DESC(cc_table_size, "Congestion control table entries 0 (CCA disabled - default), min = 128, max = 1984");
94/*
95 * qib_wc_pat parameter:
96 * 0 is WC via MTRR
97 * 1 is WC via PAT
98 * If PAT initialization fails, code reverts back to MTRR
99 */
100unsigned qib_wc_pat = 1; /* default (1) is to use PAT, not MTRR */
101module_param_named(wc_pat, qib_wc_pat, uint, S_IRUGO);
102MODULE_PARM_DESC(wc_pat, "enable write-combining via PAT mechanism");
103 94
104static void verify_interrupt(unsigned long); 95static void verify_interrupt(unsigned long);
105 96
@@ -1377,8 +1368,7 @@ static void cleanup_device_data(struct qib_devdata *dd)
1377 spin_unlock(&dd->pport[pidx].cc_shadow_lock); 1368 spin_unlock(&dd->pport[pidx].cc_shadow_lock);
1378 } 1369 }
1379 1370
1380 if (!qib_wc_pat) 1371 qib_disable_wc(dd);
1381 qib_disable_wc(dd);
1382 1372
1383 if (dd->pioavailregs_dma) { 1373 if (dd->pioavailregs_dma) {
1384 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE, 1374 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
@@ -1547,14 +1537,12 @@ static int qib_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1547 goto bail; 1537 goto bail;
1548 } 1538 }
1549 1539
1550 if (!qib_wc_pat) { 1540 ret = qib_enable_wc(dd);
1551 ret = qib_enable_wc(dd); 1541 if (ret) {
1552 if (ret) { 1542 qib_dev_err(dd,
1553 qib_dev_err(dd, 1543 "Write combining not enabled (err %d): performance may be poor\n",
1554 "Write combining not enabled (err %d): performance may be poor\n", 1544 -ret);
1555 -ret); 1545 ret = 0;
1556 ret = 0;
1557 }
1558 } 1546 }
1559 1547
1560 qib_verify_pioperf(dd); 1548 qib_verify_pioperf(dd);
diff --git a/drivers/infiniband/hw/qib/qib_wc_x86_64.c b/drivers/infiniband/hw/qib/qib_wc_x86_64.c
index 81b225f2300a..edd0ddbd4481 100644
--- a/drivers/infiniband/hw/qib/qib_wc_x86_64.c
+++ b/drivers/infiniband/hw/qib/qib_wc_x86_64.c
@@ -116,21 +116,10 @@ int qib_enable_wc(struct qib_devdata *dd)
116 } 116 }
117 117
118 if (!ret) { 118 if (!ret) {
119 int cookie; 119 dd->wc_cookie = arch_phys_wc_add(pioaddr, piolen);
120 120 if (dd->wc_cookie < 0)
121 cookie = mtrr_add(pioaddr, piolen, MTRR_TYPE_WRCOMB, 0); 121 /* use error from routine */
122 if (cookie < 0) { 122 ret = dd->wc_cookie;
123 {
124 qib_devinfo(dd->pcidev,
125 "mtrr_add() WC for PIO bufs failed (%d)\n",
126 cookie);
127 ret = -EINVAL;
128 }
129 } else {
130 dd->wc_cookie = cookie;
131 dd->wc_base = (unsigned long) pioaddr;
132 dd->wc_len = (unsigned long) piolen;
133 }
134 } 123 }
135 124
136 return ret; 125 return ret;
@@ -142,18 +131,7 @@ int qib_enable_wc(struct qib_devdata *dd)
142 */ 131 */
143void qib_disable_wc(struct qib_devdata *dd) 132void qib_disable_wc(struct qib_devdata *dd)
144{ 133{
145 if (dd->wc_cookie) { 134 arch_phys_wc_del(dd->wc_cookie);
146 int r;
147
148 r = mtrr_del(dd->wc_cookie, dd->wc_base,
149 dd->wc_len);
150 if (r < 0)
151 qib_devinfo(dd->pcidev,
152 "mtrr_del(%lx, %lx, %lx) failed: %d\n",
153 dd->wc_cookie, dd->wc_base,
154 dd->wc_len, r);
155 dd->wc_cookie = 0; /* even on failure */
156 }
157} 135}
158 136
159/** 137/**
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 56959adb6c7d..cf32a778e7d0 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -386,8 +386,8 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i
386 rx->rx_ring[i].mapping, 386 rx->rx_ring[i].mapping,
387 GFP_KERNEL)) { 387 GFP_KERNEL)) {
388 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); 388 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
389 ret = -ENOMEM; 389 ret = -ENOMEM;
390 goto err_count; 390 goto err_count;
391 } 391 }
392 ret = ipoib_cm_post_receive_nonsrq(dev, rx, &t->wr, t->sge, i); 392 ret = ipoib_cm_post_receive_nonsrq(dev, rx, &t->wr, t->sge, i);
393 if (ret) { 393 if (ret) {
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 327529ee85eb..3f40319a55da 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -547,11 +547,11 @@ isert_create_pi_ctx(struct fast_reg_descriptor *desc,
547 return 0; 547 return 0;
548 548
549err_prot_mr: 549err_prot_mr:
550 ib_dereg_mr(desc->pi_ctx->prot_mr); 550 ib_dereg_mr(pi_ctx->prot_mr);
551err_prot_frpl: 551err_prot_frpl:
552 ib_free_fast_reg_page_list(desc->pi_ctx->prot_frpl); 552 ib_free_fast_reg_page_list(pi_ctx->prot_frpl);
553err_pi_ctx: 553err_pi_ctx:
554 kfree(desc->pi_ctx); 554 kfree(pi_ctx);
555 555
556 return ret; 556 return ret;
557} 557}
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index f362883c94e3..1d247bcf2ae2 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -747,6 +747,63 @@ static void joydev_cleanup(struct joydev *joydev)
747 input_close_device(handle); 747 input_close_device(handle);
748} 748}
749 749
750static bool joydev_dev_is_absolute_mouse(struct input_dev *dev)
751{
752 DECLARE_BITMAP(jd_scratch, KEY_CNT);
753
754 BUILD_BUG_ON(ABS_CNT > KEY_CNT || EV_CNT > KEY_CNT);
755
756 /*
757 * Virtualization (VMware, etc) and remote management (HP
758 * ILO2) solutions use absolute coordinates for their virtual
759 * pointing devices so that there is one-to-one relationship
760 * between pointer position on the host screen and virtual
761 * guest screen, and so their mice use ABS_X, ABS_Y and 3
762 * primary button events. This clashes with what joydev
763 * considers to be joysticks (a device with at minimum ABS_X
764 * axis).
765 *
766 * Here we are trying to separate absolute mice from
767 * joysticks. A device is, for joystick detection purposes,
768 * considered to be an absolute mouse if the following is
769 * true:
770 *
771 * 1) Event types are exactly EV_ABS, EV_KEY and EV_SYN.
772 * 2) Absolute events are exactly ABS_X and ABS_Y.
773 * 3) Keys are exactly BTN_LEFT, BTN_RIGHT and BTN_MIDDLE.
774 * 4) Device is not on "Amiga" bus.
775 */
776
777 bitmap_zero(jd_scratch, EV_CNT);
778 __set_bit(EV_ABS, jd_scratch);
779 __set_bit(EV_KEY, jd_scratch);
780 __set_bit(EV_SYN, jd_scratch);
781 if (!bitmap_equal(jd_scratch, dev->evbit, EV_CNT))
782 return false;
783
784 bitmap_zero(jd_scratch, ABS_CNT);
785 __set_bit(ABS_X, jd_scratch);
786 __set_bit(ABS_Y, jd_scratch);
787 if (!bitmap_equal(dev->absbit, jd_scratch, ABS_CNT))
788 return false;
789
790 bitmap_zero(jd_scratch, KEY_CNT);
791 __set_bit(BTN_LEFT, jd_scratch);
792 __set_bit(BTN_RIGHT, jd_scratch);
793 __set_bit(BTN_MIDDLE, jd_scratch);
794
795 if (!bitmap_equal(dev->keybit, jd_scratch, KEY_CNT))
796 return false;
797
798 /*
799 * Amiga joystick (amijoy) historically uses left/middle/right
800 * button events.
801 */
802 if (dev->id.bustype == BUS_AMIGA)
803 return false;
804
805 return true;
806}
750 807
751static bool joydev_match(struct input_handler *handler, struct input_dev *dev) 808static bool joydev_match(struct input_handler *handler, struct input_dev *dev)
752{ 809{
@@ -758,6 +815,10 @@ static bool joydev_match(struct input_handler *handler, struct input_dev *dev)
758 if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_DIGI, dev->keybit)) 815 if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_DIGI, dev->keybit))
759 return false; 816 return false;
760 817
818 /* Avoid absolute mice */
819 if (joydev_dev_is_absolute_mouse(dev))
820 return false;
821
761 return true; 822 return true;
762} 823}
763 824
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 7462d2fc8cfe..d7820d1152d2 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -156,7 +156,7 @@ config MOUSE_PS2_VMMOUSE
156 Say Y here if you are running under control of VMware hypervisor 156 Say Y here if you are running under control of VMware hypervisor
157 (ESXi, Workstation or Fusion). Also make sure that when you enable 157 (ESXi, Workstation or Fusion). Also make sure that when you enable
158 this option, you remove the xf86-input-vmmouse user-space driver 158 this option, you remove the xf86-input-vmmouse user-space driver
159 or upgrade it to at least xf86-input-vmmouse 13.0.1, which doesn't 159 or upgrade it to at least xf86-input-vmmouse 13.1.0, which doesn't
160 load in the presence of an in-kernel vmmouse driver. 160 load in the presence of an in-kernel vmmouse driver.
161 161
162 If unsure, say N. 162 If unsure, say N.
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index e6708f6efb4d..7752bd59d4b7 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -941,6 +941,11 @@ static void alps_get_finger_coordinate_v7(struct input_mt_pos *mt,
941 case V7_PACKET_ID_TWO: 941 case V7_PACKET_ID_TWO:
942 mt[1].x &= ~0x000F; 942 mt[1].x &= ~0x000F;
943 mt[1].y |= 0x000F; 943 mt[1].y |= 0x000F;
944 /* Detect false-postive touches where x & y report max value */
945 if (mt[1].y == 0x7ff && mt[1].x == 0xff0) {
946 mt[1].x = 0;
947 /* y gets set to 0 at the end of this function */
948 }
944 break; 949 break;
945 950
946 case V7_PACKET_ID_MULTI: 951 case V7_PACKET_ID_MULTI:
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 991dc6b20a58..79363b687195 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -315,7 +315,7 @@ static void elantech_report_semi_mt_data(struct input_dev *dev,
315 unsigned int x2, unsigned int y2) 315 unsigned int x2, unsigned int y2)
316{ 316{
317 elantech_set_slot(dev, 0, num_fingers != 0, x1, y1); 317 elantech_set_slot(dev, 0, num_fingers != 0, x1, y1);
318 elantech_set_slot(dev, 1, num_fingers == 2, x2, y2); 318 elantech_set_slot(dev, 1, num_fingers >= 2, x2, y2);
319} 319}
320 320
321/* 321/*
diff --git a/drivers/input/touchscreen/stmpe-ts.c b/drivers/input/touchscreen/stmpe-ts.c
index 2d5ff86b343f..e4c31256a74d 100644
--- a/drivers/input/touchscreen/stmpe-ts.c
+++ b/drivers/input/touchscreen/stmpe-ts.c
@@ -164,7 +164,7 @@ static irqreturn_t stmpe_ts_handler(int irq, void *data)
164 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN); 164 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
165 165
166 /* start polling for touch_det to detect release */ 166 /* start polling for touch_det to detect release */
167 schedule_delayed_work(&ts->work, HZ / 50); 167 schedule_delayed_work(&ts->work, msecs_to_jiffies(50));
168 168
169 return IRQ_HANDLED; 169 return IRQ_HANDLED;
170} 170}
diff --git a/drivers/input/touchscreen/sx8654.c b/drivers/input/touchscreen/sx8654.c
index aecb9ad2e701..642f4a53de50 100644
--- a/drivers/input/touchscreen/sx8654.c
+++ b/drivers/input/touchscreen/sx8654.c
@@ -187,7 +187,7 @@ static int sx8654_probe(struct i2c_client *client,
187 return -ENOMEM; 187 return -ENOMEM;
188 188
189 input = devm_input_allocate_device(&client->dev); 189 input = devm_input_allocate_device(&client->dev);
190 if (!sx8654) 190 if (!input)
191 return -ENOMEM; 191 return -ENOMEM;
192 192
193 input->name = "SX8654 I2C Touchscreen"; 193 input->name = "SX8654 I2C Touchscreen";
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index a1cbba9056fd..3465faf1809e 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -266,6 +266,7 @@ static void put_pasid_state(struct pasid_state *pasid_state)
266 266
267static void put_pasid_state_wait(struct pasid_state *pasid_state) 267static void put_pasid_state_wait(struct pasid_state *pasid_state)
268{ 268{
269 atomic_dec(&pasid_state->count);
269 wait_event(pasid_state->wq, !atomic_read(&pasid_state->count)); 270 wait_event(pasid_state->wq, !atomic_read(&pasid_state->count));
270 free_pasid_state(pasid_state); 271 free_pasid_state(pasid_state);
271} 272}
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 9f7e1d34a32b..66a803b9dd3a 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -224,14 +224,7 @@
224#define RESUME_TERMINATE (1 << 0) 224#define RESUME_TERMINATE (1 << 0)
225 225
226#define TTBCR2_SEP_SHIFT 15 226#define TTBCR2_SEP_SHIFT 15
227#define TTBCR2_SEP_MASK 0x7 227#define TTBCR2_SEP_UPSTREAM (0x7 << TTBCR2_SEP_SHIFT)
228
229#define TTBCR2_ADDR_32 0
230#define TTBCR2_ADDR_36 1
231#define TTBCR2_ADDR_40 2
232#define TTBCR2_ADDR_42 3
233#define TTBCR2_ADDR_44 4
234#define TTBCR2_ADDR_48 5
235 228
236#define TTBRn_HI_ASID_SHIFT 16 229#define TTBRn_HI_ASID_SHIFT 16
237 230
@@ -793,26 +786,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
793 writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBCR); 786 writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBCR);
794 if (smmu->version > ARM_SMMU_V1) { 787 if (smmu->version > ARM_SMMU_V1) {
795 reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32; 788 reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
796 switch (smmu->va_size) { 789 reg |= TTBCR2_SEP_UPSTREAM;
797 case 32:
798 reg |= (TTBCR2_ADDR_32 << TTBCR2_SEP_SHIFT);
799 break;
800 case 36:
801 reg |= (TTBCR2_ADDR_36 << TTBCR2_SEP_SHIFT);
802 break;
803 case 40:
804 reg |= (TTBCR2_ADDR_40 << TTBCR2_SEP_SHIFT);
805 break;
806 case 42:
807 reg |= (TTBCR2_ADDR_42 << TTBCR2_SEP_SHIFT);
808 break;
809 case 44:
810 reg |= (TTBCR2_ADDR_44 << TTBCR2_SEP_SHIFT);
811 break;
812 case 48:
813 reg |= (TTBCR2_ADDR_48 << TTBCR2_SEP_SHIFT);
814 break;
815 }
816 writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBCR2); 790 writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBCR2);
817 } 791 }
818 } else { 792 } else {
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 4015560bf486..cab214544237 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1004,20 +1004,18 @@ static int rk_iommu_remove(struct platform_device *pdev)
1004 return 0; 1004 return 0;
1005} 1005}
1006 1006
1007#ifdef CONFIG_OF
1008static const struct of_device_id rk_iommu_dt_ids[] = { 1007static const struct of_device_id rk_iommu_dt_ids[] = {
1009 { .compatible = "rockchip,iommu" }, 1008 { .compatible = "rockchip,iommu" },
1010 { /* sentinel */ } 1009 { /* sentinel */ }
1011}; 1010};
1012MODULE_DEVICE_TABLE(of, rk_iommu_dt_ids); 1011MODULE_DEVICE_TABLE(of, rk_iommu_dt_ids);
1013#endif
1014 1012
1015static struct platform_driver rk_iommu_driver = { 1013static struct platform_driver rk_iommu_driver = {
1016 .probe = rk_iommu_probe, 1014 .probe = rk_iommu_probe,
1017 .remove = rk_iommu_remove, 1015 .remove = rk_iommu_remove,
1018 .driver = { 1016 .driver = {
1019 .name = "rk_iommu", 1017 .name = "rk_iommu",
1020 .of_match_table = of_match_ptr(rk_iommu_dt_ids), 1018 .of_match_table = rk_iommu_dt_ids,
1021 }, 1019 },
1022}; 1020};
1023 1021
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 9687f8afebff..1b7e155869f6 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -828,7 +828,14 @@ static int its_alloc_tables(struct its_node *its)
828 u64 typer = readq_relaxed(its->base + GITS_TYPER); 828 u64 typer = readq_relaxed(its->base + GITS_TYPER);
829 u32 ids = GITS_TYPER_DEVBITS(typer); 829 u32 ids = GITS_TYPER_DEVBITS(typer);
830 830
831 order = get_order((1UL << ids) * entry_size); 831 /*
832 * 'order' was initialized earlier to the default page
833 * granule of the the ITS. We can't have an allocation
834 * smaller than that. If the requested allocation
835 * is smaller, round up to the default page granule.
836 */
837 order = max(get_order((1UL << ids) * entry_size),
838 order);
832 if (order >= MAX_ORDER) { 839 if (order >= MAX_ORDER) {
833 order = MAX_ORDER - 1; 840 order = MAX_ORDER - 1;
834 pr_warn("%s: Device Table too large, reduce its page order to %u\n", 841 pr_warn("%s: Device Table too large, reduce its page order to %u\n",
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 7b315e385ba3..01999d74bd3a 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -82,19 +82,6 @@ static DEFINE_RAW_SPINLOCK(irq_controller_lock);
82#define NR_GIC_CPU_IF 8 82#define NR_GIC_CPU_IF 8
83static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly; 83static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
84 84
85/*
86 * Supported arch specific GIC irq extension.
87 * Default make them NULL.
88 */
89struct irq_chip gic_arch_extn = {
90 .irq_eoi = NULL,
91 .irq_mask = NULL,
92 .irq_unmask = NULL,
93 .irq_retrigger = NULL,
94 .irq_set_type = NULL,
95 .irq_set_wake = NULL,
96};
97
98#ifndef MAX_GIC_NR 85#ifndef MAX_GIC_NR
99#define MAX_GIC_NR 1 86#define MAX_GIC_NR 1
100#endif 87#endif
@@ -167,34 +154,16 @@ static int gic_peek_irq(struct irq_data *d, u32 offset)
167 154
168static void gic_mask_irq(struct irq_data *d) 155static void gic_mask_irq(struct irq_data *d)
169{ 156{
170 unsigned long flags;
171
172 raw_spin_lock_irqsave(&irq_controller_lock, flags);
173 gic_poke_irq(d, GIC_DIST_ENABLE_CLEAR); 157 gic_poke_irq(d, GIC_DIST_ENABLE_CLEAR);
174 if (gic_arch_extn.irq_mask)
175 gic_arch_extn.irq_mask(d);
176 raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
177} 158}
178 159
179static void gic_unmask_irq(struct irq_data *d) 160static void gic_unmask_irq(struct irq_data *d)
180{ 161{
181 unsigned long flags;
182
183 raw_spin_lock_irqsave(&irq_controller_lock, flags);
184 if (gic_arch_extn.irq_unmask)
185 gic_arch_extn.irq_unmask(d);
186 gic_poke_irq(d, GIC_DIST_ENABLE_SET); 162 gic_poke_irq(d, GIC_DIST_ENABLE_SET);
187 raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
188} 163}
189 164
190static void gic_eoi_irq(struct irq_data *d) 165static void gic_eoi_irq(struct irq_data *d)
191{ 166{
192 if (gic_arch_extn.irq_eoi) {
193 raw_spin_lock(&irq_controller_lock);
194 gic_arch_extn.irq_eoi(d);
195 raw_spin_unlock(&irq_controller_lock);
196 }
197
198 writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI); 167 writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI);
199} 168}
200 169
@@ -251,8 +220,6 @@ static int gic_set_type(struct irq_data *d, unsigned int type)
251{ 220{
252 void __iomem *base = gic_dist_base(d); 221 void __iomem *base = gic_dist_base(d);
253 unsigned int gicirq = gic_irq(d); 222 unsigned int gicirq = gic_irq(d);
254 unsigned long flags;
255 int ret;
256 223
257 /* Interrupt configuration for SGIs can't be changed */ 224 /* Interrupt configuration for SGIs can't be changed */
258 if (gicirq < 16) 225 if (gicirq < 16)
@@ -263,25 +230,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type)
263 type != IRQ_TYPE_EDGE_RISING) 230 type != IRQ_TYPE_EDGE_RISING)
264 return -EINVAL; 231 return -EINVAL;
265 232
266 raw_spin_lock_irqsave(&irq_controller_lock, flags); 233 return gic_configure_irq(gicirq, type, base, NULL);
267
268 if (gic_arch_extn.irq_set_type)
269 gic_arch_extn.irq_set_type(d, type);
270
271 ret = gic_configure_irq(gicirq, type, base, NULL);
272
273 raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
274
275 return ret;
276}
277
278static int gic_retrigger(struct irq_data *d)
279{
280 if (gic_arch_extn.irq_retrigger)
281 return gic_arch_extn.irq_retrigger(d);
282
283 /* the genirq layer expects 0 if we can't retrigger in hardware */
284 return 0;
285} 234}
286 235
287#ifdef CONFIG_SMP 236#ifdef CONFIG_SMP
@@ -312,21 +261,6 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
312} 261}
313#endif 262#endif
314 263
315#ifdef CONFIG_PM
316static int gic_set_wake(struct irq_data *d, unsigned int on)
317{
318 int ret = -ENXIO;
319
320 if (gic_arch_extn.irq_set_wake)
321 ret = gic_arch_extn.irq_set_wake(d, on);
322
323 return ret;
324}
325
326#else
327#define gic_set_wake NULL
328#endif
329
330static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) 264static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs)
331{ 265{
332 u32 irqstat, irqnr; 266 u32 irqstat, irqnr;
@@ -385,11 +319,9 @@ static struct irq_chip gic_chip = {
385 .irq_unmask = gic_unmask_irq, 319 .irq_unmask = gic_unmask_irq,
386 .irq_eoi = gic_eoi_irq, 320 .irq_eoi = gic_eoi_irq,
387 .irq_set_type = gic_set_type, 321 .irq_set_type = gic_set_type,
388 .irq_retrigger = gic_retrigger,
389#ifdef CONFIG_SMP 322#ifdef CONFIG_SMP
390 .irq_set_affinity = gic_set_affinity, 323 .irq_set_affinity = gic_set_affinity,
391#endif 324#endif
392 .irq_set_wake = gic_set_wake,
393 .irq_get_irqchip_state = gic_irq_get_irqchip_state, 325 .irq_get_irqchip_state = gic_irq_get_irqchip_state,
394 .irq_set_irqchip_state = gic_irq_set_irqchip_state, 326 .irq_set_irqchip_state = gic_irq_set_irqchip_state,
395}; 327};
@@ -1055,7 +987,6 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start,
1055 set_handle_irq(gic_handle_irq); 987 set_handle_irq(gic_handle_irq);
1056 } 988 }
1057 989
1058 gic_chip.flags |= gic_arch_extn.flags;
1059 gic_dist_init(gic); 990 gic_dist_init(gic);
1060 gic_cpu_init(gic); 991 gic_cpu_init(gic);
1061 gic_pm_init(gic); 992 gic_pm_init(gic);
diff --git a/drivers/irqchip/irq-tegra.c b/drivers/irqchip/irq-tegra.c
index 51c485d9a877..f67bbd80433e 100644
--- a/drivers/irqchip/irq-tegra.c
+++ b/drivers/irqchip/irq-tegra.c
@@ -264,7 +264,7 @@ static int tegra_ictlr_domain_alloc(struct irq_domain *domain,
264 264
265 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i, 265 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
266 &tegra_ictlr_chip, 266 &tegra_ictlr_chip,
267 &info->base[ictlr]); 267 info->base[ictlr]);
268 } 268 }
269 269
270 parent_args = *args; 270 parent_args = *args;
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
index 7dc93aa004c8..312ffd3d0017 100644
--- a/drivers/lguest/core.c
+++ b/drivers/lguest/core.c
@@ -173,7 +173,7 @@ static void unmap_switcher(void)
173bool lguest_address_ok(const struct lguest *lg, 173bool lguest_address_ok(const struct lguest *lg,
174 unsigned long addr, unsigned long len) 174 unsigned long addr, unsigned long len)
175{ 175{
176 return (addr+len) / PAGE_SIZE < lg->pfn_limit && (addr+len >= addr); 176 return addr+len <= lg->pfn_limit * PAGE_SIZE && (addr+len >= addr);
177} 177}
178 178
179/* 179/*
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 2bc56e2a3526..135a0907e9de 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -177,11 +177,16 @@ static struct md_rdev *next_active_rdev(struct md_rdev *rdev, struct mddev *mdde
177 * nr_pending is 0 and In_sync is clear, the entries we return will 177 * nr_pending is 0 and In_sync is clear, the entries we return will
178 * still be in the same position on the list when we re-enter 178 * still be in the same position on the list when we re-enter
179 * list_for_each_entry_continue_rcu. 179 * list_for_each_entry_continue_rcu.
180 *
181 * Note that if entered with 'rdev == NULL' to start at the
182 * beginning, we temporarily assign 'rdev' to an address which
183 * isn't really an rdev, but which can be used by
184 * list_for_each_entry_continue_rcu() to find the first entry.
180 */ 185 */
181 rcu_read_lock(); 186 rcu_read_lock();
182 if (rdev == NULL) 187 if (rdev == NULL)
183 /* start at the beginning */ 188 /* start at the beginning */
184 rdev = list_entry_rcu(&mddev->disks, struct md_rdev, same_set); 189 rdev = list_entry(&mddev->disks, struct md_rdev, same_set);
185 else { 190 else {
186 /* release the previous rdev and start from there. */ 191 /* release the previous rdev and start from there. */
187 rdev_dec_pending(rdev, mddev); 192 rdev_dec_pending(rdev, mddev);
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 9eeea196328a..5503e43e5f28 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -925,10 +925,11 @@ static int crypt_convert(struct crypt_config *cc,
925 925
926 switch (r) { 926 switch (r) {
927 /* async */ 927 /* async */
928 case -EINPROGRESS:
929 case -EBUSY: 928 case -EBUSY:
930 wait_for_completion(&ctx->restart); 929 wait_for_completion(&ctx->restart);
931 reinit_completion(&ctx->restart); 930 reinit_completion(&ctx->restart);
931 /* fall through*/
932 case -EINPROGRESS:
932 ctx->req = NULL; 933 ctx->req = NULL;
933 ctx->cc_sector++; 934 ctx->cc_sector++;
934 continue; 935 continue;
@@ -1345,8 +1346,10 @@ static void kcryptd_async_done(struct crypto_async_request *async_req,
1345 struct dm_crypt_io *io = container_of(ctx, struct dm_crypt_io, ctx); 1346 struct dm_crypt_io *io = container_of(ctx, struct dm_crypt_io, ctx);
1346 struct crypt_config *cc = io->cc; 1347 struct crypt_config *cc = io->cc;
1347 1348
1348 if (error == -EINPROGRESS) 1349 if (error == -EINPROGRESS) {
1350 complete(&ctx->restart);
1349 return; 1351 return;
1352 }
1350 1353
1351 if (!error && cc->iv_gen_ops && cc->iv_gen_ops->post) 1354 if (!error && cc->iv_gen_ops && cc->iv_gen_ops->post)
1352 error = cc->iv_gen_ops->post(cc, iv_of_dmreq(cc, dmreq), dmreq); 1355 error = cc->iv_gen_ops->post(cc, iv_of_dmreq(cc, dmreq), dmreq);
@@ -1357,15 +1360,12 @@ static void kcryptd_async_done(struct crypto_async_request *async_req,
1357 crypt_free_req(cc, req_of_dmreq(cc, dmreq), io->base_bio); 1360 crypt_free_req(cc, req_of_dmreq(cc, dmreq), io->base_bio);
1358 1361
1359 if (!atomic_dec_and_test(&ctx->cc_pending)) 1362 if (!atomic_dec_and_test(&ctx->cc_pending))
1360 goto done; 1363 return;
1361 1364
1362 if (bio_data_dir(io->base_bio) == READ) 1365 if (bio_data_dir(io->base_bio) == READ)
1363 kcryptd_crypt_read_done(io); 1366 kcryptd_crypt_read_done(io);
1364 else 1367 else
1365 kcryptd_crypt_write_io_submit(io, 1); 1368 kcryptd_crypt_write_io_submit(io, 1);
1366done:
1367 if (!completion_done(&ctx->restart))
1368 complete(&ctx->restart);
1369} 1369}
1370 1370
1371static void kcryptd_crypt(struct work_struct *work) 1371static void kcryptd_crypt(struct work_struct *work)
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index c8a18e4ee9dc..720ceeb7fa9b 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1298,21 +1298,22 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1298 goto err_unlock_md_type; 1298 goto err_unlock_md_type;
1299 } 1299 }
1300 1300
1301 if (dm_get_md_type(md) == DM_TYPE_NONE) 1301 if (dm_get_md_type(md) == DM_TYPE_NONE) {
1302 /* Initial table load: acquire type of table. */ 1302 /* Initial table load: acquire type of table. */
1303 dm_set_md_type(md, dm_table_get_type(t)); 1303 dm_set_md_type(md, dm_table_get_type(t));
1304 else if (dm_get_md_type(md) != dm_table_get_type(t)) { 1304
1305 /* setup md->queue to reflect md's type (may block) */
1306 r = dm_setup_md_queue(md);
1307 if (r) {
1308 DMWARN("unable to set up device queue for new table.");
1309 goto err_unlock_md_type;
1310 }
1311 } else if (dm_get_md_type(md) != dm_table_get_type(t)) {
1305 DMWARN("can't change device type after initial table load."); 1312 DMWARN("can't change device type after initial table load.");
1306 r = -EINVAL; 1313 r = -EINVAL;
1307 goto err_unlock_md_type; 1314 goto err_unlock_md_type;
1308 } 1315 }
1309 1316
1310 /* setup md->queue to reflect md's type (may block) */
1311 r = dm_setup_md_queue(md);
1312 if (r) {
1313 DMWARN("unable to set up device queue for new table.");
1314 goto err_unlock_md_type;
1315 }
1316 dm_unlock_md_type(md); 1317 dm_unlock_md_type(md);
1317 1318
1318 /* stage inactive table */ 1319 /* stage inactive table */
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 63953477a07c..eff7bdd7731d 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -429,9 +429,11 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
429 /* blk-mq request-based interface */ 429 /* blk-mq request-based interface */
430 *__clone = blk_get_request(bdev_get_queue(bdev), 430 *__clone = blk_get_request(bdev_get_queue(bdev),
431 rq_data_dir(rq), GFP_ATOMIC); 431 rq_data_dir(rq), GFP_ATOMIC);
432 if (IS_ERR(*__clone)) 432 if (IS_ERR(*__clone)) {
433 /* ENOMEM, requeue */ 433 /* ENOMEM, requeue */
434 clear_mapinfo(m, map_context);
434 return r; 435 return r;
436 }
435 (*__clone)->bio = (*__clone)->biotail = NULL; 437 (*__clone)->bio = (*__clone)->biotail = NULL;
436 (*__clone)->rq_disk = bdev->bd_disk; 438 (*__clone)->rq_disk = bdev->bd_disk;
437 (*__clone)->cmd_flags |= REQ_FAILFAST_TRANSPORT; 439 (*__clone)->cmd_flags |= REQ_FAILFAST_TRANSPORT;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index d9b00b8565c6..16ba55ad7089 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -820,6 +820,12 @@ void dm_consume_args(struct dm_arg_set *as, unsigned num_args)
820} 820}
821EXPORT_SYMBOL(dm_consume_args); 821EXPORT_SYMBOL(dm_consume_args);
822 822
823static bool __table_type_request_based(unsigned table_type)
824{
825 return (table_type == DM_TYPE_REQUEST_BASED ||
826 table_type == DM_TYPE_MQ_REQUEST_BASED);
827}
828
823static int dm_table_set_type(struct dm_table *t) 829static int dm_table_set_type(struct dm_table *t)
824{ 830{
825 unsigned i; 831 unsigned i;
@@ -852,8 +858,7 @@ static int dm_table_set_type(struct dm_table *t)
852 * Determine the type from the live device. 858 * Determine the type from the live device.
853 * Default to bio-based if device is new. 859 * Default to bio-based if device is new.
854 */ 860 */
855 if (live_md_type == DM_TYPE_REQUEST_BASED || 861 if (__table_type_request_based(live_md_type))
856 live_md_type == DM_TYPE_MQ_REQUEST_BASED)
857 request_based = 1; 862 request_based = 1;
858 else 863 else
859 bio_based = 1; 864 bio_based = 1;
@@ -903,7 +908,7 @@ static int dm_table_set_type(struct dm_table *t)
903 } 908 }
904 t->type = DM_TYPE_MQ_REQUEST_BASED; 909 t->type = DM_TYPE_MQ_REQUEST_BASED;
905 910
906 } else if (hybrid && list_empty(devices) && live_md_type != DM_TYPE_NONE) { 911 } else if (list_empty(devices) && __table_type_request_based(live_md_type)) {
907 /* inherit live MD type */ 912 /* inherit live MD type */
908 t->type = live_md_type; 913 t->type = live_md_type;
909 914
@@ -925,10 +930,7 @@ struct target_type *dm_table_get_immutable_target_type(struct dm_table *t)
925 930
926bool dm_table_request_based(struct dm_table *t) 931bool dm_table_request_based(struct dm_table *t)
927{ 932{
928 unsigned table_type = dm_table_get_type(t); 933 return __table_type_request_based(dm_table_get_type(t));
929
930 return (table_type == DM_TYPE_REQUEST_BASED ||
931 table_type == DM_TYPE_MQ_REQUEST_BASED);
932} 934}
933 935
934bool dm_table_mq_request_based(struct dm_table *t) 936bool dm_table_mq_request_based(struct dm_table *t)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f8c7ca3e8947..2caf492890d6 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1089,11 +1089,17 @@ static void free_rq_clone(struct request *clone)
1089 1089
1090 blk_rq_unprep_clone(clone); 1090 blk_rq_unprep_clone(clone);
1091 1091
1092 if (clone->q->mq_ops) 1092 if (md->type == DM_TYPE_MQ_REQUEST_BASED)
1093 /* stacked on blk-mq queue(s) */
1093 tio->ti->type->release_clone_rq(clone); 1094 tio->ti->type->release_clone_rq(clone);
1094 else if (!md->queue->mq_ops) 1095 else if (!md->queue->mq_ops)
1095 /* request_fn queue stacked on request_fn queue(s) */ 1096 /* request_fn queue stacked on request_fn queue(s) */
1096 free_clone_request(md, clone); 1097 free_clone_request(md, clone);
1098 /*
1099 * NOTE: for the blk-mq queue stacked on request_fn queue(s) case:
1100 * no need to call free_clone_request() because we leverage blk-mq by
1101 * allocating the clone at the end of the blk-mq pdu (see: clone_rq)
1102 */
1097 1103
1098 if (!md->queue->mq_ops) 1104 if (!md->queue->mq_ops)
1099 free_rq_tio(tio); 1105 free_rq_tio(tio);
@@ -1156,6 +1162,7 @@ static void old_requeue_request(struct request *rq)
1156 1162
1157 spin_lock_irqsave(q->queue_lock, flags); 1163 spin_lock_irqsave(q->queue_lock, flags);
1158 blk_requeue_request(q, rq); 1164 blk_requeue_request(q, rq);
1165 blk_run_queue_async(q);
1159 spin_unlock_irqrestore(q->queue_lock, flags); 1166 spin_unlock_irqrestore(q->queue_lock, flags);
1160} 1167}
1161 1168
@@ -1716,8 +1723,7 @@ static int dm_merge_bvec(struct request_queue *q,
1716 struct mapped_device *md = q->queuedata; 1723 struct mapped_device *md = q->queuedata;
1717 struct dm_table *map = dm_get_live_table_fast(md); 1724 struct dm_table *map = dm_get_live_table_fast(md);
1718 struct dm_target *ti; 1725 struct dm_target *ti;
1719 sector_t max_sectors; 1726 sector_t max_sectors, max_size = 0;
1720 int max_size = 0;
1721 1727
1722 if (unlikely(!map)) 1728 if (unlikely(!map))
1723 goto out; 1729 goto out;
@@ -1732,8 +1738,16 @@ static int dm_merge_bvec(struct request_queue *q,
1732 max_sectors = min(max_io_len(bvm->bi_sector, ti), 1738 max_sectors = min(max_io_len(bvm->bi_sector, ti),
1733 (sector_t) queue_max_sectors(q)); 1739 (sector_t) queue_max_sectors(q));
1734 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size; 1740 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
1735 if (unlikely(max_size < 0)) /* this shouldn't _ever_ happen */ 1741
1736 max_size = 0; 1742 /*
1743 * FIXME: this stop-gap fix _must_ be cleaned up (by passing a sector_t
1744 * to the targets' merge function since it holds sectors not bytes).
1745 * Just doing this as an interim fix for stable@ because the more
1746 * comprehensive cleanup of switching to sector_t will impact every
1747 * DM target that implements a ->merge hook.
1748 */
1749 if (max_size > INT_MAX)
1750 max_size = INT_MAX;
1737 1751
1738 /* 1752 /*
1739 * merge_bvec_fn() returns number of bytes 1753 * merge_bvec_fn() returns number of bytes
@@ -1741,7 +1755,7 @@ static int dm_merge_bvec(struct request_queue *q,
1741 * max is precomputed maximal io size 1755 * max is precomputed maximal io size
1742 */ 1756 */
1743 if (max_size && ti->type->merge) 1757 if (max_size && ti->type->merge)
1744 max_size = ti->type->merge(ti, bvm, biovec, max_size); 1758 max_size = ti->type->merge(ti, bvm, biovec, (int) max_size);
1745 /* 1759 /*
1746 * If the target doesn't support merge method and some of the devices 1760 * If the target doesn't support merge method and some of the devices
1747 * provided their merge_bvec method (we know this by looking for the 1761 * provided their merge_bvec method (we know this by looking for the
@@ -1963,8 +1977,8 @@ static int map_request(struct dm_rq_target_io *tio, struct request *rq,
1963 dm_kill_unmapped_request(rq, r); 1977 dm_kill_unmapped_request(rq, r);
1964 return r; 1978 return r;
1965 } 1979 }
1966 if (IS_ERR(clone)) 1980 if (r != DM_MAPIO_REMAPPED)
1967 return DM_MAPIO_REQUEUE; 1981 return r;
1968 if (setup_clone(clone, rq, tio, GFP_ATOMIC)) { 1982 if (setup_clone(clone, rq, tio, GFP_ATOMIC)) {
1969 /* -ENOMEM */ 1983 /* -ENOMEM */
1970 ti->type->release_clone_rq(clone); 1984 ti->type->release_clone_rq(clone);
@@ -2662,9 +2676,6 @@ static int dm_init_request_based_queue(struct mapped_device *md)
2662{ 2676{
2663 struct request_queue *q = NULL; 2677 struct request_queue *q = NULL;
2664 2678
2665 if (md->queue->elevator)
2666 return 0;
2667
2668 /* Fully initialize the queue */ 2679 /* Fully initialize the queue */
2669 q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL); 2680 q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL);
2670 if (!q) 2681 if (!q)
@@ -2748,13 +2759,15 @@ static int dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
2748 if (dm_table_get_type(map) == DM_TYPE_REQUEST_BASED) { 2759 if (dm_table_get_type(map) == DM_TYPE_REQUEST_BASED) {
2749 /* clone request is allocated at the end of the pdu */ 2760 /* clone request is allocated at the end of the pdu */
2750 tio->clone = (void *)blk_mq_rq_to_pdu(rq) + sizeof(struct dm_rq_target_io); 2761 tio->clone = (void *)blk_mq_rq_to_pdu(rq) + sizeof(struct dm_rq_target_io);
2751 if (!clone_rq(rq, md, tio, GFP_ATOMIC)) 2762 (void) clone_rq(rq, md, tio, GFP_ATOMIC);
2752 return BLK_MQ_RQ_QUEUE_BUSY;
2753 queue_kthread_work(&md->kworker, &tio->work); 2763 queue_kthread_work(&md->kworker, &tio->work);
2754 } else { 2764 } else {
2755 /* Direct call is fine since .queue_rq allows allocations */ 2765 /* Direct call is fine since .queue_rq allows allocations */
2756 if (map_request(tio, rq, md) == DM_MAPIO_REQUEUE) 2766 if (map_request(tio, rq, md) == DM_MAPIO_REQUEUE) {
2757 dm_requeue_unmapped_original_request(md, rq); 2767 /* Undo dm_start_request() before requeuing */
2768 rq_completed(md, rq_data_dir(rq), false);
2769 return BLK_MQ_RQ_QUEUE_BUSY;
2770 }
2758 } 2771 }
2759 2772
2760 return BLK_MQ_RQ_QUEUE_OK; 2773 return BLK_MQ_RQ_QUEUE_OK;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index d4f31e195e26..27506302eb7a 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4211,12 +4211,12 @@ action_store(struct mddev *mddev, const char *page, size_t len)
4211 if (!mddev->pers || !mddev->pers->sync_request) 4211 if (!mddev->pers || !mddev->pers->sync_request)
4212 return -EINVAL; 4212 return -EINVAL;
4213 4213
4214 if (cmd_match(page, "frozen"))
4215 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4216 else
4217 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4218 4214
4219 if (cmd_match(page, "idle") || cmd_match(page, "frozen")) { 4215 if (cmd_match(page, "idle") || cmd_match(page, "frozen")) {
4216 if (cmd_match(page, "frozen"))
4217 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4218 else
4219 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4220 flush_workqueue(md_misc_wq); 4220 flush_workqueue(md_misc_wq);
4221 if (mddev->sync_thread) { 4221 if (mddev->sync_thread) {
4222 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 4222 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
@@ -4229,16 +4229,17 @@ action_store(struct mddev *mddev, const char *page, size_t len)
4229 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) 4229 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
4230 return -EBUSY; 4230 return -EBUSY;
4231 else if (cmd_match(page, "resync")) 4231 else if (cmd_match(page, "resync"))
4232 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4232 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4233 else if (cmd_match(page, "recover")) { 4233 else if (cmd_match(page, "recover")) {
4234 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4234 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 4235 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
4235 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
4236 } else if (cmd_match(page, "reshape")) { 4236 } else if (cmd_match(page, "reshape")) {
4237 int err; 4237 int err;
4238 if (mddev->pers->start_reshape == NULL) 4238 if (mddev->pers->start_reshape == NULL)
4239 return -EINVAL; 4239 return -EINVAL;
4240 err = mddev_lock(mddev); 4240 err = mddev_lock(mddev);
4241 if (!err) { 4241 if (!err) {
4242 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4242 err = mddev->pers->start_reshape(mddev); 4243 err = mddev->pers->start_reshape(mddev);
4243 mddev_unlock(mddev); 4244 mddev_unlock(mddev);
4244 } 4245 }
@@ -4250,6 +4251,7 @@ action_store(struct mddev *mddev, const char *page, size_t len)
4250 set_bit(MD_RECOVERY_CHECK, &mddev->recovery); 4251 set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
4251 else if (!cmd_match(page, "repair")) 4252 else if (!cmd_match(page, "repair"))
4252 return -EINVAL; 4253 return -EINVAL;
4254 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4253 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); 4255 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
4254 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); 4256 set_bit(MD_RECOVERY_SYNC, &mddev->recovery);
4255 } 4257 }
@@ -4818,12 +4820,12 @@ static void md_free(struct kobject *ko)
4818 if (mddev->sysfs_state) 4820 if (mddev->sysfs_state)
4819 sysfs_put(mddev->sysfs_state); 4821 sysfs_put(mddev->sysfs_state);
4820 4822
4823 if (mddev->queue)
4824 blk_cleanup_queue(mddev->queue);
4821 if (mddev->gendisk) { 4825 if (mddev->gendisk) {
4822 del_gendisk(mddev->gendisk); 4826 del_gendisk(mddev->gendisk);
4823 put_disk(mddev->gendisk); 4827 put_disk(mddev->gendisk);
4824 } 4828 }
4825 if (mddev->queue)
4826 blk_cleanup_queue(mddev->queue);
4827 4829
4828 kfree(mddev); 4830 kfree(mddev);
4829} 4831}
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 2cb59a641cd2..efb654eb5399 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -188,8 +188,9 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
188 } 188 }
189 dev[j] = rdev1; 189 dev[j] = rdev1;
190 190
191 disk_stack_limits(mddev->gendisk, rdev1->bdev, 191 if (mddev->queue)
192 rdev1->data_offset << 9); 192 disk_stack_limits(mddev->gendisk, rdev1->bdev,
193 rdev1->data_offset << 9);
193 194
194 if (rdev1->bdev->bd_disk->queue->merge_bvec_fn) 195 if (rdev1->bdev->bd_disk->queue->merge_bvec_fn)
195 conf->has_merge_bvec = 1; 196 conf->has_merge_bvec = 1;
@@ -523,6 +524,9 @@ static void raid0_make_request(struct mddev *mddev, struct bio *bio)
523 ? (sector & (chunk_sects-1)) 524 ? (sector & (chunk_sects-1))
524 : sector_div(sector, chunk_sects)); 525 : sector_div(sector, chunk_sects));
525 526
527 /* Restore due to sector_div */
528 sector = bio->bi_iter.bi_sector;
529
526 if (sectors < bio_sectors(bio)) { 530 if (sectors < bio_sectors(bio)) {
527 split = bio_split(bio, sectors, GFP_NOIO, fs_bio_set); 531 split = bio_split(bio, sectors, GFP_NOIO, fs_bio_set);
528 bio_chain(split, bio); 532 bio_chain(split, bio);
@@ -530,7 +534,6 @@ static void raid0_make_request(struct mddev *mddev, struct bio *bio)
530 split = bio; 534 split = bio;
531 } 535 }
532 536
533 sector = bio->bi_iter.bi_sector;
534 zone = find_zone(mddev->private, &sector); 537 zone = find_zone(mddev->private, &sector);
535 tmp_dev = map_sector(mddev, zone, sector, &sector); 538 tmp_dev = map_sector(mddev, zone, sector, &sector);
536 split->bi_bdev = tmp_dev->bdev; 539 split->bi_bdev = tmp_dev->bdev;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 77dfd720aaa0..553d54b87052 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -749,6 +749,7 @@ static void unlock_two_stripes(struct stripe_head *sh1, struct stripe_head *sh2)
749static bool stripe_can_batch(struct stripe_head *sh) 749static bool stripe_can_batch(struct stripe_head *sh)
750{ 750{
751 return test_bit(STRIPE_BATCH_READY, &sh->state) && 751 return test_bit(STRIPE_BATCH_READY, &sh->state) &&
752 !test_bit(STRIPE_BITMAP_PENDING, &sh->state) &&
752 is_full_stripe_write(sh); 753 is_full_stripe_write(sh);
753} 754}
754 755
@@ -837,6 +838,15 @@ static void stripe_add_to_batch_list(struct r5conf *conf, struct stripe_head *sh
837 < IO_THRESHOLD) 838 < IO_THRESHOLD)
838 md_wakeup_thread(conf->mddev->thread); 839 md_wakeup_thread(conf->mddev->thread);
839 840
841 if (test_and_clear_bit(STRIPE_BIT_DELAY, &sh->state)) {
842 int seq = sh->bm_seq;
843 if (test_bit(STRIPE_BIT_DELAY, &sh->batch_head->state) &&
844 sh->batch_head->bm_seq > seq)
845 seq = sh->batch_head->bm_seq;
846 set_bit(STRIPE_BIT_DELAY, &sh->batch_head->state);
847 sh->batch_head->bm_seq = seq;
848 }
849
840 atomic_inc(&sh->count); 850 atomic_inc(&sh->count);
841unlock_out: 851unlock_out:
842 unlock_two_stripes(head, sh); 852 unlock_two_stripes(head, sh);
@@ -1078,9 +1088,6 @@ again:
1078 pr_debug("skip op %ld on disc %d for sector %llu\n", 1088 pr_debug("skip op %ld on disc %d for sector %llu\n",
1079 bi->bi_rw, i, (unsigned long long)sh->sector); 1089 bi->bi_rw, i, (unsigned long long)sh->sector);
1080 clear_bit(R5_LOCKED, &sh->dev[i].flags); 1090 clear_bit(R5_LOCKED, &sh->dev[i].flags);
1081 if (sh->batch_head)
1082 set_bit(STRIPE_BATCH_ERR,
1083 &sh->batch_head->state);
1084 set_bit(STRIPE_HANDLE, &sh->state); 1091 set_bit(STRIPE_HANDLE, &sh->state);
1085 } 1092 }
1086 1093
@@ -1825,7 +1832,7 @@ again:
1825 } else 1832 } else
1826 init_async_submit(&submit, 0, tx, NULL, NULL, 1833 init_async_submit(&submit, 0, tx, NULL, NULL,
1827 to_addr_conv(sh, percpu, j)); 1834 to_addr_conv(sh, percpu, j));
1828 async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); 1835 tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit);
1829 if (!last_stripe) { 1836 if (!last_stripe) {
1830 j++; 1837 j++;
1831 sh = list_first_entry(&sh->batch_list, struct stripe_head, 1838 sh = list_first_entry(&sh->batch_list, struct stripe_head,
@@ -1971,17 +1978,30 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
1971 put_cpu(); 1978 put_cpu();
1972} 1979}
1973 1980
1981static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp)
1982{
1983 struct stripe_head *sh;
1984
1985 sh = kmem_cache_zalloc(sc, gfp);
1986 if (sh) {
1987 spin_lock_init(&sh->stripe_lock);
1988 spin_lock_init(&sh->batch_lock);
1989 INIT_LIST_HEAD(&sh->batch_list);
1990 INIT_LIST_HEAD(&sh->lru);
1991 atomic_set(&sh->count, 1);
1992 }
1993 return sh;
1994}
1974static int grow_one_stripe(struct r5conf *conf, gfp_t gfp) 1995static int grow_one_stripe(struct r5conf *conf, gfp_t gfp)
1975{ 1996{
1976 struct stripe_head *sh; 1997 struct stripe_head *sh;
1977 sh = kmem_cache_zalloc(conf->slab_cache, gfp); 1998
1999 sh = alloc_stripe(conf->slab_cache, gfp);
1978 if (!sh) 2000 if (!sh)
1979 return 0; 2001 return 0;
1980 2002
1981 sh->raid_conf = conf; 2003 sh->raid_conf = conf;
1982 2004
1983 spin_lock_init(&sh->stripe_lock);
1984
1985 if (grow_buffers(sh, gfp)) { 2005 if (grow_buffers(sh, gfp)) {
1986 shrink_buffers(sh); 2006 shrink_buffers(sh);
1987 kmem_cache_free(conf->slab_cache, sh); 2007 kmem_cache_free(conf->slab_cache, sh);
@@ -1990,13 +2010,8 @@ static int grow_one_stripe(struct r5conf *conf, gfp_t gfp)
1990 sh->hash_lock_index = 2010 sh->hash_lock_index =
1991 conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS; 2011 conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS;
1992 /* we just created an active stripe so... */ 2012 /* we just created an active stripe so... */
1993 atomic_set(&sh->count, 1);
1994 atomic_inc(&conf->active_stripes); 2013 atomic_inc(&conf->active_stripes);
1995 INIT_LIST_HEAD(&sh->lru);
1996 2014
1997 spin_lock_init(&sh->batch_lock);
1998 INIT_LIST_HEAD(&sh->batch_list);
1999 sh->batch_head = NULL;
2000 release_stripe(sh); 2015 release_stripe(sh);
2001 conf->max_nr_stripes++; 2016 conf->max_nr_stripes++;
2002 return 1; 2017 return 1;
@@ -2060,6 +2075,35 @@ static struct flex_array *scribble_alloc(int num, int cnt, gfp_t flags)
2060 return ret; 2075 return ret;
2061} 2076}
2062 2077
2078static int resize_chunks(struct r5conf *conf, int new_disks, int new_sectors)
2079{
2080 unsigned long cpu;
2081 int err = 0;
2082
2083 mddev_suspend(conf->mddev);
2084 get_online_cpus();
2085 for_each_present_cpu(cpu) {
2086 struct raid5_percpu *percpu;
2087 struct flex_array *scribble;
2088
2089 percpu = per_cpu_ptr(conf->percpu, cpu);
2090 scribble = scribble_alloc(new_disks,
2091 new_sectors / STRIPE_SECTORS,
2092 GFP_NOIO);
2093
2094 if (scribble) {
2095 flex_array_free(percpu->scribble);
2096 percpu->scribble = scribble;
2097 } else {
2098 err = -ENOMEM;
2099 break;
2100 }
2101 }
2102 put_online_cpus();
2103 mddev_resume(conf->mddev);
2104 return err;
2105}
2106
2063static int resize_stripes(struct r5conf *conf, int newsize) 2107static int resize_stripes(struct r5conf *conf, int newsize)
2064{ 2108{
2065 /* Make all the stripes able to hold 'newsize' devices. 2109 /* Make all the stripes able to hold 'newsize' devices.
@@ -2088,7 +2132,6 @@ static int resize_stripes(struct r5conf *conf, int newsize)
2088 struct stripe_head *osh, *nsh; 2132 struct stripe_head *osh, *nsh;
2089 LIST_HEAD(newstripes); 2133 LIST_HEAD(newstripes);
2090 struct disk_info *ndisks; 2134 struct disk_info *ndisks;
2091 unsigned long cpu;
2092 int err; 2135 int err;
2093 struct kmem_cache *sc; 2136 struct kmem_cache *sc;
2094 int i; 2137 int i;
@@ -2109,13 +2152,11 @@ static int resize_stripes(struct r5conf *conf, int newsize)
2109 return -ENOMEM; 2152 return -ENOMEM;
2110 2153
2111 for (i = conf->max_nr_stripes; i; i--) { 2154 for (i = conf->max_nr_stripes; i; i--) {
2112 nsh = kmem_cache_zalloc(sc, GFP_KERNEL); 2155 nsh = alloc_stripe(sc, GFP_KERNEL);
2113 if (!nsh) 2156 if (!nsh)
2114 break; 2157 break;
2115 2158
2116 nsh->raid_conf = conf; 2159 nsh->raid_conf = conf;
2117 spin_lock_init(&nsh->stripe_lock);
2118
2119 list_add(&nsh->lru, &newstripes); 2160 list_add(&nsh->lru, &newstripes);
2120 } 2161 }
2121 if (i) { 2162 if (i) {
@@ -2142,13 +2183,11 @@ static int resize_stripes(struct r5conf *conf, int newsize)
2142 lock_device_hash_lock(conf, hash)); 2183 lock_device_hash_lock(conf, hash));
2143 osh = get_free_stripe(conf, hash); 2184 osh = get_free_stripe(conf, hash);
2144 unlock_device_hash_lock(conf, hash); 2185 unlock_device_hash_lock(conf, hash);
2145 atomic_set(&nsh->count, 1); 2186
2146 for(i=0; i<conf->pool_size; i++) { 2187 for(i=0; i<conf->pool_size; i++) {
2147 nsh->dev[i].page = osh->dev[i].page; 2188 nsh->dev[i].page = osh->dev[i].page;
2148 nsh->dev[i].orig_page = osh->dev[i].page; 2189 nsh->dev[i].orig_page = osh->dev[i].page;
2149 } 2190 }
2150 for( ; i<newsize; i++)
2151 nsh->dev[i].page = NULL;
2152 nsh->hash_lock_index = hash; 2191 nsh->hash_lock_index = hash;
2153 kmem_cache_free(conf->slab_cache, osh); 2192 kmem_cache_free(conf->slab_cache, osh);
2154 cnt++; 2193 cnt++;
@@ -2174,25 +2213,6 @@ static int resize_stripes(struct r5conf *conf, int newsize)
2174 } else 2213 } else
2175 err = -ENOMEM; 2214 err = -ENOMEM;
2176 2215
2177 get_online_cpus();
2178 for_each_present_cpu(cpu) {
2179 struct raid5_percpu *percpu;
2180 struct flex_array *scribble;
2181
2182 percpu = per_cpu_ptr(conf->percpu, cpu);
2183 scribble = scribble_alloc(newsize, conf->chunk_sectors /
2184 STRIPE_SECTORS, GFP_NOIO);
2185
2186 if (scribble) {
2187 flex_array_free(percpu->scribble);
2188 percpu->scribble = scribble;
2189 } else {
2190 err = -ENOMEM;
2191 break;
2192 }
2193 }
2194 put_online_cpus();
2195
2196 /* Step 4, return new stripes to service */ 2216 /* Step 4, return new stripes to service */
2197 while(!list_empty(&newstripes)) { 2217 while(!list_empty(&newstripes)) {
2198 nsh = list_entry(newstripes.next, struct stripe_head, lru); 2218 nsh = list_entry(newstripes.next, struct stripe_head, lru);
@@ -2212,7 +2232,8 @@ static int resize_stripes(struct r5conf *conf, int newsize)
2212 2232
2213 conf->slab_cache = sc; 2233 conf->slab_cache = sc;
2214 conf->active_name = 1-conf->active_name; 2234 conf->active_name = 1-conf->active_name;
2215 conf->pool_size = newsize; 2235 if (!err)
2236 conf->pool_size = newsize;
2216 return err; 2237 return err;
2217} 2238}
2218 2239
@@ -2434,7 +2455,7 @@ static void raid5_end_write_request(struct bio *bi, int error)
2434 } 2455 }
2435 rdev_dec_pending(rdev, conf->mddev); 2456 rdev_dec_pending(rdev, conf->mddev);
2436 2457
2437 if (sh->batch_head && !uptodate) 2458 if (sh->batch_head && !uptodate && !replacement)
2438 set_bit(STRIPE_BATCH_ERR, &sh->batch_head->state); 2459 set_bit(STRIPE_BATCH_ERR, &sh->batch_head->state);
2439 2460
2440 if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) 2461 if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags))
@@ -2976,14 +2997,32 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx,
2976 pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", 2997 pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
2977 (unsigned long long)(*bip)->bi_iter.bi_sector, 2998 (unsigned long long)(*bip)->bi_iter.bi_sector,
2978 (unsigned long long)sh->sector, dd_idx); 2999 (unsigned long long)sh->sector, dd_idx);
2979 spin_unlock_irq(&sh->stripe_lock);
2980 3000
2981 if (conf->mddev->bitmap && firstwrite) { 3001 if (conf->mddev->bitmap && firstwrite) {
3002 /* Cannot hold spinlock over bitmap_startwrite,
3003 * but must ensure this isn't added to a batch until
3004 * we have added to the bitmap and set bm_seq.
3005 * So set STRIPE_BITMAP_PENDING to prevent
3006 * batching.
3007 * If multiple add_stripe_bio() calls race here they
3008 * much all set STRIPE_BITMAP_PENDING. So only the first one
3009 * to complete "bitmap_startwrite" gets to set
3010 * STRIPE_BIT_DELAY. This is important as once a stripe
3011 * is added to a batch, STRIPE_BIT_DELAY cannot be changed
3012 * any more.
3013 */
3014 set_bit(STRIPE_BITMAP_PENDING, &sh->state);
3015 spin_unlock_irq(&sh->stripe_lock);
2982 bitmap_startwrite(conf->mddev->bitmap, sh->sector, 3016 bitmap_startwrite(conf->mddev->bitmap, sh->sector,
2983 STRIPE_SECTORS, 0); 3017 STRIPE_SECTORS, 0);
2984 sh->bm_seq = conf->seq_flush+1; 3018 spin_lock_irq(&sh->stripe_lock);
2985 set_bit(STRIPE_BIT_DELAY, &sh->state); 3019 clear_bit(STRIPE_BITMAP_PENDING, &sh->state);
3020 if (!sh->batch_head) {
3021 sh->bm_seq = conf->seq_flush+1;
3022 set_bit(STRIPE_BIT_DELAY, &sh->state);
3023 }
2986 } 3024 }
3025 spin_unlock_irq(&sh->stripe_lock);
2987 3026
2988 if (stripe_can_batch(sh)) 3027 if (stripe_can_batch(sh))
2989 stripe_add_to_batch_list(conf, sh); 3028 stripe_add_to_batch_list(conf, sh);
@@ -3278,7 +3317,9 @@ static int need_this_block(struct stripe_head *sh, struct stripe_head_state *s,
3278 /* reconstruct-write isn't being forced */ 3317 /* reconstruct-write isn't being forced */
3279 return 0; 3318 return 0;
3280 for (i = 0; i < s->failed; i++) { 3319 for (i = 0; i < s->failed; i++) {
3281 if (!test_bit(R5_UPTODATE, &fdev[i]->flags) && 3320 if (s->failed_num[i] != sh->pd_idx &&
3321 s->failed_num[i] != sh->qd_idx &&
3322 !test_bit(R5_UPTODATE, &fdev[i]->flags) &&
3282 !test_bit(R5_OVERWRITE, &fdev[i]->flags)) 3323 !test_bit(R5_OVERWRITE, &fdev[i]->flags))
3283 return 1; 3324 return 1;
3284 } 3325 }
@@ -3298,6 +3339,7 @@ static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s,
3298 */ 3339 */
3299 BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); 3340 BUG_ON(test_bit(R5_Wantcompute, &dev->flags));
3300 BUG_ON(test_bit(R5_Wantread, &dev->flags)); 3341 BUG_ON(test_bit(R5_Wantread, &dev->flags));
3342 BUG_ON(sh->batch_head);
3301 if ((s->uptodate == disks - 1) && 3343 if ((s->uptodate == disks - 1) &&
3302 (s->failed && (disk_idx == s->failed_num[0] || 3344 (s->failed && (disk_idx == s->failed_num[0] ||
3303 disk_idx == s->failed_num[1]))) { 3345 disk_idx == s->failed_num[1]))) {
@@ -3366,7 +3408,6 @@ static void handle_stripe_fill(struct stripe_head *sh,
3366{ 3408{
3367 int i; 3409 int i;
3368 3410
3369 BUG_ON(sh->batch_head);
3370 /* look for blocks to read/compute, skip this if a compute 3411 /* look for blocks to read/compute, skip this if a compute
3371 * is already in flight, or if the stripe contents are in the 3412 * is already in flight, or if the stripe contents are in the
3372 * midst of changing due to a write 3413 * midst of changing due to a write
@@ -3379,6 +3420,8 @@ static void handle_stripe_fill(struct stripe_head *sh,
3379 set_bit(STRIPE_HANDLE, &sh->state); 3420 set_bit(STRIPE_HANDLE, &sh->state);
3380} 3421}
3381 3422
3423static void break_stripe_batch_list(struct stripe_head *head_sh,
3424 unsigned long handle_flags);
3382/* handle_stripe_clean_event 3425/* handle_stripe_clean_event
3383 * any written block on an uptodate or failed drive can be returned. 3426 * any written block on an uptodate or failed drive can be returned.
3384 * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but 3427 * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but
@@ -3392,7 +3435,6 @@ static void handle_stripe_clean_event(struct r5conf *conf,
3392 int discard_pending = 0; 3435 int discard_pending = 0;
3393 struct stripe_head *head_sh = sh; 3436 struct stripe_head *head_sh = sh;
3394 bool do_endio = false; 3437 bool do_endio = false;
3395 int wakeup_nr = 0;
3396 3438
3397 for (i = disks; i--; ) 3439 for (i = disks; i--; )
3398 if (sh->dev[i].written) { 3440 if (sh->dev[i].written) {
@@ -3481,44 +3523,8 @@ unhash:
3481 if (atomic_dec_and_test(&conf->pending_full_writes)) 3523 if (atomic_dec_and_test(&conf->pending_full_writes))
3482 md_wakeup_thread(conf->mddev->thread); 3524 md_wakeup_thread(conf->mddev->thread);
3483 3525
3484 if (!head_sh->batch_head || !do_endio) 3526 if (head_sh->batch_head && do_endio)
3485 return; 3527 break_stripe_batch_list(head_sh, STRIPE_EXPAND_SYNC_FLAGS);
3486 for (i = 0; i < head_sh->disks; i++) {
3487 if (test_and_clear_bit(R5_Overlap, &head_sh->dev[i].flags))
3488 wakeup_nr++;
3489 }
3490 while (!list_empty(&head_sh->batch_list)) {
3491 int i;
3492 sh = list_first_entry(&head_sh->batch_list,
3493 struct stripe_head, batch_list);
3494 list_del_init(&sh->batch_list);
3495
3496 set_mask_bits(&sh->state, ~STRIPE_EXPAND_SYNC_FLAG,
3497 head_sh->state & ~((1 << STRIPE_ACTIVE) |
3498 (1 << STRIPE_PREREAD_ACTIVE) |
3499 STRIPE_EXPAND_SYNC_FLAG));
3500 sh->check_state = head_sh->check_state;
3501 sh->reconstruct_state = head_sh->reconstruct_state;
3502 for (i = 0; i < sh->disks; i++) {
3503 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
3504 wakeup_nr++;
3505 sh->dev[i].flags = head_sh->dev[i].flags;
3506 }
3507
3508 spin_lock_irq(&sh->stripe_lock);
3509 sh->batch_head = NULL;
3510 spin_unlock_irq(&sh->stripe_lock);
3511 if (sh->state & STRIPE_EXPAND_SYNC_FLAG)
3512 set_bit(STRIPE_HANDLE, &sh->state);
3513 release_stripe(sh);
3514 }
3515
3516 spin_lock_irq(&head_sh->stripe_lock);
3517 head_sh->batch_head = NULL;
3518 spin_unlock_irq(&head_sh->stripe_lock);
3519 wake_up_nr(&conf->wait_for_overlap, wakeup_nr);
3520 if (head_sh->state & STRIPE_EXPAND_SYNC_FLAG)
3521 set_bit(STRIPE_HANDLE, &head_sh->state);
3522} 3528}
3523 3529
3524static void handle_stripe_dirtying(struct r5conf *conf, 3530static void handle_stripe_dirtying(struct r5conf *conf,
@@ -4159,9 +4165,13 @@ static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s)
4159 4165
4160static int clear_batch_ready(struct stripe_head *sh) 4166static int clear_batch_ready(struct stripe_head *sh)
4161{ 4167{
4168 /* Return '1' if this is a member of batch, or
4169 * '0' if it is a lone stripe or a head which can now be
4170 * handled.
4171 */
4162 struct stripe_head *tmp; 4172 struct stripe_head *tmp;
4163 if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state)) 4173 if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state))
4164 return 0; 4174 return (sh->batch_head && sh->batch_head != sh);
4165 spin_lock(&sh->stripe_lock); 4175 spin_lock(&sh->stripe_lock);
4166 if (!sh->batch_head) { 4176 if (!sh->batch_head) {
4167 spin_unlock(&sh->stripe_lock); 4177 spin_unlock(&sh->stripe_lock);
@@ -4189,46 +4199,65 @@ static int clear_batch_ready(struct stripe_head *sh)
4189 return 0; 4199 return 0;
4190} 4200}
4191 4201
4192static void check_break_stripe_batch_list(struct stripe_head *sh) 4202static void break_stripe_batch_list(struct stripe_head *head_sh,
4203 unsigned long handle_flags)
4193{ 4204{
4194 struct stripe_head *head_sh, *next; 4205 struct stripe_head *sh, *next;
4195 int i; 4206 int i;
4207 int do_wakeup = 0;
4196 4208
4197 if (!test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state)) 4209 list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) {
4198 return;
4199 4210
4200 head_sh = sh;
4201 do {
4202 sh = list_first_entry(&sh->batch_list,
4203 struct stripe_head, batch_list);
4204 BUG_ON(sh == head_sh);
4205 } while (!test_bit(STRIPE_DEGRADED, &sh->state));
4206
4207 while (sh != head_sh) {
4208 next = list_first_entry(&sh->batch_list,
4209 struct stripe_head, batch_list);
4210 list_del_init(&sh->batch_list); 4211 list_del_init(&sh->batch_list);
4211 4212
4212 set_mask_bits(&sh->state, ~STRIPE_EXPAND_SYNC_FLAG, 4213 WARN_ON_ONCE(sh->state & ((1 << STRIPE_ACTIVE) |
4213 head_sh->state & ~((1 << STRIPE_ACTIVE) | 4214 (1 << STRIPE_SYNCING) |
4214 (1 << STRIPE_PREREAD_ACTIVE) | 4215 (1 << STRIPE_REPLACED) |
4215 (1 << STRIPE_DEGRADED) | 4216 (1 << STRIPE_PREREAD_ACTIVE) |
4216 STRIPE_EXPAND_SYNC_FLAG)); 4217 (1 << STRIPE_DELAYED) |
4218 (1 << STRIPE_BIT_DELAY) |
4219 (1 << STRIPE_FULL_WRITE) |
4220 (1 << STRIPE_BIOFILL_RUN) |
4221 (1 << STRIPE_COMPUTE_RUN) |
4222 (1 << STRIPE_OPS_REQ_PENDING) |
4223 (1 << STRIPE_DISCARD) |
4224 (1 << STRIPE_BATCH_READY) |
4225 (1 << STRIPE_BATCH_ERR) |
4226 (1 << STRIPE_BITMAP_PENDING)));
4227 WARN_ON_ONCE(head_sh->state & ((1 << STRIPE_DISCARD) |
4228 (1 << STRIPE_REPLACED)));
4229
4230 set_mask_bits(&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS |
4231 (1 << STRIPE_DEGRADED)),
4232 head_sh->state & (1 << STRIPE_INSYNC));
4233
4217 sh->check_state = head_sh->check_state; 4234 sh->check_state = head_sh->check_state;
4218 sh->reconstruct_state = head_sh->reconstruct_state; 4235 sh->reconstruct_state = head_sh->reconstruct_state;
4219 for (i = 0; i < sh->disks; i++) 4236 for (i = 0; i < sh->disks; i++) {
4237 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
4238 do_wakeup = 1;
4220 sh->dev[i].flags = head_sh->dev[i].flags & 4239 sh->dev[i].flags = head_sh->dev[i].flags &
4221 (~((1 << R5_WriteError) | (1 << R5_Overlap))); 4240 (~((1 << R5_WriteError) | (1 << R5_Overlap)));
4222 4241 }
4223 spin_lock_irq(&sh->stripe_lock); 4242 spin_lock_irq(&sh->stripe_lock);
4224 sh->batch_head = NULL; 4243 sh->batch_head = NULL;
4225 spin_unlock_irq(&sh->stripe_lock); 4244 spin_unlock_irq(&sh->stripe_lock);
4226 4245 if (handle_flags == 0 ||
4227 set_bit(STRIPE_HANDLE, &sh->state); 4246 sh->state & handle_flags)
4247 set_bit(STRIPE_HANDLE, &sh->state);
4228 release_stripe(sh); 4248 release_stripe(sh);
4229
4230 sh = next;
4231 } 4249 }
4250 spin_lock_irq(&head_sh->stripe_lock);
4251 head_sh->batch_head = NULL;
4252 spin_unlock_irq(&head_sh->stripe_lock);
4253 for (i = 0; i < head_sh->disks; i++)
4254 if (test_and_clear_bit(R5_Overlap, &head_sh->dev[i].flags))
4255 do_wakeup = 1;
4256 if (head_sh->state & handle_flags)
4257 set_bit(STRIPE_HANDLE, &head_sh->state);
4258
4259 if (do_wakeup)
4260 wake_up(&head_sh->raid_conf->wait_for_overlap);
4232} 4261}
4233 4262
4234static void handle_stripe(struct stripe_head *sh) 4263static void handle_stripe(struct stripe_head *sh)
@@ -4253,7 +4282,8 @@ static void handle_stripe(struct stripe_head *sh)
4253 return; 4282 return;
4254 } 4283 }
4255 4284
4256 check_break_stripe_batch_list(sh); 4285 if (test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state))
4286 break_stripe_batch_list(sh, 0);
4257 4287
4258 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) { 4288 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) {
4259 spin_lock(&sh->stripe_lock); 4289 spin_lock(&sh->stripe_lock);
@@ -4307,6 +4337,7 @@ static void handle_stripe(struct stripe_head *sh)
4307 if (s.failed > conf->max_degraded) { 4337 if (s.failed > conf->max_degraded) {
4308 sh->check_state = 0; 4338 sh->check_state = 0;
4309 sh->reconstruct_state = 0; 4339 sh->reconstruct_state = 0;
4340 break_stripe_batch_list(sh, 0);
4310 if (s.to_read+s.to_write+s.written) 4341 if (s.to_read+s.to_write+s.written)
4311 handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); 4342 handle_failed_stripe(conf, sh, &s, disks, &s.return_bi);
4312 if (s.syncing + s.replacing) 4343 if (s.syncing + s.replacing)
@@ -6221,8 +6252,11 @@ static int alloc_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu
6221 percpu->spare_page = alloc_page(GFP_KERNEL); 6252 percpu->spare_page = alloc_page(GFP_KERNEL);
6222 if (!percpu->scribble) 6253 if (!percpu->scribble)
6223 percpu->scribble = scribble_alloc(max(conf->raid_disks, 6254 percpu->scribble = scribble_alloc(max(conf->raid_disks,
6224 conf->previous_raid_disks), conf->chunk_sectors / 6255 conf->previous_raid_disks),
6225 STRIPE_SECTORS, GFP_KERNEL); 6256 max(conf->chunk_sectors,
6257 conf->prev_chunk_sectors)
6258 / STRIPE_SECTORS,
6259 GFP_KERNEL);
6226 6260
6227 if (!percpu->scribble || (conf->level == 6 && !percpu->spare_page)) { 6261 if (!percpu->scribble || (conf->level == 6 && !percpu->spare_page)) {
6228 free_scratch_buffer(conf, percpu); 6262 free_scratch_buffer(conf, percpu);
@@ -7198,6 +7232,15 @@ static int check_reshape(struct mddev *mddev)
7198 if (!check_stripe_cache(mddev)) 7232 if (!check_stripe_cache(mddev))
7199 return -ENOSPC; 7233 return -ENOSPC;
7200 7234
7235 if (mddev->new_chunk_sectors > mddev->chunk_sectors ||
7236 mddev->delta_disks > 0)
7237 if (resize_chunks(conf,
7238 conf->previous_raid_disks
7239 + max(0, mddev->delta_disks),
7240 max(mddev->new_chunk_sectors,
7241 mddev->chunk_sectors)
7242 ) < 0)
7243 return -ENOMEM;
7201 return resize_stripes(conf, (conf->previous_raid_disks 7244 return resize_stripes(conf, (conf->previous_raid_disks
7202 + mddev->delta_disks)); 7245 + mddev->delta_disks));
7203} 7246}
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 7dc0dd86074b..896d603ad0da 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -337,9 +337,12 @@ enum {
337 STRIPE_ON_RELEASE_LIST, 337 STRIPE_ON_RELEASE_LIST,
338 STRIPE_BATCH_READY, 338 STRIPE_BATCH_READY,
339 STRIPE_BATCH_ERR, 339 STRIPE_BATCH_ERR,
340 STRIPE_BITMAP_PENDING, /* Being added to bitmap, don't add
341 * to batch yet.
342 */
340}; 343};
341 344
342#define STRIPE_EXPAND_SYNC_FLAG \ 345#define STRIPE_EXPAND_SYNC_FLAGS \
343 ((1 << STRIPE_EXPAND_SOURCE) |\ 346 ((1 << STRIPE_EXPAND_SOURCE) |\
344 (1 << STRIPE_EXPAND_READY) |\ 347 (1 << STRIPE_EXPAND_READY) |\
345 (1 << STRIPE_EXPANDING) |\ 348 (1 << STRIPE_EXPANDING) |\
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 9c64b5d01c6a..110fd70c7326 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -116,8 +116,8 @@ static struct mcam_format_struct {
116 .planar = false, 116 .planar = false,
117 }, 117 },
118 { 118 {
119 .desc = "UYVY 4:2:2", 119 .desc = "YVYU 4:2:2",
120 .pixelformat = V4L2_PIX_FMT_UYVY, 120 .pixelformat = V4L2_PIX_FMT_YVYU,
121 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8, 121 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
122 .bpp = 2, 122 .bpp = 2,
123 .planar = false, 123 .planar = false,
@@ -748,7 +748,7 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
748 748
749 switch (fmt->pixelformat) { 749 switch (fmt->pixelformat) {
750 case V4L2_PIX_FMT_YUYV: 750 case V4L2_PIX_FMT_YUYV:
751 case V4L2_PIX_FMT_UYVY: 751 case V4L2_PIX_FMT_YVYU:
752 widthy = fmt->width * 2; 752 widthy = fmt->width * 2;
753 widthuv = 0; 753 widthuv = 0;
754 break; 754 break;
@@ -784,15 +784,15 @@ static void mcam_ctlr_image(struct mcam_camera *cam)
784 case V4L2_PIX_FMT_YUV420: 784 case V4L2_PIX_FMT_YUV420:
785 case V4L2_PIX_FMT_YVU420: 785 case V4L2_PIX_FMT_YVU420:
786 mcam_reg_write_mask(cam, REG_CTRL0, 786 mcam_reg_write_mask(cam, REG_CTRL0,
787 C0_DF_YUV | C0_YUV_420PL | C0_YUVE_YVYU, C0_DF_MASK); 787 C0_DF_YUV | C0_YUV_420PL | C0_YUVE_VYUY, C0_DF_MASK);
788 break; 788 break;
789 case V4L2_PIX_FMT_YUYV: 789 case V4L2_PIX_FMT_YUYV:
790 mcam_reg_write_mask(cam, REG_CTRL0, 790 mcam_reg_write_mask(cam, REG_CTRL0,
791 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_UYVY, C0_DF_MASK); 791 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_NOSWAP, C0_DF_MASK);
792 break; 792 break;
793 case V4L2_PIX_FMT_UYVY: 793 case V4L2_PIX_FMT_YVYU:
794 mcam_reg_write_mask(cam, REG_CTRL0, 794 mcam_reg_write_mask(cam, REG_CTRL0,
795 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_YUYV, C0_DF_MASK); 795 C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_SWAP24, C0_DF_MASK);
796 break; 796 break;
797 case V4L2_PIX_FMT_JPEG: 797 case V4L2_PIX_FMT_JPEG:
798 mcam_reg_write_mask(cam, REG_CTRL0, 798 mcam_reg_write_mask(cam, REG_CTRL0,
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index aa0c6eac254a..7ffdf4dbaf8c 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -330,10 +330,10 @@ int mccic_resume(struct mcam_camera *cam);
330#define C0_YUVE_YVYU 0x00010000 /* Y1CrY0Cb */ 330#define C0_YUVE_YVYU 0x00010000 /* Y1CrY0Cb */
331#define C0_YUVE_VYUY 0x00020000 /* CrY1CbY0 */ 331#define C0_YUVE_VYUY 0x00020000 /* CrY1CbY0 */
332#define C0_YUVE_UYVY 0x00030000 /* CbY1CrY0 */ 332#define C0_YUVE_UYVY 0x00030000 /* CbY1CrY0 */
333#define C0_YUVE_XYUV 0x00000000 /* 420: .YUV */ 333#define C0_YUVE_NOSWAP 0x00000000 /* no bytes swapping */
334#define C0_YUVE_XYVU 0x00010000 /* 420: .YVU */ 334#define C0_YUVE_SWAP13 0x00010000 /* swap byte 1 and 3 */
335#define C0_YUVE_XUVY 0x00020000 /* 420: .UVY */ 335#define C0_YUVE_SWAP24 0x00020000 /* swap byte 2 and 4 */
336#define C0_YUVE_XVUY 0x00030000 /* 420: .VUY */ 336#define C0_YUVE_SWAP1324 0x00030000 /* swap bytes 1&3 and 2&4 */
337/* Bayer bits 18,19 if needed */ 337/* Bayer bits 18,19 if needed */
338#define C0_EOF_VSYNC 0x00400000 /* Generate EOF by VSYNC */ 338#define C0_EOF_VSYNC 0x00400000 /* Generate EOF by VSYNC */
339#define C0_VEDGE_CTRL 0x00800000 /* Detect falling edge of VSYNC */ 339#define C0_VEDGE_CTRL 0x00800000 /* Detect falling edge of VSYNC */
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index 9351f64dee7b..6460f8e1b07f 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -135,6 +135,8 @@
135#define VIN_MAX_WIDTH 2048 135#define VIN_MAX_WIDTH 2048
136#define VIN_MAX_HEIGHT 2048 136#define VIN_MAX_HEIGHT 2048
137 137
138#define TIMEOUT_MS 100
139
138enum chip_id { 140enum chip_id {
139 RCAR_GEN2, 141 RCAR_GEN2,
140 RCAR_H1, 142 RCAR_H1,
@@ -820,7 +822,10 @@ static void rcar_vin_wait_stop_streaming(struct rcar_vin_priv *priv)
820 if (priv->state == STOPPING) { 822 if (priv->state == STOPPING) {
821 priv->request_to_stop = true; 823 priv->request_to_stop = true;
822 spin_unlock_irq(&priv->lock); 824 spin_unlock_irq(&priv->lock);
823 wait_for_completion(&priv->capture_stop); 825 if (!wait_for_completion_timeout(
826 &priv->capture_stop,
827 msecs_to_jiffies(TIMEOUT_MS)))
828 priv->state = STOPPED;
824 spin_lock_irq(&priv->lock); 829 spin_lock_irq(&priv->lock);
825 } 830 }
826 } 831 }
diff --git a/drivers/mfd/da9052-core.c b/drivers/mfd/da9052-core.c
index ae498b53ee40..46e3840c7a37 100644
--- a/drivers/mfd/da9052-core.c
+++ b/drivers/mfd/da9052-core.c
@@ -433,6 +433,10 @@ EXPORT_SYMBOL_GPL(da9052_adc_read_temp);
433static const struct mfd_cell da9052_subdev_info[] = { 433static const struct mfd_cell da9052_subdev_info[] = {
434 { 434 {
435 .name = "da9052-regulator", 435 .name = "da9052-regulator",
436 .id = 0,
437 },
438 {
439 .name = "da9052-regulator",
436 .id = 1, 440 .id = 1,
437 }, 441 },
438 { 442 {
@@ -484,10 +488,6 @@ static const struct mfd_cell da9052_subdev_info[] = {
484 .id = 13, 488 .id = 13,
485 }, 489 },
486 { 490 {
487 .name = "da9052-regulator",
488 .id = 14,
489 },
490 {
491 .name = "da9052-onkey", 491 .name = "da9052-onkey",
492 }, 492 },
493 { 493 {
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 2c25271f8c41..60f7141a6b02 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -1029,6 +1029,18 @@ static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
1029 md->reset_done &= ~type; 1029 md->reset_done &= ~type;
1030} 1030}
1031 1031
1032int mmc_access_rpmb(struct mmc_queue *mq)
1033{
1034 struct mmc_blk_data *md = mq->data;
1035 /*
1036 * If this is a RPMB partition access, return ture
1037 */
1038 if (md && md->part_type == EXT_CSD_PART_CONFIG_ACC_RPMB)
1039 return true;
1040
1041 return false;
1042}
1043
1032static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) 1044static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
1033{ 1045{
1034 struct mmc_blk_data *md = mq->data; 1046 struct mmc_blk_data *md = mq->data;
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 236d194c2883..8efa3684aef8 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -38,7 +38,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
38 return BLKPREP_KILL; 38 return BLKPREP_KILL;
39 } 39 }
40 40
41 if (mq && mmc_card_removed(mq->card)) 41 if (mq && (mmc_card_removed(mq->card) || mmc_access_rpmb(mq)))
42 return BLKPREP_KILL; 42 return BLKPREP_KILL;
43 43
44 req->cmd_flags |= REQ_DONTPREP; 44 req->cmd_flags |= REQ_DONTPREP;
diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h
index 5752d50049a3..99e6521e6169 100644
--- a/drivers/mmc/card/queue.h
+++ b/drivers/mmc/card/queue.h
@@ -73,4 +73,6 @@ extern void mmc_queue_bounce_post(struct mmc_queue_req *);
73extern int mmc_packed_init(struct mmc_queue *, struct mmc_card *); 73extern int mmc_packed_init(struct mmc_queue *, struct mmc_card *);
74extern void mmc_packed_clean(struct mmc_queue *); 74extern void mmc_packed_clean(struct mmc_queue *);
75 75
76extern int mmc_access_rpmb(struct mmc_queue *);
77
76#endif 78#endif
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index c296bc098fe2..92e7671426eb 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2651,6 +2651,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2651 switch (mode) { 2651 switch (mode) {
2652 case PM_HIBERNATION_PREPARE: 2652 case PM_HIBERNATION_PREPARE:
2653 case PM_SUSPEND_PREPARE: 2653 case PM_SUSPEND_PREPARE:
2654 case PM_RESTORE_PREPARE:
2654 spin_lock_irqsave(&host->lock, flags); 2655 spin_lock_irqsave(&host->lock, flags);
2655 host->rescan_disable = 1; 2656 host->rescan_disable = 1;
2656 spin_unlock_irqrestore(&host->lock, flags); 2657 spin_unlock_irqrestore(&host->lock, flags);
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 03d7c7521d97..9a39e0b7e583 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -1304,7 +1304,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1304 1304
1305 if (ios->clock) { 1305 if (ios->clock) {
1306 unsigned int clock_min = ~0U; 1306 unsigned int clock_min = ~0U;
1307 u32 clkdiv; 1307 int clkdiv;
1308 1308
1309 spin_lock_bh(&host->lock); 1309 spin_lock_bh(&host->lock);
1310 if (!host->mode_reg) { 1310 if (!host->mode_reg) {
@@ -1328,7 +1328,12 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1328 /* Calculate clock divider */ 1328 /* Calculate clock divider */
1329 if (host->caps.has_odd_clk_div) { 1329 if (host->caps.has_odd_clk_div) {
1330 clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2; 1330 clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2;
1331 if (clkdiv > 511) { 1331 if (clkdiv < 0) {
1332 dev_warn(&mmc->class_dev,
1333 "clock %u too fast; using %lu\n",
1334 clock_min, host->bus_hz / 2);
1335 clkdiv = 0;
1336 } else if (clkdiv > 511) {
1332 dev_warn(&mmc->class_dev, 1337 dev_warn(&mmc->class_dev,
1333 "clock %u too slow; using %lu\n", 1338 "clock %u too slow; using %lu\n",
1334 clock_min, host->bus_hz / (511 + 2)); 1339 clock_min, host->bus_hz / (511 + 2));
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 38b29265cc7c..5f5adafb253a 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -589,9 +589,11 @@ static int dw_mci_idmac_init(struct dw_mci *host)
589 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); 589 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
590 590
591 /* Forward link the descriptor list */ 591 /* Forward link the descriptor list */
592 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) 592 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) {
593 p->des3 = cpu_to_le32(host->sg_dma + 593 p->des3 = cpu_to_le32(host->sg_dma +
594 (sizeof(struct idmac_desc) * (i + 1))); 594 (sizeof(struct idmac_desc) * (i + 1)));
595 p->des1 = 0;
596 }
595 597
596 /* Set the last descriptor as the end-of-ring descriptor */ 598 /* Set the last descriptor as the end-of-ring descriptor */
597 p->des3 = cpu_to_le32(host->sg_dma); 599 p->des3 = cpu_to_le32(host->sg_dma);
@@ -1300,7 +1302,8 @@ static int dw_mci_get_cd(struct mmc_host *mmc)
1300 int gpio_cd = mmc_gpio_get_cd(mmc); 1302 int gpio_cd = mmc_gpio_get_cd(mmc);
1301 1303
1302 /* Use platform get_cd function, else try onboard card detect */ 1304 /* Use platform get_cd function, else try onboard card detect */
1303 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) 1305 if ((brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION) ||
1306 (mmc->caps & MMC_CAP_NONREMOVABLE))
1304 present = 1; 1307 present = 1;
1305 else if (!IS_ERR_VALUE(gpio_cd)) 1308 else if (!IS_ERR_VALUE(gpio_cd))
1306 present = gpio_cd; 1309 present = gpio_cd;
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 2b6ef6bd5d5f..7eff087cf515 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -1408,7 +1408,7 @@ static int sh_mmcif_probe(struct platform_device *pdev)
1408 host = mmc_priv(mmc); 1408 host = mmc_priv(mmc);
1409 host->mmc = mmc; 1409 host->mmc = mmc;
1410 host->addr = reg; 1410 host->addr = reg;
1411 host->timeout = msecs_to_jiffies(1000); 1411 host->timeout = msecs_to_jiffies(10000);
1412 host->ccs_enable = !pd || !pd->ccs_unsupported; 1412 host->ccs_enable = !pd || !pd->ccs_unsupported;
1413 host->clk_ctrl2_enable = pd && pd->clk_ctrl2_present; 1413 host->clk_ctrl2_enable = pd && pd->clk_ctrl2_present;
1414 1414
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 7c8b1694a134..3af137f49ac9 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -223,7 +223,7 @@ static int m25p_probe(struct spi_device *spi)
223 */ 223 */
224 if (data && data->type) 224 if (data && data->type)
225 flash_name = data->type; 225 flash_name = data->type;
226 else if (!strcmp(spi->modalias, "nor-jedec")) 226 else if (!strcmp(spi->modalias, "spi-nor"))
227 flash_name = NULL; /* auto-detect */ 227 flash_name = NULL; /* auto-detect */
228 else 228 else
229 flash_name = spi->modalias; 229 flash_name = spi->modalias;
@@ -255,7 +255,7 @@ static int m25p_remove(struct spi_device *spi)
255 * since most of these flash are compatible to some extent, and their 255 * since most of these flash are compatible to some extent, and their
256 * differences can often be differentiated by the JEDEC read-ID command, we 256 * differences can often be differentiated by the JEDEC read-ID command, we
257 * encourage new users to add support to the spi-nor library, and simply bind 257 * encourage new users to add support to the spi-nor library, and simply bind
258 * against a generic string here (e.g., "nor-jedec"). 258 * against a generic string here (e.g., "jedec,spi-nor").
259 * 259 *
260 * Many flash names are kept here in this list (as well as in spi-nor.c) to 260 * Many flash names are kept here in this list (as well as in spi-nor.c) to
261 * keep them available as module aliases for existing platforms. 261 * keep them available as module aliases for existing platforms.
@@ -305,7 +305,7 @@ static const struct spi_device_id m25p_ids[] = {
305 * Generic support for SPI NOR that can be identified by the JEDEC READ 305 * Generic support for SPI NOR that can be identified by the JEDEC READ
306 * ID opcode (0x9F). Use this, if possible. 306 * ID opcode (0x9F). Use this, if possible.
307 */ 307 */
308 {"nor-jedec"}, 308 {"spi-nor"},
309 { }, 309 { },
310}; 310};
311MODULE_DEVICE_TABLE(spi, m25p_ids); 311MODULE_DEVICE_TABLE(spi, m25p_ids);
diff --git a/drivers/mtd/tests/readtest.c b/drivers/mtd/tests/readtest.c
index a3196b750a22..58df07acdbdb 100644
--- a/drivers/mtd/tests/readtest.c
+++ b/drivers/mtd/tests/readtest.c
@@ -191,9 +191,11 @@ static int __init mtd_readtest_init(void)
191 err = ret; 191 err = ret;
192 } 192 }
193 193
194 err = mtdtest_relax(); 194 ret = mtdtest_relax();
195 if (err) 195 if (ret) {
196 err = ret;
196 goto out; 197 goto out;
198 }
197 } 199 }
198 200
199 if (err) 201 if (err)
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index db2c05b6fe7f..c9eb78f10a0d 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -310,6 +310,8 @@ static void ubiblock_do_work(struct work_struct *work)
310 blk_rq_map_sg(req->q, req, pdu->usgl.sg); 310 blk_rq_map_sg(req->q, req, pdu->usgl.sg);
311 311
312 ret = ubiblock_read(pdu); 312 ret = ubiblock_read(pdu);
313 rq_flush_dcache_pages(req);
314
313 blk_mq_end_request(req, ret); 315 blk_mq_end_request(req, ret);
314} 316}
315 317
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 78dde56ae6e6..d5fe5d5f490f 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -82,6 +82,8 @@
82#include <net/bond_3ad.h> 82#include <net/bond_3ad.h>
83#include <net/bond_alb.h> 83#include <net/bond_alb.h>
84 84
85#include "bonding_priv.h"
86
85/*---------------------------- Module parameters ----------------------------*/ 87/*---------------------------- Module parameters ----------------------------*/
86 88
87/* monitor all links that often (in milliseconds). <=0 disables monitoring */ 89/* monitor all links that often (in milliseconds). <=0 disables monitoring */
@@ -4542,6 +4544,8 @@ unsigned int bond_get_num_tx_queues(void)
4542int bond_create(struct net *net, const char *name) 4544int bond_create(struct net *net, const char *name)
4543{ 4545{
4544 struct net_device *bond_dev; 4546 struct net_device *bond_dev;
4547 struct bonding *bond;
4548 struct alb_bond_info *bond_info;
4545 int res; 4549 int res;
4546 4550
4547 rtnl_lock(); 4551 rtnl_lock();
@@ -4555,6 +4559,14 @@ int bond_create(struct net *net, const char *name)
4555 return -ENOMEM; 4559 return -ENOMEM;
4556 } 4560 }
4557 4561
4562 /*
4563 * Initialize rx_hashtbl_used_head to RLB_NULL_INDEX.
4564 * It is set to 0 by default which is wrong.
4565 */
4566 bond = netdev_priv(bond_dev);
4567 bond_info = &(BOND_ALB_INFO(bond));
4568 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX;
4569
4558 dev_net_set(bond_dev, net); 4570 dev_net_set(bond_dev, net);
4559 bond_dev->rtnl_link_ops = &bond_link_ops; 4571 bond_dev->rtnl_link_ops = &bond_link_ops;
4560 4572
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 4df28943d222..e8d3c1d35453 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -624,7 +624,7 @@ int __bond_opt_set(struct bonding *bond,
624out: 624out:
625 if (ret) 625 if (ret)
626 bond_opt_error_interpret(bond, opt, ret, val); 626 bond_opt_error_interpret(bond, opt, ret, val);
627 else 627 else if (bond->dev->reg_state == NETREG_REGISTERED)
628 call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev); 628 call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev);
629 629
630 return ret; 630 return ret;
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index 62694cfc05b6..b20b35acb47d 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -4,6 +4,7 @@
4#include <net/netns/generic.h> 4#include <net/netns/generic.h>
5#include <net/bonding.h> 5#include <net/bonding.h>
6 6
7#include "bonding_priv.h"
7 8
8static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) 9static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
9 __acquires(RCU) 10 __acquires(RCU)
diff --git a/drivers/net/bonding/bonding_priv.h b/drivers/net/bonding/bonding_priv.h
new file mode 100644
index 000000000000..5a4d81a9437c
--- /dev/null
+++ b/drivers/net/bonding/bonding_priv.h
@@ -0,0 +1,25 @@
1/*
2 * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
3 *
4 * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
5 * NCM: Network and Communications Management, Inc.
6 *
7 * BUT, I'm the one who modified it for ethernet, so:
8 * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
9 *
10 * This software may be used and distributed according to the terms
11 * of the GNU Public License, incorporated herein by reference.
12 *
13 */
14
15#ifndef _BONDING_PRIV_H
16#define _BONDING_PRIV_H
17
18#define DRV_VERSION "3.7.1"
19#define DRV_RELDATE "April 27, 2011"
20#define DRV_NAME "bonding"
21#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
22
23#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
24
25#endif
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 58808f651452..e8c96b8e86f4 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -112,7 +112,7 @@ config PCH_CAN
112 112
113config CAN_GRCAN 113config CAN_GRCAN
114 tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices" 114 tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices"
115 depends on OF 115 depends on OF && HAS_DMA
116 ---help--- 116 ---help---
117 Say Y here if you want to use Aeroflex Gaisler GRCAN or GRHCAN. 117 Say Y here if you want to use Aeroflex Gaisler GRCAN or GRHCAN.
118 Note that the driver supports little endian, even though little 118 Note that the driver supports little endian, even though little
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 4643914859b2..8b17a9065b0b 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1102,7 +1102,7 @@ static void kvaser_usb_rx_can_err(const struct kvaser_usb_net_priv *priv,
1102 1102
1103 if (msg->u.rx_can_header.flag & (MSG_FLAG_ERROR_FRAME | 1103 if (msg->u.rx_can_header.flag & (MSG_FLAG_ERROR_FRAME |
1104 MSG_FLAG_NERR)) { 1104 MSG_FLAG_NERR)) {
1105 netdev_err(priv->netdev, "Unknow error (flags: 0x%02x)\n", 1105 netdev_err(priv->netdev, "Unknown error (flags: 0x%02x)\n",
1106 msg->u.rx_can_header.flag); 1106 msg->u.rx_can_header.flag);
1107 1107
1108 stats->rx_errors++; 1108 stats->rx_errors++;
diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 6bddfe062b51..fc55e8e0351d 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -509,10 +509,11 @@ static int xcan_rx(struct net_device *ndev)
509 cf->can_id |= CAN_RTR_FLAG; 509 cf->can_id |= CAN_RTR_FLAG;
510 } 510 }
511 511
512 if (!(id_xcan & XCAN_IDR_SRR_MASK)) { 512 /* DW1/DW2 must always be read to remove message from RXFIFO */
513 data[0] = priv->read_reg(priv, XCAN_RXFIFO_DW1_OFFSET); 513 data[0] = priv->read_reg(priv, XCAN_RXFIFO_DW1_OFFSET);
514 data[1] = priv->read_reg(priv, XCAN_RXFIFO_DW2_OFFSET); 514 data[1] = priv->read_reg(priv, XCAN_RXFIFO_DW2_OFFSET);
515 515
516 if (!(cf->can_id & CAN_RTR_FLAG)) {
516 /* Change Xilinx CAN data format to socketCAN data format */ 517 /* Change Xilinx CAN data format to socketCAN data format */
517 if (cf->can_dlc > 0) 518 if (cf->can_dlc > 0)
518 *(__be32 *)(cf->data) = cpu_to_be32(data[0]); 519 *(__be32 *)(cf->data) = cpu_to_be32(data[0]);
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index af639ab4c55b..cf309aa92802 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -1469,6 +1469,9 @@ static void __exit mv88e6xxx_cleanup(void)
1469#if IS_ENABLED(CONFIG_NET_DSA_MV88E6171) 1469#if IS_ENABLED(CONFIG_NET_DSA_MV88E6171)
1470 unregister_switch_driver(&mv88e6171_switch_driver); 1470 unregister_switch_driver(&mv88e6171_switch_driver);
1471#endif 1471#endif
1472#if IS_ENABLED(CONFIG_NET_DSA_MV88E6352)
1473 unregister_switch_driver(&mv88e6352_switch_driver);
1474#endif
1472#if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65) 1475#if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65)
1473 unregister_switch_driver(&mv88e6123_61_65_switch_driver); 1476 unregister_switch_driver(&mv88e6123_61_65_switch_driver);
1474#endif 1477#endif
diff --git a/drivers/net/ethernet/8390/etherh.c b/drivers/net/ethernet/8390/etherh.c
index b36ee9e0d220..d686b9cac29f 100644
--- a/drivers/net/ethernet/8390/etherh.c
+++ b/drivers/net/ethernet/8390/etherh.c
@@ -523,7 +523,7 @@ static int etherh_addr(char *addr, struct expansion_card *ec)
523 char *s; 523 char *s;
524 524
525 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) { 525 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
526 printk(KERN_ERR "%s: unable to read podule description string\n", 526 printk(KERN_ERR "%s: unable to read module description string\n",
527 dev_name(&ec->dev)); 527 dev_name(&ec->dev));
528 goto no_addr; 528 goto no_addr;
529 } 529 }
diff --git a/drivers/net/ethernet/altera/altera_msgdmahw.h b/drivers/net/ethernet/altera/altera_msgdmahw.h
index eba070f16782..89cd11d86642 100644
--- a/drivers/net/ethernet/altera/altera_msgdmahw.h
+++ b/drivers/net/ethernet/altera/altera_msgdmahw.h
@@ -58,15 +58,12 @@ struct msgdma_extended_desc {
58/* Tx buffer control flags 58/* Tx buffer control flags
59 */ 59 */
60#define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \ 60#define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \
61 MSGDMA_DESC_CTL_TR_ERR_IRQ | \
62 MSGDMA_DESC_CTL_GO) 61 MSGDMA_DESC_CTL_GO)
63 62
64#define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 63#define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_GO)
65 MSGDMA_DESC_CTL_GO)
66 64
67#define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \ 65#define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \
68 MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 66 MSGDMA_DESC_CTL_TR_COMP_IRQ | \
69 MSGDMA_DESC_CTL_TR_ERR_IRQ | \
70 MSGDMA_DESC_CTL_GO) 67 MSGDMA_DESC_CTL_GO)
71 68
72#define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \ 69#define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 90a76306ad0f..da48e66377b5 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -391,6 +391,12 @@ static int tse_rx(struct altera_tse_private *priv, int limit)
391 "RCV pktstatus %08X pktlength %08X\n", 391 "RCV pktstatus %08X pktlength %08X\n",
392 pktstatus, pktlength); 392 pktstatus, pktlength);
393 393
394 /* DMA trasfer from TSE starts with 2 aditional bytes for
395 * IP payload alignment. Status returned by get_rx_status()
396 * contains DMA transfer length. Packet is 2 bytes shorter.
397 */
398 pktlength -= 2;
399
394 count++; 400 count++;
395 next_entry = (++priv->rx_cons) % priv->rx_ring_size; 401 next_entry = (++priv->rx_cons) % priv->rx_ring_size;
396 402
@@ -777,6 +783,8 @@ static int init_phy(struct net_device *dev)
777 struct altera_tse_private *priv = netdev_priv(dev); 783 struct altera_tse_private *priv = netdev_priv(dev);
778 struct phy_device *phydev; 784 struct phy_device *phydev;
779 struct device_node *phynode; 785 struct device_node *phynode;
786 bool fixed_link = false;
787 int rc = 0;
780 788
781 /* Avoid init phy in case of no phy present */ 789 /* Avoid init phy in case of no phy present */
782 if (!priv->phy_iface) 790 if (!priv->phy_iface)
@@ -789,13 +797,32 @@ static int init_phy(struct net_device *dev)
789 phynode = of_parse_phandle(priv->device->of_node, "phy-handle", 0); 797 phynode = of_parse_phandle(priv->device->of_node, "phy-handle", 0);
790 798
791 if (!phynode) { 799 if (!phynode) {
792 netdev_dbg(dev, "no phy-handle found\n"); 800 /* check if a fixed-link is defined in device-tree */
793 if (!priv->mdio) { 801 if (of_phy_is_fixed_link(priv->device->of_node)) {
794 netdev_err(dev, 802 rc = of_phy_register_fixed_link(priv->device->of_node);
795 "No phy-handle nor local mdio specified\n"); 803 if (rc < 0) {
796 return -ENODEV; 804 netdev_err(dev, "cannot register fixed PHY\n");
805 return rc;
806 }
807
808 /* In the case of a fixed PHY, the DT node associated
809 * to the PHY is the Ethernet MAC DT node.
810 */
811 phynode = of_node_get(priv->device->of_node);
812 fixed_link = true;
813
814 netdev_dbg(dev, "fixed-link detected\n");
815 phydev = of_phy_connect(dev, phynode,
816 &altera_tse_adjust_link,
817 0, priv->phy_iface);
818 } else {
819 netdev_dbg(dev, "no phy-handle found\n");
820 if (!priv->mdio) {
821 netdev_err(dev, "No phy-handle nor local mdio specified\n");
822 return -ENODEV;
823 }
824 phydev = connect_local_phy(dev);
797 } 825 }
798 phydev = connect_local_phy(dev);
799 } else { 826 } else {
800 netdev_dbg(dev, "phy-handle found\n"); 827 netdev_dbg(dev, "phy-handle found\n");
801 phydev = of_phy_connect(dev, phynode, 828 phydev = of_phy_connect(dev, phynode,
@@ -819,10 +846,10 @@ static int init_phy(struct net_device *dev)
819 /* Broken HW is sometimes missing the pull-up resistor on the 846 /* Broken HW is sometimes missing the pull-up resistor on the
820 * MDIO line, which results in reads to non-existent devices returning 847 * MDIO line, which results in reads to non-existent devices returning
821 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent 848 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
822 * device as well. 849 * device as well. If a fixed-link is used the phy_id is always 0.
823 * Note: phydev->phy_id is the result of reading the UID PHY registers. 850 * Note: phydev->phy_id is the result of reading the UID PHY registers.
824 */ 851 */
825 if (phydev->phy_id == 0) { 852 if ((phydev->phy_id == 0) && !fixed_link) {
826 netdev_err(dev, "Bad PHY UID 0x%08x\n", phydev->phy_id); 853 netdev_err(dev, "Bad PHY UID 0x%08x\n", phydev->phy_id);
827 phy_disconnect(phydev); 854 phy_disconnect(phydev);
828 return -ENODEV; 855 return -ENODEV;
diff --git a/drivers/net/ethernet/amd/Kconfig b/drivers/net/ethernet/amd/Kconfig
index c638c85f3954..426916036151 100644
--- a/drivers/net/ethernet/amd/Kconfig
+++ b/drivers/net/ethernet/amd/Kconfig
@@ -179,7 +179,8 @@ config SUNLANCE
179 179
180config AMD_XGBE 180config AMD_XGBE
181 tristate "AMD 10GbE Ethernet driver" 181 tristate "AMD 10GbE Ethernet driver"
182 depends on (OF_NET || ACPI) && HAS_IOMEM 182 depends on (OF_NET || ACPI) && HAS_IOMEM && HAS_DMA
183 depends on ARM64 || COMPILE_TEST
183 select PHYLIB 184 select PHYLIB
184 select AMD_XGBE_PHY 185 select AMD_XGBE_PHY
185 select BITREVERSE 186 select BITREVERSE
diff --git a/drivers/net/ethernet/apm/xgene/Kconfig b/drivers/net/ethernet/apm/xgene/Kconfig
index f4054d242f3c..19e38afbc5ee 100644
--- a/drivers/net/ethernet/apm/xgene/Kconfig
+++ b/drivers/net/ethernet/apm/xgene/Kconfig
@@ -1,6 +1,7 @@
1config NET_XGENE 1config NET_XGENE
2 tristate "APM X-Gene SoC Ethernet Driver" 2 tristate "APM X-Gene SoC Ethernet Driver"
3 depends on HAS_DMA 3 depends on HAS_DMA
4 depends on ARCH_XGENE || COMPILE_TEST
4 select PHYLIB 5 select PHYLIB
5 help 6 help
6 This is the Ethernet driver for the on-chip ethernet interface on the 7 This is the Ethernet driver for the on-chip ethernet interface on the
diff --git a/drivers/net/ethernet/arc/Kconfig b/drivers/net/ethernet/arc/Kconfig
index 8e262e2b39b6..dea29ee24da4 100644
--- a/drivers/net/ethernet/arc/Kconfig
+++ b/drivers/net/ethernet/arc/Kconfig
@@ -25,8 +25,7 @@ config ARC_EMAC_CORE
25config ARC_EMAC 25config ARC_EMAC
26 tristate "ARC EMAC support" 26 tristate "ARC EMAC support"
27 select ARC_EMAC_CORE 27 select ARC_EMAC_CORE
28 depends on OF_IRQ 28 depends on OF_IRQ && OF_NET && HAS_DMA
29 depends on OF_NET
30 ---help--- 29 ---help---
31 On some legacy ARC (Synopsys) FPGA boards such as ARCAngel4/ML50x 30 On some legacy ARC (Synopsys) FPGA boards such as ARCAngel4/ML50x
32 non-standard on-chip ethernet device ARC EMAC 10/100 is used. 31 non-standard on-chip ethernet device ARC EMAC 10/100 is used.
@@ -35,7 +34,7 @@ config ARC_EMAC
35config EMAC_ROCKCHIP 34config EMAC_ROCKCHIP
36 tristate "Rockchip EMAC support" 35 tristate "Rockchip EMAC support"
37 select ARC_EMAC_CORE 36 select ARC_EMAC_CORE
38 depends on OF_IRQ && OF_NET && REGULATOR 37 depends on OF_IRQ && OF_NET && REGULATOR && HAS_DMA
39 ---help--- 38 ---help---
40 Support for Rockchip RK3066/RK3188 EMAC ethernet controllers. 39 Support for Rockchip RK3066/RK3188 EMAC ethernet controllers.
41 This selects Rockchip SoC glue layer support for the 40 This selects Rockchip SoC glue layer support for the
diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_hw.h b/drivers/net/ethernet/atheros/atl1e/atl1e_hw.h
index 74df16aef793..88a6271de5bc 100644
--- a/drivers/net/ethernet/atheros/atl1e/atl1e_hw.h
+++ b/drivers/net/ethernet/atheros/atl1e/atl1e_hw.h
@@ -129,7 +129,7 @@ s32 atl1e_restart_autoneg(struct atl1e_hw *hw);
129#define TWSI_CTRL_LD_SLV_ADDR_SHIFT 8 129#define TWSI_CTRL_LD_SLV_ADDR_SHIFT 8
130#define TWSI_CTRL_SW_LDSTART 0x800 130#define TWSI_CTRL_SW_LDSTART 0x800
131#define TWSI_CTRL_HW_LDSTART 0x1000 131#define TWSI_CTRL_HW_LDSTART 0x1000
132#define TWSI_CTRL_SMB_SLV_ADDR_MASK 0x0x7F 132#define TWSI_CTRL_SMB_SLV_ADDR_MASK 0x7F
133#define TWSI_CTRL_SMB_SLV_ADDR_SHIFT 15 133#define TWSI_CTRL_SMB_SLV_ADDR_SHIFT 15
134#define TWSI_CTRL_LD_EXIST 0x400000 134#define TWSI_CTRL_LD_EXIST 0x400000
135#define TWSI_CTRL_READ_FREQ_SEL_MASK 0x3 135#define TWSI_CTRL_READ_FREQ_SEL_MASK 0x3
diff --git a/drivers/net/ethernet/broadcom/bcmsysport.h b/drivers/net/ethernet/broadcom/bcmsysport.h
index 7e3d87a88c76..e2c043eabbf3 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.h
+++ b/drivers/net/ethernet/broadcom/bcmsysport.h
@@ -543,7 +543,7 @@ struct bcm_sysport_tx_counters {
543 u32 jbr; /* RO # of xmited jabber count*/ 543 u32 jbr; /* RO # of xmited jabber count*/
544 u32 bytes; /* RO # of xmited byte count */ 544 u32 bytes; /* RO # of xmited byte count */
545 u32 pok; /* RO # of xmited good pkt */ 545 u32 pok; /* RO # of xmited good pkt */
546 u32 uc; /* RO (0x0x4f0)# of xmited unitcast pkt */ 546 u32 uc; /* RO (0x4f0) # of xmited unicast pkt */
547}; 547};
548 548
549struct bcm_sysport_mib { 549struct bcm_sysport_mib {
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index de77d3a74abc..21e3c38c7c75 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -1260,7 +1260,7 @@ static int bgmac_poll(struct napi_struct *napi, int weight)
1260 1260
1261 /* Poll again if more events arrived in the meantime */ 1261 /* Poll again if more events arrived in the meantime */
1262 if (bgmac_read(bgmac, BGMAC_INT_STATUS) & (BGMAC_IS_TX0 | BGMAC_IS_RX)) 1262 if (bgmac_read(bgmac, BGMAC_INT_STATUS) & (BGMAC_IS_TX0 | BGMAC_IS_RX))
1263 return handled; 1263 return weight;
1264 1264
1265 if (handled < weight) { 1265 if (handled < weight) {
1266 napi_complete(napi); 1266 napi_complete(napi);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index 355d5fea5be9..a3b0f7a0c61e 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -521,6 +521,7 @@ struct bnx2x_fp_txdata {
521}; 521};
522 522
523enum bnx2x_tpa_mode_t { 523enum bnx2x_tpa_mode_t {
524 TPA_MODE_DISABLED,
524 TPA_MODE_LRO, 525 TPA_MODE_LRO,
525 TPA_MODE_GRO 526 TPA_MODE_GRO
526}; 527};
@@ -589,7 +590,6 @@ struct bnx2x_fastpath {
589 590
590 /* TPA related */ 591 /* TPA related */
591 struct bnx2x_agg_info *tpa_info; 592 struct bnx2x_agg_info *tpa_info;
592 u8 disable_tpa;
593#ifdef BNX2X_STOP_ON_ERROR 593#ifdef BNX2X_STOP_ON_ERROR
594 u64 tpa_queue_used; 594 u64 tpa_queue_used;
595#endif 595#endif
@@ -1545,9 +1545,7 @@ struct bnx2x {
1545#define USING_MSIX_FLAG (1 << 5) 1545#define USING_MSIX_FLAG (1 << 5)
1546#define USING_MSI_FLAG (1 << 6) 1546#define USING_MSI_FLAG (1 << 6)
1547#define DISABLE_MSI_FLAG (1 << 7) 1547#define DISABLE_MSI_FLAG (1 << 7)
1548#define TPA_ENABLE_FLAG (1 << 8)
1549#define NO_MCP_FLAG (1 << 9) 1548#define NO_MCP_FLAG (1 << 9)
1550#define GRO_ENABLE_FLAG (1 << 10)
1551#define MF_FUNC_DIS (1 << 11) 1549#define MF_FUNC_DIS (1 << 11)
1552#define OWN_CNIC_IRQ (1 << 12) 1550#define OWN_CNIC_IRQ (1 << 12)
1553#define NO_ISCSI_OOO_FLAG (1 << 13) 1551#define NO_ISCSI_OOO_FLAG (1 << 13)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 2f63467bce46..ec56a9b65dc3 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -947,10 +947,10 @@ static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
947 u16 frag_size, pages; 947 u16 frag_size, pages;
948#ifdef BNX2X_STOP_ON_ERROR 948#ifdef BNX2X_STOP_ON_ERROR
949 /* sanity check */ 949 /* sanity check */
950 if (fp->disable_tpa && 950 if (fp->mode == TPA_MODE_DISABLED &&
951 (CQE_TYPE_START(cqe_fp_type) || 951 (CQE_TYPE_START(cqe_fp_type) ||
952 CQE_TYPE_STOP(cqe_fp_type))) 952 CQE_TYPE_STOP(cqe_fp_type)))
953 BNX2X_ERR("START/STOP packet while disable_tpa type %x\n", 953 BNX2X_ERR("START/STOP packet while TPA disabled, type %x\n",
954 CQE_TYPE(cqe_fp_type)); 954 CQE_TYPE(cqe_fp_type));
955#endif 955#endif
956 956
@@ -1396,7 +1396,7 @@ void bnx2x_init_rx_rings(struct bnx2x *bp)
1396 DP(NETIF_MSG_IFUP, 1396 DP(NETIF_MSG_IFUP,
1397 "mtu %d rx_buf_size %d\n", bp->dev->mtu, fp->rx_buf_size); 1397 "mtu %d rx_buf_size %d\n", bp->dev->mtu, fp->rx_buf_size);
1398 1398
1399 if (!fp->disable_tpa) { 1399 if (fp->mode != TPA_MODE_DISABLED) {
1400 /* Fill the per-aggregation pool */ 1400 /* Fill the per-aggregation pool */
1401 for (i = 0; i < MAX_AGG_QS(bp); i++) { 1401 for (i = 0; i < MAX_AGG_QS(bp); i++) {
1402 struct bnx2x_agg_info *tpa_info = 1402 struct bnx2x_agg_info *tpa_info =
@@ -1410,7 +1410,7 @@ void bnx2x_init_rx_rings(struct bnx2x *bp)
1410 BNX2X_ERR("Failed to allocate TPA skb pool for queue[%d] - disabling TPA on this queue!\n", 1410 BNX2X_ERR("Failed to allocate TPA skb pool for queue[%d] - disabling TPA on this queue!\n",
1411 j); 1411 j);
1412 bnx2x_free_tpa_pool(bp, fp, i); 1412 bnx2x_free_tpa_pool(bp, fp, i);
1413 fp->disable_tpa = 1; 1413 fp->mode = TPA_MODE_DISABLED;
1414 break; 1414 break;
1415 } 1415 }
1416 dma_unmap_addr_set(first_buf, mapping, 0); 1416 dma_unmap_addr_set(first_buf, mapping, 0);
@@ -1438,7 +1438,7 @@ void bnx2x_init_rx_rings(struct bnx2x *bp)
1438 ring_prod); 1438 ring_prod);
1439 bnx2x_free_tpa_pool(bp, fp, 1439 bnx2x_free_tpa_pool(bp, fp,
1440 MAX_AGG_QS(bp)); 1440 MAX_AGG_QS(bp));
1441 fp->disable_tpa = 1; 1441 fp->mode = TPA_MODE_DISABLED;
1442 ring_prod = 0; 1442 ring_prod = 0;
1443 break; 1443 break;
1444 } 1444 }
@@ -1560,7 +1560,7 @@ static void bnx2x_free_rx_skbs(struct bnx2x *bp)
1560 1560
1561 bnx2x_free_rx_bds(fp); 1561 bnx2x_free_rx_bds(fp);
1562 1562
1563 if (!fp->disable_tpa) 1563 if (fp->mode != TPA_MODE_DISABLED)
1564 bnx2x_free_tpa_pool(bp, fp, MAX_AGG_QS(bp)); 1564 bnx2x_free_tpa_pool(bp, fp, MAX_AGG_QS(bp));
1565 } 1565 }
1566} 1566}
@@ -2477,17 +2477,19 @@ static void bnx2x_bz_fp(struct bnx2x *bp, int index)
2477 /* set the tpa flag for each queue. The tpa flag determines the queue 2477 /* set the tpa flag for each queue. The tpa flag determines the queue
2478 * minimal size so it must be set prior to queue memory allocation 2478 * minimal size so it must be set prior to queue memory allocation
2479 */ 2479 */
2480 fp->disable_tpa = !(bp->flags & TPA_ENABLE_FLAG || 2480 if (bp->dev->features & NETIF_F_LRO)
2481 (bp->flags & GRO_ENABLE_FLAG &&
2482 bnx2x_mtu_allows_gro(bp->dev->mtu)));
2483 if (bp->flags & TPA_ENABLE_FLAG)
2484 fp->mode = TPA_MODE_LRO; 2481 fp->mode = TPA_MODE_LRO;
2485 else if (bp->flags & GRO_ENABLE_FLAG) 2482 else if (bp->dev->features & NETIF_F_GRO &&
2483 bnx2x_mtu_allows_gro(bp->dev->mtu))
2486 fp->mode = TPA_MODE_GRO; 2484 fp->mode = TPA_MODE_GRO;
2485 else
2486 fp->mode = TPA_MODE_DISABLED;
2487 2487
2488 /* We don't want TPA on an FCoE L2 ring */ 2488 /* We don't want TPA if it's disabled in bp
2489 if (IS_FCOE_FP(fp)) 2489 * or if this is an FCoE L2 ring.
2490 fp->disable_tpa = 1; 2490 */
2491 if (bp->disable_tpa || IS_FCOE_FP(fp))
2492 fp->mode = TPA_MODE_DISABLED;
2491} 2493}
2492 2494
2493int bnx2x_load_cnic(struct bnx2x *bp) 2495int bnx2x_load_cnic(struct bnx2x *bp)
@@ -2608,7 +2610,7 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
2608 /* 2610 /*
2609 * Zero fastpath structures preserving invariants like napi, which are 2611 * Zero fastpath structures preserving invariants like napi, which are
2610 * allocated only once, fp index, max_cos, bp pointer. 2612 * allocated only once, fp index, max_cos, bp pointer.
2611 * Also set fp->disable_tpa and txdata_ptr. 2613 * Also set fp->mode and txdata_ptr.
2612 */ 2614 */
2613 DP(NETIF_MSG_IFUP, "num queues: %d", bp->num_queues); 2615 DP(NETIF_MSG_IFUP, "num queues: %d", bp->num_queues);
2614 for_each_queue(bp, i) 2616 for_each_queue(bp, i)
@@ -3247,7 +3249,7 @@ int bnx2x_low_latency_recv(struct napi_struct *napi)
3247 3249
3248 if ((bp->state == BNX2X_STATE_CLOSED) || 3250 if ((bp->state == BNX2X_STATE_CLOSED) ||
3249 (bp->state == BNX2X_STATE_ERROR) || 3251 (bp->state == BNX2X_STATE_ERROR) ||
3250 (bp->flags & (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG))) 3252 (bp->dev->features & (NETIF_F_LRO | NETIF_F_GRO)))
3251 return LL_FLUSH_FAILED; 3253 return LL_FLUSH_FAILED;
3252 3254
3253 if (!bnx2x_fp_lock_poll(fp)) 3255 if (!bnx2x_fp_lock_poll(fp))
@@ -4543,7 +4545,7 @@ alloc_mem_err:
4543 * In these cases we disable the queue 4545 * In these cases we disable the queue
4544 * Min size is different for OOO, TPA and non-TPA queues 4546 * Min size is different for OOO, TPA and non-TPA queues
4545 */ 4547 */
4546 if (ring_size < (fp->disable_tpa ? 4548 if (ring_size < (fp->mode == TPA_MODE_DISABLED ?
4547 MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA)) { 4549 MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA)) {
4548 /* release memory allocated for this queue */ 4550 /* release memory allocated for this queue */
4549 bnx2x_free_fp_mem_at(bp, index); 4551 bnx2x_free_fp_mem_at(bp, index);
@@ -4784,6 +4786,11 @@ int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
4784{ 4786{
4785 struct bnx2x *bp = netdev_priv(dev); 4787 struct bnx2x *bp = netdev_priv(dev);
4786 4788
4789 if (pci_num_vf(bp->pdev)) {
4790 DP(BNX2X_MSG_IOV, "VFs are enabled, can not change MTU\n");
4791 return -EPERM;
4792 }
4793
4787 if (bp->recovery_state != BNX2X_RECOVERY_DONE) { 4794 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
4788 BNX2X_ERR("Can't perform change MTU during parity recovery\n"); 4795 BNX2X_ERR("Can't perform change MTU during parity recovery\n");
4789 return -EAGAIN; 4796 return -EAGAIN;
@@ -4809,66 +4816,71 @@ netdev_features_t bnx2x_fix_features(struct net_device *dev,
4809{ 4816{
4810 struct bnx2x *bp = netdev_priv(dev); 4817 struct bnx2x *bp = netdev_priv(dev);
4811 4818
4819 if (pci_num_vf(bp->pdev)) {
4820 netdev_features_t changed = dev->features ^ features;
4821
4822 /* Revert the requested changes in features if they
4823 * would require internal reload of PF in bnx2x_set_features().
4824 */
4825 if (!(features & NETIF_F_RXCSUM) && !bp->disable_tpa) {
4826 features &= ~NETIF_F_RXCSUM;
4827 features |= dev->features & NETIF_F_RXCSUM;
4828 }
4829
4830 if (changed & NETIF_F_LOOPBACK) {
4831 features &= ~NETIF_F_LOOPBACK;
4832 features |= dev->features & NETIF_F_LOOPBACK;
4833 }
4834 }
4835
4812 /* TPA requires Rx CSUM offloading */ 4836 /* TPA requires Rx CSUM offloading */
4813 if (!(features & NETIF_F_RXCSUM)) { 4837 if (!(features & NETIF_F_RXCSUM)) {
4814 features &= ~NETIF_F_LRO; 4838 features &= ~NETIF_F_LRO;
4815 features &= ~NETIF_F_GRO; 4839 features &= ~NETIF_F_GRO;
4816 } 4840 }
4817 4841
4818 /* Note: do not disable SW GRO in kernel when HW GRO is off */
4819 if (bp->disable_tpa)
4820 features &= ~NETIF_F_LRO;
4821
4822 return features; 4842 return features;
4823} 4843}
4824 4844
4825int bnx2x_set_features(struct net_device *dev, netdev_features_t features) 4845int bnx2x_set_features(struct net_device *dev, netdev_features_t features)
4826{ 4846{
4827 struct bnx2x *bp = netdev_priv(dev); 4847 struct bnx2x *bp = netdev_priv(dev);
4828 u32 flags = bp->flags; 4848 netdev_features_t changes = features ^ dev->features;
4829 u32 changes;
4830 bool bnx2x_reload = false; 4849 bool bnx2x_reload = false;
4850 int rc;
4831 4851
4832 if (features & NETIF_F_LRO) 4852 /* VFs or non SRIOV PFs should be able to change loopback feature */
4833 flags |= TPA_ENABLE_FLAG; 4853 if (!pci_num_vf(bp->pdev)) {
4834 else 4854 if (features & NETIF_F_LOOPBACK) {
4835 flags &= ~TPA_ENABLE_FLAG; 4855 if (bp->link_params.loopback_mode != LOOPBACK_BMAC) {
4836 4856 bp->link_params.loopback_mode = LOOPBACK_BMAC;
4837 if (features & NETIF_F_GRO) 4857 bnx2x_reload = true;
4838 flags |= GRO_ENABLE_FLAG; 4858 }
4839 else 4859 } else {
4840 flags &= ~GRO_ENABLE_FLAG; 4860 if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
4841 4861 bp->link_params.loopback_mode = LOOPBACK_NONE;
4842 if (features & NETIF_F_LOOPBACK) { 4862 bnx2x_reload = true;
4843 if (bp->link_params.loopback_mode != LOOPBACK_BMAC) { 4863 }
4844 bp->link_params.loopback_mode = LOOPBACK_BMAC;
4845 bnx2x_reload = true;
4846 }
4847 } else {
4848 if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
4849 bp->link_params.loopback_mode = LOOPBACK_NONE;
4850 bnx2x_reload = true;
4851 } 4864 }
4852 } 4865 }
4853 4866
4854 changes = flags ^ bp->flags;
4855
4856 /* if GRO is changed while LRO is enabled, don't force a reload */ 4867 /* if GRO is changed while LRO is enabled, don't force a reload */
4857 if ((changes & GRO_ENABLE_FLAG) && (flags & TPA_ENABLE_FLAG)) 4868 if ((changes & NETIF_F_GRO) && (features & NETIF_F_LRO))
4858 changes &= ~GRO_ENABLE_FLAG; 4869 changes &= ~NETIF_F_GRO;
4859 4870
4860 /* if GRO is changed while HW TPA is off, don't force a reload */ 4871 /* if GRO is changed while HW TPA is off, don't force a reload */
4861 if ((changes & GRO_ENABLE_FLAG) && bp->disable_tpa) 4872 if ((changes & NETIF_F_GRO) && bp->disable_tpa)
4862 changes &= ~GRO_ENABLE_FLAG; 4873 changes &= ~NETIF_F_GRO;
4863 4874
4864 if (changes) 4875 if (changes)
4865 bnx2x_reload = true; 4876 bnx2x_reload = true;
4866 4877
4867 bp->flags = flags;
4868
4869 if (bnx2x_reload) { 4878 if (bnx2x_reload) {
4870 if (bp->recovery_state == BNX2X_RECOVERY_DONE) 4879 if (bp->recovery_state == BNX2X_RECOVERY_DONE) {
4871 return bnx2x_reload_if_running(dev); 4880 dev->features = features;
4881 rc = bnx2x_reload_if_running(dev);
4882 return rc ? rc : 1;
4883 }
4872 /* else: bnx2x_nic_load() will be called at end of recovery */ 4884 /* else: bnx2x_nic_load() will be called at end of recovery */
4873 } 4885 }
4874 4886
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
index adcacda7af7b..d7a71758e876 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
@@ -969,7 +969,7 @@ static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
969{ 969{
970 int i; 970 int i;
971 971
972 if (fp->disable_tpa) 972 if (fp->mode == TPA_MODE_DISABLED)
973 return; 973 return;
974 974
975 for (i = 0; i < last; i++) 975 for (i = 0; i < last; i++)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
index e3d853cab7c9..48ed005ba73f 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
@@ -1843,6 +1843,12 @@ static int bnx2x_set_ringparam(struct net_device *dev,
1843 "set ring params command parameters: rx_pending = %d, tx_pending = %d\n", 1843 "set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
1844 ering->rx_pending, ering->tx_pending); 1844 ering->rx_pending, ering->tx_pending);
1845 1845
1846 if (pci_num_vf(bp->pdev)) {
1847 DP(BNX2X_MSG_IOV,
1848 "VFs are enabled, can not change ring parameters\n");
1849 return -EPERM;
1850 }
1851
1846 if (bp->recovery_state != BNX2X_RECOVERY_DONE) { 1852 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1847 DP(BNX2X_MSG_ETHTOOL, 1853 DP(BNX2X_MSG_ETHTOOL,
1848 "Handling parity error recovery. Try again later\n"); 1854 "Handling parity error recovery. Try again later\n");
@@ -2899,6 +2905,12 @@ static void bnx2x_self_test(struct net_device *dev,
2899 u8 is_serdes, link_up; 2905 u8 is_serdes, link_up;
2900 int rc, cnt = 0; 2906 int rc, cnt = 0;
2901 2907
2908 if (pci_num_vf(bp->pdev)) {
2909 DP(BNX2X_MSG_IOV,
2910 "VFs are enabled, can not perform self test\n");
2911 return;
2912 }
2913
2902 if (bp->recovery_state != BNX2X_RECOVERY_DONE) { 2914 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
2903 netdev_err(bp->dev, 2915 netdev_err(bp->dev,
2904 "Handling parity error recovery. Try again later\n"); 2916 "Handling parity error recovery. Try again later\n");
@@ -3468,6 +3480,11 @@ static int bnx2x_set_channels(struct net_device *dev,
3468 channels->rx_count, channels->tx_count, channels->other_count, 3480 channels->rx_count, channels->tx_count, channels->other_count,
3469 channels->combined_count); 3481 channels->combined_count);
3470 3482
3483 if (pci_num_vf(bp->pdev)) {
3484 DP(BNX2X_MSG_IOV, "VFs are enabled, can not set channels\n");
3485 return -EPERM;
3486 }
3487
3471 /* We don't support separate rx / tx channels. 3488 /* We don't support separate rx / tx channels.
3472 * We don't allow setting 'other' channels. 3489 * We don't allow setting 'other' channels.
3473 */ 3490 */
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index b9f85fccb419..fd52ce95127e 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -3128,7 +3128,7 @@ static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
3128 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags); 3128 __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
3129 } 3129 }
3130 3130
3131 if (!fp->disable_tpa) { 3131 if (fp->mode != TPA_MODE_DISABLED) {
3132 __set_bit(BNX2X_Q_FLG_TPA, &flags); 3132 __set_bit(BNX2X_Q_FLG_TPA, &flags);
3133 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags); 3133 __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
3134 if (fp->mode == TPA_MODE_GRO) 3134 if (fp->mode == TPA_MODE_GRO)
@@ -3176,7 +3176,7 @@ static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
3176 u16 sge_sz = 0; 3176 u16 sge_sz = 0;
3177 u16 tpa_agg_size = 0; 3177 u16 tpa_agg_size = 0;
3178 3178
3179 if (!fp->disable_tpa) { 3179 if (fp->mode != TPA_MODE_DISABLED) {
3180 pause->sge_th_lo = SGE_TH_LO(bp); 3180 pause->sge_th_lo = SGE_TH_LO(bp);
3181 pause->sge_th_hi = SGE_TH_HI(bp); 3181 pause->sge_th_hi = SGE_TH_HI(bp);
3182 3182
@@ -3304,7 +3304,7 @@ static void bnx2x_pf_init(struct bnx2x *bp)
3304 /* This flag is relevant for E1x only. 3304 /* This flag is relevant for E1x only.
3305 * E2 doesn't have a TPA configuration in a function level. 3305 * E2 doesn't have a TPA configuration in a function level.
3306 */ 3306 */
3307 flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0; 3307 flags |= (bp->dev->features & NETIF_F_LRO) ? FUNC_FLG_TPA : 0;
3308 3308
3309 func_init.func_flgs = flags; 3309 func_init.func_flgs = flags;
3310 func_init.pf_id = BP_FUNC(bp); 3310 func_init.pf_id = BP_FUNC(bp);
@@ -12107,11 +12107,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
12107 12107
12108 /* Set TPA flags */ 12108 /* Set TPA flags */
12109 if (bp->disable_tpa) { 12109 if (bp->disable_tpa) {
12110 bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG); 12110 bp->dev->hw_features &= ~NETIF_F_LRO;
12111 bp->dev->features &= ~NETIF_F_LRO; 12111 bp->dev->features &= ~NETIF_F_LRO;
12112 } else {
12113 bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
12114 bp->dev->features |= NETIF_F_LRO;
12115 } 12112 }
12116 12113
12117 if (CHIP_IS_E1(bp)) 12114 if (CHIP_IS_E1(bp))
@@ -13371,6 +13368,17 @@ static int bnx2x_init_one(struct pci_dev *pdev,
13371 bool is_vf; 13368 bool is_vf;
13372 int cnic_cnt; 13369 int cnic_cnt;
13373 13370
13371 /* Management FW 'remembers' living interfaces. Allow it some time
13372 * to forget previously living interfaces, allowing a proper re-load.
13373 */
13374 if (is_kdump_kernel()) {
13375 ktime_t now = ktime_get_boottime();
13376 ktime_t fw_ready_time = ktime_set(5, 0);
13377
13378 if (ktime_before(now, fw_ready_time))
13379 msleep(ktime_ms_delta(fw_ready_time, now));
13380 }
13381
13374 /* An estimated maximum supported CoS number according to the chip 13382 /* An estimated maximum supported CoS number according to the chip
13375 * version. 13383 * version.
13376 * We will try to roughly estimate the maximum number of CoSes this chip 13384 * We will try to roughly estimate the maximum number of CoSes this chip
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
index 15b2d1647560..06b8c0d8fd3b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
@@ -594,7 +594,7 @@ int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
594 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req)); 594 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
595 595
596 /* select tpa mode to request */ 596 /* select tpa mode to request */
597 if (!fp->disable_tpa) { 597 if (fp->mode != TPA_MODE_DISABLED) {
598 flags |= VFPF_QUEUE_FLG_TPA; 598 flags |= VFPF_QUEUE_FLG_TPA;
599 flags |= VFPF_QUEUE_FLG_TPA_IPV6; 599 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
600 if (fp->mode == TPA_MODE_GRO) 600 if (fp->mode == TPA_MODE_GRO)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 1270b189a9a2..069952fa5d64 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -18129,7 +18129,9 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
18129 18129
18130 rtnl_lock(); 18130 rtnl_lock();
18131 18131
18132 tp->pcierr_recovery = true; 18132 /* We needn't recover from permanent error */
18133 if (state == pci_channel_io_frozen)
18134 tp->pcierr_recovery = true;
18133 18135
18134 /* We probably don't have netdev yet */ 18136 /* We probably don't have netdev yet */
18135 if (!netdev || !netif_running(netdev)) 18137 if (!netdev || !netif_running(netdev))
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 9f5387249f24..fc646a41d548 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -350,6 +350,9 @@ static int macb_mii_probe(struct net_device *dev)
350 else 350 else
351 phydev->supported &= PHY_BASIC_FEATURES; 351 phydev->supported &= PHY_BASIC_FEATURES;
352 352
353 if (bp->caps & MACB_CAPS_NO_GIGABIT_HALF)
354 phydev->supported &= ~SUPPORTED_1000baseT_Half;
355
353 phydev->advertising = phydev->supported; 356 phydev->advertising = phydev->supported;
354 357
355 bp->link = 0; 358 bp->link = 0;
@@ -707,6 +710,9 @@ static void gem_rx_refill(struct macb *bp)
707 710
708 /* properly align Ethernet header */ 711 /* properly align Ethernet header */
709 skb_reserve(skb, NET_IP_ALIGN); 712 skb_reserve(skb, NET_IP_ALIGN);
713 } else {
714 bp->rx_ring[entry].addr &= ~MACB_BIT(RX_USED);
715 bp->rx_ring[entry].ctrl = 0;
710 } 716 }
711 } 717 }
712 718
@@ -978,7 +984,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
978 struct macb_queue *queue = dev_id; 984 struct macb_queue *queue = dev_id;
979 struct macb *bp = queue->bp; 985 struct macb *bp = queue->bp;
980 struct net_device *dev = bp->dev; 986 struct net_device *dev = bp->dev;
981 u32 status; 987 u32 status, ctrl;
982 988
983 status = queue_readl(queue, ISR); 989 status = queue_readl(queue, ISR);
984 990
@@ -1034,6 +1040,21 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
1034 * add that if/when we get our hands on a full-blown MII PHY. 1040 * add that if/when we get our hands on a full-blown MII PHY.
1035 */ 1041 */
1036 1042
1043 /* There is a hardware issue under heavy load where DMA can
1044 * stop, this causes endless "used buffer descriptor read"
1045 * interrupts but it can be cleared by re-enabling RX. See
1046 * the at91 manual, section 41.3.1 or the Zynq manual
1047 * section 16.7.4 for details.
1048 */
1049 if (status & MACB_BIT(RXUBR)) {
1050 ctrl = macb_readl(bp, NCR);
1051 macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE));
1052 macb_writel(bp, NCR, ctrl | MACB_BIT(RE));
1053
1054 if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
1055 macb_writel(bp, ISR, MACB_BIT(RXUBR));
1056 }
1057
1037 if (status & MACB_BIT(ISR_ROVR)) { 1058 if (status & MACB_BIT(ISR_ROVR)) {
1038 /* We missed at least one packet */ 1059 /* We missed at least one packet */
1039 if (macb_is_gem(bp)) 1060 if (macb_is_gem(bp))
@@ -1473,9 +1494,9 @@ static void macb_init_rings(struct macb *bp)
1473 for (i = 0; i < TX_RING_SIZE; i++) { 1494 for (i = 0; i < TX_RING_SIZE; i++) {
1474 bp->queues[0].tx_ring[i].addr = 0; 1495 bp->queues[0].tx_ring[i].addr = 0;
1475 bp->queues[0].tx_ring[i].ctrl = MACB_BIT(TX_USED); 1496 bp->queues[0].tx_ring[i].ctrl = MACB_BIT(TX_USED);
1476 bp->queues[0].tx_head = 0;
1477 bp->queues[0].tx_tail = 0;
1478 } 1497 }
1498 bp->queues[0].tx_head = 0;
1499 bp->queues[0].tx_tail = 0;
1479 bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP); 1500 bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
1480 1501
1481 bp->rx_tail = 0; 1502 bp->rx_tail = 0;
@@ -2681,6 +2702,14 @@ static const struct macb_config emac_config = {
2681 .init = at91ether_init, 2702 .init = at91ether_init,
2682}; 2703};
2683 2704
2705static const struct macb_config zynq_config = {
2706 .caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_GIGABIT_MODE_AVAILABLE |
2707 MACB_CAPS_NO_GIGABIT_HALF,
2708 .dma_burst_length = 16,
2709 .clk_init = macb_clk_init,
2710 .init = macb_init,
2711};
2712
2684static const struct of_device_id macb_dt_ids[] = { 2713static const struct of_device_id macb_dt_ids[] = {
2685 { .compatible = "cdns,at32ap7000-macb" }, 2714 { .compatible = "cdns,at32ap7000-macb" },
2686 { .compatible = "cdns,at91sam9260-macb", .data = &at91sam9260_config }, 2715 { .compatible = "cdns,at91sam9260-macb", .data = &at91sam9260_config },
@@ -2691,6 +2720,7 @@ static const struct of_device_id macb_dt_ids[] = {
2691 { .compatible = "atmel,sama5d4-gem", .data = &sama5d4_config }, 2720 { .compatible = "atmel,sama5d4-gem", .data = &sama5d4_config },
2692 { .compatible = "cdns,at91rm9200-emac", .data = &emac_config }, 2721 { .compatible = "cdns,at91rm9200-emac", .data = &emac_config },
2693 { .compatible = "cdns,emac", .data = &emac_config }, 2722 { .compatible = "cdns,emac", .data = &emac_config },
2723 { .compatible = "cdns,zynq-gem", .data = &zynq_config },
2694 { /* sentinel */ } 2724 { /* sentinel */ }
2695}; 2725};
2696MODULE_DEVICE_TABLE(of, macb_dt_ids); 2726MODULE_DEVICE_TABLE(of, macb_dt_ids);
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index eb7d76f7bf6a..24b1d9bcd865 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -393,6 +393,7 @@
393#define MACB_CAPS_ISR_CLEAR_ON_WRITE 0x00000001 393#define MACB_CAPS_ISR_CLEAR_ON_WRITE 0x00000001
394#define MACB_CAPS_USRIO_HAS_CLKEN 0x00000002 394#define MACB_CAPS_USRIO_HAS_CLKEN 0x00000002
395#define MACB_CAPS_USRIO_DEFAULT_IS_MII 0x00000004 395#define MACB_CAPS_USRIO_DEFAULT_IS_MII 0x00000004
396#define MACB_CAPS_NO_GIGABIT_HALF 0x00000008
396#define MACB_CAPS_FIFO_MODE 0x10000000 397#define MACB_CAPS_FIFO_MODE 0x10000000
397#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000 398#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000
398#define MACB_CAPS_SG_DISABLED 0x40000000 399#define MACB_CAPS_SG_DISABLED 0x40000000
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index 5959e3ae72da..e8578a742f2a 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -492,7 +492,7 @@ int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr,
492 memoffset = (mtype * (edc_size * 1024 * 1024)); 492 memoffset = (mtype * (edc_size * 1024 * 1024));
493 else { 493 else {
494 mc_size = EXT_MEM0_SIZE_G(t4_read_reg(adap, 494 mc_size = EXT_MEM0_SIZE_G(t4_read_reg(adap,
495 MA_EXT_MEMORY1_BAR_A)); 495 MA_EXT_MEMORY0_BAR_A));
496 memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024; 496 memoffset = (MEM_MC0 * edc_size + mc_size) * 1024 * 1024;
497 } 497 }
498 498
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index fb0bc3c3620e..6f9ffb9026cd 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -2358,11 +2358,11 @@ static int be_evt_queues_create(struct be_adapter *adapter)
2358 adapter->cfg_num_qs); 2358 adapter->cfg_num_qs);
2359 2359
2360 for_all_evt_queues(adapter, eqo, i) { 2360 for_all_evt_queues(adapter, eqo, i) {
2361 int numa_node = dev_to_node(&adapter->pdev->dev);
2361 if (!zalloc_cpumask_var(&eqo->affinity_mask, GFP_KERNEL)) 2362 if (!zalloc_cpumask_var(&eqo->affinity_mask, GFP_KERNEL))
2362 return -ENOMEM; 2363 return -ENOMEM;
2363 cpumask_set_cpu_local_first(i, dev_to_node(&adapter->pdev->dev), 2364 cpumask_set_cpu(cpumask_local_spread(i, numa_node),
2364 eqo->affinity_mask); 2365 eqo->affinity_mask);
2365
2366 netif_napi_add(adapter->netdev, &eqo->napi, be_poll, 2366 netif_napi_add(adapter->netdev, &eqo->napi, be_poll,
2367 BE_NAPI_WEIGHT); 2367 BE_NAPI_WEIGHT);
2368 napi_hash_add(&eqo->napi); 2368 napi_hash_add(&eqo->napi);
@@ -4846,7 +4846,8 @@ err:
4846} 4846}
4847 4847
4848static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 4848static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4849 struct net_device *dev, u32 filter_mask) 4849 struct net_device *dev, u32 filter_mask,
4850 int nlflags)
4850{ 4851{
4851 struct be_adapter *adapter = netdev_priv(dev); 4852 struct be_adapter *adapter = netdev_priv(dev);
4852 int status = 0; 4853 int status = 0;
@@ -4868,7 +4869,7 @@ static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4868 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, 4869 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
4869 hsw_mode == PORT_FWD_TYPE_VEPA ? 4870 hsw_mode == PORT_FWD_TYPE_VEPA ?
4870 BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB, 4871 BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB,
4871 0, 0); 4872 0, 0, nlflags);
4872} 4873}
4873 4874
4874#ifdef CONFIG_BE2NET_VXLAN 4875#ifdef CONFIG_BE2NET_VXLAN
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index f6a3a7abd468..66d47e448e4d 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -988,7 +988,10 @@ fec_restart(struct net_device *ndev)
988 rcntl |= 0x40000000 | 0x00000020; 988 rcntl |= 0x40000000 | 0x00000020;
989 989
990 /* RGMII, RMII or MII */ 990 /* RGMII, RMII or MII */
991 if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII) 991 if (fep->phy_interface == PHY_INTERFACE_MODE_RGMII ||
992 fep->phy_interface == PHY_INTERFACE_MODE_RGMII_ID ||
993 fep->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID ||
994 fep->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID)
992 rcntl |= (1 << 6); 995 rcntl |= (1 << 6);
993 else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII) 996 else if (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
994 rcntl |= (1 << 8); 997 rcntl |= (1 << 8);
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_main.c b/drivers/net/ethernet/ibm/ehea/ehea_main.c
index 291c87036e17..2a0dc127df3f 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_main.c
+++ b/drivers/net/ethernet/ibm/ehea/ehea_main.c
@@ -3347,7 +3347,7 @@ static int ehea_register_memory_hooks(void)
3347{ 3347{
3348 int ret = 0; 3348 int ret = 0;
3349 3349
3350 if (atomic_inc_and_test(&ehea_memory_hooks_registered)) 3350 if (atomic_inc_return(&ehea_memory_hooks_registered) > 1)
3351 return 0; 3351 return 0;
3352 3352
3353 ret = ehea_create_busmap(); 3353 ret = ehea_create_busmap();
@@ -3381,12 +3381,14 @@ out3:
3381out2: 3381out2:
3382 unregister_reboot_notifier(&ehea_reboot_nb); 3382 unregister_reboot_notifier(&ehea_reboot_nb);
3383out: 3383out:
3384 atomic_dec(&ehea_memory_hooks_registered);
3384 return ret; 3385 return ret;
3385} 3386}
3386 3387
3387static void ehea_unregister_memory_hooks(void) 3388static void ehea_unregister_memory_hooks(void)
3388{ 3389{
3389 if (atomic_read(&ehea_memory_hooks_registered)) 3390 /* Only remove the hooks if we've registered them */
3391 if (atomic_read(&ehea_memory_hooks_registered) == 0)
3390 return; 3392 return;
3391 3393
3392 unregister_reboot_notifier(&ehea_reboot_nb); 3394 unregister_reboot_notifier(&ehea_reboot_nb);
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index de7919322190..b9df0cbd0a38 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2084,12 +2084,8 @@ static void emac_ethtool_get_pauseparam(struct net_device *ndev,
2084 2084
2085static int emac_get_regs_len(struct emac_instance *dev) 2085static int emac_get_regs_len(struct emac_instance *dev)
2086{ 2086{
2087 if (emac_has_feature(dev, EMAC_FTR_EMAC4))
2088 return sizeof(struct emac_ethtool_regs_subhdr) +
2089 EMAC4_ETHTOOL_REGS_SIZE(dev);
2090 else
2091 return sizeof(struct emac_ethtool_regs_subhdr) + 2087 return sizeof(struct emac_ethtool_regs_subhdr) +
2092 EMAC_ETHTOOL_REGS_SIZE(dev); 2088 sizeof(struct emac_regs);
2093} 2089}
2094 2090
2095static int emac_ethtool_get_regs_len(struct net_device *ndev) 2091static int emac_ethtool_get_regs_len(struct net_device *ndev)
@@ -2114,15 +2110,15 @@ static void *emac_dump_regs(struct emac_instance *dev, void *buf)
2114 struct emac_ethtool_regs_subhdr *hdr = buf; 2110 struct emac_ethtool_regs_subhdr *hdr = buf;
2115 2111
2116 hdr->index = dev->cell_index; 2112 hdr->index = dev->cell_index;
2117 if (emac_has_feature(dev, EMAC_FTR_EMAC4)) { 2113 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) {
2114 hdr->version = EMAC4SYNC_ETHTOOL_REGS_VER;
2115 } else if (emac_has_feature(dev, EMAC_FTR_EMAC4)) {
2118 hdr->version = EMAC4_ETHTOOL_REGS_VER; 2116 hdr->version = EMAC4_ETHTOOL_REGS_VER;
2119 memcpy_fromio(hdr + 1, dev->emacp, EMAC4_ETHTOOL_REGS_SIZE(dev));
2120 return (void *)(hdr + 1) + EMAC4_ETHTOOL_REGS_SIZE(dev);
2121 } else { 2117 } else {
2122 hdr->version = EMAC_ETHTOOL_REGS_VER; 2118 hdr->version = EMAC_ETHTOOL_REGS_VER;
2123 memcpy_fromio(hdr + 1, dev->emacp, EMAC_ETHTOOL_REGS_SIZE(dev));
2124 return (void *)(hdr + 1) + EMAC_ETHTOOL_REGS_SIZE(dev);
2125 } 2119 }
2120 memcpy_fromio(hdr + 1, dev->emacp, sizeof(struct emac_regs));
2121 return (void *)(hdr + 1) + sizeof(struct emac_regs);
2126} 2122}
2127 2123
2128static void emac_ethtool_get_regs(struct net_device *ndev, 2124static void emac_ethtool_get_regs(struct net_device *ndev,
diff --git a/drivers/net/ethernet/ibm/emac/core.h b/drivers/net/ethernet/ibm/emac/core.h
index 67f342a9f65e..28df37420da9 100644
--- a/drivers/net/ethernet/ibm/emac/core.h
+++ b/drivers/net/ethernet/ibm/emac/core.h
@@ -461,10 +461,7 @@ struct emac_ethtool_regs_subhdr {
461}; 461};
462 462
463#define EMAC_ETHTOOL_REGS_VER 0 463#define EMAC_ETHTOOL_REGS_VER 0
464#define EMAC_ETHTOOL_REGS_SIZE(dev) ((dev)->rsrc_regs.end - \ 464#define EMAC4_ETHTOOL_REGS_VER 1
465 (dev)->rsrc_regs.start + 1) 465#define EMAC4SYNC_ETHTOOL_REGS_VER 2
466#define EMAC4_ETHTOOL_REGS_VER 1
467#define EMAC4_ETHTOOL_REGS_SIZE(dev) ((dev)->rsrc_regs.end - \
468 (dev)->rsrc_regs.start + 1)
469 466
470#endif /* __IBM_NEWEMAC_CORE_H */ 467#endif /* __IBM_NEWEMAC_CORE_H */
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index cd7675ac5bf9..18134766a114 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1238,7 +1238,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1238 return -EINVAL; 1238 return -EINVAL;
1239 1239
1240 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) 1240 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
1241 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) 1241 if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size)
1242 break; 1242 break;
1243 1243
1244 if (i == IBMVETH_NUM_BUFF_POOLS) 1244 if (i == IBMVETH_NUM_BUFF_POOLS)
@@ -1257,7 +1257,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1257 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { 1257 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1258 adapter->rx_buff_pool[i].active = 1; 1258 adapter->rx_buff_pool[i].active = 1;
1259 1259
1260 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { 1260 if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size) {
1261 dev->mtu = new_mtu; 1261 dev->mtu = new_mtu;
1262 vio_cmo_set_dev_desired(viodev, 1262 vio_cmo_set_dev_desired(viodev,
1263 ibmveth_get_desired_dma 1263 ibmveth_get_desired_dma
diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
index 5d9ceb17b4cb..0abc942c966e 100644
--- a/drivers/net/ethernet/intel/e1000e/e1000.h
+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
@@ -40,6 +40,7 @@
40#include <linux/ptp_classify.h> 40#include <linux/ptp_classify.h>
41#include <linux/mii.h> 41#include <linux/mii.h>
42#include <linux/mdio.h> 42#include <linux/mdio.h>
43#include <linux/pm_qos.h>
43#include "hw.h" 44#include "hw.h"
44 45
45struct e1000_info; 46struct e1000_info;
diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_main.c b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
index 1b0661e3573b..c754b2027281 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
@@ -610,7 +610,7 @@ static bool fm10k_clean_rx_irq(struct fm10k_q_vector *q_vector,
610 unsigned int total_bytes = 0, total_packets = 0; 610 unsigned int total_bytes = 0, total_packets = 0;
611 u16 cleaned_count = fm10k_desc_unused(rx_ring); 611 u16 cleaned_count = fm10k_desc_unused(rx_ring);
612 612
613 do { 613 while (likely(total_packets < budget)) {
614 union fm10k_rx_desc *rx_desc; 614 union fm10k_rx_desc *rx_desc;
615 615
616 /* return some buffers to hardware, one at a time is too slow */ 616 /* return some buffers to hardware, one at a time is too slow */
@@ -659,7 +659,7 @@ static bool fm10k_clean_rx_irq(struct fm10k_q_vector *q_vector,
659 659
660 /* update budget accounting */ 660 /* update budget accounting */
661 total_packets++; 661 total_packets++;
662 } while (likely(total_packets < budget)); 662 }
663 663
664 /* place incomplete frames back on ring for completion */ 664 /* place incomplete frames back on ring for completion */
665 rx_ring->skb = skb; 665 rx_ring->skb = skb;
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 24481cd7e59a..a54c14491e3b 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -8053,10 +8053,10 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
8053#ifdef HAVE_BRIDGE_FILTER 8053#ifdef HAVE_BRIDGE_FILTER
8054static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 8054static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8055 struct net_device *dev, 8055 struct net_device *dev,
8056 u32 __always_unused filter_mask) 8056 u32 __always_unused filter_mask, int nlflags)
8057#else 8057#else
8058static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 8058static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8059 struct net_device *dev) 8059 struct net_device *dev, int nlflags)
8060#endif /* HAVE_BRIDGE_FILTER */ 8060#endif /* HAVE_BRIDGE_FILTER */
8061{ 8061{
8062 struct i40e_netdev_priv *np = netdev_priv(dev); 8062 struct i40e_netdev_priv *np = netdev_priv(dev);
@@ -8078,7 +8078,8 @@ static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8078 if (!veb) 8078 if (!veb)
8079 return 0; 8079 return 0;
8080 8080
8081 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode); 8081 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
8082 nlflags);
8082} 8083}
8083#endif /* HAVE_BRIDGE_ATTRIBS */ 8084#endif /* HAVE_BRIDGE_ATTRIBS */
8084 8085
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 8457d0306e3a..a0a9b1fcb5e8 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -1036,7 +1036,7 @@ static void igb_reset_q_vector(struct igb_adapter *adapter, int v_idx)
1036 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL; 1036 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
1037 1037
1038 if (q_vector->rx.ring) 1038 if (q_vector->rx.ring)
1039 adapter->tx_ring[q_vector->rx.ring->queue_index] = NULL; 1039 adapter->rx_ring[q_vector->rx.ring->queue_index] = NULL;
1040 1040
1041 netif_napi_del(&q_vector->napi); 1041 netif_napi_del(&q_vector->napi);
1042 1042
@@ -1207,6 +1207,8 @@ static int igb_alloc_q_vector(struct igb_adapter *adapter,
1207 q_vector = adapter->q_vector[v_idx]; 1207 q_vector = adapter->q_vector[v_idx];
1208 if (!q_vector) 1208 if (!q_vector)
1209 q_vector = kzalloc(size, GFP_KERNEL); 1209 q_vector = kzalloc(size, GFP_KERNEL);
1210 else
1211 memset(q_vector, 0, size);
1210 if (!q_vector) 1212 if (!q_vector)
1211 return -ENOMEM; 1213 return -ENOMEM;
1212 1214
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index d3f4b0ceb3f7..5be12a00e1f4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -8044,7 +8044,7 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
8044 8044
8045static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 8045static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8046 struct net_device *dev, 8046 struct net_device *dev,
8047 u32 filter_mask) 8047 u32 filter_mask, int nlflags)
8048{ 8048{
8049 struct ixgbe_adapter *adapter = netdev_priv(dev); 8049 struct ixgbe_adapter *adapter = netdev_priv(dev);
8050 8050
@@ -8052,7 +8052,7 @@ static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8052 return 0; 8052 return 0;
8053 8053
8054 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, 8054 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
8055 adapter->bridge_mode, 0, 0); 8055 adapter->bridge_mode, 0, 0, nlflags);
8056} 8056}
8057 8057
8058static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) 8058static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index a16d267fbce4..e71cdde9cb01 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -3612,7 +3612,7 @@ static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3612 u8 *dst_mac = skb_header_pointer(skb, 0, 0, NULL); 3612 u8 *dst_mac = skb_header_pointer(skb, 0, 0, NULL);
3613 3613
3614 if (!dst_mac || is_link_local_ether_addr(dst_mac)) { 3614 if (!dst_mac || is_link_local_ether_addr(dst_mac)) {
3615 dev_kfree_skb(skb); 3615 dev_kfree_skb_any(skb);
3616 return NETDEV_TX_OK; 3616 return NETDEV_TX_OK;
3617 } 3617 }
3618 3618
diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c
index af829c578400..7ace07dad6a3 100644
--- a/drivers/net/ethernet/marvell/pxa168_eth.c
+++ b/drivers/net/ethernet/marvell/pxa168_eth.c
@@ -1508,7 +1508,8 @@ static int pxa168_eth_probe(struct platform_device *pdev)
1508 np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0); 1508 np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
1509 if (!np) { 1509 if (!np) {
1510 dev_err(&pdev->dev, "missing phy-handle\n"); 1510 dev_err(&pdev->dev, "missing phy-handle\n");
1511 return -EINVAL; 1511 err = -EINVAL;
1512 goto err_netdev;
1512 } 1513 }
1513 of_property_read_u32(np, "reg", &pep->phy_addr); 1514 of_property_read_u32(np, "reg", &pep->phy_addr);
1514 pep->phy_intf = of_get_phy_mode(pdev->dev.of_node); 1515 pep->phy_intf = of_get_phy_mode(pdev->dev.of_node);
@@ -1526,7 +1527,7 @@ static int pxa168_eth_probe(struct platform_device *pdev)
1526 pep->smi_bus = mdiobus_alloc(); 1527 pep->smi_bus = mdiobus_alloc();
1527 if (pep->smi_bus == NULL) { 1528 if (pep->smi_bus == NULL) {
1528 err = -ENOMEM; 1529 err = -ENOMEM;
1529 goto err_base; 1530 goto err_netdev;
1530 } 1531 }
1531 pep->smi_bus->priv = pep; 1532 pep->smi_bus->priv = pep;
1532 pep->smi_bus->name = "pxa168_eth smi"; 1533 pep->smi_bus->name = "pxa168_eth smi";
@@ -1551,13 +1552,10 @@ err_mdiobus:
1551 mdiobus_unregister(pep->smi_bus); 1552 mdiobus_unregister(pep->smi_bus);
1552err_free_mdio: 1553err_free_mdio:
1553 mdiobus_free(pep->smi_bus); 1554 mdiobus_free(pep->smi_bus);
1554err_base:
1555 iounmap(pep->base);
1556err_netdev: 1555err_netdev:
1557 free_netdev(dev); 1556 free_netdev(dev);
1558err_clk: 1557err_clk:
1559 clk_disable(clk); 1558 clk_disable_unprepare(clk);
1560 clk_put(clk);
1561 return err; 1559 return err;
1562} 1560}
1563 1561
@@ -1574,13 +1572,9 @@ static int pxa168_eth_remove(struct platform_device *pdev)
1574 if (pep->phy) 1572 if (pep->phy)
1575 phy_disconnect(pep->phy); 1573 phy_disconnect(pep->phy);
1576 if (pep->clk) { 1574 if (pep->clk) {
1577 clk_disable(pep->clk); 1575 clk_disable_unprepare(pep->clk);
1578 clk_put(pep->clk);
1579 pep->clk = NULL;
1580 } 1576 }
1581 1577
1582 iounmap(pep->base);
1583 pep->base = NULL;
1584 mdiobus_unregister(pep->smi_bus); 1578 mdiobus_unregister(pep->smi_bus);
1585 mdiobus_free(pep->smi_bus); 1579 mdiobus_free(pep->smi_bus);
1586 unregister_netdev(dev); 1580 unregister_netdev(dev);
diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index 4f7dc044601e..529ef0594b90 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -714,8 +714,13 @@ static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
714 msecs_to_jiffies(timeout))) { 714 msecs_to_jiffies(timeout))) {
715 mlx4_warn(dev, "command 0x%x timed out (go bit not cleared)\n", 715 mlx4_warn(dev, "command 0x%x timed out (go bit not cleared)\n",
716 op); 716 op);
717 err = -EIO; 717 if (op == MLX4_CMD_NOP) {
718 goto out_reset; 718 err = -EBUSY;
719 goto out;
720 } else {
721 err = -EIO;
722 goto out_reset;
723 }
719 } 724 }
720 725
721 err = context->result; 726 err = context->result;
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
index 3f44e2bbb982..a2ddf3d75ff8 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
@@ -1102,20 +1102,21 @@ static int mlx4_en_check_rxfh_func(struct net_device *dev, u8 hfunc)
1102 struct mlx4_en_priv *priv = netdev_priv(dev); 1102 struct mlx4_en_priv *priv = netdev_priv(dev);
1103 1103
1104 /* check if requested function is supported by the device */ 1104 /* check if requested function is supported by the device */
1105 if ((hfunc == ETH_RSS_HASH_TOP && 1105 if (hfunc == ETH_RSS_HASH_TOP) {
1106 !(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP)) || 1106 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP))
1107 (hfunc == ETH_RSS_HASH_XOR && 1107 return -EINVAL;
1108 !(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR))) 1108 if (!(dev->features & NETIF_F_RXHASH))
1109 return -EINVAL; 1109 en_warn(priv, "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n");
1110 return 0;
1111 } else if (hfunc == ETH_RSS_HASH_XOR) {
1112 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR))
1113 return -EINVAL;
1114 if (dev->features & NETIF_F_RXHASH)
1115 en_warn(priv, "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n");
1116 return 0;
1117 }
1110 1118
1111 priv->rss_hash_fn = hfunc; 1119 return -EINVAL;
1112 if (hfunc == ETH_RSS_HASH_TOP && !(dev->features & NETIF_F_RXHASH))
1113 en_warn(priv,
1114 "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n");
1115 if (hfunc == ETH_RSS_HASH_XOR && (dev->features & NETIF_F_RXHASH))
1116 en_warn(priv,
1117 "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n");
1118 return 0;
1119} 1120}
1120 1121
1121static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key, 1122static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key,
@@ -1189,6 +1190,8 @@ static int mlx4_en_set_rxfh(struct net_device *dev, const u32 *ring_index,
1189 priv->prof->rss_rings = rss_rings; 1190 priv->prof->rss_rings = rss_rings;
1190 if (key) 1191 if (key)
1191 memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE); 1192 memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE);
1193 if (hfunc != ETH_RSS_HASH_NO_CHANGE)
1194 priv->rss_hash_fn = hfunc;
1192 1195
1193 if (port_up) { 1196 if (port_up) {
1194 err = mlx4_en_start_port(dev); 1197 err = mlx4_en_start_port(dev);
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 0f1afc085d58..cf467a9f6cc7 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -1467,6 +1467,7 @@ static void mlx4_en_service_task(struct work_struct *work)
1467 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) 1467 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)
1468 mlx4_en_ptp_overflow_check(mdev); 1468 mlx4_en_ptp_overflow_check(mdev);
1469 1469
1470 mlx4_en_recover_from_oom(priv);
1470 queue_delayed_work(mdev->workqueue, &priv->service_task, 1471 queue_delayed_work(mdev->workqueue, &priv->service_task,
1471 SERVICE_TASK_DELAY); 1472 SERVICE_TASK_DELAY);
1472 } 1473 }
@@ -1500,17 +1501,13 @@ static int mlx4_en_init_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
1500{ 1501{
1501 struct mlx4_en_rx_ring *ring = priv->rx_ring[ring_idx]; 1502 struct mlx4_en_rx_ring *ring = priv->rx_ring[ring_idx];
1502 int numa_node = priv->mdev->dev->numa_node; 1503 int numa_node = priv->mdev->dev->numa_node;
1503 int ret = 0;
1504 1504
1505 if (!zalloc_cpumask_var(&ring->affinity_mask, GFP_KERNEL)) 1505 if (!zalloc_cpumask_var(&ring->affinity_mask, GFP_KERNEL))
1506 return -ENOMEM; 1506 return -ENOMEM;
1507 1507
1508 ret = cpumask_set_cpu_local_first(ring_idx, numa_node, 1508 cpumask_set_cpu(cpumask_local_spread(ring_idx, numa_node),
1509 ring->affinity_mask); 1509 ring->affinity_mask);
1510 if (ret) 1510 return 0;
1511 free_cpumask_var(ring->affinity_mask);
1512
1513 return ret;
1514} 1511}
1515 1512
1516static void mlx4_en_free_affinity_hint(struct mlx4_en_priv *priv, int ring_idx) 1513static void mlx4_en_free_affinity_hint(struct mlx4_en_priv *priv, int ring_idx)
@@ -1721,7 +1718,7 @@ mac_err:
1721cq_err: 1718cq_err:
1722 while (rx_index--) { 1719 while (rx_index--) {
1723 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]); 1720 mlx4_en_deactivate_cq(priv, priv->rx_cq[rx_index]);
1724 mlx4_en_free_affinity_hint(priv, i); 1721 mlx4_en_free_affinity_hint(priv, rx_index);
1725 } 1722 }
1726 for (i = 0; i < priv->rx_ring_num; i++) 1723 for (i = 0; i < priv->rx_ring_num; i++)
1727 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]); 1724 mlx4_en_deactivate_rx_ring(priv, priv->rx_ring[i]);
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_port.c b/drivers/net/ethernet/mellanox/mlx4/en_port.c
index 54f0e5ab2e55..0a56f010c846 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_port.c
@@ -139,7 +139,7 @@ static unsigned long en_stats_adder(__be64 *start, __be64 *next, int num)
139 int i; 139 int i;
140 int offset = next - start; 140 int offset = next - start;
141 141
142 for (i = 0; i <= num; i++) { 142 for (i = 0; i < num; i++) {
143 ret += be64_to_cpu(*curr); 143 ret += be64_to_cpu(*curr);
144 curr += offset; 144 curr += offset;
145 } 145 }
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 4fdd3c37e47b..2a77a6b19121 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -244,6 +244,12 @@ static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv,
244 return mlx4_en_alloc_frags(priv, rx_desc, frags, ring->page_alloc, gfp); 244 return mlx4_en_alloc_frags(priv, rx_desc, frags, ring->page_alloc, gfp);
245} 245}
246 246
247static inline bool mlx4_en_is_ring_empty(struct mlx4_en_rx_ring *ring)
248{
249 BUG_ON((u32)(ring->prod - ring->cons) > ring->actual_size);
250 return ring->prod == ring->cons;
251}
252
247static inline void mlx4_en_update_rx_prod_db(struct mlx4_en_rx_ring *ring) 253static inline void mlx4_en_update_rx_prod_db(struct mlx4_en_rx_ring *ring)
248{ 254{
249 *ring->wqres.db.db = cpu_to_be32(ring->prod & 0xffff); 255 *ring->wqres.db.db = cpu_to_be32(ring->prod & 0xffff);
@@ -315,8 +321,7 @@ static void mlx4_en_free_rx_buf(struct mlx4_en_priv *priv,
315 ring->cons, ring->prod); 321 ring->cons, ring->prod);
316 322
317 /* Unmap and free Rx buffers */ 323 /* Unmap and free Rx buffers */
318 BUG_ON((u32) (ring->prod - ring->cons) > ring->actual_size); 324 while (!mlx4_en_is_ring_empty(ring)) {
319 while (ring->cons != ring->prod) {
320 index = ring->cons & ring->size_mask; 325 index = ring->cons & ring->size_mask;
321 en_dbg(DRV, priv, "Processing descriptor:%d\n", index); 326 en_dbg(DRV, priv, "Processing descriptor:%d\n", index);
322 mlx4_en_free_rx_desc(priv, ring, index); 327 mlx4_en_free_rx_desc(priv, ring, index);
@@ -491,6 +496,23 @@ err_allocator:
491 return err; 496 return err;
492} 497}
493 498
499/* We recover from out of memory by scheduling our napi poll
500 * function (mlx4_en_process_cq), which tries to allocate
501 * all missing RX buffers (call to mlx4_en_refill_rx_buffers).
502 */
503void mlx4_en_recover_from_oom(struct mlx4_en_priv *priv)
504{
505 int ring;
506
507 if (!priv->port_up)
508 return;
509
510 for (ring = 0; ring < priv->rx_ring_num; ring++) {
511 if (mlx4_en_is_ring_empty(priv->rx_ring[ring]))
512 napi_reschedule(&priv->rx_cq[ring]->napi);
513 }
514}
515
494void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv, 516void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv,
495 struct mlx4_en_rx_ring **pring, 517 struct mlx4_en_rx_ring **pring,
496 u32 size, u16 stride) 518 u32 size, u16 stride)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 1783705273d8..7bed3a88579f 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -143,8 +143,10 @@ int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
143 ring->hwtstamp_tx_type = priv->hwtstamp_config.tx_type; 143 ring->hwtstamp_tx_type = priv->hwtstamp_config.tx_type;
144 ring->queue_index = queue_index; 144 ring->queue_index = queue_index;
145 145
146 if (queue_index < priv->num_tx_rings_p_up && cpu_online(queue_index)) 146 if (queue_index < priv->num_tx_rings_p_up)
147 cpumask_set_cpu(queue_index, &ring->affinity_mask); 147 cpumask_set_cpu(cpumask_local_spread(queue_index,
148 priv->mdev->dev->numa_node),
149 &ring->affinity_mask);
148 150
149 *pring = ring; 151 *pring = ring;
150 return 0; 152 return 0;
@@ -213,7 +215,7 @@ int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
213 215
214 err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, &ring->context, 216 err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, &ring->context,
215 &ring->qp, &ring->qp_state); 217 &ring->qp, &ring->qp_state);
216 if (!user_prio && cpu_online(ring->queue_index)) 218 if (!cpumask_empty(&ring->affinity_mask))
217 netif_set_xps_queue(priv->dev, &ring->affinity_mask, 219 netif_set_xps_queue(priv->dev, &ring->affinity_mask,
218 ring->queue_index); 220 ring->queue_index);
219 221
diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index a4079811b176..e30bf57ad7a1 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -56,11 +56,13 @@ MODULE_PARM_DESC(enable_qos, "Enable Enhanced QoS support (default: on)");
56#define MLX4_GET(dest, source, offset) \ 56#define MLX4_GET(dest, source, offset) \
57 do { \ 57 do { \
58 void *__p = (char *) (source) + (offset); \ 58 void *__p = (char *) (source) + (offset); \
59 u64 val; \
59 switch (sizeof (dest)) { \ 60 switch (sizeof (dest)) { \
60 case 1: (dest) = *(u8 *) __p; break; \ 61 case 1: (dest) = *(u8 *) __p; break; \
61 case 2: (dest) = be16_to_cpup(__p); break; \ 62 case 2: (dest) = be16_to_cpup(__p); break; \
62 case 4: (dest) = be32_to_cpup(__p); break; \ 63 case 4: (dest) = be32_to_cpup(__p); break; \
63 case 8: (dest) = be64_to_cpup(__p); break; \ 64 case 8: val = get_unaligned((u64 *)__p); \
65 (dest) = be64_to_cpu(val); break; \
64 default: __buggy_use_of_MLX4_GET(); \ 66 default: __buggy_use_of_MLX4_GET(); \
65 } \ 67 } \
66 } while (0) 68 } while (0)
@@ -1605,9 +1607,17 @@ static void get_board_id(void *vsd, char *board_id)
1605 * swaps each 4-byte word before passing it back to 1607 * swaps each 4-byte word before passing it back to
1606 * us. Therefore we need to swab it before printing. 1608 * us. Therefore we need to swab it before printing.
1607 */ 1609 */
1608 for (i = 0; i < 4; ++i) 1610 u32 *bid_u32 = (u32 *)board_id;
1609 ((u32 *) board_id)[i] = 1611
1610 swab32(*(u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4)); 1612 for (i = 0; i < 4; ++i) {
1613 u32 *addr;
1614 u32 val;
1615
1616 addr = (u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4);
1617 val = get_unaligned(addr);
1618 val = swab32(val);
1619 put_unaligned(val, &bid_u32[i]);
1620 }
1611 } 1621 }
1612} 1622}
1613 1623
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 9de30216b146..d021f079f181 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -774,6 +774,7 @@ int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
774void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv, 774void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
775 struct mlx4_en_tx_ring *ring); 775 struct mlx4_en_tx_ring *ring);
776void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev); 776void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev);
777void mlx4_en_recover_from_oom(struct mlx4_en_priv *priv);
777int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv, 778int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv,
778 struct mlx4_en_rx_ring **pring, 779 struct mlx4_en_rx_ring **pring,
779 u32 size, u16 stride, int node); 780 u32 size, u16 stride, int node);
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index c7f28bf4b8e2..bafe2180cf0c 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -2845,7 +2845,7 @@ int mlx4_SW2HW_EQ_wrapper(struct mlx4_dev *dev, int slave,
2845{ 2845{
2846 int err; 2846 int err;
2847 int eqn = vhcr->in_modifier; 2847 int eqn = vhcr->in_modifier;
2848 int res_id = (slave << 8) | eqn; 2848 int res_id = (slave << 10) | eqn;
2849 struct mlx4_eq_context *eqc = inbox->buf; 2849 struct mlx4_eq_context *eqc = inbox->buf;
2850 int mtt_base = eq_get_mtt_addr(eqc) / dev->caps.mtt_entry_sz; 2850 int mtt_base = eq_get_mtt_addr(eqc) / dev->caps.mtt_entry_sz;
2851 int mtt_size = eq_get_mtt_size(eqc); 2851 int mtt_size = eq_get_mtt_size(eqc);
@@ -3051,7 +3051,7 @@ int mlx4_HW2SW_EQ_wrapper(struct mlx4_dev *dev, int slave,
3051 struct mlx4_cmd_info *cmd) 3051 struct mlx4_cmd_info *cmd)
3052{ 3052{
3053 int eqn = vhcr->in_modifier; 3053 int eqn = vhcr->in_modifier;
3054 int res_id = eqn | (slave << 8); 3054 int res_id = eqn | (slave << 10);
3055 struct res_eq *eq; 3055 struct res_eq *eq;
3056 int err; 3056 int err;
3057 3057
@@ -3108,7 +3108,7 @@ int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe)
3108 return 0; 3108 return 0;
3109 3109
3110 mutex_lock(&priv->mfunc.master.gen_eqe_mutex[slave]); 3110 mutex_lock(&priv->mfunc.master.gen_eqe_mutex[slave]);
3111 res_id = (slave << 8) | event_eq->eqn; 3111 res_id = (slave << 10) | event_eq->eqn;
3112 err = get_res(dev, slave, res_id, RES_EQ, &req); 3112 err = get_res(dev, slave, res_id, RES_EQ, &req);
3113 if (err) 3113 if (err)
3114 goto unlock; 3114 goto unlock;
@@ -3131,7 +3131,7 @@ int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe)
3131 3131
3132 memcpy(mailbox->buf, (u8 *) eqe, 28); 3132 memcpy(mailbox->buf, (u8 *) eqe, 28);
3133 3133
3134 in_modifier = (slave & 0xff) | ((event_eq->eqn & 0xff) << 16); 3134 in_modifier = (slave & 0xff) | ((event_eq->eqn & 0x3ff) << 16);
3135 3135
3136 err = mlx4_cmd(dev, mailbox->dma, in_modifier, 0, 3136 err = mlx4_cmd(dev, mailbox->dma, in_modifier, 0,
3137 MLX4_CMD_GEN_EQE, MLX4_CMD_TIME_CLASS_B, 3137 MLX4_CMD_GEN_EQE, MLX4_CMD_TIME_CLASS_B,
@@ -3157,7 +3157,7 @@ int mlx4_QUERY_EQ_wrapper(struct mlx4_dev *dev, int slave,
3157 struct mlx4_cmd_info *cmd) 3157 struct mlx4_cmd_info *cmd)
3158{ 3158{
3159 int eqn = vhcr->in_modifier; 3159 int eqn = vhcr->in_modifier;
3160 int res_id = eqn | (slave << 8); 3160 int res_id = eqn | (slave << 10);
3161 struct res_eq *eq; 3161 struct res_eq *eq;
3162 int err; 3162 int err;
3163 3163
@@ -3187,7 +3187,7 @@ int mlx4_SW2HW_CQ_wrapper(struct mlx4_dev *dev, int slave,
3187 int cqn = vhcr->in_modifier; 3187 int cqn = vhcr->in_modifier;
3188 struct mlx4_cq_context *cqc = inbox->buf; 3188 struct mlx4_cq_context *cqc = inbox->buf;
3189 int mtt_base = cq_get_mtt_addr(cqc) / dev->caps.mtt_entry_sz; 3189 int mtt_base = cq_get_mtt_addr(cqc) / dev->caps.mtt_entry_sz;
3190 struct res_cq *cq; 3190 struct res_cq *cq = NULL;
3191 struct res_mtt *mtt; 3191 struct res_mtt *mtt;
3192 3192
3193 err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_HW, &cq); 3193 err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_HW, &cq);
@@ -3223,7 +3223,7 @@ int mlx4_HW2SW_CQ_wrapper(struct mlx4_dev *dev, int slave,
3223{ 3223{
3224 int err; 3224 int err;
3225 int cqn = vhcr->in_modifier; 3225 int cqn = vhcr->in_modifier;
3226 struct res_cq *cq; 3226 struct res_cq *cq = NULL;
3227 3227
3228 err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_ALLOCATED, &cq); 3228 err = cq_res_start_move_to(dev, slave, cqn, RES_CQ_ALLOCATED, &cq);
3229 if (err) 3229 if (err)
@@ -3362,7 +3362,7 @@ int mlx4_SW2HW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
3362 int err; 3362 int err;
3363 int srqn = vhcr->in_modifier; 3363 int srqn = vhcr->in_modifier;
3364 struct res_mtt *mtt; 3364 struct res_mtt *mtt;
3365 struct res_srq *srq; 3365 struct res_srq *srq = NULL;
3366 struct mlx4_srq_context *srqc = inbox->buf; 3366 struct mlx4_srq_context *srqc = inbox->buf;
3367 int mtt_base = srq_get_mtt_addr(srqc) / dev->caps.mtt_entry_sz; 3367 int mtt_base = srq_get_mtt_addr(srqc) / dev->caps.mtt_entry_sz;
3368 3368
@@ -3406,7 +3406,7 @@ int mlx4_HW2SW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
3406{ 3406{
3407 int err; 3407 int err;
3408 int srqn = vhcr->in_modifier; 3408 int srqn = vhcr->in_modifier;
3409 struct res_srq *srq; 3409 struct res_srq *srq = NULL;
3410 3410
3411 err = srq_res_start_move_to(dev, slave, srqn, RES_SRQ_ALLOCATED, &srq); 3411 err = srq_res_start_move_to(dev, slave, srqn, RES_SRQ_ALLOCATED, &srq);
3412 if (err) 3412 if (err)
@@ -4714,13 +4714,13 @@ static void rem_slave_eqs(struct mlx4_dev *dev, int slave)
4714 break; 4714 break;
4715 4715
4716 case RES_EQ_HW: 4716 case RES_EQ_HW:
4717 err = mlx4_cmd(dev, slave, eqn & 0xff, 4717 err = mlx4_cmd(dev, slave, eqn & 0x3ff,
4718 1, MLX4_CMD_HW2SW_EQ, 4718 1, MLX4_CMD_HW2SW_EQ,
4719 MLX4_CMD_TIME_CLASS_A, 4719 MLX4_CMD_TIME_CLASS_A,
4720 MLX4_CMD_NATIVE); 4720 MLX4_CMD_NATIVE);
4721 if (err) 4721 if (err)
4722 mlx4_dbg(dev, "rem_slave_eqs: failed to move slave %d eqs %d to SW ownership\n", 4722 mlx4_dbg(dev, "rem_slave_eqs: failed to move slave %d eqs %d to SW ownership\n",
4723 slave, eqn); 4723 slave, eqn & 0x3ff);
4724 atomic_dec(&eq->mtt->ref_count); 4724 atomic_dec(&eq->mtt->ref_count);
4725 state = RES_EQ_RESERVED; 4725 state = RES_EQ_RESERVED;
4726 break; 4726 break;
diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
index 1412f5af05ec..2bae50292dcd 100644
--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
+++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
@@ -69,11 +69,7 @@
69#include <net/ip.h> 69#include <net/ip.h>
70#include <net/tcp.h> 70#include <net/tcp.h>
71#include <asm/byteorder.h> 71#include <asm/byteorder.h>
72#include <asm/io.h>
73#include <asm/processor.h> 72#include <asm/processor.h>
74#ifdef CONFIG_MTRR
75#include <asm/mtrr.h>
76#endif
77#include <net/busy_poll.h> 73#include <net/busy_poll.h>
78 74
79#include "myri10ge_mcp.h" 75#include "myri10ge_mcp.h"
@@ -242,8 +238,7 @@ struct myri10ge_priv {
242 unsigned int rdma_tags_available; 238 unsigned int rdma_tags_available;
243 int intr_coal_delay; 239 int intr_coal_delay;
244 __be32 __iomem *intr_coal_delay_ptr; 240 __be32 __iomem *intr_coal_delay_ptr;
245 int mtrr; 241 int wc_cookie;
246 int wc_enabled;
247 int down_cnt; 242 int down_cnt;
248 wait_queue_head_t down_wq; 243 wait_queue_head_t down_wq;
249 struct work_struct watchdog_work; 244 struct work_struct watchdog_work;
@@ -1905,7 +1900,7 @@ static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = {
1905 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", 1900 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
1906 "tx_heartbeat_errors", "tx_window_errors", 1901 "tx_heartbeat_errors", "tx_window_errors",
1907 /* device-specific stats */ 1902 /* device-specific stats */
1908 "tx_boundary", "WC", "irq", "MSI", "MSIX", 1903 "tx_boundary", "irq", "MSI", "MSIX",
1909 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs", 1904 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
1910 "serial_number", "watchdog_resets", 1905 "serial_number", "watchdog_resets",
1911#ifdef CONFIG_MYRI10GE_DCA 1906#ifdef CONFIG_MYRI10GE_DCA
@@ -1984,7 +1979,6 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,
1984 data[i] = ((u64 *)&link_stats)[i]; 1979 data[i] = ((u64 *)&link_stats)[i];
1985 1980
1986 data[i++] = (unsigned int)mgp->tx_boundary; 1981 data[i++] = (unsigned int)mgp->tx_boundary;
1987 data[i++] = (unsigned int)mgp->wc_enabled;
1988 data[i++] = (unsigned int)mgp->pdev->irq; 1982 data[i++] = (unsigned int)mgp->pdev->irq;
1989 data[i++] = (unsigned int)mgp->msi_enabled; 1983 data[i++] = (unsigned int)mgp->msi_enabled;
1990 data[i++] = (unsigned int)mgp->msix_enabled; 1984 data[i++] = (unsigned int)mgp->msix_enabled;
@@ -4040,14 +4034,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4040 4034
4041 mgp->board_span = pci_resource_len(pdev, 0); 4035 mgp->board_span = pci_resource_len(pdev, 0);
4042 mgp->iomem_base = pci_resource_start(pdev, 0); 4036 mgp->iomem_base = pci_resource_start(pdev, 0);
4043 mgp->mtrr = -1; 4037 mgp->wc_cookie = arch_phys_wc_add(mgp->iomem_base, mgp->board_span);
4044 mgp->wc_enabled = 0;
4045#ifdef CONFIG_MTRR
4046 mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span,
4047 MTRR_TYPE_WRCOMB, 1);
4048 if (mgp->mtrr >= 0)
4049 mgp->wc_enabled = 1;
4050#endif
4051 mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span); 4038 mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span);
4052 if (mgp->sram == NULL) { 4039 if (mgp->sram == NULL) {
4053 dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n", 4040 dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n",
@@ -4146,14 +4133,14 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4146 goto abort_with_state; 4133 goto abort_with_state;
4147 } 4134 }
4148 if (mgp->msix_enabled) 4135 if (mgp->msix_enabled)
4149 dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, WC %s\n", 4136 dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
4150 mgp->num_slices, mgp->tx_boundary, mgp->fw_name, 4137 mgp->num_slices, mgp->tx_boundary, mgp->fw_name,
4151 (mgp->wc_enabled ? "Enabled" : "Disabled")); 4138 (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
4152 else 4139 else
4153 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", 4140 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
4154 mgp->msi_enabled ? "MSI" : "xPIC", 4141 mgp->msi_enabled ? "MSI" : "xPIC",
4155 pdev->irq, mgp->tx_boundary, mgp->fw_name, 4142 pdev->irq, mgp->tx_boundary, mgp->fw_name,
4156 (mgp->wc_enabled ? "Enabled" : "Disabled")); 4143 (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
4157 4144
4158 board_number++; 4145 board_number++;
4159 return 0; 4146 return 0;
@@ -4175,10 +4162,7 @@ abort_with_ioremap:
4175 iounmap(mgp->sram); 4162 iounmap(mgp->sram);
4176 4163
4177abort_with_mtrr: 4164abort_with_mtrr:
4178#ifdef CONFIG_MTRR 4165 arch_phys_wc_del(mgp->wc_cookie);
4179 if (mgp->mtrr >= 0)
4180 mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
4181#endif
4182 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4166 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
4183 mgp->cmd, mgp->cmd_bus); 4167 mgp->cmd, mgp->cmd_bus);
4184 4168
@@ -4220,11 +4204,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
4220 pci_restore_state(pdev); 4204 pci_restore_state(pdev);
4221 4205
4222 iounmap(mgp->sram); 4206 iounmap(mgp->sram);
4223 4207 arch_phys_wc_del(mgp->wc_cookie);
4224#ifdef CONFIG_MTRR
4225 if (mgp->mtrr >= 0)
4226 mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
4227#endif
4228 myri10ge_free_slices(mgp); 4208 myri10ge_free_slices(mgp);
4229 kfree(mgp->msix_vectors); 4209 kfree(mgp->msix_vectors);
4230 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4210 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c
index 5c4068353f66..7b43a3b4abdc 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_init.c
@@ -135,7 +135,7 @@ void netxen_release_tx_buffers(struct netxen_adapter *adapter)
135 int i, j; 135 int i, j;
136 struct nx_host_tx_ring *tx_ring = adapter->tx_ring; 136 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
137 137
138 spin_lock(&adapter->tx_clean_lock); 138 spin_lock_bh(&adapter->tx_clean_lock);
139 cmd_buf = tx_ring->cmd_buf_arr; 139 cmd_buf = tx_ring->cmd_buf_arr;
140 for (i = 0; i < tx_ring->num_desc; i++) { 140 for (i = 0; i < tx_ring->num_desc; i++) {
141 buffrag = cmd_buf->frag_array; 141 buffrag = cmd_buf->frag_array;
@@ -159,7 +159,7 @@ void netxen_release_tx_buffers(struct netxen_adapter *adapter)
159 } 159 }
160 cmd_buf++; 160 cmd_buf++;
161 } 161 }
162 spin_unlock(&adapter->tx_clean_lock); 162 spin_unlock_bh(&adapter->tx_clean_lock);
163} 163}
164 164
165void netxen_free_sw_resources(struct netxen_adapter *adapter) 165void netxen_free_sw_resources(struct netxen_adapter *adapter)
@@ -1764,7 +1764,7 @@ int netxen_process_cmd_ring(struct netxen_adapter *adapter)
1764 int done = 0; 1764 int done = 0;
1765 struct nx_host_tx_ring *tx_ring = adapter->tx_ring; 1765 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
1766 1766
1767 if (!spin_trylock(&adapter->tx_clean_lock)) 1767 if (!spin_trylock_bh(&adapter->tx_clean_lock))
1768 return 1; 1768 return 1;
1769 1769
1770 sw_consumer = tx_ring->sw_consumer; 1770 sw_consumer = tx_ring->sw_consumer;
@@ -1819,7 +1819,7 @@ int netxen_process_cmd_ring(struct netxen_adapter *adapter)
1819 */ 1819 */
1820 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); 1820 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
1821 done = (sw_consumer == hw_consumer); 1821 done = (sw_consumer == hw_consumer);
1822 spin_unlock(&adapter->tx_clean_lock); 1822 spin_unlock_bh(&adapter->tx_clean_lock);
1823 1823
1824 return done; 1824 return done;
1825} 1825}
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
index e0c31e3947d1..6409a06bbdf6 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
@@ -3025,9 +3025,9 @@ netxen_sysfs_read_dimm(struct file *filp, struct kobject *kobj,
3025 u8 dw, rows, cols, banks, ranks; 3025 u8 dw, rows, cols, banks, ranks;
3026 u32 val; 3026 u32 val;
3027 3027
3028 if (size != sizeof(struct netxen_dimm_cfg)) { 3028 if (size < attr->size) {
3029 netdev_err(netdev, "Invalid size\n"); 3029 netdev_err(netdev, "Invalid size\n");
3030 return -1; 3030 return -EINVAL;
3031 } 3031 }
3032 3032
3033 memset(&dimm, 0, sizeof(struct netxen_dimm_cfg)); 3033 memset(&dimm, 0, sizeof(struct netxen_dimm_cfg));
@@ -3137,7 +3137,7 @@ out:
3137 3137
3138static struct bin_attribute bin_attr_dimm = { 3138static struct bin_attribute bin_attr_dimm = {
3139 .attr = { .name = "dimm", .mode = (S_IRUGO | S_IWUSR) }, 3139 .attr = { .name = "dimm", .mode = (S_IRUGO | S_IWUSR) },
3140 .size = 0, 3140 .size = sizeof(struct netxen_dimm_cfg),
3141 .read = netxen_sysfs_read_dimm, 3141 .read = netxen_sysfs_read_dimm,
3142}; 3142};
3143 3143
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c
index f66641d961e3..6af028d5f9bc 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -912,6 +912,8 @@ qca_spi_probe(struct spi_device *spi_device)
912 qca->spi_dev = spi_device; 912 qca->spi_dev = spi_device;
913 qca->legacy_mode = legacy_mode; 913 qca->legacy_mode = legacy_mode;
914 914
915 spi_set_drvdata(spi_device, qcaspi_devs);
916
915 mac = of_get_mac_address(spi_device->dev.of_node); 917 mac = of_get_mac_address(spi_device->dev.of_node);
916 918
917 if (mac) 919 if (mac)
@@ -944,8 +946,6 @@ qca_spi_probe(struct spi_device *spi_device)
944 return -EFAULT; 946 return -EFAULT;
945 } 947 }
946 948
947 spi_set_drvdata(spi_device, qcaspi_devs);
948
949 qcaspi_init_device_debugfs(qca); 949 qcaspi_init_device_debugfs(qca);
950 950
951 return 0; 951 return 0;
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index c70ab40d8698..3df51faf18ae 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -6884,7 +6884,7 @@ static void r8169_csum_workaround(struct rtl8169_private *tp,
6884 rtl8169_start_xmit(nskb, tp->dev); 6884 rtl8169_start_xmit(nskb, tp->dev);
6885 } while (segs); 6885 } while (segs);
6886 6886
6887 dev_kfree_skb(skb); 6887 dev_consume_skb_any(skb);
6888 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { 6888 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
6889 if (skb_checksum_help(skb) < 0) 6889 if (skb_checksum_help(skb) < 0)
6890 goto drop; 6890 goto drop;
@@ -6896,7 +6896,7 @@ static void r8169_csum_workaround(struct rtl8169_private *tp,
6896drop: 6896drop:
6897 stats = &tp->dev->stats; 6897 stats = &tp->dev->stats;
6898 stats->tx_dropped++; 6898 stats->tx_dropped++;
6899 dev_kfree_skb(skb); 6899 dev_kfree_skb_any(skb);
6900 } 6900 }
6901} 6901}
6902 6902
diff --git a/drivers/net/ethernet/rocker/rocker.c b/drivers/net/ethernet/rocker/rocker.c
index a570a60533be..cf98cc9bbc8d 100644
--- a/drivers/net/ethernet/rocker/rocker.c
+++ b/drivers/net/ethernet/rocker/rocker.c
@@ -2921,10 +2921,11 @@ static int rocker_port_ipv4_resolve(struct rocker_port *rocker_port,
2921 struct neighbour *n = __ipv4_neigh_lookup(dev, (__force u32)ip_addr); 2921 struct neighbour *n = __ipv4_neigh_lookup(dev, (__force u32)ip_addr);
2922 int err = 0; 2922 int err = 0;
2923 2923
2924 if (!n) 2924 if (!n) {
2925 n = neigh_create(&arp_tbl, &ip_addr, dev); 2925 n = neigh_create(&arp_tbl, &ip_addr, dev);
2926 if (!n) 2926 if (IS_ERR(n))
2927 return -ENOMEM; 2927 return IS_ERR(n);
2928 }
2928 2929
2929 /* If the neigh is already resolved, then go ahead and 2930 /* If the neigh is already resolved, then go ahead and
2930 * install the entry, otherwise start the ARP process to 2931 * install the entry, otherwise start the ARP process to
@@ -2936,6 +2937,7 @@ static int rocker_port_ipv4_resolve(struct rocker_port *rocker_port,
2936 else 2937 else
2937 neigh_event_send(n, NULL); 2938 neigh_event_send(n, NULL);
2938 2939
2940 neigh_release(n);
2939 return err; 2941 return err;
2940} 2942}
2941 2943
@@ -4176,14 +4178,15 @@ static int rocker_port_bridge_setlink(struct net_device *dev,
4176 4178
4177static int rocker_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 4179static int rocker_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4178 struct net_device *dev, 4180 struct net_device *dev,
4179 u32 filter_mask) 4181 u32 filter_mask, int nlflags)
4180{ 4182{
4181 struct rocker_port *rocker_port = netdev_priv(dev); 4183 struct rocker_port *rocker_port = netdev_priv(dev);
4182 u16 mode = BRIDGE_MODE_UNDEF; 4184 u16 mode = BRIDGE_MODE_UNDEF;
4183 u32 mask = BR_LEARNING | BR_LEARNING_SYNC; 4185 u32 mask = BR_LEARNING | BR_LEARNING_SYNC;
4184 4186
4185 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode, 4187 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode,
4186 rocker_port->brport_flags, mask); 4188 rocker_port->brport_flags, mask,
4189 nlflags);
4187} 4190}
4188 4191
4189static int rocker_port_get_phys_port_name(struct net_device *dev, 4192static int rocker_port_get_phys_port_name(struct net_device *dev,
diff --git a/drivers/net/ethernet/smsc/smc91x.c b/drivers/net/ethernet/smsc/smc91x.c
index 14b363a25c02..630f0b7800e4 100644
--- a/drivers/net/ethernet/smsc/smc91x.c
+++ b/drivers/net/ethernet/smsc/smc91x.c
@@ -2238,9 +2238,10 @@ static int smc_drv_probe(struct platform_device *pdev)
2238 const struct of_device_id *match = NULL; 2238 const struct of_device_id *match = NULL;
2239 struct smc_local *lp; 2239 struct smc_local *lp;
2240 struct net_device *ndev; 2240 struct net_device *ndev;
2241 struct resource *res, *ires; 2241 struct resource *res;
2242 unsigned int __iomem *addr; 2242 unsigned int __iomem *addr;
2243 unsigned long irq_flags = SMC_IRQ_FLAGS; 2243 unsigned long irq_flags = SMC_IRQ_FLAGS;
2244 unsigned long irq_resflags;
2244 int ret; 2245 int ret;
2245 2246
2246 ndev = alloc_etherdev(sizeof(struct smc_local)); 2247 ndev = alloc_etherdev(sizeof(struct smc_local));
@@ -2332,16 +2333,19 @@ static int smc_drv_probe(struct platform_device *pdev)
2332 goto out_free_netdev; 2333 goto out_free_netdev;
2333 } 2334 }
2334 2335
2335 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 2336 ndev->irq = platform_get_irq(pdev, 0);
2336 if (!ires) { 2337 if (ndev->irq <= 0) {
2337 ret = -ENODEV; 2338 ret = -ENODEV;
2338 goto out_release_io; 2339 goto out_release_io;
2339 } 2340 }
2340 2341 /*
2341 ndev->irq = ires->start; 2342 * If this platform does not specify any special irqflags, or if
2342 2343 * the resource supplies a trigger, override the irqflags with
2343 if (irq_flags == -1 || ires->flags & IRQF_TRIGGER_MASK) 2344 * the trigger flags from the resource.
2344 irq_flags = ires->flags & IRQF_TRIGGER_MASK; 2345 */
2346 irq_resflags = irqd_get_trigger_type(irq_get_irq_data(ndev->irq));
2347 if (irq_flags == -1 || irq_resflags & IRQF_TRIGGER_MASK)
2348 irq_flags = irq_resflags & IRQF_TRIGGER_MASK;
2345 2349
2346 ret = smc_request_attrib(pdev, ndev); 2350 ret = smc_request_attrib(pdev, ndev);
2347 if (ret) 2351 if (ret)
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 41047c9143d0..959aeeade0c9 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -2418,9 +2418,9 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
2418 struct net_device *dev; 2418 struct net_device *dev;
2419 struct smsc911x_data *pdata; 2419 struct smsc911x_data *pdata;
2420 struct smsc911x_platform_config *config = dev_get_platdata(&pdev->dev); 2420 struct smsc911x_platform_config *config = dev_get_platdata(&pdev->dev);
2421 struct resource *res, *irq_res; 2421 struct resource *res;
2422 unsigned int intcfg = 0; 2422 unsigned int intcfg = 0;
2423 int res_size, irq_flags; 2423 int res_size, irq, irq_flags;
2424 int retval; 2424 int retval;
2425 2425
2426 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 2426 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
@@ -2434,8 +2434,8 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
2434 } 2434 }
2435 res_size = resource_size(res); 2435 res_size = resource_size(res);
2436 2436
2437 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 2437 irq = platform_get_irq(pdev, 0);
2438 if (!irq_res) { 2438 if (irq <= 0) {
2439 pr_warn("Could not allocate irq resource\n"); 2439 pr_warn("Could not allocate irq resource\n");
2440 retval = -ENODEV; 2440 retval = -ENODEV;
2441 goto out_0; 2441 goto out_0;
@@ -2455,8 +2455,8 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
2455 SET_NETDEV_DEV(dev, &pdev->dev); 2455 SET_NETDEV_DEV(dev, &pdev->dev);
2456 2456
2457 pdata = netdev_priv(dev); 2457 pdata = netdev_priv(dev);
2458 dev->irq = irq_res->start; 2458 dev->irq = irq;
2459 irq_flags = irq_res->flags & IRQF_TRIGGER_MASK; 2459 irq_flags = irq_get_trigger_type(irq);
2460 pdata->ioaddr = ioremap_nocache(res->start, res_size); 2460 pdata->ioaddr = ioremap_nocache(res->start, res_size);
2461 2461
2462 pdata->dev = dev; 2462 pdata->dev = dev;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 2ac9552d1fa3..73bab983edd9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -117,6 +117,12 @@ struct stmmac_priv {
117 int use_riwt; 117 int use_riwt;
118 int irq_wake; 118 int irq_wake;
119 spinlock_t ptp_lock; 119 spinlock_t ptp_lock;
120
121#ifdef CONFIG_DEBUG_FS
122 struct dentry *dbgfs_dir;
123 struct dentry *dbgfs_rings_status;
124 struct dentry *dbgfs_dma_cap;
125#endif
120}; 126};
121 127
122int stmmac_mdio_unregister(struct net_device *ndev); 128int stmmac_mdio_unregister(struct net_device *ndev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 05c146f718a3..2c5ce2baca87 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -118,7 +118,7 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
118 118
119#ifdef CONFIG_DEBUG_FS 119#ifdef CONFIG_DEBUG_FS
120static int stmmac_init_fs(struct net_device *dev); 120static int stmmac_init_fs(struct net_device *dev);
121static void stmmac_exit_fs(void); 121static void stmmac_exit_fs(struct net_device *dev);
122#endif 122#endif
123 123
124#define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x)) 124#define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
@@ -1916,7 +1916,7 @@ static int stmmac_release(struct net_device *dev)
1916 netif_carrier_off(dev); 1916 netif_carrier_off(dev);
1917 1917
1918#ifdef CONFIG_DEBUG_FS 1918#ifdef CONFIG_DEBUG_FS
1919 stmmac_exit_fs(); 1919 stmmac_exit_fs(dev);
1920#endif 1920#endif
1921 1921
1922 stmmac_release_ptp(priv); 1922 stmmac_release_ptp(priv);
@@ -2508,8 +2508,6 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2508 2508
2509#ifdef CONFIG_DEBUG_FS 2509#ifdef CONFIG_DEBUG_FS
2510static struct dentry *stmmac_fs_dir; 2510static struct dentry *stmmac_fs_dir;
2511static struct dentry *stmmac_rings_status;
2512static struct dentry *stmmac_dma_cap;
2513 2511
2514static void sysfs_display_ring(void *head, int size, int extend_desc, 2512static void sysfs_display_ring(void *head, int size, int extend_desc,
2515 struct seq_file *seq) 2513 struct seq_file *seq)
@@ -2648,36 +2646,39 @@ static const struct file_operations stmmac_dma_cap_fops = {
2648 2646
2649static int stmmac_init_fs(struct net_device *dev) 2647static int stmmac_init_fs(struct net_device *dev)
2650{ 2648{
2651 /* Create debugfs entries */ 2649 struct stmmac_priv *priv = netdev_priv(dev);
2652 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL); 2650
2651 /* Create per netdev entries */
2652 priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir);
2653 2653
2654 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) { 2654 if (!priv->dbgfs_dir || IS_ERR(priv->dbgfs_dir)) {
2655 pr_err("ERROR %s, debugfs create directory failed\n", 2655 pr_err("ERROR %s/%s, debugfs create directory failed\n",
2656 STMMAC_RESOURCE_NAME); 2656 STMMAC_RESOURCE_NAME, dev->name);
2657 2657
2658 return -ENOMEM; 2658 return -ENOMEM;
2659 } 2659 }
2660 2660
2661 /* Entry to report DMA RX/TX rings */ 2661 /* Entry to report DMA RX/TX rings */
2662 stmmac_rings_status = debugfs_create_file("descriptors_status", 2662 priv->dbgfs_rings_status =
2663 S_IRUGO, stmmac_fs_dir, dev, 2663 debugfs_create_file("descriptors_status", S_IRUGO,
2664 &stmmac_rings_status_fops); 2664 priv->dbgfs_dir, dev,
2665 &stmmac_rings_status_fops);
2665 2666
2666 if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) { 2667 if (!priv->dbgfs_rings_status || IS_ERR(priv->dbgfs_rings_status)) {
2667 pr_info("ERROR creating stmmac ring debugfs file\n"); 2668 pr_info("ERROR creating stmmac ring debugfs file\n");
2668 debugfs_remove(stmmac_fs_dir); 2669 debugfs_remove_recursive(priv->dbgfs_dir);
2669 2670
2670 return -ENOMEM; 2671 return -ENOMEM;
2671 } 2672 }
2672 2673
2673 /* Entry to report the DMA HW features */ 2674 /* Entry to report the DMA HW features */
2674 stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir, 2675 priv->dbgfs_dma_cap = debugfs_create_file("dma_cap", S_IRUGO,
2675 dev, &stmmac_dma_cap_fops); 2676 priv->dbgfs_dir,
2677 dev, &stmmac_dma_cap_fops);
2676 2678
2677 if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) { 2679 if (!priv->dbgfs_dma_cap || IS_ERR(priv->dbgfs_dma_cap)) {
2678 pr_info("ERROR creating stmmac MMC debugfs file\n"); 2680 pr_info("ERROR creating stmmac MMC debugfs file\n");
2679 debugfs_remove(stmmac_rings_status); 2681 debugfs_remove_recursive(priv->dbgfs_dir);
2680 debugfs_remove(stmmac_fs_dir);
2681 2682
2682 return -ENOMEM; 2683 return -ENOMEM;
2683 } 2684 }
@@ -2685,11 +2686,11 @@ static int stmmac_init_fs(struct net_device *dev)
2685 return 0; 2686 return 0;
2686} 2687}
2687 2688
2688static void stmmac_exit_fs(void) 2689static void stmmac_exit_fs(struct net_device *dev)
2689{ 2690{
2690 debugfs_remove(stmmac_rings_status); 2691 struct stmmac_priv *priv = netdev_priv(dev);
2691 debugfs_remove(stmmac_dma_cap); 2692
2692 debugfs_remove(stmmac_fs_dir); 2693 debugfs_remove_recursive(priv->dbgfs_dir);
2693} 2694}
2694#endif /* CONFIG_DEBUG_FS */ 2695#endif /* CONFIG_DEBUG_FS */
2695 2696
@@ -3149,6 +3150,35 @@ err:
3149__setup("stmmaceth=", stmmac_cmdline_opt); 3150__setup("stmmaceth=", stmmac_cmdline_opt);
3150#endif /* MODULE */ 3151#endif /* MODULE */
3151 3152
3153static int __init stmmac_init(void)
3154{
3155#ifdef CONFIG_DEBUG_FS
3156 /* Create debugfs main directory if it doesn't exist yet */
3157 if (!stmmac_fs_dir) {
3158 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
3159
3160 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
3161 pr_err("ERROR %s, debugfs create directory failed\n",
3162 STMMAC_RESOURCE_NAME);
3163
3164 return -ENOMEM;
3165 }
3166 }
3167#endif
3168
3169 return 0;
3170}
3171
3172static void __exit stmmac_exit(void)
3173{
3174#ifdef CONFIG_DEBUG_FS
3175 debugfs_remove_recursive(stmmac_fs_dir);
3176#endif
3177}
3178
3179module_init(stmmac_init)
3180module_exit(stmmac_exit)
3181
3152MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver"); 3182MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
3153MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); 3183MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
3154MODULE_LICENSE("GPL"); 3184MODULE_LICENSE("GPL");
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 705bbdf93940..68aec5c460db 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -23,6 +23,7 @@
23*******************************************************************************/ 23*******************************************************************************/
24 24
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/module.h>
26#include <linux/io.h> 27#include <linux/io.h>
27#include <linux/of.h> 28#include <linux/of.h>
28#include <linux/of_net.h> 29#include <linux/of_net.h>
diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c
index 2bef655279f3..9b7e0a34c98b 100644
--- a/drivers/net/ethernet/ti/netcp_ethss.c
+++ b/drivers/net/ethernet/ti/netcp_ethss.c
@@ -1765,7 +1765,9 @@ static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev,
1765 ALE_PORT_STATE, 1765 ALE_PORT_STATE,
1766 ALE_PORT_STATE_FORWARD); 1766 ALE_PORT_STATE_FORWARD);
1767 1767
1768 if (ndev && slave->open) 1768 if (ndev && slave->open &&
1769 slave->link_interface != SGMII_LINK_MAC_PHY &&
1770 slave->link_interface != XGMII_LINK_MAC_PHY)
1769 netif_carrier_on(ndev); 1771 netif_carrier_on(ndev);
1770 } else { 1772 } else {
1771 writel(mac_control, GBE_REG_ADDR(slave, emac_regs, 1773 writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
@@ -1773,7 +1775,9 @@ static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev,
1773 cpsw_ale_control_set(gbe_dev->ale, slave->port_num, 1775 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
1774 ALE_PORT_STATE, 1776 ALE_PORT_STATE,
1775 ALE_PORT_STATE_DISABLE); 1777 ALE_PORT_STATE_DISABLE);
1776 if (ndev) 1778 if (ndev &&
1779 slave->link_interface != SGMII_LINK_MAC_PHY &&
1780 slave->link_interface != XGMII_LINK_MAC_PHY)
1777 netif_carrier_off(ndev); 1781 netif_carrier_off(ndev);
1778 } 1782 }
1779 1783
diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 690a4c36b316..af2694dc6f90 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -707,8 +707,8 @@ static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
707 707
708 cur_p->app0 |= STS_CTRL_APP0_SOP; 708 cur_p->app0 |= STS_CTRL_APP0_SOP;
709 cur_p->len = skb_headlen(skb); 709 cur_p->len = skb_headlen(skb);
710 cur_p->phys = dma_map_single(ndev->dev.parent, skb->data, skb->len, 710 cur_p->phys = dma_map_single(ndev->dev.parent, skb->data,
711 DMA_TO_DEVICE); 711 skb_headlen(skb), DMA_TO_DEVICE);
712 cur_p->app4 = (unsigned long)skb; 712 cur_p->app4 = (unsigned long)skb;
713 713
714 for (ii = 0; ii < num_frag; ii++) { 714 for (ii = 0; ii < num_frag; ii++) {
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index a10b31664709..41071d32bc8e 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -128,7 +128,6 @@ struct ndis_tcp_ip_checksum_info;
128struct hv_netvsc_packet { 128struct hv_netvsc_packet {
129 /* Bookkeeping stuff */ 129 /* Bookkeeping stuff */
130 u32 status; 130 u32 status;
131 bool part_of_skb;
132 131
133 bool is_data_pkt; 132 bool is_data_pkt;
134 bool xmit_more; /* from skb */ 133 bool xmit_more; /* from skb */
@@ -612,6 +611,15 @@ struct multi_send_data {
612 u32 count; /* counter of batched packets */ 611 u32 count; /* counter of batched packets */
613}; 612};
614 613
614/* The context of the netvsc device */
615struct net_device_context {
616 /* point back to our device context */
617 struct hv_device *device_ctx;
618 struct delayed_work dwork;
619 struct work_struct work;
620 u32 msg_enable; /* debug level */
621};
622
615/* Per netvsc device */ 623/* Per netvsc device */
616struct netvsc_device { 624struct netvsc_device {
617 struct hv_device *dev; 625 struct hv_device *dev;
@@ -667,6 +675,9 @@ struct netvsc_device {
667 struct multi_send_data msd[NR_CPUS]; 675 struct multi_send_data msd[NR_CPUS];
668 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */ 676 u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
669 u32 pkt_align; /* alignment bytes, e.g. 8 */ 677 u32 pkt_align; /* alignment bytes, e.g. 8 */
678
679 /* The net device context */
680 struct net_device_context *nd_ctx;
670}; 681};
671 682
672/* NdisInitialize message */ 683/* NdisInitialize message */
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 2e8ad0636b46..ea091bc5ff09 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -826,7 +826,6 @@ int netvsc_send(struct hv_device *device,
826 u16 q_idx = packet->q_idx; 826 u16 q_idx = packet->q_idx;
827 u32 pktlen = packet->total_data_buflen, msd_len = 0; 827 u32 pktlen = packet->total_data_buflen, msd_len = 0;
828 unsigned int section_index = NETVSC_INVALID_INDEX; 828 unsigned int section_index = NETVSC_INVALID_INDEX;
829 struct sk_buff *skb = NULL;
830 unsigned long flag; 829 unsigned long flag;
831 struct multi_send_data *msdp; 830 struct multi_send_data *msdp;
832 struct hv_netvsc_packet *msd_send = NULL, *cur_send = NULL; 831 struct hv_netvsc_packet *msd_send = NULL, *cur_send = NULL;
@@ -889,11 +888,6 @@ int netvsc_send(struct hv_device *device,
889 } else { 888 } else {
890 packet->page_buf_cnt = 0; 889 packet->page_buf_cnt = 0;
891 packet->total_data_buflen += msd_len; 890 packet->total_data_buflen += msd_len;
892 if (!packet->part_of_skb) {
893 skb = (struct sk_buff *)(unsigned long)packet->
894 send_completion_tid;
895 packet->send_completion_tid = 0;
896 }
897 } 891 }
898 892
899 if (msdp->pkt) 893 if (msdp->pkt)
@@ -929,12 +923,8 @@ int netvsc_send(struct hv_device *device,
929 if (cur_send) 923 if (cur_send)
930 ret = netvsc_send_pkt(cur_send, net_device); 924 ret = netvsc_send_pkt(cur_send, net_device);
931 925
932 if (ret != 0) { 926 if (ret != 0 && section_index != NETVSC_INVALID_INDEX)
933 if (section_index != NETVSC_INVALID_INDEX) 927 netvsc_free_send_slot(net_device, section_index);
934 netvsc_free_send_slot(net_device, section_index);
935 } else if (skb) {
936 dev_kfree_skb_any(skb);
937 }
938 928
939 return ret; 929 return ret;
940} 930}
@@ -1197,6 +1187,9 @@ int netvsc_device_add(struct hv_device *device, void *additional_info)
1197 */ 1187 */
1198 ndev = net_device->ndev; 1188 ndev = net_device->ndev;
1199 1189
1190 /* Add netvsc_device context to netvsc_device */
1191 net_device->nd_ctx = netdev_priv(ndev);
1192
1200 /* Initialize the NetVSC channel extension */ 1193 /* Initialize the NetVSC channel extension */
1201 init_completion(&net_device->channel_init_wait); 1194 init_completion(&net_device->channel_init_wait);
1202 1195
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index a3a9d3898a6e..5993c7e2d723 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -40,18 +40,21 @@
40 40
41#include "hyperv_net.h" 41#include "hyperv_net.h"
42 42
43struct net_device_context {
44 /* point back to our device context */
45 struct hv_device *device_ctx;
46 struct delayed_work dwork;
47 struct work_struct work;
48};
49 43
50#define RING_SIZE_MIN 64 44#define RING_SIZE_MIN 64
51static int ring_size = 128; 45static int ring_size = 128;
52module_param(ring_size, int, S_IRUGO); 46module_param(ring_size, int, S_IRUGO);
53MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); 47MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
54 48
49static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
50 NETIF_MSG_LINK | NETIF_MSG_IFUP |
51 NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR |
52 NETIF_MSG_TX_ERR;
53
54static int debug = -1;
55module_param(debug, int, S_IRUGO);
56MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
57
55static void do_set_multicast(struct work_struct *w) 58static void do_set_multicast(struct work_struct *w)
56{ 59{
57 struct net_device_context *ndevctx = 60 struct net_device_context *ndevctx =
@@ -235,9 +238,6 @@ void netvsc_xmit_completion(void *context)
235 struct sk_buff *skb = (struct sk_buff *) 238 struct sk_buff *skb = (struct sk_buff *)
236 (unsigned long)packet->send_completion_tid; 239 (unsigned long)packet->send_completion_tid;
237 240
238 if (!packet->part_of_skb)
239 kfree(packet);
240
241 if (skb) 241 if (skb)
242 dev_kfree_skb_any(skb); 242 dev_kfree_skb_any(skb);
243} 243}
@@ -389,7 +389,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
389 u32 net_trans_info; 389 u32 net_trans_info;
390 u32 hash; 390 u32 hash;
391 u32 skb_length; 391 u32 skb_length;
392 u32 head_room;
393 u32 pkt_sz; 392 u32 pkt_sz;
394 struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT]; 393 struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT];
395 394
@@ -402,7 +401,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
402 401
403check_size: 402check_size:
404 skb_length = skb->len; 403 skb_length = skb->len;
405 head_room = skb_headroom(skb);
406 num_data_pgs = netvsc_get_slots(skb) + 2; 404 num_data_pgs = netvsc_get_slots(skb) + 2;
407 if (num_data_pgs > MAX_PAGE_BUFFER_COUNT && linear) { 405 if (num_data_pgs > MAX_PAGE_BUFFER_COUNT && linear) {
408 net_alert_ratelimited("packet too big: %u pages (%u bytes)\n", 406 net_alert_ratelimited("packet too big: %u pages (%u bytes)\n",
@@ -421,20 +419,14 @@ check_size:
421 419
422 pkt_sz = sizeof(struct hv_netvsc_packet) + RNDIS_AND_PPI_SIZE; 420 pkt_sz = sizeof(struct hv_netvsc_packet) + RNDIS_AND_PPI_SIZE;
423 421
424 if (head_room < pkt_sz) { 422 ret = skb_cow_head(skb, pkt_sz);
425 packet = kmalloc(pkt_sz, GFP_ATOMIC); 423 if (ret) {
426 if (!packet) { 424 netdev_err(net, "unable to alloc hv_netvsc_packet\n");
427 /* out of memory, drop packet */ 425 ret = -ENOMEM;
428 netdev_err(net, "unable to alloc hv_netvsc_packet\n"); 426 goto drop;
429 ret = -ENOMEM;
430 goto drop;
431 }
432 packet->part_of_skb = false;
433 } else {
434 /* Use the headroom for building up the packet */
435 packet = (struct hv_netvsc_packet *)skb->head;
436 packet->part_of_skb = true;
437 } 427 }
428 /* Use the headroom for building up the packet */
429 packet = (struct hv_netvsc_packet *)skb->head;
438 430
439 packet->status = 0; 431 packet->status = 0;
440 packet->xmit_more = skb->xmit_more; 432 packet->xmit_more = skb->xmit_more;
@@ -591,8 +583,6 @@ drop:
591 net->stats.tx_bytes += skb_length; 583 net->stats.tx_bytes += skb_length;
592 net->stats.tx_packets++; 584 net->stats.tx_packets++;
593 } else { 585 } else {
594 if (packet && !packet->part_of_skb)
595 kfree(packet);
596 if (ret != -EAGAIN) { 586 if (ret != -EAGAIN) {
597 dev_kfree_skb_any(skb); 587 dev_kfree_skb_any(skb);
598 net->stats.tx_dropped++; 588 net->stats.tx_dropped++;
@@ -888,6 +878,11 @@ static int netvsc_probe(struct hv_device *dev,
888 878
889 net_device_ctx = netdev_priv(net); 879 net_device_ctx = netdev_priv(net);
890 net_device_ctx->device_ctx = dev; 880 net_device_ctx->device_ctx = dev;
881 net_device_ctx->msg_enable = netif_msg_init(debug, default_msg);
882 if (netif_msg_probe(net_device_ctx))
883 netdev_dbg(net, "netvsc msg_enable: %d\n",
884 net_device_ctx->msg_enable);
885
891 hv_set_drvdata(dev, net); 886 hv_set_drvdata(dev, net);
892 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change); 887 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change);
893 INIT_WORK(&net_device_ctx->work, do_set_multicast); 888 INIT_WORK(&net_device_ctx->work, do_set_multicast);
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 0d92efefd796..9118cea91882 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -429,7 +429,8 @@ int rndis_filter_receive(struct hv_device *dev,
429 429
430 rndis_msg = pkt->data; 430 rndis_msg = pkt->data;
431 431
432 dump_rndis_message(dev, rndis_msg); 432 if (netif_msg_rx_err(net_dev->nd_ctx))
433 dump_rndis_message(dev, rndis_msg);
433 434
434 switch (rndis_msg->ndis_msg_type) { 435 switch (rndis_msg->ndis_msg_type) {
435 case RNDIS_MSG_PACKET: 436 case RNDIS_MSG_PACKET:
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 38026650c038..67d00fbc2e0e 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -85,6 +85,7 @@ struct at86rf230_local {
85 struct ieee802154_hw *hw; 85 struct ieee802154_hw *hw;
86 struct at86rf2xx_chip_data *data; 86 struct at86rf2xx_chip_data *data;
87 struct regmap *regmap; 87 struct regmap *regmap;
88 int slp_tr;
88 89
89 struct completion state_complete; 90 struct completion state_complete;
90 struct at86rf230_state_change state; 91 struct at86rf230_state_change state;
@@ -95,163 +96,164 @@ struct at86rf230_local {
95 unsigned long cal_timeout; 96 unsigned long cal_timeout;
96 s8 max_frame_retries; 97 s8 max_frame_retries;
97 bool is_tx; 98 bool is_tx;
99 bool is_tx_from_off;
98 u8 tx_retry; 100 u8 tx_retry;
99 struct sk_buff *tx_skb; 101 struct sk_buff *tx_skb;
100 struct at86rf230_state_change tx; 102 struct at86rf230_state_change tx;
101}; 103};
102 104
103#define RG_TRX_STATUS (0x01) 105#define RG_TRX_STATUS (0x01)
104#define SR_TRX_STATUS 0x01, 0x1f, 0 106#define SR_TRX_STATUS 0x01, 0x1f, 0
105#define SR_RESERVED_01_3 0x01, 0x20, 5 107#define SR_RESERVED_01_3 0x01, 0x20, 5
106#define SR_CCA_STATUS 0x01, 0x40, 6 108#define SR_CCA_STATUS 0x01, 0x40, 6
107#define SR_CCA_DONE 0x01, 0x80, 7 109#define SR_CCA_DONE 0x01, 0x80, 7
108#define RG_TRX_STATE (0x02) 110#define RG_TRX_STATE (0x02)
109#define SR_TRX_CMD 0x02, 0x1f, 0 111#define SR_TRX_CMD 0x02, 0x1f, 0
110#define SR_TRAC_STATUS 0x02, 0xe0, 5 112#define SR_TRAC_STATUS 0x02, 0xe0, 5
111#define RG_TRX_CTRL_0 (0x03) 113#define RG_TRX_CTRL_0 (0x03)
112#define SR_CLKM_CTRL 0x03, 0x07, 0 114#define SR_CLKM_CTRL 0x03, 0x07, 0
113#define SR_CLKM_SHA_SEL 0x03, 0x08, 3 115#define SR_CLKM_SHA_SEL 0x03, 0x08, 3
114#define SR_PAD_IO_CLKM 0x03, 0x30, 4 116#define SR_PAD_IO_CLKM 0x03, 0x30, 4
115#define SR_PAD_IO 0x03, 0xc0, 6 117#define SR_PAD_IO 0x03, 0xc0, 6
116#define RG_TRX_CTRL_1 (0x04) 118#define RG_TRX_CTRL_1 (0x04)
117#define SR_IRQ_POLARITY 0x04, 0x01, 0 119#define SR_IRQ_POLARITY 0x04, 0x01, 0
118#define SR_IRQ_MASK_MODE 0x04, 0x02, 1 120#define SR_IRQ_MASK_MODE 0x04, 0x02, 1
119#define SR_SPI_CMD_MODE 0x04, 0x0c, 2 121#define SR_SPI_CMD_MODE 0x04, 0x0c, 2
120#define SR_RX_BL_CTRL 0x04, 0x10, 4 122#define SR_RX_BL_CTRL 0x04, 0x10, 4
121#define SR_TX_AUTO_CRC_ON 0x04, 0x20, 5 123#define SR_TX_AUTO_CRC_ON 0x04, 0x20, 5
122#define SR_IRQ_2_EXT_EN 0x04, 0x40, 6 124#define SR_IRQ_2_EXT_EN 0x04, 0x40, 6
123#define SR_PA_EXT_EN 0x04, 0x80, 7 125#define SR_PA_EXT_EN 0x04, 0x80, 7
124#define RG_PHY_TX_PWR (0x05) 126#define RG_PHY_TX_PWR (0x05)
125#define SR_TX_PWR 0x05, 0x0f, 0 127#define SR_TX_PWR 0x05, 0x0f, 0
126#define SR_PA_LT 0x05, 0x30, 4 128#define SR_PA_LT 0x05, 0x30, 4
127#define SR_PA_BUF_LT 0x05, 0xc0, 6 129#define SR_PA_BUF_LT 0x05, 0xc0, 6
128#define RG_PHY_RSSI (0x06) 130#define RG_PHY_RSSI (0x06)
129#define SR_RSSI 0x06, 0x1f, 0 131#define SR_RSSI 0x06, 0x1f, 0
130#define SR_RND_VALUE 0x06, 0x60, 5 132#define SR_RND_VALUE 0x06, 0x60, 5
131#define SR_RX_CRC_VALID 0x06, 0x80, 7 133#define SR_RX_CRC_VALID 0x06, 0x80, 7
132#define RG_PHY_ED_LEVEL (0x07) 134#define RG_PHY_ED_LEVEL (0x07)
133#define SR_ED_LEVEL 0x07, 0xff, 0 135#define SR_ED_LEVEL 0x07, 0xff, 0
134#define RG_PHY_CC_CCA (0x08) 136#define RG_PHY_CC_CCA (0x08)
135#define SR_CHANNEL 0x08, 0x1f, 0 137#define SR_CHANNEL 0x08, 0x1f, 0
136#define SR_CCA_MODE 0x08, 0x60, 5 138#define SR_CCA_MODE 0x08, 0x60, 5
137#define SR_CCA_REQUEST 0x08, 0x80, 7 139#define SR_CCA_REQUEST 0x08, 0x80, 7
138#define RG_CCA_THRES (0x09) 140#define RG_CCA_THRES (0x09)
139#define SR_CCA_ED_THRES 0x09, 0x0f, 0 141#define SR_CCA_ED_THRES 0x09, 0x0f, 0
140#define SR_RESERVED_09_1 0x09, 0xf0, 4 142#define SR_RESERVED_09_1 0x09, 0xf0, 4
141#define RG_RX_CTRL (0x0a) 143#define RG_RX_CTRL (0x0a)
142#define SR_PDT_THRES 0x0a, 0x0f, 0 144#define SR_PDT_THRES 0x0a, 0x0f, 0
143#define SR_RESERVED_0a_1 0x0a, 0xf0, 4 145#define SR_RESERVED_0a_1 0x0a, 0xf0, 4
144#define RG_SFD_VALUE (0x0b) 146#define RG_SFD_VALUE (0x0b)
145#define SR_SFD_VALUE 0x0b, 0xff, 0 147#define SR_SFD_VALUE 0x0b, 0xff, 0
146#define RG_TRX_CTRL_2 (0x0c) 148#define RG_TRX_CTRL_2 (0x0c)
147#define SR_OQPSK_DATA_RATE 0x0c, 0x03, 0 149#define SR_OQPSK_DATA_RATE 0x0c, 0x03, 0
148#define SR_SUB_MODE 0x0c, 0x04, 2 150#define SR_SUB_MODE 0x0c, 0x04, 2
149#define SR_BPSK_QPSK 0x0c, 0x08, 3 151#define SR_BPSK_QPSK 0x0c, 0x08, 3
150#define SR_OQPSK_SUB1_RC_EN 0x0c, 0x10, 4 152#define SR_OQPSK_SUB1_RC_EN 0x0c, 0x10, 4
151#define SR_RESERVED_0c_5 0x0c, 0x60, 5 153#define SR_RESERVED_0c_5 0x0c, 0x60, 5
152#define SR_RX_SAFE_MODE 0x0c, 0x80, 7 154#define SR_RX_SAFE_MODE 0x0c, 0x80, 7
153#define RG_ANT_DIV (0x0d) 155#define RG_ANT_DIV (0x0d)
154#define SR_ANT_CTRL 0x0d, 0x03, 0 156#define SR_ANT_CTRL 0x0d, 0x03, 0
155#define SR_ANT_EXT_SW_EN 0x0d, 0x04, 2 157#define SR_ANT_EXT_SW_EN 0x0d, 0x04, 2
156#define SR_ANT_DIV_EN 0x0d, 0x08, 3 158#define SR_ANT_DIV_EN 0x0d, 0x08, 3
157#define SR_RESERVED_0d_2 0x0d, 0x70, 4 159#define SR_RESERVED_0d_2 0x0d, 0x70, 4
158#define SR_ANT_SEL 0x0d, 0x80, 7 160#define SR_ANT_SEL 0x0d, 0x80, 7
159#define RG_IRQ_MASK (0x0e) 161#define RG_IRQ_MASK (0x0e)
160#define SR_IRQ_MASK 0x0e, 0xff, 0 162#define SR_IRQ_MASK 0x0e, 0xff, 0
161#define RG_IRQ_STATUS (0x0f) 163#define RG_IRQ_STATUS (0x0f)
162#define SR_IRQ_0_PLL_LOCK 0x0f, 0x01, 0 164#define SR_IRQ_0_PLL_LOCK 0x0f, 0x01, 0
163#define SR_IRQ_1_PLL_UNLOCK 0x0f, 0x02, 1 165#define SR_IRQ_1_PLL_UNLOCK 0x0f, 0x02, 1
164#define SR_IRQ_2_RX_START 0x0f, 0x04, 2 166#define SR_IRQ_2_RX_START 0x0f, 0x04, 2
165#define SR_IRQ_3_TRX_END 0x0f, 0x08, 3 167#define SR_IRQ_3_TRX_END 0x0f, 0x08, 3
166#define SR_IRQ_4_CCA_ED_DONE 0x0f, 0x10, 4 168#define SR_IRQ_4_CCA_ED_DONE 0x0f, 0x10, 4
167#define SR_IRQ_5_AMI 0x0f, 0x20, 5 169#define SR_IRQ_5_AMI 0x0f, 0x20, 5
168#define SR_IRQ_6_TRX_UR 0x0f, 0x40, 6 170#define SR_IRQ_6_TRX_UR 0x0f, 0x40, 6
169#define SR_IRQ_7_BAT_LOW 0x0f, 0x80, 7 171#define SR_IRQ_7_BAT_LOW 0x0f, 0x80, 7
170#define RG_VREG_CTRL (0x10) 172#define RG_VREG_CTRL (0x10)
171#define SR_RESERVED_10_6 0x10, 0x03, 0 173#define SR_RESERVED_10_6 0x10, 0x03, 0
172#define SR_DVDD_OK 0x10, 0x04, 2 174#define SR_DVDD_OK 0x10, 0x04, 2
173#define SR_DVREG_EXT 0x10, 0x08, 3 175#define SR_DVREG_EXT 0x10, 0x08, 3
174#define SR_RESERVED_10_3 0x10, 0x30, 4 176#define SR_RESERVED_10_3 0x10, 0x30, 4
175#define SR_AVDD_OK 0x10, 0x40, 6 177#define SR_AVDD_OK 0x10, 0x40, 6
176#define SR_AVREG_EXT 0x10, 0x80, 7 178#define SR_AVREG_EXT 0x10, 0x80, 7
177#define RG_BATMON (0x11) 179#define RG_BATMON (0x11)
178#define SR_BATMON_VTH 0x11, 0x0f, 0 180#define SR_BATMON_VTH 0x11, 0x0f, 0
179#define SR_BATMON_HR 0x11, 0x10, 4 181#define SR_BATMON_HR 0x11, 0x10, 4
180#define SR_BATMON_OK 0x11, 0x20, 5 182#define SR_BATMON_OK 0x11, 0x20, 5
181#define SR_RESERVED_11_1 0x11, 0xc0, 6 183#define SR_RESERVED_11_1 0x11, 0xc0, 6
182#define RG_XOSC_CTRL (0x12) 184#define RG_XOSC_CTRL (0x12)
183#define SR_XTAL_TRIM 0x12, 0x0f, 0 185#define SR_XTAL_TRIM 0x12, 0x0f, 0
184#define SR_XTAL_MODE 0x12, 0xf0, 4 186#define SR_XTAL_MODE 0x12, 0xf0, 4
185#define RG_RX_SYN (0x15) 187#define RG_RX_SYN (0x15)
186#define SR_RX_PDT_LEVEL 0x15, 0x0f, 0 188#define SR_RX_PDT_LEVEL 0x15, 0x0f, 0
187#define SR_RESERVED_15_2 0x15, 0x70, 4 189#define SR_RESERVED_15_2 0x15, 0x70, 4
188#define SR_RX_PDT_DIS 0x15, 0x80, 7 190#define SR_RX_PDT_DIS 0x15, 0x80, 7
189#define RG_XAH_CTRL_1 (0x17) 191#define RG_XAH_CTRL_1 (0x17)
190#define SR_RESERVED_17_8 0x17, 0x01, 0 192#define SR_RESERVED_17_8 0x17, 0x01, 0
191#define SR_AACK_PROM_MODE 0x17, 0x02, 1 193#define SR_AACK_PROM_MODE 0x17, 0x02, 1
192#define SR_AACK_ACK_TIME 0x17, 0x04, 2 194#define SR_AACK_ACK_TIME 0x17, 0x04, 2
193#define SR_RESERVED_17_5 0x17, 0x08, 3 195#define SR_RESERVED_17_5 0x17, 0x08, 3
194#define SR_AACK_UPLD_RES_FT 0x17, 0x10, 4 196#define SR_AACK_UPLD_RES_FT 0x17, 0x10, 4
195#define SR_AACK_FLTR_RES_FT 0x17, 0x20, 5 197#define SR_AACK_FLTR_RES_FT 0x17, 0x20, 5
196#define SR_CSMA_LBT_MODE 0x17, 0x40, 6 198#define SR_CSMA_LBT_MODE 0x17, 0x40, 6
197#define SR_RESERVED_17_1 0x17, 0x80, 7 199#define SR_RESERVED_17_1 0x17, 0x80, 7
198#define RG_FTN_CTRL (0x18) 200#define RG_FTN_CTRL (0x18)
199#define SR_RESERVED_18_2 0x18, 0x7f, 0 201#define SR_RESERVED_18_2 0x18, 0x7f, 0
200#define SR_FTN_START 0x18, 0x80, 7 202#define SR_FTN_START 0x18, 0x80, 7
201#define RG_PLL_CF (0x1a) 203#define RG_PLL_CF (0x1a)
202#define SR_RESERVED_1a_2 0x1a, 0x7f, 0 204#define SR_RESERVED_1a_2 0x1a, 0x7f, 0
203#define SR_PLL_CF_START 0x1a, 0x80, 7 205#define SR_PLL_CF_START 0x1a, 0x80, 7
204#define RG_PLL_DCU (0x1b) 206#define RG_PLL_DCU (0x1b)
205#define SR_RESERVED_1b_3 0x1b, 0x3f, 0 207#define SR_RESERVED_1b_3 0x1b, 0x3f, 0
206#define SR_RESERVED_1b_2 0x1b, 0x40, 6 208#define SR_RESERVED_1b_2 0x1b, 0x40, 6
207#define SR_PLL_DCU_START 0x1b, 0x80, 7 209#define SR_PLL_DCU_START 0x1b, 0x80, 7
208#define RG_PART_NUM (0x1c) 210#define RG_PART_NUM (0x1c)
209#define SR_PART_NUM 0x1c, 0xff, 0 211#define SR_PART_NUM 0x1c, 0xff, 0
210#define RG_VERSION_NUM (0x1d) 212#define RG_VERSION_NUM (0x1d)
211#define SR_VERSION_NUM 0x1d, 0xff, 0 213#define SR_VERSION_NUM 0x1d, 0xff, 0
212#define RG_MAN_ID_0 (0x1e) 214#define RG_MAN_ID_0 (0x1e)
213#define SR_MAN_ID_0 0x1e, 0xff, 0 215#define SR_MAN_ID_0 0x1e, 0xff, 0
214#define RG_MAN_ID_1 (0x1f) 216#define RG_MAN_ID_1 (0x1f)
215#define SR_MAN_ID_1 0x1f, 0xff, 0 217#define SR_MAN_ID_1 0x1f, 0xff, 0
216#define RG_SHORT_ADDR_0 (0x20) 218#define RG_SHORT_ADDR_0 (0x20)
217#define SR_SHORT_ADDR_0 0x20, 0xff, 0 219#define SR_SHORT_ADDR_0 0x20, 0xff, 0
218#define RG_SHORT_ADDR_1 (0x21) 220#define RG_SHORT_ADDR_1 (0x21)
219#define SR_SHORT_ADDR_1 0x21, 0xff, 0 221#define SR_SHORT_ADDR_1 0x21, 0xff, 0
220#define RG_PAN_ID_0 (0x22) 222#define RG_PAN_ID_0 (0x22)
221#define SR_PAN_ID_0 0x22, 0xff, 0 223#define SR_PAN_ID_0 0x22, 0xff, 0
222#define RG_PAN_ID_1 (0x23) 224#define RG_PAN_ID_1 (0x23)
223#define SR_PAN_ID_1 0x23, 0xff, 0 225#define SR_PAN_ID_1 0x23, 0xff, 0
224#define RG_IEEE_ADDR_0 (0x24) 226#define RG_IEEE_ADDR_0 (0x24)
225#define SR_IEEE_ADDR_0 0x24, 0xff, 0 227#define SR_IEEE_ADDR_0 0x24, 0xff, 0
226#define RG_IEEE_ADDR_1 (0x25) 228#define RG_IEEE_ADDR_1 (0x25)
227#define SR_IEEE_ADDR_1 0x25, 0xff, 0 229#define SR_IEEE_ADDR_1 0x25, 0xff, 0
228#define RG_IEEE_ADDR_2 (0x26) 230#define RG_IEEE_ADDR_2 (0x26)
229#define SR_IEEE_ADDR_2 0x26, 0xff, 0 231#define SR_IEEE_ADDR_2 0x26, 0xff, 0
230#define RG_IEEE_ADDR_3 (0x27) 232#define RG_IEEE_ADDR_3 (0x27)
231#define SR_IEEE_ADDR_3 0x27, 0xff, 0 233#define SR_IEEE_ADDR_3 0x27, 0xff, 0
232#define RG_IEEE_ADDR_4 (0x28) 234#define RG_IEEE_ADDR_4 (0x28)
233#define SR_IEEE_ADDR_4 0x28, 0xff, 0 235#define SR_IEEE_ADDR_4 0x28, 0xff, 0
234#define RG_IEEE_ADDR_5 (0x29) 236#define RG_IEEE_ADDR_5 (0x29)
235#define SR_IEEE_ADDR_5 0x29, 0xff, 0 237#define SR_IEEE_ADDR_5 0x29, 0xff, 0
236#define RG_IEEE_ADDR_6 (0x2a) 238#define RG_IEEE_ADDR_6 (0x2a)
237#define SR_IEEE_ADDR_6 0x2a, 0xff, 0 239#define SR_IEEE_ADDR_6 0x2a, 0xff, 0
238#define RG_IEEE_ADDR_7 (0x2b) 240#define RG_IEEE_ADDR_7 (0x2b)
239#define SR_IEEE_ADDR_7 0x2b, 0xff, 0 241#define SR_IEEE_ADDR_7 0x2b, 0xff, 0
240#define RG_XAH_CTRL_0 (0x2c) 242#define RG_XAH_CTRL_0 (0x2c)
241#define SR_SLOTTED_OPERATION 0x2c, 0x01, 0 243#define SR_SLOTTED_OPERATION 0x2c, 0x01, 0
242#define SR_MAX_CSMA_RETRIES 0x2c, 0x0e, 1 244#define SR_MAX_CSMA_RETRIES 0x2c, 0x0e, 1
243#define SR_MAX_FRAME_RETRIES 0x2c, 0xf0, 4 245#define SR_MAX_FRAME_RETRIES 0x2c, 0xf0, 4
244#define RG_CSMA_SEED_0 (0x2d) 246#define RG_CSMA_SEED_0 (0x2d)
245#define SR_CSMA_SEED_0 0x2d, 0xff, 0 247#define SR_CSMA_SEED_0 0x2d, 0xff, 0
246#define RG_CSMA_SEED_1 (0x2e) 248#define RG_CSMA_SEED_1 (0x2e)
247#define SR_CSMA_SEED_1 0x2e, 0x07, 0 249#define SR_CSMA_SEED_1 0x2e, 0x07, 0
248#define SR_AACK_I_AM_COORD 0x2e, 0x08, 3 250#define SR_AACK_I_AM_COORD 0x2e, 0x08, 3
249#define SR_AACK_DIS_ACK 0x2e, 0x10, 4 251#define SR_AACK_DIS_ACK 0x2e, 0x10, 4
250#define SR_AACK_SET_PD 0x2e, 0x20, 5 252#define SR_AACK_SET_PD 0x2e, 0x20, 5
251#define SR_AACK_FVN_MODE 0x2e, 0xc0, 6 253#define SR_AACK_FVN_MODE 0x2e, 0xc0, 6
252#define RG_CSMA_BE (0x2f) 254#define RG_CSMA_BE (0x2f)
253#define SR_MIN_BE 0x2f, 0x0f, 0 255#define SR_MIN_BE 0x2f, 0x0f, 0
254#define SR_MAX_BE 0x2f, 0xf0, 4 256#define SR_MAX_BE 0x2f, 0xf0, 4
255 257
256#define CMD_REG 0x80 258#define CMD_REG 0x80
257#define CMD_REG_MASK 0x3f 259#define CMD_REG_MASK 0x3f
@@ -292,6 +294,8 @@ struct at86rf230_local {
292#define STATE_BUSY_RX_AACK_NOCLK 0x1E 294#define STATE_BUSY_RX_AACK_NOCLK 0x1E
293#define STATE_TRANSITION_IN_PROGRESS 0x1F 295#define STATE_TRANSITION_IN_PROGRESS 0x1F
294 296
297#define TRX_STATE_MASK (0x1F)
298
295#define AT86RF2XX_NUMREGS 0x3F 299#define AT86RF2XX_NUMREGS 0x3F
296 300
297static void 301static void
@@ -336,6 +340,14 @@ at86rf230_write_subreg(struct at86rf230_local *lp,
336 return regmap_update_bits(lp->regmap, addr, mask, data << shift); 340 return regmap_update_bits(lp->regmap, addr, mask, data << shift);
337} 341}
338 342
343static inline void
344at86rf230_slp_tr_rising_edge(struct at86rf230_local *lp)
345{
346 gpio_set_value(lp->slp_tr, 1);
347 udelay(1);
348 gpio_set_value(lp->slp_tr, 0);
349}
350
339static bool 351static bool
340at86rf230_reg_writeable(struct device *dev, unsigned int reg) 352at86rf230_reg_writeable(struct device *dev, unsigned int reg)
341{ 353{
@@ -509,7 +521,7 @@ at86rf230_async_state_assert(void *context)
509 struct at86rf230_state_change *ctx = context; 521 struct at86rf230_state_change *ctx = context;
510 struct at86rf230_local *lp = ctx->lp; 522 struct at86rf230_local *lp = ctx->lp;
511 const u8 *buf = ctx->buf; 523 const u8 *buf = ctx->buf;
512 const u8 trx_state = buf[1] & 0x1f; 524 const u8 trx_state = buf[1] & TRX_STATE_MASK;
513 525
514 /* Assert state change */ 526 /* Assert state change */
515 if (trx_state != ctx->to_state) { 527 if (trx_state != ctx->to_state) {
@@ -609,11 +621,17 @@ at86rf230_async_state_delay(void *context)
609 switch (ctx->to_state) { 621 switch (ctx->to_state) {
610 case STATE_RX_AACK_ON: 622 case STATE_RX_AACK_ON:
611 tim = ktime_set(0, c->t_off_to_aack * NSEC_PER_USEC); 623 tim = ktime_set(0, c->t_off_to_aack * NSEC_PER_USEC);
624 /* state change from TRX_OFF to RX_AACK_ON to do a
625 * calibration, we need to reset the timeout for the
626 * next one.
627 */
628 lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT;
612 goto change; 629 goto change;
630 case STATE_TX_ARET_ON:
613 case STATE_TX_ON: 631 case STATE_TX_ON:
614 tim = ktime_set(0, c->t_off_to_tx_on * NSEC_PER_USEC); 632 tim = ktime_set(0, c->t_off_to_tx_on * NSEC_PER_USEC);
615 /* state change from TRX_OFF to TX_ON to do a 633 /* state change from TRX_OFF to TX_ON or ARET_ON to do
616 * calibration, we need to reset the timeout for the 634 * a calibration, we need to reset the timeout for the
617 * next one. 635 * next one.
618 */ 636 */
619 lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT; 637 lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT;
@@ -667,7 +685,7 @@ at86rf230_async_state_change_start(void *context)
667 struct at86rf230_state_change *ctx = context; 685 struct at86rf230_state_change *ctx = context;
668 struct at86rf230_local *lp = ctx->lp; 686 struct at86rf230_local *lp = ctx->lp;
669 u8 *buf = ctx->buf; 687 u8 *buf = ctx->buf;
670 const u8 trx_state = buf[1] & 0x1f; 688 const u8 trx_state = buf[1] & TRX_STATE_MASK;
671 int rc; 689 int rc;
672 690
673 /* Check for "possible" STATE_TRANSITION_IN_PROGRESS */ 691 /* Check for "possible" STATE_TRANSITION_IN_PROGRESS */
@@ -773,16 +791,6 @@ at86rf230_tx_on(void *context)
773} 791}
774 792
775static void 793static void
776at86rf230_tx_trac_error(void *context)
777{
778 struct at86rf230_state_change *ctx = context;
779 struct at86rf230_local *lp = ctx->lp;
780
781 at86rf230_async_state_change(lp, ctx, STATE_TX_ON,
782 at86rf230_tx_on, true);
783}
784
785static void
786at86rf230_tx_trac_check(void *context) 794at86rf230_tx_trac_check(void *context)
787{ 795{
788 struct at86rf230_state_change *ctx = context; 796 struct at86rf230_state_change *ctx = context;
@@ -791,12 +799,12 @@ at86rf230_tx_trac_check(void *context)
791 const u8 trac = (buf[1] & 0xe0) >> 5; 799 const u8 trac = (buf[1] & 0xe0) >> 5;
792 800
793 /* If trac status is different than zero we need to do a state change 801 /* If trac status is different than zero we need to do a state change
794 * to STATE_FORCE_TRX_OFF then STATE_TX_ON to recover the transceiver 802 * to STATE_FORCE_TRX_OFF then STATE_RX_AACK_ON to recover the
795 * state to TX_ON. 803 * transceiver.
796 */ 804 */
797 if (trac) 805 if (trac)
798 at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF, 806 at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF,
799 at86rf230_tx_trac_error, true); 807 at86rf230_tx_on, true);
800 else 808 else
801 at86rf230_tx_on(context); 809 at86rf230_tx_on(context);
802} 810}
@@ -941,13 +949,18 @@ at86rf230_write_frame_complete(void *context)
941 u8 *buf = ctx->buf; 949 u8 *buf = ctx->buf;
942 int rc; 950 int rc;
943 951
944 buf[0] = (RG_TRX_STATE & CMD_REG_MASK) | CMD_REG | CMD_WRITE;
945 buf[1] = STATE_BUSY_TX;
946 ctx->trx.len = 2; 952 ctx->trx.len = 2;
947 ctx->msg.complete = NULL; 953
948 rc = spi_async(lp->spi, &ctx->msg); 954 if (gpio_is_valid(lp->slp_tr)) {
949 if (rc) 955 at86rf230_slp_tr_rising_edge(lp);
950 at86rf230_async_error(lp, ctx, rc); 956 } else {
957 buf[0] = (RG_TRX_STATE & CMD_REG_MASK) | CMD_REG | CMD_WRITE;
958 buf[1] = STATE_BUSY_TX;
959 ctx->msg.complete = NULL;
960 rc = spi_async(lp->spi, &ctx->msg);
961 if (rc)
962 at86rf230_async_error(lp, ctx, rc);
963 }
951} 964}
952 965
953static void 966static void
@@ -993,12 +1006,21 @@ at86rf230_xmit_start(void *context)
993 * are in STATE_TX_ON. The pfad differs here, so we change 1006 * are in STATE_TX_ON. The pfad differs here, so we change
994 * the complete handler. 1007 * the complete handler.
995 */ 1008 */
996 if (lp->tx_aret) 1009 if (lp->tx_aret) {
997 at86rf230_async_state_change(lp, ctx, STATE_TX_ON, 1010 if (lp->is_tx_from_off) {
998 at86rf230_xmit_tx_on, false); 1011 lp->is_tx_from_off = false;
999 else 1012 at86rf230_async_state_change(lp, ctx, STATE_TX_ARET_ON,
1013 at86rf230_xmit_tx_on,
1014 false);
1015 } else {
1016 at86rf230_async_state_change(lp, ctx, STATE_TX_ON,
1017 at86rf230_xmit_tx_on,
1018 false);
1019 }
1020 } else {
1000 at86rf230_async_state_change(lp, ctx, STATE_TX_ON, 1021 at86rf230_async_state_change(lp, ctx, STATE_TX_ON,
1001 at86rf230_write_frame, false); 1022 at86rf230_write_frame, false);
1023 }
1002} 1024}
1003 1025
1004static int 1026static int
@@ -1017,11 +1039,13 @@ at86rf230_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)
1017 * to TX_ON, the lp->cal_timeout should be reinit by state_delay 1039 * to TX_ON, the lp->cal_timeout should be reinit by state_delay
1018 * function then to start in the next 5 minutes. 1040 * function then to start in the next 5 minutes.
1019 */ 1041 */
1020 if (time_is_before_jiffies(lp->cal_timeout)) 1042 if (time_is_before_jiffies(lp->cal_timeout)) {
1043 lp->is_tx_from_off = true;
1021 at86rf230_async_state_change(lp, ctx, STATE_TRX_OFF, 1044 at86rf230_async_state_change(lp, ctx, STATE_TRX_OFF,
1022 at86rf230_xmit_start, false); 1045 at86rf230_xmit_start, false);
1023 else 1046 } else {
1024 at86rf230_xmit_start(ctx); 1047 at86rf230_xmit_start(ctx);
1048 }
1025 1049
1026 return 0; 1050 return 0;
1027} 1051}
@@ -1037,9 +1061,6 @@ at86rf230_ed(struct ieee802154_hw *hw, u8 *level)
1037static int 1061static int
1038at86rf230_start(struct ieee802154_hw *hw) 1062at86rf230_start(struct ieee802154_hw *hw)
1039{ 1063{
1040 struct at86rf230_local *lp = hw->priv;
1041
1042 lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT;
1043 return at86rf230_sync_state_change(hw->priv, STATE_RX_AACK_ON); 1064 return at86rf230_sync_state_change(hw->priv, STATE_RX_AACK_ON);
1044} 1065}
1045 1066
@@ -1673,6 +1694,7 @@ static int at86rf230_probe(struct spi_device *spi)
1673 lp = hw->priv; 1694 lp = hw->priv;
1674 lp->hw = hw; 1695 lp->hw = hw;
1675 lp->spi = spi; 1696 lp->spi = spi;
1697 lp->slp_tr = slp_tr;
1676 hw->parent = &spi->dev; 1698 hw->parent = &spi->dev;
1677 hw->vif_data_size = sizeof(*lp); 1699 hw->vif_data_size = sizeof(*lp);
1678 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr); 1700 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index b227a13f6473..9f59f17dc317 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -599,10 +599,18 @@ static int macvlan_open(struct net_device *dev)
599 goto del_unicast; 599 goto del_unicast;
600 } 600 }
601 601
602 if (dev->flags & IFF_PROMISC) {
603 err = dev_set_promiscuity(lowerdev, 1);
604 if (err < 0)
605 goto clear_multi;
606 }
607
602hash_add: 608hash_add:
603 macvlan_hash_add(vlan); 609 macvlan_hash_add(vlan);
604 return 0; 610 return 0;
605 611
612clear_multi:
613 dev_set_allmulti(lowerdev, -1);
606del_unicast: 614del_unicast:
607 dev_uc_del(lowerdev, dev->dev_addr); 615 dev_uc_del(lowerdev, dev->dev_addr);
608out: 616out:
@@ -638,6 +646,9 @@ static int macvlan_stop(struct net_device *dev)
638 if (dev->flags & IFF_ALLMULTI) 646 if (dev->flags & IFF_ALLMULTI)
639 dev_set_allmulti(lowerdev, -1); 647 dev_set_allmulti(lowerdev, -1);
640 648
649 if (dev->flags & IFF_PROMISC)
650 dev_set_promiscuity(lowerdev, -1);
651
641 dev_uc_del(lowerdev, dev->dev_addr); 652 dev_uc_del(lowerdev, dev->dev_addr);
642 653
643hash_del: 654hash_del:
@@ -696,6 +707,10 @@ static void macvlan_change_rx_flags(struct net_device *dev, int change)
696 if (dev->flags & IFF_UP) { 707 if (dev->flags & IFF_UP) {
697 if (change & IFF_ALLMULTI) 708 if (change & IFF_ALLMULTI)
698 dev_set_allmulti(lowerdev, dev->flags & IFF_ALLMULTI ? 1 : -1); 709 dev_set_allmulti(lowerdev, dev->flags & IFF_ALLMULTI ? 1 : -1);
710 if (change & IFF_PROMISC)
711 dev_set_promiscuity(lowerdev,
712 dev->flags & IFF_PROMISC ? 1 : -1);
713
699 } 714 }
700} 715}
701 716
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 8fadaa14b9f0..70641d2c0429 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -27,6 +27,7 @@ config AMD_PHY
27config AMD_XGBE_PHY 27config AMD_XGBE_PHY
28 tristate "Driver for the AMD 10GbE (amd-xgbe) PHYs" 28 tristate "Driver for the AMD 10GbE (amd-xgbe) PHYs"
29 depends on (OF || ACPI) && HAS_IOMEM 29 depends on (OF || ACPI) && HAS_IOMEM
30 depends on ARM64 || COMPILE_TEST
30 ---help--- 31 ---help---
31 Currently supports the AMD 10GbE PHY 32 Currently supports the AMD 10GbE PHY
32 33
diff --git a/drivers/net/phy/amd-xgbe-phy.c b/drivers/net/phy/amd-xgbe-phy.c
index fb276f64cd64..34a75cba3b73 100644
--- a/drivers/net/phy/amd-xgbe-phy.c
+++ b/drivers/net/phy/amd-xgbe-phy.c
@@ -755,6 +755,45 @@ static int amd_xgbe_phy_set_mode(struct phy_device *phydev,
755 return ret; 755 return ret;
756} 756}
757 757
758static bool amd_xgbe_phy_use_xgmii_mode(struct phy_device *phydev)
759{
760 if (phydev->autoneg == AUTONEG_ENABLE) {
761 if (phydev->advertising & ADVERTISED_10000baseKR_Full)
762 return true;
763 } else {
764 if (phydev->speed == SPEED_10000)
765 return true;
766 }
767
768 return false;
769}
770
771static bool amd_xgbe_phy_use_gmii_2500_mode(struct phy_device *phydev)
772{
773 if (phydev->autoneg == AUTONEG_ENABLE) {
774 if (phydev->advertising & ADVERTISED_2500baseX_Full)
775 return true;
776 } else {
777 if (phydev->speed == SPEED_2500)
778 return true;
779 }
780
781 return false;
782}
783
784static bool amd_xgbe_phy_use_gmii_mode(struct phy_device *phydev)
785{
786 if (phydev->autoneg == AUTONEG_ENABLE) {
787 if (phydev->advertising & ADVERTISED_1000baseKX_Full)
788 return true;
789 } else {
790 if (phydev->speed == SPEED_1000)
791 return true;
792 }
793
794 return false;
795}
796
758static int amd_xgbe_phy_set_an(struct phy_device *phydev, bool enable, 797static int amd_xgbe_phy_set_an(struct phy_device *phydev, bool enable,
759 bool restart) 798 bool restart)
760{ 799{
@@ -1235,11 +1274,11 @@ static int amd_xgbe_phy_config_init(struct phy_device *phydev)
1235 /* Set initial mode - call the mode setting routines 1274 /* Set initial mode - call the mode setting routines
1236 * directly to insure we are properly configured 1275 * directly to insure we are properly configured
1237 */ 1276 */
1238 if (phydev->advertising & SUPPORTED_10000baseKR_Full) 1277 if (amd_xgbe_phy_use_xgmii_mode(phydev))
1239 ret = amd_xgbe_phy_xgmii_mode(phydev); 1278 ret = amd_xgbe_phy_xgmii_mode(phydev);
1240 else if (phydev->advertising & SUPPORTED_1000baseKX_Full) 1279 else if (amd_xgbe_phy_use_gmii_mode(phydev))
1241 ret = amd_xgbe_phy_gmii_mode(phydev); 1280 ret = amd_xgbe_phy_gmii_mode(phydev);
1242 else if (phydev->advertising & SUPPORTED_2500baseX_Full) 1281 else if (amd_xgbe_phy_use_gmii_2500_mode(phydev))
1243 ret = amd_xgbe_phy_gmii_2500_mode(phydev); 1282 ret = amd_xgbe_phy_gmii_2500_mode(phydev);
1244 else 1283 else
1245 ret = -EINVAL; 1284 ret = -EINVAL;
diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index 64c74c6a4828..b5dc59de094e 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -404,7 +404,7 @@ static struct phy_driver bcm7xxx_driver[] = {
404 .name = "Broadcom BCM7425", 404 .name = "Broadcom BCM7425",
405 .features = PHY_GBIT_FEATURES | 405 .features = PHY_GBIT_FEATURES |
406 SUPPORTED_Pause | SUPPORTED_Asym_Pause, 406 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
407 .flags = 0, 407 .flags = PHY_IS_INTERNAL,
408 .config_init = bcm7xxx_config_init, 408 .config_init = bcm7xxx_config_init,
409 .config_aneg = genphy_config_aneg, 409 .config_aneg = genphy_config_aneg,
410 .read_status = genphy_read_status, 410 .read_status = genphy_read_status,
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 496e02f961d3..00cb41e71312 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -47,7 +47,7 @@
47#define PSF_TX 0x1000 47#define PSF_TX 0x1000
48#define EXT_EVENT 1 48#define EXT_EVENT 1
49#define CAL_EVENT 7 49#define CAL_EVENT 7
50#define CAL_TRIGGER 7 50#define CAL_TRIGGER 1
51#define DP83640_N_PINS 12 51#define DP83640_N_PINS 12
52 52
53#define MII_DP83640_MICR 0x11 53#define MII_DP83640_MICR 0x11
@@ -496,7 +496,9 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
496 else 496 else
497 evnt |= EVNT_RISE; 497 evnt |= EVNT_RISE;
498 } 498 }
499 mutex_lock(&clock->extreg_lock);
499 ext_write(0, phydev, PAGE5, PTP_EVNT, evnt); 500 ext_write(0, phydev, PAGE5, PTP_EVNT, evnt);
501 mutex_unlock(&clock->extreg_lock);
500 return 0; 502 return 0;
501 503
502 case PTP_CLK_REQ_PEROUT: 504 case PTP_CLK_REQ_PEROUT:
@@ -532,6 +534,8 @@ static u8 status_frame_src[6] = { 0x08, 0x00, 0x17, 0x0B, 0x6B, 0x0F };
532 534
533static void enable_status_frames(struct phy_device *phydev, bool on) 535static void enable_status_frames(struct phy_device *phydev, bool on)
534{ 536{
537 struct dp83640_private *dp83640 = phydev->priv;
538 struct dp83640_clock *clock = dp83640->clock;
535 u16 cfg0 = 0, ver; 539 u16 cfg0 = 0, ver;
536 540
537 if (on) 541 if (on)
@@ -539,9 +543,13 @@ static void enable_status_frames(struct phy_device *phydev, bool on)
539 543
540 ver = (PSF_PTPVER & VERSIONPTP_MASK) << VERSIONPTP_SHIFT; 544 ver = (PSF_PTPVER & VERSIONPTP_MASK) << VERSIONPTP_SHIFT;
541 545
546 mutex_lock(&clock->extreg_lock);
547
542 ext_write(0, phydev, PAGE5, PSF_CFG0, cfg0); 548 ext_write(0, phydev, PAGE5, PSF_CFG0, cfg0);
543 ext_write(0, phydev, PAGE6, PSF_CFG1, ver); 549 ext_write(0, phydev, PAGE6, PSF_CFG1, ver);
544 550
551 mutex_unlock(&clock->extreg_lock);
552
545 if (!phydev->attached_dev) { 553 if (!phydev->attached_dev) {
546 pr_warn("expected to find an attached netdevice\n"); 554 pr_warn("expected to find an attached netdevice\n");
547 return; 555 return;
@@ -838,7 +846,7 @@ static void decode_rxts(struct dp83640_private *dp83640,
838 list_del_init(&rxts->list); 846 list_del_init(&rxts->list);
839 phy2rxts(phy_rxts, rxts); 847 phy2rxts(phy_rxts, rxts);
840 848
841 spin_lock_irqsave(&dp83640->rx_queue.lock, flags); 849 spin_lock(&dp83640->rx_queue.lock);
842 skb_queue_walk(&dp83640->rx_queue, skb) { 850 skb_queue_walk(&dp83640->rx_queue, skb) {
843 struct dp83640_skb_info *skb_info; 851 struct dp83640_skb_info *skb_info;
844 852
@@ -853,7 +861,7 @@ static void decode_rxts(struct dp83640_private *dp83640,
853 break; 861 break;
854 } 862 }
855 } 863 }
856 spin_unlock_irqrestore(&dp83640->rx_queue.lock, flags); 864 spin_unlock(&dp83640->rx_queue.lock);
857 865
858 if (!shhwtstamps) 866 if (!shhwtstamps)
859 list_add_tail(&rxts->list, &dp83640->rxts); 867 list_add_tail(&rxts->list, &dp83640->rxts);
@@ -1173,11 +1181,18 @@ static int dp83640_config_init(struct phy_device *phydev)
1173 1181
1174 if (clock->chosen && !list_empty(&clock->phylist)) 1182 if (clock->chosen && !list_empty(&clock->phylist))
1175 recalibrate(clock); 1183 recalibrate(clock);
1176 else 1184 else {
1185 mutex_lock(&clock->extreg_lock);
1177 enable_broadcast(phydev, clock->page, 1); 1186 enable_broadcast(phydev, clock->page, 1);
1187 mutex_unlock(&clock->extreg_lock);
1188 }
1178 1189
1179 enable_status_frames(phydev, true); 1190 enable_status_frames(phydev, true);
1191
1192 mutex_lock(&clock->extreg_lock);
1180 ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE); 1193 ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE);
1194 mutex_unlock(&clock->extreg_lock);
1195
1181 return 0; 1196 return 0;
1182} 1197}
1183 1198
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 49ce7ece5af3..53d18150f4e2 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -80,7 +80,8 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
80 * assume the pin serves as pull-up. If direction is 80 * assume the pin serves as pull-up. If direction is
81 * output, the default value is high. 81 * output, the default value is high.
82 */ 82 */
83 gpio_set_value(bitbang->mdo, 1 ^ bitbang->mdo_active_low); 83 gpio_set_value_cansleep(bitbang->mdo,
84 1 ^ bitbang->mdo_active_low);
84 return; 85 return;
85 } 86 }
86 87
@@ -96,7 +97,8 @@ static int mdio_get(struct mdiobb_ctrl *ctrl)
96 struct mdio_gpio_info *bitbang = 97 struct mdio_gpio_info *bitbang =
97 container_of(ctrl, struct mdio_gpio_info, ctrl); 98 container_of(ctrl, struct mdio_gpio_info, ctrl);
98 99
99 return gpio_get_value(bitbang->mdio) ^ bitbang->mdio_active_low; 100 return gpio_get_value_cansleep(bitbang->mdio) ^
101 bitbang->mdio_active_low;
100} 102}
101 103
102static void mdio_set(struct mdiobb_ctrl *ctrl, int what) 104static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
@@ -105,9 +107,11 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
105 container_of(ctrl, struct mdio_gpio_info, ctrl); 107 container_of(ctrl, struct mdio_gpio_info, ctrl);
106 108
107 if (bitbang->mdo) 109 if (bitbang->mdo)
108 gpio_set_value(bitbang->mdo, what ^ bitbang->mdo_active_low); 110 gpio_set_value_cansleep(bitbang->mdo,
111 what ^ bitbang->mdo_active_low);
109 else 112 else
110 gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low); 113 gpio_set_value_cansleep(bitbang->mdio,
114 what ^ bitbang->mdio_active_low);
111} 115}
112 116
113static void mdc_set(struct mdiobb_ctrl *ctrl, int what) 117static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -115,7 +119,7 @@ static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
115 struct mdio_gpio_info *bitbang = 119 struct mdio_gpio_info *bitbang =
116 container_of(ctrl, struct mdio_gpio_info, ctrl); 120 container_of(ctrl, struct mdio_gpio_info, ctrl);
117 121
118 gpio_set_value(bitbang->mdc, what ^ bitbang->mdc_active_low); 122 gpio_set_value_cansleep(bitbang->mdc, what ^ bitbang->mdc_active_low);
119} 123}
120 124
121static struct mdiobb_ops mdio_gpio_ops = { 125static struct mdiobb_ops mdio_gpio_ops = {
@@ -164,7 +168,10 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
164 if (!new_bus->irq[i]) 168 if (!new_bus->irq[i])
165 new_bus->irq[i] = PHY_POLL; 169 new_bus->irq[i] = PHY_POLL;
166 170
167 snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id); 171 if (bus_id != -1)
172 snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);
173 else
174 strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE);
168 175
169 if (devm_gpio_request(dev, bitbang->mdc, "mdc")) 176 if (devm_gpio_request(dev, bitbang->mdc, "mdc"))
170 goto out_free_bus; 177 goto out_free_bus;
diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 1a87a585e74d..66edd99bc302 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -12,33 +12,30 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/phy.h> 13#include <linux/phy.h>
14#include <linux/mdio-mux.h> 14#include <linux/mdio-mux.h>
15#include <linux/of_gpio.h> 15#include <linux/gpio/consumer.h>
16 16
17#define DRV_VERSION "1.1" 17#define DRV_VERSION "1.1"
18#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver" 18#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver"
19 19
20#define MDIO_MUX_GPIO_MAX_BITS 8
21
22struct mdio_mux_gpio_state { 20struct mdio_mux_gpio_state {
23 struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS]; 21 struct gpio_descs *gpios;
24 unsigned int num_gpios;
25 void *mux_handle; 22 void *mux_handle;
26}; 23};
27 24
28static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, 25static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
29 void *data) 26 void *data)
30{ 27{
31 int values[MDIO_MUX_GPIO_MAX_BITS];
32 unsigned int n;
33 struct mdio_mux_gpio_state *s = data; 28 struct mdio_mux_gpio_state *s = data;
29 int values[s->gpios->ndescs];
30 unsigned int n;
34 31
35 if (current_child == desired_child) 32 if (current_child == desired_child)
36 return 0; 33 return 0;
37 34
38 for (n = 0; n < s->num_gpios; n++) { 35 for (n = 0; n < s->gpios->ndescs; n++)
39 values[n] = (desired_child >> n) & 1; 36 values[n] = (desired_child >> n) & 1;
40 } 37
41 gpiod_set_array_cansleep(s->num_gpios, s->gpio, values); 38 gpiod_set_array_cansleep(s->gpios->ndescs, s->gpios->desc, values);
42 39
43 return 0; 40 return 0;
44} 41}
@@ -46,56 +43,33 @@ static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
46static int mdio_mux_gpio_probe(struct platform_device *pdev) 43static int mdio_mux_gpio_probe(struct platform_device *pdev)
47{ 44{
48 struct mdio_mux_gpio_state *s; 45 struct mdio_mux_gpio_state *s;
49 int num_gpios;
50 unsigned int n;
51 int r; 46 int r;
52 47
53 if (!pdev->dev.of_node)
54 return -ENODEV;
55
56 num_gpios = of_gpio_count(pdev->dev.of_node);
57 if (num_gpios <= 0 || num_gpios > MDIO_MUX_GPIO_MAX_BITS)
58 return -ENODEV;
59
60 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); 48 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
61 if (!s) 49 if (!s)
62 return -ENOMEM; 50 return -ENOMEM;
63 51
64 s->num_gpios = num_gpios; 52 s->gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW);
65 53 if (IS_ERR(s->gpios))
66 for (n = 0; n < num_gpios; ) { 54 return PTR_ERR(s->gpios);
67 struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
68 GPIOD_OUT_LOW);
69 if (IS_ERR(gpio)) {
70 r = PTR_ERR(gpio);
71 goto err;
72 }
73 s->gpio[n] = gpio;
74 n++;
75 }
76 55
77 r = mdio_mux_init(&pdev->dev, 56 r = mdio_mux_init(&pdev->dev,
78 mdio_mux_gpio_switch_fn, &s->mux_handle, s); 57 mdio_mux_gpio_switch_fn, &s->mux_handle, s);
79 58
80 if (r == 0) { 59 if (r != 0) {
81 pdev->dev.platform_data = s; 60 gpiod_put_array(s->gpios);
82 return 0; 61 return r;
83 }
84err:
85 while (n) {
86 n--;
87 gpiod_put(s->gpio[n]);
88 } 62 }
89 return r; 63
64 pdev->dev.platform_data = s;
65 return 0;
90} 66}
91 67
92static int mdio_mux_gpio_remove(struct platform_device *pdev) 68static int mdio_mux_gpio_remove(struct platform_device *pdev)
93{ 69{
94 unsigned int n;
95 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev); 70 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
96 mdio_mux_uninit(s->mux_handle); 71 mdio_mux_uninit(s->mux_handle);
97 for (n = 0; n < s->num_gpios; n++) 72 gpiod_put_array(s->gpios);
98 gpiod_put(s->gpio[n]);
99 return 0; 73 return 0;
100} 74}
101 75
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 1190fd8f0088..ebdc357c5131 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -548,7 +548,8 @@ static int kszphy_probe(struct phy_device *phydev)
548 } 548 }
549 549
550 clk = devm_clk_get(&phydev->dev, "rmii-ref"); 550 clk = devm_clk_get(&phydev->dev, "rmii-ref");
551 if (!IS_ERR(clk)) { 551 /* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */
552 if (!IS_ERR_OR_NULL(clk)) {
552 unsigned long rate = clk_get_rate(clk); 553 unsigned long rate = clk_get_rate(clk);
553 bool rmii_ref_clk_sel_25_mhz; 554 bool rmii_ref_clk_sel_25_mhz;
554 555
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 52cd8db2c57d..47cd578052fc 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -742,6 +742,9 @@ EXPORT_SYMBOL(phy_stop);
742 */ 742 */
743void phy_start(struct phy_device *phydev) 743void phy_start(struct phy_device *phydev)
744{ 744{
745 bool do_resume = false;
746 int err = 0;
747
745 mutex_lock(&phydev->lock); 748 mutex_lock(&phydev->lock);
746 749
747 switch (phydev->state) { 750 switch (phydev->state) {
@@ -752,11 +755,22 @@ void phy_start(struct phy_device *phydev)
752 phydev->state = PHY_UP; 755 phydev->state = PHY_UP;
753 break; 756 break;
754 case PHY_HALTED: 757 case PHY_HALTED:
758 /* make sure interrupts are re-enabled for the PHY */
759 err = phy_enable_interrupts(phydev);
760 if (err < 0)
761 break;
762
755 phydev->state = PHY_RESUMING; 763 phydev->state = PHY_RESUMING;
764 do_resume = true;
765 break;
756 default: 766 default:
757 break; 767 break;
758 } 768 }
759 mutex_unlock(&phydev->lock); 769 mutex_unlock(&phydev->lock);
770
771 /* if phy was suspended, bring the physical link up again */
772 if (do_resume)
773 phy_resume(phydev);
760} 774}
761EXPORT_SYMBOL(phy_start); 775EXPORT_SYMBOL(phy_start);
762 776
@@ -769,7 +783,7 @@ void phy_state_machine(struct work_struct *work)
769 struct delayed_work *dwork = to_delayed_work(work); 783 struct delayed_work *dwork = to_delayed_work(work);
770 struct phy_device *phydev = 784 struct phy_device *phydev =
771 container_of(dwork, struct phy_device, state_queue); 785 container_of(dwork, struct phy_device, state_queue);
772 bool needs_aneg = false, do_suspend = false, do_resume = false; 786 bool needs_aneg = false, do_suspend = false;
773 int err = 0; 787 int err = 0;
774 788
775 mutex_lock(&phydev->lock); 789 mutex_lock(&phydev->lock);
@@ -888,14 +902,6 @@ void phy_state_machine(struct work_struct *work)
888 } 902 }
889 break; 903 break;
890 case PHY_RESUMING: 904 case PHY_RESUMING:
891 err = phy_clear_interrupt(phydev);
892 if (err)
893 break;
894
895 err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED);
896 if (err)
897 break;
898
899 if (AUTONEG_ENABLE == phydev->autoneg) { 905 if (AUTONEG_ENABLE == phydev->autoneg) {
900 err = phy_aneg_done(phydev); 906 err = phy_aneg_done(phydev);
901 if (err < 0) 907 if (err < 0)
@@ -933,7 +939,6 @@ void phy_state_machine(struct work_struct *work)
933 } 939 }
934 phydev->adjust_link(phydev->attached_dev); 940 phydev->adjust_link(phydev->attached_dev);
935 } 941 }
936 do_resume = true;
937 break; 942 break;
938 } 943 }
939 944
@@ -943,8 +948,6 @@ void phy_state_machine(struct work_struct *work)
943 err = phy_start_aneg(phydev); 948 err = phy_start_aneg(phydev);
944 else if (do_suspend) 949 else if (do_suspend)
945 phy_suspend(phydev); 950 phy_suspend(phydev);
946 else if (do_resume)
947 phy_resume(phydev);
948 951
949 if (err < 0) 952 if (err < 0)
950 phy_error(phydev); 953 phy_error(phydev);
@@ -1053,13 +1056,14 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
1053{ 1056{
1054 /* According to 802.3az,the EEE is supported only in full duplex-mode. 1057 /* According to 802.3az,the EEE is supported only in full duplex-mode.
1055 * Also EEE feature is active when core is operating with MII, GMII 1058 * Also EEE feature is active when core is operating with MII, GMII
1056 * or RGMII. Internal PHYs are also allowed to proceed and should 1059 * or RGMII (all kinds). Internal PHYs are also allowed to proceed and
1057 * return an error if they do not support EEE. 1060 * should return an error if they do not support EEE.
1058 */ 1061 */
1059 if ((phydev->duplex == DUPLEX_FULL) && 1062 if ((phydev->duplex == DUPLEX_FULL) &&
1060 ((phydev->interface == PHY_INTERFACE_MODE_MII) || 1063 ((phydev->interface == PHY_INTERFACE_MODE_MII) ||
1061 (phydev->interface == PHY_INTERFACE_MODE_GMII) || 1064 (phydev->interface == PHY_INTERFACE_MODE_GMII) ||
1062 (phydev->interface == PHY_INTERFACE_MODE_RGMII) || 1065 (phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
1066 phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID) ||
1063 phy_is_internal(phydev))) { 1067 phy_is_internal(phydev))) {
1064 int eee_lp, eee_cap, eee_adv; 1068 int eee_lp, eee_cap, eee_adv;
1065 u32 lp, cap, adv; 1069 u32 lp, cap, adv;
diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
index 911b21602ff2..05005c660d4d 100644
--- a/drivers/net/ppp/ppp_mppe.c
+++ b/drivers/net/ppp/ppp_mppe.c
@@ -478,7 +478,6 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
478 struct blkcipher_desc desc = { .tfm = state->arc4 }; 478 struct blkcipher_desc desc = { .tfm = state->arc4 };
479 unsigned ccount; 479 unsigned ccount;
480 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED; 480 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
481 int sanity = 0;
482 struct scatterlist sg_in[1], sg_out[1]; 481 struct scatterlist sg_in[1], sg_out[1];
483 482
484 if (isize <= PPP_HDRLEN + MPPE_OVHD) { 483 if (isize <= PPP_HDRLEN + MPPE_OVHD) {
@@ -514,31 +513,19 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
514 "mppe_decompress[%d]: ENCRYPTED bit not set!\n", 513 "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
515 state->unit); 514 state->unit);
516 state->sanity_errors += 100; 515 state->sanity_errors += 100;
517 sanity = 1; 516 goto sanity_error;
518 } 517 }
519 if (!state->stateful && !flushed) { 518 if (!state->stateful && !flushed) {
520 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in " 519 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in "
521 "stateless mode!\n", state->unit); 520 "stateless mode!\n", state->unit);
522 state->sanity_errors += 100; 521 state->sanity_errors += 100;
523 sanity = 1; 522 goto sanity_error;
524 } 523 }
525 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) { 524 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
526 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on " 525 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on "
527 "flag packet!\n", state->unit); 526 "flag packet!\n", state->unit);
528 state->sanity_errors += 100; 527 state->sanity_errors += 100;
529 sanity = 1; 528 goto sanity_error;
530 }
531
532 if (sanity) {
533 if (state->sanity_errors < SANITY_MAX)
534 return DECOMP_ERROR;
535 else
536 /*
537 * Take LCP down if the peer is sending too many bogons.
538 * We don't want to do this for a single or just a few
539 * instances since it could just be due to packet corruption.
540 */
541 return DECOMP_FATALERROR;
542 } 529 }
543 530
544 /* 531 /*
@@ -546,6 +533,13 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
546 */ 533 */
547 534
548 if (!state->stateful) { 535 if (!state->stateful) {
536 /* Discard late packet */
537 if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE
538 > MPPE_CCOUNT_SPACE / 2) {
539 state->sanity_errors++;
540 goto sanity_error;
541 }
542
549 /* RFC 3078, sec 8.1. Rekey for every packet. */ 543 /* RFC 3078, sec 8.1. Rekey for every packet. */
550 while (state->ccount != ccount) { 544 while (state->ccount != ccount) {
551 mppe_rekey(state, 0); 545 mppe_rekey(state, 0);
@@ -649,6 +643,16 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
649 state->sanity_errors >>= 1; 643 state->sanity_errors >>= 1;
650 644
651 return osize; 645 return osize;
646
647sanity_error:
648 if (state->sanity_errors < SANITY_MAX)
649 return DECOMP_ERROR;
650 else
651 /* Take LCP down if the peer is sending too many bogons.
652 * We don't want to do this for a single or just a few
653 * instances since it could just be due to packet corruption.
654 */
655 return DECOMP_FATALERROR;
652} 656}
653 657
654/* 658/*
diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
index aa1dd926623a..b62a5e3a1c65 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -465,6 +465,10 @@ static void pppoe_unbind_sock_work(struct work_struct *work)
465 struct sock *sk = sk_pppox(po); 465 struct sock *sk = sk_pppox(po);
466 466
467 lock_sock(sk); 467 lock_sock(sk);
468 if (po->pppoe_dev) {
469 dev_put(po->pppoe_dev);
470 po->pppoe_dev = NULL;
471 }
468 pppox_unbind_sock(sk); 472 pppox_unbind_sock(sk);
469 release_sock(sk); 473 release_sock(sk);
470 sock_put(sk); 474 sock_put(sk);
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index c3e4da9e79ca..8067b8fbb0ee 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1182,7 +1182,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
1182 * payload data instead. 1182 * payload data instead.
1183 */ 1183 */
1184 usbnet_set_skb_tx_stats(skb_out, n, 1184 usbnet_set_skb_tx_stats(skb_out, n,
1185 ctx->tx_curr_frame_payload - skb_out->len); 1185 (long)ctx->tx_curr_frame_payload - skb_out->len);
1186 1186
1187 return skb_out; 1187 return skb_out;
1188 1188
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index ac4d03b328b1..aafa1a1898e4 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -4116,6 +4116,7 @@ static struct usb_device_id rtl8152_table[] = {
4116 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8153)}, 4116 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8153)},
4117 {REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, 0xa101)}, 4117 {REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, 0xa101)},
4118 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7205)}, 4118 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7205)},
4119 {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x304f)},
4119 {} 4120 {}
4120}; 4121};
4121 4122
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 733f4feb2ef3..3c86b107275a 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1285,7 +1285,7 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1285 struct net_device *net) 1285 struct net_device *net)
1286{ 1286{
1287 struct usbnet *dev = netdev_priv(net); 1287 struct usbnet *dev = netdev_priv(net);
1288 int length; 1288 unsigned int length;
1289 struct urb *urb = NULL; 1289 struct urb *urb = NULL;
1290 struct skb_data *entry; 1290 struct skb_data *entry;
1291 struct driver_info *info = dev->driver_info; 1291 struct driver_info *info = dev->driver_info;
@@ -1413,7 +1413,7 @@ not_drop:
1413 } 1413 }
1414 } else 1414 } else
1415 netif_dbg(dev, tx_queued, dev->net, 1415 netif_dbg(dev, tx_queued, dev->net,
1416 "> tx, len %d, type 0x%x\n", length, skb->protocol); 1416 "> tx, len %u, type 0x%x\n", length, skb->protocol);
1417#ifdef CONFIG_PM 1417#ifdef CONFIG_PM
1418deferred: 1418deferred:
1419#endif 1419#endif
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 154116aafd0d..21a0fbf1ed94 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -730,12 +730,8 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
730 /* Only change unicasts */ 730 /* Only change unicasts */
731 if (!(is_multicast_ether_addr(f->eth_addr) || 731 if (!(is_multicast_ether_addr(f->eth_addr) ||
732 is_zero_ether_addr(f->eth_addr))) { 732 is_zero_ether_addr(f->eth_addr))) {
733 int rc = vxlan_fdb_replace(f, ip, port, vni, 733 notify |= vxlan_fdb_replace(f, ip, port, vni,
734 ifindex); 734 ifindex);
735
736 if (rc < 0)
737 return rc;
738 notify |= rc;
739 } else 735 } else
740 return -EOPNOTSUPP; 736 return -EOPNOTSUPP;
741 } 737 }
@@ -2965,7 +2961,7 @@ static void __net_exit vxlan_exit_net(struct net *net)
2965 * to the list by the previous loop. 2961 * to the list by the previous loop.
2966 */ 2962 */
2967 if (!net_eq(dev_net(vxlan->dev), net)) 2963 if (!net_eq(dev_net(vxlan->dev), net))
2968 unregister_netdevice_queue(dev, &list); 2964 unregister_netdevice_queue(vxlan->dev, &list);
2969 } 2965 }
2970 2966
2971 unregister_netdevice_many(&list); 2967 unregister_netdevice_many(&list);
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 0acd079ba96b..3ad79bb4f2c2 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1103,28 +1103,14 @@ static u8 ath_get_rate_txpower(struct ath_softc *sc, struct ath_buf *bf,
1103 struct sk_buff *skb; 1103 struct sk_buff *skb;
1104 struct ath_frame_info *fi; 1104 struct ath_frame_info *fi;
1105 struct ieee80211_tx_info *info; 1105 struct ieee80211_tx_info *info;
1106 struct ieee80211_vif *vif;
1107 struct ath_hw *ah = sc->sc_ah; 1106 struct ath_hw *ah = sc->sc_ah;
1108 1107
1109 if (sc->tx99_state || !ah->tpc_enabled) 1108 if (sc->tx99_state || !ah->tpc_enabled)
1110 return MAX_RATE_POWER; 1109 return MAX_RATE_POWER;
1111 1110
1112 skb = bf->bf_mpdu; 1111 skb = bf->bf_mpdu;
1113 info = IEEE80211_SKB_CB(skb);
1114 vif = info->control.vif;
1115
1116 if (!vif) {
1117 max_power = sc->cur_chan->cur_txpower;
1118 goto out;
1119 }
1120
1121 if (vif->bss_conf.txpower_type != NL80211_TX_POWER_LIMITED) {
1122 max_power = min_t(u8, sc->cur_chan->cur_txpower,
1123 2 * vif->bss_conf.txpower);
1124 goto out;
1125 }
1126
1127 fi = get_frame_info(skb); 1112 fi = get_frame_info(skb);
1113 info = IEEE80211_SKB_CB(skb);
1128 1114
1129 if (!AR_SREV_9300_20_OR_LATER(ah)) { 1115 if (!AR_SREV_9300_20_OR_LATER(ah)) {
1130 int txpower = fi->tx_power; 1116 int txpower = fi->tx_power;
@@ -1161,25 +1147,26 @@ static u8 ath_get_rate_txpower(struct ath_softc *sc, struct ath_buf *bf,
1161 txpower -= 2; 1147 txpower -= 2;
1162 1148
1163 txpower = max(txpower, 0); 1149 txpower = max(txpower, 0);
1164 max_power = min_t(u8, ah->tx_power[rateidx], 1150 max_power = min_t(u8, ah->tx_power[rateidx], txpower);
1165 2 * vif->bss_conf.txpower); 1151
1166 max_power = min_t(u8, max_power, txpower); 1152 /* XXX: clamp minimum TX power at 1 for AR9160 since if
1153 * max_power is set to 0, frames are transmitted at max
1154 * TX power
1155 */
1156 if (!max_power && !AR_SREV_9280_20_OR_LATER(ah))
1157 max_power = 1;
1167 } else if (!bf->bf_state.bfs_paprd) { 1158 } else if (!bf->bf_state.bfs_paprd) {
1168 if (rateidx < 8 && (info->flags & IEEE80211_TX_CTL_STBC)) 1159 if (rateidx < 8 && (info->flags & IEEE80211_TX_CTL_STBC))
1169 max_power = min_t(u8, ah->tx_power_stbc[rateidx], 1160 max_power = min_t(u8, ah->tx_power_stbc[rateidx],
1170 2 * vif->bss_conf.txpower); 1161 fi->tx_power);
1171 else 1162 else
1172 max_power = min_t(u8, ah->tx_power[rateidx], 1163 max_power = min_t(u8, ah->tx_power[rateidx],
1173 2 * vif->bss_conf.txpower); 1164 fi->tx_power);
1174 max_power = min(max_power, fi->tx_power);
1175 } else { 1165 } else {
1176 max_power = ah->paprd_training_power; 1166 max_power = ah->paprd_training_power;
1177 } 1167 }
1178out: 1168
1179 /* XXX: clamp minimum TX power at 1 for AR9160 since if max_power 1169 return max_power;
1180 * is set to 0, frames are transmitted at max TX power
1181 */
1182 return (!max_power && !AR_SREV_9280_20_OR_LATER(ah)) ? 1 : max_power;
1183} 1170}
1184 1171
1185static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf, 1172static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf,
@@ -2129,6 +2116,7 @@ static void setup_frame_info(struct ieee80211_hw *hw,
2129 struct ath_node *an = NULL; 2116 struct ath_node *an = NULL;
2130 enum ath9k_key_type keytype; 2117 enum ath9k_key_type keytype;
2131 bool short_preamble = false; 2118 bool short_preamble = false;
2119 u8 txpower;
2132 2120
2133 /* 2121 /*
2134 * We check if Short Preamble is needed for the CTS rate by 2122 * We check if Short Preamble is needed for the CTS rate by
@@ -2145,6 +2133,16 @@ static void setup_frame_info(struct ieee80211_hw *hw,
2145 if (sta) 2133 if (sta)
2146 an = (struct ath_node *) sta->drv_priv; 2134 an = (struct ath_node *) sta->drv_priv;
2147 2135
2136 if (tx_info->control.vif) {
2137 struct ieee80211_vif *vif = tx_info->control.vif;
2138
2139 txpower = 2 * vif->bss_conf.txpower;
2140 } else {
2141 struct ath_softc *sc = hw->priv;
2142
2143 txpower = sc->cur_chan->cur_txpower;
2144 }
2145
2148 memset(fi, 0, sizeof(*fi)); 2146 memset(fi, 0, sizeof(*fi));
2149 fi->txq = -1; 2147 fi->txq = -1;
2150 if (hw_key) 2148 if (hw_key)
@@ -2155,7 +2153,7 @@ static void setup_frame_info(struct ieee80211_hw *hw,
2155 fi->keyix = ATH9K_TXKEYIX_INVALID; 2153 fi->keyix = ATH9K_TXKEYIX_INVALID;
2156 fi->keytype = keytype; 2154 fi->keytype = keytype;
2157 fi->framelen = framelen; 2155 fi->framelen = framelen;
2158 fi->tx_power = MAX_RATE_POWER; 2156 fi->tx_power = txpower;
2159 2157
2160 if (!rate) 2158 if (!rate)
2161 return; 2159 return;
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index ab019b45551b..f89f446e5c8a 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -21,6 +21,7 @@ config IWLWIFI
21 Intel 7260 Wi-Fi Adapter 21 Intel 7260 Wi-Fi Adapter
22 Intel 3160 Wi-Fi Adapter 22 Intel 3160 Wi-Fi Adapter
23 Intel 7265 Wi-Fi Adapter 23 Intel 7265 Wi-Fi Adapter
24 Intel 3165 Wi-Fi Adapter
24 25
25 26
26 This driver uses the kernel's mac80211 subsystem. 27 This driver uses the kernel's mac80211 subsystem.
diff --git a/drivers/net/wireless/iwlwifi/iwl-7000.c b/drivers/net/wireless/iwlwifi/iwl-7000.c
index 36e786f0387b..74ad278116be 100644
--- a/drivers/net/wireless/iwlwifi/iwl-7000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-7000.c
@@ -70,15 +70,14 @@
70 70
71/* Highest firmware API version supported */ 71/* Highest firmware API version supported */
72#define IWL7260_UCODE_API_MAX 13 72#define IWL7260_UCODE_API_MAX 13
73#define IWL3160_UCODE_API_MAX 13
74 73
75/* Oldest version we won't warn about */ 74/* Oldest version we won't warn about */
76#define IWL7260_UCODE_API_OK 12 75#define IWL7260_UCODE_API_OK 12
77#define IWL3160_UCODE_API_OK 12 76#define IWL3165_UCODE_API_OK 13
78 77
79/* Lowest firmware API version supported */ 78/* Lowest firmware API version supported */
80#define IWL7260_UCODE_API_MIN 10 79#define IWL7260_UCODE_API_MIN 10
81#define IWL3160_UCODE_API_MIN 10 80#define IWL3165_UCODE_API_MIN 13
82 81
83/* NVM versions */ 82/* NVM versions */
84#define IWL7260_NVM_VERSION 0x0a1d 83#define IWL7260_NVM_VERSION 0x0a1d
@@ -104,9 +103,6 @@
104#define IWL3160_FW_PRE "iwlwifi-3160-" 103#define IWL3160_FW_PRE "iwlwifi-3160-"
105#define IWL3160_MODULE_FIRMWARE(api) IWL3160_FW_PRE __stringify(api) ".ucode" 104#define IWL3160_MODULE_FIRMWARE(api) IWL3160_FW_PRE __stringify(api) ".ucode"
106 105
107#define IWL3165_FW_PRE "iwlwifi-3165-"
108#define IWL3165_MODULE_FIRMWARE(api) IWL3165_FW_PRE __stringify(api) ".ucode"
109
110#define IWL7265_FW_PRE "iwlwifi-7265-" 106#define IWL7265_FW_PRE "iwlwifi-7265-"
111#define IWL7265_MODULE_FIRMWARE(api) IWL7265_FW_PRE __stringify(api) ".ucode" 107#define IWL7265_MODULE_FIRMWARE(api) IWL7265_FW_PRE __stringify(api) ".ucode"
112 108
@@ -248,8 +244,13 @@ static const struct iwl_ht_params iwl7265_ht_params = {
248 244
249const struct iwl_cfg iwl3165_2ac_cfg = { 245const struct iwl_cfg iwl3165_2ac_cfg = {
250 .name = "Intel(R) Dual Band Wireless AC 3165", 246 .name = "Intel(R) Dual Band Wireless AC 3165",
251 .fw_name_pre = IWL3165_FW_PRE, 247 .fw_name_pre = IWL7265D_FW_PRE,
252 IWL_DEVICE_7000, 248 IWL_DEVICE_7000,
249 /* sparse doens't like the re-assignment but it is safe */
250#ifndef __CHECKER__
251 .ucode_api_ok = IWL3165_UCODE_API_OK,
252 .ucode_api_min = IWL3165_UCODE_API_MIN,
253#endif
253 .ht_params = &iwl7000_ht_params, 254 .ht_params = &iwl7000_ht_params,
254 .nvm_ver = IWL3165_NVM_VERSION, 255 .nvm_ver = IWL3165_NVM_VERSION,
255 .nvm_calib_ver = IWL3165_TX_POWER_VERSION, 256 .nvm_calib_ver = IWL3165_TX_POWER_VERSION,
@@ -325,6 +326,5 @@ const struct iwl_cfg iwl7265d_n_cfg = {
325 326
326MODULE_FIRMWARE(IWL7260_MODULE_FIRMWARE(IWL7260_UCODE_API_OK)); 327MODULE_FIRMWARE(IWL7260_MODULE_FIRMWARE(IWL7260_UCODE_API_OK));
327MODULE_FIRMWARE(IWL3160_MODULE_FIRMWARE(IWL3160_UCODE_API_OK)); 328MODULE_FIRMWARE(IWL3160_MODULE_FIRMWARE(IWL3160_UCODE_API_OK));
328MODULE_FIRMWARE(IWL3165_MODULE_FIRMWARE(IWL3160_UCODE_API_OK));
329MODULE_FIRMWARE(IWL7265_MODULE_FIRMWARE(IWL7260_UCODE_API_OK)); 329MODULE_FIRMWARE(IWL7265_MODULE_FIRMWARE(IWL7260_UCODE_API_OK));
330MODULE_FIRMWARE(IWL7265D_MODULE_FIRMWARE(IWL7260_UCODE_API_OK)); 330MODULE_FIRMWARE(IWL7265D_MODULE_FIRMWARE(IWL7260_UCODE_API_OK));
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
index 41ff85de7334..21302b6f2bfd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
@@ -6,6 +6,7 @@
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2015 Intel Mobile Communications GmbH
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -31,6 +32,7 @@
31 * BSD LICENSE 32 * BSD LICENSE
32 * 33 *
33 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2015 Intel Mobile Communications GmbH
34 * All rights reserved. 36 * All rights reserved.
35 * 37 *
36 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
@@ -748,6 +750,9 @@ void iwl_init_ht_hw_capab(const struct iwl_cfg *cfg,
748 return; 750 return;
749 } 751 }
750 752
753 if (data->sku_cap_mimo_disabled)
754 rx_chains = 1;
755
751 ht_info->ht_supported = true; 756 ht_info->ht_supported = true;
752 ht_info->cap = IEEE80211_HT_CAP_DSSSCCK40; 757 ht_info->cap = IEEE80211_HT_CAP_DSSSCCK40;
753 758
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h
index 5234a0bf11e4..750c8c9ee70d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h
@@ -6,6 +6,7 @@
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2015 Intel Mobile Communications GmbH
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -31,6 +32,7 @@
31 * BSD LICENSE 32 * BSD LICENSE
32 * 33 *
33 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2015 Intel Mobile Communications GmbH
34 * All rights reserved. 36 * All rights reserved.
35 * 37 *
36 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
@@ -84,6 +86,7 @@ struct iwl_nvm_data {
84 bool sku_cap_11ac_enable; 86 bool sku_cap_11ac_enable;
85 bool sku_cap_amt_enable; 87 bool sku_cap_amt_enable;
86 bool sku_cap_ipan_enable; 88 bool sku_cap_ipan_enable;
89 bool sku_cap_mimo_disabled;
87 90
88 u16 radio_cfg_type; 91 u16 radio_cfg_type;
89 u8 radio_cfg_step; 92 u8 radio_cfg_step;
diff --git a/drivers/net/wireless/iwlwifi/iwl-fw-file.h b/drivers/net/wireless/iwlwifi/iwl-fw-file.h
index bfdf3faa6c47..62db2e5e45eb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fw-file.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fw-file.h
@@ -244,6 +244,7 @@ enum iwl_ucode_tlv_flag {
244 * longer than the passive one, which is essential for fragmented scan. 244 * longer than the passive one, which is essential for fragmented scan.
245 * @IWL_UCODE_TLV_API_WIFI_MCC_UPDATE: ucode supports MCC updates with source. 245 * @IWL_UCODE_TLV_API_WIFI_MCC_UPDATE: ucode supports MCC updates with source.
246 * IWL_UCODE_TLV_API_HDC_PHASE_0: ucode supports finer configuration of LTR 246 * IWL_UCODE_TLV_API_HDC_PHASE_0: ucode supports finer configuration of LTR
247 * @IWL_UCODE_TLV_API_TX_POWER_DEV: new API for tx power.
247 * @IWL_UCODE_TLV_API_BASIC_DWELL: use only basic dwell time in scan command, 248 * @IWL_UCODE_TLV_API_BASIC_DWELL: use only basic dwell time in scan command,
248 * regardless of the band or the number of the probes. FW will calculate 249 * regardless of the band or the number of the probes. FW will calculate
249 * the actual dwell time. 250 * the actual dwell time.
@@ -260,6 +261,7 @@ enum iwl_ucode_tlv_api {
260 IWL_UCODE_TLV_API_FRAGMENTED_SCAN = BIT(8), 261 IWL_UCODE_TLV_API_FRAGMENTED_SCAN = BIT(8),
261 IWL_UCODE_TLV_API_WIFI_MCC_UPDATE = BIT(9), 262 IWL_UCODE_TLV_API_WIFI_MCC_UPDATE = BIT(9),
262 IWL_UCODE_TLV_API_HDC_PHASE_0 = BIT(10), 263 IWL_UCODE_TLV_API_HDC_PHASE_0 = BIT(10),
264 IWL_UCODE_TLV_API_TX_POWER_DEV = BIT(11),
263 IWL_UCODE_TLV_API_BASIC_DWELL = BIT(13), 265 IWL_UCODE_TLV_API_BASIC_DWELL = BIT(13),
264 IWL_UCODE_TLV_API_SCD_CFG = BIT(15), 266 IWL_UCODE_TLV_API_SCD_CFG = BIT(15),
265 IWL_UCODE_TLV_API_SINGLE_SCAN_EBS = BIT(16), 267 IWL_UCODE_TLV_API_SINGLE_SCAN_EBS = BIT(16),
diff --git a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
index 83903a5025c2..75e96db6626b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/iwlwifi/iwl-nvm-parse.c
@@ -6,7 +6,7 @@
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -32,7 +32,7 @@
32 * BSD LICENSE 32 * BSD LICENSE
33 * 33 *
34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved. 36 * All rights reserved.
37 * 37 *
38 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
@@ -116,10 +116,11 @@ enum family_8000_nvm_offsets {
116 116
117/* SKU Capabilities (actual values from NVM definition) */ 117/* SKU Capabilities (actual values from NVM definition) */
118enum nvm_sku_bits { 118enum nvm_sku_bits {
119 NVM_SKU_CAP_BAND_24GHZ = BIT(0), 119 NVM_SKU_CAP_BAND_24GHZ = BIT(0),
120 NVM_SKU_CAP_BAND_52GHZ = BIT(1), 120 NVM_SKU_CAP_BAND_52GHZ = BIT(1),
121 NVM_SKU_CAP_11N_ENABLE = BIT(2), 121 NVM_SKU_CAP_11N_ENABLE = BIT(2),
122 NVM_SKU_CAP_11AC_ENABLE = BIT(3), 122 NVM_SKU_CAP_11AC_ENABLE = BIT(3),
123 NVM_SKU_CAP_MIMO_DISABLE = BIT(5),
123}; 124};
124 125
125/* 126/*
@@ -368,6 +369,11 @@ static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
368 if (cfg->ht_params->ldpc) 369 if (cfg->ht_params->ldpc)
369 vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC; 370 vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
370 371
372 if (data->sku_cap_mimo_disabled) {
373 num_rx_ants = 1;
374 num_tx_ants = 1;
375 }
376
371 if (num_tx_ants > 1) 377 if (num_tx_ants > 1)
372 vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC; 378 vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
373 else 379 else
@@ -527,6 +533,10 @@ static void iwl_set_hw_address_family_8000(struct device *dev,
527 const u8 *hw_addr; 533 const u8 *hw_addr;
528 534
529 if (mac_override) { 535 if (mac_override) {
536 static const u8 reserved_mac[] = {
537 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
538 };
539
530 hw_addr = (const u8 *)(mac_override + 540 hw_addr = (const u8 *)(mac_override +
531 MAC_ADDRESS_OVERRIDE_FAMILY_8000); 541 MAC_ADDRESS_OVERRIDE_FAMILY_8000);
532 542
@@ -538,7 +548,12 @@ static void iwl_set_hw_address_family_8000(struct device *dev,
538 data->hw_addr[4] = hw_addr[5]; 548 data->hw_addr[4] = hw_addr[5];
539 data->hw_addr[5] = hw_addr[4]; 549 data->hw_addr[5] = hw_addr[4];
540 550
541 if (is_valid_ether_addr(data->hw_addr)) 551 /*
552 * Force the use of the OTP MAC address in case of reserved MAC
553 * address in the NVM, or if address is given but invalid.
554 */
555 if (is_valid_ether_addr(data->hw_addr) &&
556 memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
542 return; 557 return;
543 558
544 IWL_ERR_DEV(dev, 559 IWL_ERR_DEV(dev,
@@ -610,6 +625,7 @@ iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg,
610 data->sku_cap_11n_enable = false; 625 data->sku_cap_11n_enable = false;
611 data->sku_cap_11ac_enable = data->sku_cap_11n_enable && 626 data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
612 (sku & NVM_SKU_CAP_11AC_ENABLE); 627 (sku & NVM_SKU_CAP_11AC_ENABLE);
628 data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
613 629
614 data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw); 630 data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
615 631
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans.h b/drivers/net/wireless/iwlwifi/iwl-trans.h
index 6dfed1259260..56254a837214 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans.h
+++ b/drivers/net/wireless/iwlwifi/iwl-trans.h
@@ -6,7 +6,7 @@
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -32,7 +32,7 @@
32 * BSD LICENSE 32 * BSD LICENSE
33 * 33 *
34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved. 36 * All rights reserved.
37 * 37 *
38 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
@@ -421,8 +421,9 @@ struct iwl_trans_txq_scd_cfg {
421 * 421 *
422 * All the handlers MUST be implemented 422 * All the handlers MUST be implemented
423 * 423 *
424 * @start_hw: starts the HW- from that point on, the HW can send interrupts 424 * @start_hw: starts the HW. If low_power is true, the NIC needs to be taken
425 * May sleep 425 * out of a low power state. From that point on, the HW can send
426 * interrupts. May sleep.
426 * @op_mode_leave: Turn off the HW RF kill indication if on 427 * @op_mode_leave: Turn off the HW RF kill indication if on
427 * May sleep 428 * May sleep
428 * @start_fw: allocates and inits all the resources for the transport 429 * @start_fw: allocates and inits all the resources for the transport
@@ -432,10 +433,11 @@ struct iwl_trans_txq_scd_cfg {
432 * the SCD base address in SRAM, then provide it here, or 0 otherwise. 433 * the SCD base address in SRAM, then provide it here, or 0 otherwise.
433 * May sleep 434 * May sleep
434 * @stop_device: stops the whole device (embedded CPU put to reset) and stops 435 * @stop_device: stops the whole device (embedded CPU put to reset) and stops
435 * the HW. From that point on, the HW will be in low power but will still 436 * the HW. If low_power is true, the NIC will be put in low power state.
436 * issue interrupt if the HW RF kill is triggered. This callback must do 437 * From that point on, the HW will be stopped but will still issue an
437 * the right thing and not crash even if start_hw() was called but not 438 * interrupt if the HW RF kill switch is triggered.
438 * start_fw(). May sleep 439 * This callback must do the right thing and not crash even if %start_hw()
440 * was called but not &start_fw(). May sleep.
439 * @d3_suspend: put the device into the correct mode for WoWLAN during 441 * @d3_suspend: put the device into the correct mode for WoWLAN during
440 * suspend. This is optional, if not implemented WoWLAN will not be 442 * suspend. This is optional, if not implemented WoWLAN will not be
441 * supported. This callback may sleep. 443 * supported. This callback may sleep.
@@ -491,14 +493,14 @@ struct iwl_trans_txq_scd_cfg {
491 */ 493 */
492struct iwl_trans_ops { 494struct iwl_trans_ops {
493 495
494 int (*start_hw)(struct iwl_trans *iwl_trans); 496 int (*start_hw)(struct iwl_trans *iwl_trans, bool low_power);
495 void (*op_mode_leave)(struct iwl_trans *iwl_trans); 497 void (*op_mode_leave)(struct iwl_trans *iwl_trans);
496 int (*start_fw)(struct iwl_trans *trans, const struct fw_img *fw, 498 int (*start_fw)(struct iwl_trans *trans, const struct fw_img *fw,
497 bool run_in_rfkill); 499 bool run_in_rfkill);
498 int (*update_sf)(struct iwl_trans *trans, 500 int (*update_sf)(struct iwl_trans *trans,
499 struct iwl_sf_region *st_fwrd_space); 501 struct iwl_sf_region *st_fwrd_space);
500 void (*fw_alive)(struct iwl_trans *trans, u32 scd_addr); 502 void (*fw_alive)(struct iwl_trans *trans, u32 scd_addr);
501 void (*stop_device)(struct iwl_trans *trans); 503 void (*stop_device)(struct iwl_trans *trans, bool low_power);
502 504
503 void (*d3_suspend)(struct iwl_trans *trans, bool test); 505 void (*d3_suspend)(struct iwl_trans *trans, bool test);
504 int (*d3_resume)(struct iwl_trans *trans, enum iwl_d3_status *status, 506 int (*d3_resume)(struct iwl_trans *trans, enum iwl_d3_status *status,
@@ -652,11 +654,16 @@ static inline void iwl_trans_configure(struct iwl_trans *trans,
652 trans->ops->configure(trans, trans_cfg); 654 trans->ops->configure(trans, trans_cfg);
653} 655}
654 656
655static inline int iwl_trans_start_hw(struct iwl_trans *trans) 657static inline int _iwl_trans_start_hw(struct iwl_trans *trans, bool low_power)
656{ 658{
657 might_sleep(); 659 might_sleep();
658 660
659 return trans->ops->start_hw(trans); 661 return trans->ops->start_hw(trans, low_power);
662}
663
664static inline int iwl_trans_start_hw(struct iwl_trans *trans)
665{
666 return trans->ops->start_hw(trans, true);
660} 667}
661 668
662static inline void iwl_trans_op_mode_leave(struct iwl_trans *trans) 669static inline void iwl_trans_op_mode_leave(struct iwl_trans *trans)
@@ -703,15 +710,21 @@ static inline int iwl_trans_update_sf(struct iwl_trans *trans,
703 return 0; 710 return 0;
704} 711}
705 712
706static inline void iwl_trans_stop_device(struct iwl_trans *trans) 713static inline void _iwl_trans_stop_device(struct iwl_trans *trans,
714 bool low_power)
707{ 715{
708 might_sleep(); 716 might_sleep();
709 717
710 trans->ops->stop_device(trans); 718 trans->ops->stop_device(trans, low_power);
711 719
712 trans->state = IWL_TRANS_NO_FW; 720 trans->state = IWL_TRANS_NO_FW;
713} 721}
714 722
723static inline void iwl_trans_stop_device(struct iwl_trans *trans)
724{
725 _iwl_trans_stop_device(trans, true);
726}
727
715static inline void iwl_trans_d3_suspend(struct iwl_trans *trans, bool test) 728static inline void iwl_trans_d3_suspend(struct iwl_trans *trans, bool test)
716{ 729{
717 might_sleep(); 730 might_sleep();
diff --git a/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c b/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c
index d954591e0be5..6ac6de2af977 100644
--- a/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c
+++ b/drivers/net/wireless/iwlwifi/mvm/coex_legacy.c
@@ -776,7 +776,7 @@ static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
776 struct iwl_host_cmd cmd = { 776 struct iwl_host_cmd cmd = {
777 .id = BT_CONFIG, 777 .id = BT_CONFIG,
778 .len = { sizeof(*bt_cmd), }, 778 .len = { sizeof(*bt_cmd), },
779 .dataflags = { IWL_HCMD_DFL_NOCOPY, }, 779 .dataflags = { IWL_HCMD_DFL_DUP, },
780 .flags = CMD_ASYNC, 780 .flags = CMD_ASYNC,
781 }; 781 };
782 struct iwl_mvm_sta *mvmsta; 782 struct iwl_mvm_sta *mvmsta;
diff --git a/drivers/net/wireless/iwlwifi/mvm/d3.c b/drivers/net/wireless/iwlwifi/mvm/d3.c
index a6c48c7b1e16..4310cf102d78 100644
--- a/drivers/net/wireless/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/iwlwifi/mvm/d3.c
@@ -1726,7 +1726,7 @@ iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm,
1726 results->matched_profiles = le32_to_cpu(query->matched_profiles); 1726 results->matched_profiles = le32_to_cpu(query->matched_profiles);
1727 memcpy(results->matches, query->matches, sizeof(results->matches)); 1727 memcpy(results->matches, query->matches, sizeof(results->matches));
1728 1728
1729#ifdef CPTCFG_IWLWIFI_DEBUGFS 1729#ifdef CONFIG_IWLWIFI_DEBUGFS
1730 mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done); 1730 mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done);
1731#endif 1731#endif
1732 1732
@@ -1750,8 +1750,10 @@ static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
1750 int i, j, n_matches, ret; 1750 int i, j, n_matches, ret;
1751 1751
1752 fw_status = iwl_mvm_get_wakeup_status(mvm, vif); 1752 fw_status = iwl_mvm_get_wakeup_status(mvm, vif);
1753 if (!IS_ERR_OR_NULL(fw_status)) 1753 if (!IS_ERR_OR_NULL(fw_status)) {
1754 reasons = le32_to_cpu(fw_status->wakeup_reasons); 1754 reasons = le32_to_cpu(fw_status->wakeup_reasons);
1755 kfree(fw_status);
1756 }
1755 1757
1756 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) 1758 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
1757 wakeup.rfkill_release = true; 1759 wakeup.rfkill_release = true;
@@ -1868,15 +1870,15 @@ static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
1868 /* get the BSS vif pointer again */ 1870 /* get the BSS vif pointer again */
1869 vif = iwl_mvm_get_bss_vif(mvm); 1871 vif = iwl_mvm_get_bss_vif(mvm);
1870 if (IS_ERR_OR_NULL(vif)) 1872 if (IS_ERR_OR_NULL(vif))
1871 goto out_unlock; 1873 goto err;
1872 1874
1873 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test); 1875 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test);
1874 if (ret) 1876 if (ret)
1875 goto out_unlock; 1877 goto err;
1876 1878
1877 if (d3_status != IWL_D3_STATUS_ALIVE) { 1879 if (d3_status != IWL_D3_STATUS_ALIVE) {
1878 IWL_INFO(mvm, "Device was reset during suspend\n"); 1880 IWL_INFO(mvm, "Device was reset during suspend\n");
1879 goto out_unlock; 1881 goto err;
1880 } 1882 }
1881 1883
1882 /* query SRAM first in case we want event logging */ 1884 /* query SRAM first in case we want event logging */
@@ -1902,7 +1904,8 @@ static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
1902 goto out_iterate; 1904 goto out_iterate;
1903 } 1905 }
1904 1906
1905 out_unlock: 1907err:
1908 iwl_mvm_free_nd(mvm);
1906 mutex_unlock(&mvm->mutex); 1909 mutex_unlock(&mvm->mutex);
1907 1910
1908out_iterate: 1911out_iterate:
@@ -1915,6 +1918,14 @@ out:
1915 /* return 1 to reconfigure the device */ 1918 /* return 1 to reconfigure the device */
1916 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1919 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1917 set_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status); 1920 set_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status);
1921
1922 /* We always return 1, which causes mac80211 to do a reconfig
1923 * with IEEE80211_RECONFIG_TYPE_RESTART. This type of
1924 * reconfig calls iwl_mvm_restart_complete(), where we unref
1925 * the IWL_MVM_REF_UCODE_DOWN, so we need to take the
1926 * reference here.
1927 */
1928 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1918 return 1; 1929 return 1;
1919} 1930}
1920 1931
@@ -2021,7 +2032,6 @@ static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2021 __iwl_mvm_resume(mvm, true); 2032 __iwl_mvm_resume(mvm, true);
2022 rtnl_unlock(); 2033 rtnl_unlock();
2023 iwl_abort_notification_waits(&mvm->notif_wait); 2034 iwl_abort_notification_waits(&mvm->notif_wait);
2024 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
2025 ieee80211_restart_hw(mvm->hw); 2035 ieee80211_restart_hw(mvm->hw);
2026 2036
2027 /* wait for restart and disconnect all interfaces */ 2037 /* wait for restart and disconnect all interfaces */
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw-api-power.h b/drivers/net/wireless/iwlwifi/mvm/fw-api-power.h
index 4fc0938b3fb6..b1baa33cc19b 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw-api-power.h
+++ b/drivers/net/wireless/iwlwifi/mvm/fw-api-power.h
@@ -298,6 +298,40 @@ struct iwl_uapsd_misbehaving_ap_notif {
298} __packed; 298} __packed;
299 299
300/** 300/**
301 * struct iwl_reduce_tx_power_cmd - TX power reduction command
302 * REDUCE_TX_POWER_CMD = 0x9f
303 * @flags: (reserved for future implementation)
304 * @mac_context_id: id of the mac ctx for which we are reducing TX power.
305 * @pwr_restriction: TX power restriction in dBms.
306 */
307struct iwl_reduce_tx_power_cmd {
308 u8 flags;
309 u8 mac_context_id;
310 __le16 pwr_restriction;
311} __packed; /* TX_REDUCED_POWER_API_S_VER_1 */
312
313/**
314 * struct iwl_dev_tx_power_cmd - TX power reduction command
315 * REDUCE_TX_POWER_CMD = 0x9f
316 * @set_mode: 0 - MAC tx power, 1 - device tx power
317 * @mac_context_id: id of the mac ctx for which we are reducing TX power.
318 * @pwr_restriction: TX power restriction in 1/8 dBms.
319 * @dev_24: device TX power restriction in 1/8 dBms
320 * @dev_52_low: device TX power restriction upper band - low
321 * @dev_52_high: device TX power restriction upper band - high
322 */
323struct iwl_dev_tx_power_cmd {
324 __le32 set_mode;
325 __le32 mac_context_id;
326 __le16 pwr_restriction;
327 __le16 dev_24;
328 __le16 dev_52_low;
329 __le16 dev_52_high;
330} __packed; /* TX_REDUCED_POWER_API_S_VER_2 */
331
332#define IWL_DEV_MAX_TX_POWER 0x7FFF
333
334/**
301 * struct iwl_beacon_filter_cmd 335 * struct iwl_beacon_filter_cmd
302 * REPLY_BEACON_FILTERING_CMD = 0xd2 (command) 336 * REPLY_BEACON_FILTERING_CMD = 0xd2 (command)
303 * @id_and_color: MAC contex identifier 337 * @id_and_color: MAC contex identifier
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h b/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
index 4f81dcf57a73..d6cced47d561 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
+++ b/drivers/net/wireless/iwlwifi/mvm/fw-api-scan.h
@@ -122,46 +122,6 @@ enum iwl_scan_complete_status {
122 SCAN_COMP_STATUS_ERR_ALLOC_TE = 0x0C, 122 SCAN_COMP_STATUS_ERR_ALLOC_TE = 0x0C,
123}; 123};
124 124
125/**
126 * struct iwl_scan_results_notif - scan results for one channel
127 * ( SCAN_RESULTS_NOTIFICATION = 0x83 )
128 * @channel: which channel the results are from
129 * @band: 0 for 5.2 GHz, 1 for 2.4 GHz
130 * @probe_status: SCAN_PROBE_STATUS_*, indicates success of probe request
131 * @num_probe_not_sent: # of request that weren't sent due to not enough time
132 * @duration: duration spent in channel, in usecs
133 * @statistics: statistics gathered for this channel
134 */
135struct iwl_scan_results_notif {
136 u8 channel;
137 u8 band;
138 u8 probe_status;
139 u8 num_probe_not_sent;
140 __le32 duration;
141 __le32 statistics[SCAN_RESULTS_STATISTICS];
142} __packed; /* SCAN_RESULT_NTF_API_S_VER_2 */
143
144/**
145 * struct iwl_scan_complete_notif - notifies end of scanning (all channels)
146 * ( SCAN_COMPLETE_NOTIFICATION = 0x84 )
147 * @scanned_channels: number of channels scanned (and number of valid results)
148 * @status: one of SCAN_COMP_STATUS_*
149 * @bt_status: BT on/off status
150 * @last_channel: last channel that was scanned
151 * @tsf_low: TSF timer (lower half) in usecs
152 * @tsf_high: TSF timer (higher half) in usecs
153 * @results: array of scan results, only "scanned_channels" of them are valid
154 */
155struct iwl_scan_complete_notif {
156 u8 scanned_channels;
157 u8 status;
158 u8 bt_status;
159 u8 last_channel;
160 __le32 tsf_low;
161 __le32 tsf_high;
162 struct iwl_scan_results_notif results[];
163} __packed; /* SCAN_COMPLETE_NTF_API_S_VER_2 */
164
165/* scan offload */ 125/* scan offload */
166#define IWL_SCAN_MAX_BLACKLIST_LEN 64 126#define IWL_SCAN_MAX_BLACKLIST_LEN 64
167#define IWL_SCAN_SHORT_BLACKLIST_LEN 16 127#define IWL_SCAN_SHORT_BLACKLIST_LEN 16
@@ -554,7 +514,7 @@ struct iwl_scan_req_unified_lmac {
554} __packed; 514} __packed;
555 515
556/** 516/**
557 * struct iwl_lmac_scan_results_notif - scan results for one channel - 517 * struct iwl_scan_results_notif - scan results for one channel -
558 * SCAN_RESULT_NTF_API_S_VER_3 518 * SCAN_RESULT_NTF_API_S_VER_3
559 * @channel: which channel the results are from 519 * @channel: which channel the results are from
560 * @band: 0 for 5.2 GHz, 1 for 2.4 GHz 520 * @band: 0 for 5.2 GHz, 1 for 2.4 GHz
@@ -562,7 +522,7 @@ struct iwl_scan_req_unified_lmac {
562 * @num_probe_not_sent: # of request that weren't sent due to not enough time 522 * @num_probe_not_sent: # of request that weren't sent due to not enough time
563 * @duration: duration spent in channel, in usecs 523 * @duration: duration spent in channel, in usecs
564 */ 524 */
565struct iwl_lmac_scan_results_notif { 525struct iwl_scan_results_notif {
566 u8 channel; 526 u8 channel;
567 u8 band; 527 u8 band;
568 u8 probe_status; 528 u8 probe_status;
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw-api.h b/drivers/net/wireless/iwlwifi/mvm/fw-api.h
index aab68cbae754..01b1da6ad359 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw-api.h
+++ b/drivers/net/wireless/iwlwifi/mvm/fw-api.h
@@ -281,19 +281,6 @@ struct iwl_tx_ant_cfg_cmd {
281 __le32 valid; 281 __le32 valid;
282} __packed; 282} __packed;
283 283
284/**
285 * struct iwl_reduce_tx_power_cmd - TX power reduction command
286 * REDUCE_TX_POWER_CMD = 0x9f
287 * @flags: (reserved for future implementation)
288 * @mac_context_id: id of the mac ctx for which we are reducing TX power.
289 * @pwr_restriction: TX power restriction in dBms.
290 */
291struct iwl_reduce_tx_power_cmd {
292 u8 flags;
293 u8 mac_context_id;
294 __le16 pwr_restriction;
295} __packed; /* TX_REDUCED_POWER_API_S_VER_1 */
296
297/* 284/*
298 * Calibration control struct. 285 * Calibration control struct.
299 * Sent as part of the phy configuration command. 286 * Sent as part of the phy configuration command.
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw.c b/drivers/net/wireless/iwlwifi/mvm/fw.c
index bc5eac4960e1..df869633f4dd 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw.c
+++ b/drivers/net/wireless/iwlwifi/mvm/fw.c
@@ -6,7 +6,7 @@
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -32,7 +32,7 @@
32 * BSD LICENSE 32 * BSD LICENSE
33 * 33 *
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved. 36 * All rights reserved.
37 * 37 *
38 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
@@ -322,7 +322,7 @@ int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
322 322
323 lockdep_assert_held(&mvm->mutex); 323 lockdep_assert_held(&mvm->mutex);
324 324
325 if (WARN_ON_ONCE(mvm->init_ucode_complete || mvm->calibrating)) 325 if (WARN_ON_ONCE(mvm->calibrating))
326 return 0; 326 return 0;
327 327
328 iwl_init_notification_wait(&mvm->notif_wait, 328 iwl_init_notification_wait(&mvm->notif_wait,
@@ -396,8 +396,6 @@ int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
396 */ 396 */
397 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait, 397 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
398 MVM_UCODE_CALIB_TIMEOUT); 398 MVM_UCODE_CALIB_TIMEOUT);
399 if (!ret)
400 mvm->init_ucode_complete = true;
401 399
402 if (ret && iwl_mvm_is_radio_killed(mvm)) { 400 if (ret && iwl_mvm_is_radio_killed(mvm)) {
403 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n"); 401 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
@@ -494,15 +492,6 @@ int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
494 492
495 mvm->fw_dump_desc = desc; 493 mvm->fw_dump_desc = desc;
496 494
497 /* stop recording */
498 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
499 iwl_set_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
500 } else {
501 iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 0);
502 /* wait before we collect the data till the DBGC stop */
503 udelay(100);
504 }
505
506 queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay); 495 queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
507 496
508 return 0; 497 return 0;
@@ -658,25 +647,24 @@ int iwl_mvm_up(struct iwl_mvm *mvm)
658 * module loading, load init ucode now 647 * module loading, load init ucode now
659 * (for example, if we were in RFKILL) 648 * (for example, if we were in RFKILL)
660 */ 649 */
661 if (!mvm->init_ucode_complete) { 650 ret = iwl_run_init_mvm_ucode(mvm, false);
662 ret = iwl_run_init_mvm_ucode(mvm, false); 651 if (ret && !iwlmvm_mod_params.init_dbg) {
663 if (ret && !iwlmvm_mod_params.init_dbg) { 652 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
664 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret); 653 /* this can't happen */
665 /* this can't happen */ 654 if (WARN_ON(ret > 0))
666 if (WARN_ON(ret > 0)) 655 ret = -ERFKILL;
667 ret = -ERFKILL; 656 goto error;
668 goto error; 657 }
669 } 658 if (!iwlmvm_mod_params.init_dbg) {
670 if (!iwlmvm_mod_params.init_dbg) { 659 /*
671 /* 660 * Stop and start the transport without entering low power
672 * should stop and start HW since that INIT 661 * mode. This will save the state of other components on the
673 * image just loaded 662 * device that are triggered by the INIT firwmare (MFUART).
674 */ 663 */
675 iwl_trans_stop_device(mvm->trans); 664 _iwl_trans_stop_device(mvm->trans, false);
676 ret = iwl_trans_start_hw(mvm->trans); 665 _iwl_trans_start_hw(mvm->trans, false);
677 if (ret) 666 if (ret)
678 return ret; 667 return ret;
679 }
680 } 668 }
681 669
682 if (iwlmvm_mod_params.init_dbg) 670 if (iwlmvm_mod_params.init_dbg)
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index 84555170b6f7..dda9f7b5f342 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -1322,7 +1322,7 @@ static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1322 1322
1323 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1323 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1324 iwl_mvm_d0i3_enable_tx(mvm, NULL); 1324 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1325 ret = iwl_mvm_update_quotas(mvm, false, NULL); 1325 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1326 if (ret) 1326 if (ret)
1327 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1327 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1328 ret); 1328 ret);
@@ -1471,8 +1471,8 @@ static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1471 return NULL; 1471 return NULL;
1472} 1472}
1473 1473
1474static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1474static int iwl_mvm_set_tx_power_old(struct iwl_mvm *mvm,
1475 s8 tx_power) 1475 struct ieee80211_vif *vif, s8 tx_power)
1476{ 1476{
1477 /* FW is in charge of regulatory enforcement */ 1477 /* FW is in charge of regulatory enforcement */
1478 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = { 1478 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
@@ -1485,6 +1485,26 @@ static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1485 &reduce_txpwr_cmd); 1485 &reduce_txpwr_cmd);
1486} 1486}
1487 1487
1488static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1489 s16 tx_power)
1490{
1491 struct iwl_dev_tx_power_cmd cmd = {
1492 .set_mode = 0,
1493 .mac_context_id =
1494 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1495 .pwr_restriction = cpu_to_le16(8 * tx_power),
1496 };
1497
1498 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_TX_POWER_DEV))
1499 return iwl_mvm_set_tx_power_old(mvm, vif, tx_power);
1500
1501 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1502 cmd.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1503
1504 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
1505 sizeof(cmd), &cmd);
1506}
1507
1488static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 1508static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1489 struct ieee80211_vif *vif) 1509 struct ieee80211_vif *vif)
1490{ 1510{
@@ -3975,9 +3995,6 @@ static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
3975 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME)) 3995 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
3976 return; 3996 return;
3977 3997
3978 if (event->u.mlme.status == MLME_SUCCESS)
3979 return;
3980
3981 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME); 3998 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
3982 trig_mlme = (void *)trig->data; 3999 trig_mlme = (void *)trig->data;
3983 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) 4000 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
diff --git a/drivers/net/wireless/iwlwifi/mvm/mvm.h b/drivers/net/wireless/iwlwifi/mvm/mvm.h
index d5522a161242..cf70f681d1ac 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/iwlwifi/mvm/mvm.h
@@ -603,7 +603,6 @@ struct iwl_mvm {
603 603
604 enum iwl_ucode_type cur_ucode; 604 enum iwl_ucode_type cur_ucode;
605 bool ucode_loaded; 605 bool ucode_loaded;
606 bool init_ucode_complete;
607 bool calibrating; 606 bool calibrating;
608 u32 error_event_table; 607 u32 error_event_table;
609 u32 log_event_table; 608 u32 log_event_table;
diff --git a/drivers/net/wireless/iwlwifi/mvm/ops.c b/drivers/net/wireless/iwlwifi/mvm/ops.c
index a08b03d58d4b..2ea01238754e 100644
--- a/drivers/net/wireless/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/iwlwifi/mvm/ops.c
@@ -865,6 +865,16 @@ static void iwl_mvm_fw_error_dump_wk(struct work_struct *work)
865 return; 865 return;
866 866
867 mutex_lock(&mvm->mutex); 867 mutex_lock(&mvm->mutex);
868
869 /* stop recording */
870 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
871 iwl_set_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
872 } else {
873 iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 0);
874 /* wait before we collect the data till the DBGC stop */
875 udelay(100);
876 }
877
868 iwl_mvm_fw_error_dump(mvm); 878 iwl_mvm_fw_error_dump(mvm);
869 879
870 /* start recording again if the firmware is not crashed */ 880 /* start recording again if the firmware is not crashed */
@@ -1253,11 +1263,13 @@ static void iwl_mvm_d0i3_exit_work(struct work_struct *wk)
1253 ieee80211_iterate_active_interfaces( 1263 ieee80211_iterate_active_interfaces(
1254 mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1264 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1255 iwl_mvm_d0i3_disconnect_iter, mvm); 1265 iwl_mvm_d0i3_disconnect_iter, mvm);
1256
1257 iwl_free_resp(&get_status_cmd);
1258out: 1266out:
1259 iwl_mvm_d0i3_enable_tx(mvm, qos_seq); 1267 iwl_mvm_d0i3_enable_tx(mvm, qos_seq);
1260 1268
1269 /* qos_seq might point inside resp_pkt, so free it only now */
1270 if (get_status_cmd.resp_pkt)
1271 iwl_free_resp(&get_status_cmd);
1272
1261 /* the FW might have updated the regdomain */ 1273 /* the FW might have updated the regdomain */
1262 iwl_mvm_update_changed_regdom(mvm); 1274 iwl_mvm_update_changed_regdom(mvm);
1263 1275
diff --git a/drivers/net/wireless/iwlwifi/mvm/rs.c b/drivers/net/wireless/iwlwifi/mvm/rs.c
index f9928f2c125f..33cd68ae7bf9 100644
--- a/drivers/net/wireless/iwlwifi/mvm/rs.c
+++ b/drivers/net/wireless/iwlwifi/mvm/rs.c
@@ -180,6 +180,9 @@ static bool rs_mimo_allow(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
180 if (iwl_mvm_vif_low_latency(mvmvif) && mvmsta->vif->p2p) 180 if (iwl_mvm_vif_low_latency(mvmvif) && mvmsta->vif->p2p)
181 return false; 181 return false;
182 182
183 if (mvm->nvm_data->sku_cap_mimo_disabled)
184 return false;
185
183 return true; 186 return true;
184} 187}
185 188
diff --git a/drivers/net/wireless/iwlwifi/mvm/rx.c b/drivers/net/wireless/iwlwifi/mvm/rx.c
index 78ec7db64ba5..d6314ddf57b5 100644
--- a/drivers/net/wireless/iwlwifi/mvm/rx.c
+++ b/drivers/net/wireless/iwlwifi/mvm/rx.c
@@ -478,6 +478,11 @@ static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
478 if (vif->type != NL80211_IFTYPE_STATION) 478 if (vif->type != NL80211_IFTYPE_STATION)
479 return; 479 return;
480 480
481 if (sig == 0) {
482 IWL_DEBUG_RX(mvm, "RSSI is 0 - skip signal based decision\n");
483 return;
484 }
485
481 mvmvif->bf_data.ave_beacon_signal = sig; 486 mvmvif->bf_data.ave_beacon_signal = sig;
482 487
483 /* BT Coex */ 488 /* BT Coex */
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index 74e1c86289dc..1075a213bd6a 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -319,7 +319,7 @@ int iwl_mvm_rx_scan_offload_iter_complete_notif(struct iwl_mvm *mvm,
319 struct iwl_device_cmd *cmd) 319 struct iwl_device_cmd *cmd)
320{ 320{
321 struct iwl_rx_packet *pkt = rxb_addr(rxb); 321 struct iwl_rx_packet *pkt = rxb_addr(rxb);
322 struct iwl_scan_complete_notif *notif = (void *)pkt->data; 322 struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
323 323
324 IWL_DEBUG_SCAN(mvm, 324 IWL_DEBUG_SCAN(mvm,
325 "Scan offload iteration complete: status=0x%x scanned channels=%d\n", 325 "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index 2de8fbfe4edf..d6f6515fe663 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -5,8 +5,8 @@
5 * 5 *
6 * GPL LICENSE SUMMARY 6 * GPL LICENSE SUMMARY
7 * 7 *
8 * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2007 - 2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as 12 * it under the terms of version 2 of the GNU General Public License as
@@ -31,8 +31,8 @@
31 * 31 *
32 * BSD LICENSE 32 * BSD LICENSE
33 * 33 *
34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 34 * Copyright(c) 2005 - 2015 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved. 36 * All rights reserved.
37 * 37 *
38 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
@@ -104,7 +104,7 @@ static void iwl_pcie_free_fw_monitor(struct iwl_trans *trans)
104static void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans) 104static void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans)
105{ 105{
106 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 106 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
107 struct page *page; 107 struct page *page = NULL;
108 dma_addr_t phys; 108 dma_addr_t phys;
109 u32 size; 109 u32 size;
110 u8 power; 110 u8 power;
@@ -131,6 +131,7 @@ static void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans)
131 DMA_FROM_DEVICE); 131 DMA_FROM_DEVICE);
132 if (dma_mapping_error(trans->dev, phys)) { 132 if (dma_mapping_error(trans->dev, phys)) {
133 __free_pages(page, order); 133 __free_pages(page, order);
134 page = NULL;
134 continue; 135 continue;
135 } 136 }
136 IWL_INFO(trans, 137 IWL_INFO(trans,
@@ -1020,7 +1021,7 @@ static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans, u32 scd_addr)
1020 iwl_pcie_tx_start(trans, scd_addr); 1021 iwl_pcie_tx_start(trans, scd_addr);
1021} 1022}
1022 1023
1023static void iwl_trans_pcie_stop_device(struct iwl_trans *trans) 1024static void iwl_trans_pcie_stop_device(struct iwl_trans *trans, bool low_power)
1024{ 1025{
1025 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 1026 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1026 bool hw_rfkill, was_hw_rfkill; 1027 bool hw_rfkill, was_hw_rfkill;
@@ -1048,9 +1049,11 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
1048 iwl_pcie_rx_stop(trans); 1049 iwl_pcie_rx_stop(trans);
1049 1050
1050 /* Power-down device's busmaster DMA clocks */ 1051 /* Power-down device's busmaster DMA clocks */
1051 iwl_write_prph(trans, APMG_CLK_DIS_REG, 1052 if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
1052 APMG_CLK_VAL_DMA_CLK_RQT); 1053 iwl_write_prph(trans, APMG_CLK_DIS_REG,
1053 udelay(5); 1054 APMG_CLK_VAL_DMA_CLK_RQT);
1055 udelay(5);
1056 }
1054 } 1057 }
1055 1058
1056 /* Make sure (redundant) we've released our request to stay awake */ 1059 /* Make sure (redundant) we've released our request to stay awake */
@@ -1115,7 +1118,7 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
1115void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state) 1118void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state)
1116{ 1119{
1117 if (iwl_op_mode_hw_rf_kill(trans->op_mode, state)) 1120 if (iwl_op_mode_hw_rf_kill(trans->op_mode, state))
1118 iwl_trans_pcie_stop_device(trans); 1121 iwl_trans_pcie_stop_device(trans, true);
1119} 1122}
1120 1123
1121static void iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool test) 1124static void iwl_trans_pcie_d3_suspend(struct iwl_trans *trans, bool test)
@@ -1200,7 +1203,7 @@ static int iwl_trans_pcie_d3_resume(struct iwl_trans *trans,
1200 return 0; 1203 return 0;
1201} 1204}
1202 1205
1203static int iwl_trans_pcie_start_hw(struct iwl_trans *trans) 1206static int iwl_trans_pcie_start_hw(struct iwl_trans *trans, bool low_power)
1204{ 1207{
1205 bool hw_rfkill; 1208 bool hw_rfkill;
1206 int err; 1209 int err;
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index f0188c83c79f..2721cf89fb16 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -126,7 +126,7 @@ static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request,
126 126
127 do { 127 do {
128 status = usb_control_msg(udev, pipe, request, reqtype, value, 128 status = usb_control_msg(udev, pipe, request, reqtype, value,
129 index, pdata, len, 0); /*max. timeout*/ 129 index, pdata, len, 1000);
130 if (status < 0) { 130 if (status < 0) {
131 /* firmware download is checksumed, don't retry */ 131 /* firmware download is checksumed, don't retry */
132 if ((value >= FW_8192C_START_ADDRESS && 132 if ((value >= FW_8192C_START_ADDRESS &&
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index 3d8dbf5f2d39..fee02414529e 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -793,6 +793,7 @@ static void connect(struct backend_info *be)
793 goto err; 793 goto err;
794 } 794 }
795 795
796 queue->credit_bytes = credit_bytes;
796 queue->remaining_credit = credit_bytes; 797 queue->remaining_credit = credit_bytes;
797 queue->credit_usec = credit_usec; 798 queue->credit_usec = credit_usec;
798 799
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 3f45afd4382e..e031c943286e 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1698,6 +1698,7 @@ static void xennet_destroy_queues(struct netfront_info *info)
1698 1698
1699 if (netif_running(info->netdev)) 1699 if (netif_running(info->netdev))
1700 napi_disable(&queue->napi); 1700 napi_disable(&queue->napi);
1701 del_timer_sync(&queue->rx_refill_timer);
1701 netif_napi_del(&queue->napi); 1702 netif_napi_del(&queue->napi);
1702 } 1703 }
1703 1704
@@ -2102,9 +2103,6 @@ static const struct attribute_group xennet_dev_group = {
2102static int xennet_remove(struct xenbus_device *dev) 2103static int xennet_remove(struct xenbus_device *dev)
2103{ 2104{
2104 struct netfront_info *info = dev_get_drvdata(&dev->dev); 2105 struct netfront_info *info = dev_get_drvdata(&dev->dev);
2105 unsigned int num_queues = info->netdev->real_num_tx_queues;
2106 struct netfront_queue *queue = NULL;
2107 unsigned int i = 0;
2108 2106
2109 dev_dbg(&dev->dev, "%s\n", dev->nodename); 2107 dev_dbg(&dev->dev, "%s\n", dev->nodename);
2110 2108
@@ -2112,16 +2110,7 @@ static int xennet_remove(struct xenbus_device *dev)
2112 2110
2113 unregister_netdev(info->netdev); 2111 unregister_netdev(info->netdev);
2114 2112
2115 for (i = 0; i < num_queues; ++i) { 2113 xennet_destroy_queues(info);
2116 queue = &info->queues[i];
2117 del_timer_sync(&queue->rx_refill_timer);
2118 }
2119
2120 if (num_queues) {
2121 kfree(info->queues);
2122 info->queues = NULL;
2123 }
2124
2125 xennet_free_netdev(info->netdev); 2114 xennet_free_netdev(info->netdev);
2126 2115
2127 return 0; 2116 return 0;
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index 8be2096c8423..deeaed544222 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -348,7 +348,7 @@ int superio_fixup_irq(struct pci_dev *pcidev)
348 BUG(); 348 BUG();
349 return -1; 349 return -1;
350 } 350 }
351 printk("superio_fixup_irq(%s) ven 0x%x dev 0x%x from %pf\n", 351 printk(KERN_DEBUG "superio_fixup_irq(%s) ven 0x%x dev 0x%x from %ps\n",
352 pci_name(pcidev), 352 pci_name(pcidev),
353 pcidev->vendor, pcidev->device, 353 pcidev->vendor, pcidev->device,
354 __builtin_return_address(0)); 354 __builtin_return_address(0));
diff --git a/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c b/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c
index 4ad5c1a996e3..e406e3d8c1c7 100644
--- a/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c
+++ b/drivers/pinctrl/bcm/pinctrl-cygnus-gpio.c
@@ -643,7 +643,9 @@ static const struct cygnus_gpio_pin_range cygnus_gpio_pintable[] = {
643 CYGNUS_PINRANGE(87, 104, 12), 643 CYGNUS_PINRANGE(87, 104, 12),
644 CYGNUS_PINRANGE(99, 102, 2), 644 CYGNUS_PINRANGE(99, 102, 2),
645 CYGNUS_PINRANGE(101, 90, 4), 645 CYGNUS_PINRANGE(101, 90, 4),
646 CYGNUS_PINRANGE(105, 116, 10), 646 CYGNUS_PINRANGE(105, 116, 6),
647 CYGNUS_PINRANGE(111, 100, 2),
648 CYGNUS_PINRANGE(113, 122, 4),
647 CYGNUS_PINRANGE(123, 11, 1), 649 CYGNUS_PINRANGE(123, 11, 1),
648 CYGNUS_PINRANGE(124, 38, 4), 650 CYGNUS_PINRANGE(124, 38, 4),
649 CYGNUS_PINRANGE(128, 43, 1), 651 CYGNUS_PINRANGE(128, 43, 1),
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 89dca77ca038..18ee2089df4a 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1110,7 +1110,7 @@ void devm_pinctrl_put(struct pinctrl *p)
1110EXPORT_SYMBOL_GPL(devm_pinctrl_put); 1110EXPORT_SYMBOL_GPL(devm_pinctrl_put);
1111 1111
1112int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, 1112int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
1113 bool dup, bool locked) 1113 bool dup)
1114{ 1114{
1115 int i, ret; 1115 int i, ret;
1116 struct pinctrl_maps *maps_node; 1116 struct pinctrl_maps *maps_node;
@@ -1178,11 +1178,9 @@ int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
1178 maps_node->maps = maps; 1178 maps_node->maps = maps;
1179 } 1179 }
1180 1180
1181 if (!locked) 1181 mutex_lock(&pinctrl_maps_mutex);
1182 mutex_lock(&pinctrl_maps_mutex);
1183 list_add_tail(&maps_node->node, &pinctrl_maps); 1182 list_add_tail(&maps_node->node, &pinctrl_maps);
1184 if (!locked) 1183 mutex_unlock(&pinctrl_maps_mutex);
1185 mutex_unlock(&pinctrl_maps_mutex);
1186 1184
1187 return 0; 1185 return 0;
1188} 1186}
@@ -1197,7 +1195,7 @@ int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
1197int pinctrl_register_mappings(struct pinctrl_map const *maps, 1195int pinctrl_register_mappings(struct pinctrl_map const *maps,
1198 unsigned num_maps) 1196 unsigned num_maps)
1199{ 1197{
1200 return pinctrl_register_map(maps, num_maps, true, false); 1198 return pinctrl_register_map(maps, num_maps, true);
1201} 1199}
1202 1200
1203void pinctrl_unregister_map(struct pinctrl_map const *map) 1201void pinctrl_unregister_map(struct pinctrl_map const *map)
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index 75476b3d87da..b24ea846c867 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -183,7 +183,7 @@ static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
183} 183}
184 184
185int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, 185int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
186 bool dup, bool locked); 186 bool dup);
187void pinctrl_unregister_map(struct pinctrl_map const *map); 187void pinctrl_unregister_map(struct pinctrl_map const *map);
188 188
189extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); 189extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index eda13de2e7c0..0bbf7d71b281 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -92,7 +92,7 @@ static int dt_remember_or_free_map(struct pinctrl *p, const char *statename,
92 dt_map->num_maps = num_maps; 92 dt_map->num_maps = num_maps;
93 list_add_tail(&dt_map->node, &p->dt_maps); 93 list_add_tail(&dt_map->node, &p->dt_maps);
94 94
95 return pinctrl_register_map(map, num_maps, false, true); 95 return pinctrl_register_map(map, num_maps, false);
96} 96}
97 97
98struct pinctrl_dev *of_pinctrl_get(struct device_node *np) 98struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
index 82f691eeeec4..732ff757a95f 100644
--- a/drivers/pinctrl/intel/pinctrl-cherryview.c
+++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
@@ -1292,6 +1292,49 @@ static void chv_gpio_irq_unmask(struct irq_data *d)
1292 chv_gpio_irq_mask_unmask(d, false); 1292 chv_gpio_irq_mask_unmask(d, false);
1293} 1293}
1294 1294
1295static unsigned chv_gpio_irq_startup(struct irq_data *d)
1296{
1297 /*
1298 * Check if the interrupt has been requested with 0 as triggering
1299 * type. In that case it is assumed that the current values
1300 * programmed to the hardware are used (e.g BIOS configured
1301 * defaults).
1302 *
1303 * In that case ->irq_set_type() will never be called so we need to
1304 * read back the values from hardware now, set correct flow handler
1305 * and update mappings before the interrupt is being used.
1306 */
1307 if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) {
1308 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1309 struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc);
1310 unsigned offset = irqd_to_hwirq(d);
1311 int pin = chv_gpio_offset_to_pin(pctrl, offset);
1312 irq_flow_handler_t handler;
1313 unsigned long flags;
1314 u32 intsel, value;
1315
1316 intsel = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1317 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1318 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1319
1320 value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1));
1321 if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL)
1322 handler = handle_level_irq;
1323 else
1324 handler = handle_edge_irq;
1325
1326 spin_lock_irqsave(&pctrl->lock, flags);
1327 if (!pctrl->intr_lines[intsel]) {
1328 __irq_set_handler_locked(d->irq, handler);
1329 pctrl->intr_lines[intsel] = offset;
1330 }
1331 spin_unlock_irqrestore(&pctrl->lock, flags);
1332 }
1333
1334 chv_gpio_irq_unmask(d);
1335 return 0;
1336}
1337
1295static int chv_gpio_irq_type(struct irq_data *d, unsigned type) 1338static int chv_gpio_irq_type(struct irq_data *d, unsigned type)
1296{ 1339{
1297 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1340 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
@@ -1357,6 +1400,7 @@ static int chv_gpio_irq_type(struct irq_data *d, unsigned type)
1357 1400
1358static struct irq_chip chv_gpio_irqchip = { 1401static struct irq_chip chv_gpio_irqchip = {
1359 .name = "chv-gpio", 1402 .name = "chv-gpio",
1403 .irq_startup = chv_gpio_irq_startup,
1360 .irq_ack = chv_gpio_irq_ack, 1404 .irq_ack = chv_gpio_irq_ack,
1361 .irq_mask = chv_gpio_irq_mask, 1405 .irq_mask = chv_gpio_irq_mask,
1362 .irq_unmask = chv_gpio_irq_unmask, 1406 .irq_unmask = chv_gpio_irq_unmask,
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index 493294c0ebe6..474812e2b0cb 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -881,6 +881,8 @@ static int mtk_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
881 if (!mtk_eint_get_mask(pctl, eint_num)) { 881 if (!mtk_eint_get_mask(pctl, eint_num)) {
882 mtk_eint_mask(d); 882 mtk_eint_mask(d);
883 unmask = 1; 883 unmask = 1;
884 } else {
885 unmask = 0;
884 } 886 }
885 887
886 clr_bit = 0xff << eint_offset; 888 clr_bit = 0xff << eint_offset;
diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index edcd140e0899..a70a5fe79d44 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -569,7 +569,7 @@ static int meson_gpiolib_register(struct meson_pinctrl *pc)
569 domain->chip.direction_output = meson_gpio_direction_output; 569 domain->chip.direction_output = meson_gpio_direction_output;
570 domain->chip.get = meson_gpio_get; 570 domain->chip.get = meson_gpio_get;
571 domain->chip.set = meson_gpio_set; 571 domain->chip.set = meson_gpio_set;
572 domain->chip.base = -1; 572 domain->chip.base = domain->data->pin_base;
573 domain->chip.ngpio = domain->data->num_pins; 573 domain->chip.ngpio = domain->data->num_pins;
574 domain->chip.can_sleep = false; 574 domain->chip.can_sleep = false;
575 domain->chip.of_node = domain->of_node; 575 domain->chip.of_node = domain->of_node;
diff --git a/drivers/pinctrl/meson/pinctrl-meson8b.c b/drivers/pinctrl/meson/pinctrl-meson8b.c
index 2f7ea6229880..9677807db364 100644
--- a/drivers/pinctrl/meson/pinctrl-meson8b.c
+++ b/drivers/pinctrl/meson/pinctrl-meson8b.c
@@ -876,13 +876,13 @@ static struct meson_domain_data meson8b_domain_data[] = {
876 .banks = meson8b_banks, 876 .banks = meson8b_banks,
877 .num_banks = ARRAY_SIZE(meson8b_banks), 877 .num_banks = ARRAY_SIZE(meson8b_banks),
878 .pin_base = 0, 878 .pin_base = 0,
879 .num_pins = 83, 879 .num_pins = 130,
880 }, 880 },
881 { 881 {
882 .name = "ao-bank", 882 .name = "ao-bank",
883 .banks = meson8b_ao_banks, 883 .banks = meson8b_ao_banks,
884 .num_banks = ARRAY_SIZE(meson8b_ao_banks), 884 .num_banks = ARRAY_SIZE(meson8b_ao_banks),
885 .pin_base = 83, 885 .pin_base = 130,
886 .num_pins = 16, 886 .num_pins = 16,
887 }, 887 },
888}; 888};
diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-370.c b/drivers/pinctrl/mvebu/pinctrl-armada-370.c
index 42f930f70de3..03aa58c4cb85 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-370.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-370.c
@@ -364,7 +364,7 @@ static struct mvebu_mpp_mode mv88f6710_mpp_modes[] = {
364 MPP_FUNCTION(0x5, "audio", "mclk"), 364 MPP_FUNCTION(0x5, "audio", "mclk"),
365 MPP_FUNCTION(0x6, "uart0", "cts")), 365 MPP_FUNCTION(0x6, "uart0", "cts")),
366 MPP_MODE(63, 366 MPP_MODE(63,
367 MPP_FUNCTION(0x0, "gpo", NULL), 367 MPP_FUNCTION(0x0, "gpio", NULL),
368 MPP_FUNCTION(0x1, "spi0", "sck"), 368 MPP_FUNCTION(0x1, "spi0", "sck"),
369 MPP_FUNCTION(0x2, "tclk", NULL)), 369 MPP_FUNCTION(0x2, "tclk", NULL)),
370 MPP_MODE(64, 370 MPP_MODE(64,
diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
index b2d22218a258..ae4115e4b4ef 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
@@ -260,6 +260,7 @@ static int pmic_gpio_set_mux(struct pinctrl_dev *pctldev, unsigned function,
260 val = 1; 260 val = 1;
261 } 261 }
262 262
263 val = val << PMIC_GPIO_REG_MODE_DIR_SHIFT;
263 val |= pad->function << PMIC_GPIO_REG_MODE_FUNCTION_SHIFT; 264 val |= pad->function << PMIC_GPIO_REG_MODE_FUNCTION_SHIFT;
264 val |= pad->out_value & PMIC_GPIO_REG_MODE_VALUE_SHIFT; 265 val |= pad->out_value & PMIC_GPIO_REG_MODE_VALUE_SHIFT;
265 266
@@ -417,7 +418,7 @@ static int pmic_gpio_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
417 return ret; 418 return ret;
418 419
419 val = pad->buffer_type << PMIC_GPIO_REG_OUT_TYPE_SHIFT; 420 val = pad->buffer_type << PMIC_GPIO_REG_OUT_TYPE_SHIFT;
420 val = pad->strength << PMIC_GPIO_REG_OUT_STRENGTH_SHIFT; 421 val |= pad->strength << PMIC_GPIO_REG_OUT_STRENGTH_SHIFT;
421 422
422 ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_DIG_OUT_CTL, val); 423 ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_DIG_OUT_CTL, val);
423 if (ret < 0) 424 if (ret < 0)
@@ -466,12 +467,13 @@ static void pmic_gpio_config_dbg_show(struct pinctrl_dev *pctldev,
466 seq_puts(s, " ---"); 467 seq_puts(s, " ---");
467 } else { 468 } else {
468 469
469 if (!pad->input_enabled) { 470 if (pad->input_enabled) {
470 ret = pmic_gpio_read(state, pad, PMIC_MPP_REG_RT_STS); 471 ret = pmic_gpio_read(state, pad, PMIC_MPP_REG_RT_STS);
471 if (!ret) { 472 if (ret < 0)
472 ret &= PMIC_MPP_REG_RT_STS_VAL_MASK; 473 return;
473 pad->out_value = ret; 474
474 } 475 ret &= PMIC_MPP_REG_RT_STS_VAL_MASK;
476 pad->out_value = ret;
475 } 477 }
476 478
477 seq_printf(s, " %-4s", pad->output_enabled ? "out" : "in"); 479 seq_printf(s, " %-4s", pad->output_enabled ? "out" : "in");
diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 8f36c5f91949..211b942ad6d5 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -370,6 +370,7 @@ static int pmic_mpp_set_mux(struct pinctrl_dev *pctldev, unsigned function,
370 } 370 }
371 } 371 }
372 372
373 val = val << PMIC_MPP_REG_MODE_DIR_SHIFT;
373 val |= pad->function << PMIC_MPP_REG_MODE_FUNCTION_SHIFT; 374 val |= pad->function << PMIC_MPP_REG_MODE_FUNCTION_SHIFT;
374 val |= pad->out_value & PMIC_MPP_REG_MODE_VALUE_MASK; 375 val |= pad->out_value & PMIC_MPP_REG_MODE_VALUE_MASK;
375 376
@@ -576,10 +577,11 @@ static void pmic_mpp_config_dbg_show(struct pinctrl_dev *pctldev,
576 577
577 if (pad->input_enabled) { 578 if (pad->input_enabled) {
578 ret = pmic_mpp_read(state, pad, PMIC_MPP_REG_RT_STS); 579 ret = pmic_mpp_read(state, pad, PMIC_MPP_REG_RT_STS);
579 if (!ret) { 580 if (ret < 0)
580 ret &= PMIC_MPP_REG_RT_STS_VAL_MASK; 581 return;
581 pad->out_value = ret; 582
582 } 583 ret &= PMIC_MPP_REG_RT_STS_VAL_MASK;
584 pad->out_value = ret;
583 } 585 }
584 586
585 seq_printf(s, " %-4s", pad->output_enabled ? "out" : "in"); 587 seq_printf(s, " %-4s", pad->output_enabled ? "out" : "in");
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index b3d419a84723..b496db87bc05 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -830,6 +830,13 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
830 */ 830 */
831static const struct dmi_system_id no_hw_rfkill_list[] = { 831static const struct dmi_system_id no_hw_rfkill_list[] = {
832 { 832 {
833 .ident = "Lenovo G40-30",
834 .matches = {
835 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
836 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo G40-30"),
837 },
838 },
839 {
833 .ident = "Lenovo Yoga 2 11 / 13 / Pro", 840 .ident = "Lenovo Yoga 2 11 / 13 / Pro",
834 .matches = { 841 .matches = {
835 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 842 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 7769575345d8..28f328136f0d 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2115,7 +2115,7 @@ static int hotkey_mask_get(void)
2115 return 0; 2115 return 0;
2116} 2116}
2117 2117
2118void static hotkey_mask_warn_incomplete_mask(void) 2118static void hotkey_mask_warn_incomplete_mask(void)
2119{ 2119{
2120 /* log only what the user can fix... */ 2120 /* log only what the user can fix... */
2121 const u32 wantedmask = hotkey_driver_mask & 2121 const u32 wantedmask = hotkey_driver_mask &
@@ -2897,7 +2897,7 @@ static ssize_t hotkey_wakeup_reason_show(struct device *dev,
2897 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); 2897 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason);
2898} 2898}
2899 2899
2900static DEVICE_ATTR_RO(hotkey_wakeup_reason); 2900static DEVICE_ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL);
2901 2901
2902static void hotkey_wakeup_reason_notify_change(void) 2902static void hotkey_wakeup_reason_notify_change(void)
2903{ 2903{
@@ -2913,7 +2913,8 @@ static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev,
2913 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); 2913 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack);
2914} 2914}
2915 2915
2916static DEVICE_ATTR_RO(hotkey_wakeup_hotunplug_complete); 2916static DEVICE_ATTR(wakeup_hotunplug_complete, S_IRUGO,
2917 hotkey_wakeup_hotunplug_complete_show, NULL);
2917 2918
2918static void hotkey_wakeup_hotunplug_complete_notify_change(void) 2919static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2919{ 2920{
@@ -2978,8 +2979,8 @@ static struct attribute *hotkey_attributes[] __initdata = {
2978 &dev_attr_hotkey_enable.attr, 2979 &dev_attr_hotkey_enable.attr,
2979 &dev_attr_hotkey_bios_enabled.attr, 2980 &dev_attr_hotkey_bios_enabled.attr,
2980 &dev_attr_hotkey_bios_mask.attr, 2981 &dev_attr_hotkey_bios_mask.attr,
2981 &dev_attr_hotkey_wakeup_reason.attr, 2982 &dev_attr_wakeup_reason.attr,
2982 &dev_attr_hotkey_wakeup_hotunplug_complete.attr, 2983 &dev_attr_wakeup_hotunplug_complete.attr,
2983 &dev_attr_hotkey_mask.attr, 2984 &dev_attr_hotkey_mask.attr,
2984 &dev_attr_hotkey_all_mask.attr, 2985 &dev_attr_hotkey_all_mask.attr,
2985 &dev_attr_hotkey_recommended_mask.attr, 2986 &dev_attr_hotkey_recommended_mask.attr,
@@ -4393,12 +4394,13 @@ static ssize_t wan_enable_store(struct device *dev,
4393 attr, buf, count); 4394 attr, buf, count);
4394} 4395}
4395 4396
4396static DEVICE_ATTR_RW(wan_enable); 4397static DEVICE_ATTR(wwan_enable, S_IWUSR | S_IRUGO,
4398 wan_enable_show, wan_enable_store);
4397 4399
4398/* --------------------------------------------------------------------- */ 4400/* --------------------------------------------------------------------- */
4399 4401
4400static struct attribute *wan_attributes[] = { 4402static struct attribute *wan_attributes[] = {
4401 &dev_attr_wan_enable.attr, 4403 &dev_attr_wwan_enable.attr,
4402 NULL 4404 NULL
4403}; 4405};
4404 4406
@@ -8138,7 +8140,8 @@ static ssize_t fan_pwm1_enable_store(struct device *dev,
8138 return count; 8140 return count;
8139} 8141}
8140 8142
8141static DEVICE_ATTR_RW(fan_pwm1_enable); 8143static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
8144 fan_pwm1_enable_show, fan_pwm1_enable_store);
8142 8145
8143/* sysfs fan pwm1 ------------------------------------------------------ */ 8146/* sysfs fan pwm1 ------------------------------------------------------ */
8144static ssize_t fan_pwm1_show(struct device *dev, 8147static ssize_t fan_pwm1_show(struct device *dev,
@@ -8198,7 +8201,7 @@ static ssize_t fan_pwm1_store(struct device *dev,
8198 return (rc) ? rc : count; 8201 return (rc) ? rc : count;
8199} 8202}
8200 8203
8201static DEVICE_ATTR_RW(fan_pwm1); 8204static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, fan_pwm1_show, fan_pwm1_store);
8202 8205
8203/* sysfs fan fan1_input ------------------------------------------------ */ 8206/* sysfs fan fan1_input ------------------------------------------------ */
8204static ssize_t fan_fan1_input_show(struct device *dev, 8207static ssize_t fan_fan1_input_show(struct device *dev,
@@ -8215,7 +8218,7 @@ static ssize_t fan_fan1_input_show(struct device *dev,
8215 return snprintf(buf, PAGE_SIZE, "%u\n", speed); 8218 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
8216} 8219}
8217 8220
8218static DEVICE_ATTR_RO(fan_fan1_input); 8221static DEVICE_ATTR(fan1_input, S_IRUGO, fan_fan1_input_show, NULL);
8219 8222
8220/* sysfs fan fan2_input ------------------------------------------------ */ 8223/* sysfs fan fan2_input ------------------------------------------------ */
8221static ssize_t fan_fan2_input_show(struct device *dev, 8224static ssize_t fan_fan2_input_show(struct device *dev,
@@ -8232,7 +8235,7 @@ static ssize_t fan_fan2_input_show(struct device *dev,
8232 return snprintf(buf, PAGE_SIZE, "%u\n", speed); 8235 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
8233} 8236}
8234 8237
8235static DEVICE_ATTR_RO(fan_fan2_input); 8238static DEVICE_ATTR(fan2_input, S_IRUGO, fan_fan2_input_show, NULL);
8236 8239
8237/* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ 8240/* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
8238static ssize_t fan_fan_watchdog_show(struct device_driver *drv, 8241static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
@@ -8265,8 +8268,8 @@ static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
8265 8268
8266/* --------------------------------------------------------------------- */ 8269/* --------------------------------------------------------------------- */
8267static struct attribute *fan_attributes[] = { 8270static struct attribute *fan_attributes[] = {
8268 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, 8271 &dev_attr_pwm1_enable.attr, &dev_attr_pwm1.attr,
8269 &dev_attr_fan_fan1_input.attr, 8272 &dev_attr_fan1_input.attr,
8270 NULL, /* for fan2_input */ 8273 NULL, /* for fan2_input */
8271 NULL 8274 NULL
8272}; 8275};
@@ -8400,7 +8403,7 @@ static int __init fan_init(struct ibm_init_struct *iibm)
8400 if (tp_features.second_fan) { 8403 if (tp_features.second_fan) {
8401 /* attach second fan tachometer */ 8404 /* attach second fan tachometer */
8402 fan_attributes[ARRAY_SIZE(fan_attributes)-2] = 8405 fan_attributes[ARRAY_SIZE(fan_attributes)-2] =
8403 &dev_attr_fan_fan2_input.attr; 8406 &dev_attr_fan2_input.attr;
8404 } 8407 }
8405 rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, 8408 rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
8406 &fan_attr_group); 8409 &fan_attr_group);
@@ -8848,7 +8851,7 @@ static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev,
8848 return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME); 8851 return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME);
8849} 8852}
8850 8853
8851static DEVICE_ATTR_RO(thinkpad_acpi_pdev_name); 8854static DEVICE_ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL);
8852 8855
8853/* --------------------------------------------------------------------- */ 8856/* --------------------------------------------------------------------- */
8854 8857
@@ -9390,8 +9393,7 @@ static void thinkpad_acpi_module_exit(void)
9390 hwmon_device_unregister(tpacpi_hwmon); 9393 hwmon_device_unregister(tpacpi_hwmon);
9391 9394
9392 if (tp_features.sensors_pdev_attrs_registered) 9395 if (tp_features.sensors_pdev_attrs_registered)
9393 device_remove_file(&tpacpi_sensors_pdev->dev, 9396 device_remove_file(&tpacpi_sensors_pdev->dev, &dev_attr_name);
9394 &dev_attr_thinkpad_acpi_pdev_name);
9395 if (tpacpi_sensors_pdev) 9397 if (tpacpi_sensors_pdev)
9396 platform_device_unregister(tpacpi_sensors_pdev); 9398 platform_device_unregister(tpacpi_sensors_pdev);
9397 if (tpacpi_pdev) 9399 if (tpacpi_pdev)
@@ -9512,8 +9514,7 @@ static int __init thinkpad_acpi_module_init(void)
9512 thinkpad_acpi_module_exit(); 9514 thinkpad_acpi_module_exit();
9513 return ret; 9515 return ret;
9514 } 9516 }
9515 ret = device_create_file(&tpacpi_sensors_pdev->dev, 9517 ret = device_create_file(&tpacpi_sensors_pdev->dev, &dev_attr_name);
9516 &dev_attr_thinkpad_acpi_pdev_name);
9517 if (ret) { 9518 if (ret) {
9518 pr_err("unable to create sysfs hwmon device attributes\n"); 9519 pr_err("unable to create sysfs hwmon device attributes\n");
9519 thinkpad_acpi_module_exit(); 9520 thinkpad_acpi_module_exit();
diff --git a/drivers/power/axp288_fuel_gauge.c b/drivers/power/axp288_fuel_gauge.c
index ca1cc5a47eb1..bd1dbfee2515 100644
--- a/drivers/power/axp288_fuel_gauge.c
+++ b/drivers/power/axp288_fuel_gauge.c
@@ -1149,6 +1149,7 @@ static struct platform_driver axp288_fuel_gauge_driver = {
1149 1149
1150module_platform_driver(axp288_fuel_gauge_driver); 1150module_platform_driver(axp288_fuel_gauge_driver);
1151 1151
1152MODULE_AUTHOR("Ramakrishna Pallala <ramakrishna.pallala@intel.com>");
1152MODULE_AUTHOR("Todd Brandt <todd.e.brandt@linux.intel.com>"); 1153MODULE_AUTHOR("Todd Brandt <todd.e.brandt@linux.intel.com>");
1153MODULE_DESCRIPTION("Xpower AXP288 Fuel Gauge Driver"); 1154MODULE_DESCRIPTION("Xpower AXP288 Fuel Gauge Driver");
1154MODULE_LICENSE("GPL"); 1155MODULE_LICENSE("GPL");
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index a57433de5c24..b6b98378faa3 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -1109,6 +1109,14 @@ static void __exit bq27x00_battery_exit(void)
1109} 1109}
1110module_exit(bq27x00_battery_exit); 1110module_exit(bq27x00_battery_exit);
1111 1111
1112#ifdef CONFIG_BATTERY_BQ27X00_PLATFORM
1113MODULE_ALIAS("platform:bq27000-battery");
1114#endif
1115
1116#ifdef CONFIG_BATTERY_BQ27X00_I2C
1117MODULE_ALIAS("i2c:bq27000-battery");
1118#endif
1119
1112MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); 1120MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
1113MODULE_DESCRIPTION("BQ27x00 battery monitor driver"); 1121MODULE_DESCRIPTION("BQ27x00 battery monitor driver");
1114MODULE_LICENSE("GPL"); 1122MODULE_LICENSE("GPL");
diff --git a/drivers/power/collie_battery.c b/drivers/power/collie_battery.c
index 2da9ed8ccbb5..8a971b3dbe58 100644
--- a/drivers/power/collie_battery.c
+++ b/drivers/power/collie_battery.c
@@ -347,7 +347,7 @@ static int collie_bat_probe(struct ucb1x00_dev *dev)
347 goto err_psy_reg_main; 347 goto err_psy_reg_main;
348 } 348 }
349 349
350 psy_main_cfg.drv_data = &collie_bat_bu; 350 psy_bu_cfg.drv_data = &collie_bat_bu;
351 collie_bat_bu.psy = power_supply_register(&dev->ucb->dev, 351 collie_bat_bu.psy = power_supply_register(&dev->ucb->dev,
352 &collie_bat_bu_desc, 352 &collie_bat_bu_desc,
353 &psy_bu_cfg); 353 &psy_bu_cfg);
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index aad9c3318c02..17d93a73c513 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -41,6 +41,7 @@ config POWER_RESET_AXXIA
41config POWER_RESET_BRCMSTB 41config POWER_RESET_BRCMSTB
42 bool "Broadcom STB reset driver" 42 bool "Broadcom STB reset driver"
43 depends on ARM || MIPS || COMPILE_TEST 43 depends on ARM || MIPS || COMPILE_TEST
44 depends on MFD_SYSCON
44 default ARCH_BRCMSTB 45 default ARCH_BRCMSTB
45 help 46 help
46 This driver provides restart support for Broadcom STB boards. 47 This driver provides restart support for Broadcom STB boards.
diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
index 01c7055c4200..ca461ebc7ae8 100644
--- a/drivers/power/reset/at91-reset.c
+++ b/drivers/power/reset/at91-reset.c
@@ -212,9 +212,9 @@ static int at91_reset_platform_probe(struct platform_device *pdev)
212 res = platform_get_resource(pdev, IORESOURCE_MEM, idx + 1 ); 212 res = platform_get_resource(pdev, IORESOURCE_MEM, idx + 1 );
213 at91_ramc_base[idx] = devm_ioremap(&pdev->dev, res->start, 213 at91_ramc_base[idx] = devm_ioremap(&pdev->dev, res->start,
214 resource_size(res)); 214 resource_size(res));
215 if (IS_ERR(at91_ramc_base[idx])) { 215 if (!at91_ramc_base[idx]) {
216 dev_err(&pdev->dev, "Could not map ram controller address\n"); 216 dev_err(&pdev->dev, "Could not map ram controller address\n");
217 return PTR_ERR(at91_ramc_base[idx]); 217 return -ENOMEM;
218 } 218 }
219 } 219 }
220 220
diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c
index 7ef193b6f7fe..1e08195551fe 100644
--- a/drivers/power/reset/ltc2952-poweroff.c
+++ b/drivers/power/reset/ltc2952-poweroff.c
@@ -120,18 +120,7 @@ static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer)
120 120
121static void ltc2952_poweroff_start_wde(struct ltc2952_poweroff *data) 121static void ltc2952_poweroff_start_wde(struct ltc2952_poweroff *data)
122{ 122{
123 if (hrtimer_start(&data->timer_wde, data->wde_interval, 123 hrtimer_start(&data->timer_wde, data->wde_interval, HRTIMER_MODE_REL);
124 HRTIMER_MODE_REL)) {
125 /*
126 * The device will not toggle the watchdog reset,
127 * thus shut down is only safe if the PowerPath controller
128 * has a long enough time-off before triggering a hardware
129 * power-off.
130 *
131 * Only sending a warning as the system will power-off anyway
132 */
133 dev_err(data->dev, "unable to start the timer\n");
134 }
135} 124}
136 125
137static enum hrtimer_restart 126static enum hrtimer_restart
@@ -165,9 +154,8 @@ static irqreturn_t ltc2952_poweroff_handler(int irq, void *dev_id)
165 } 154 }
166 155
167 if (gpiod_get_value(data->gpio_trigger)) { 156 if (gpiod_get_value(data->gpio_trigger)) {
168 if (hrtimer_start(&data->timer_trigger, data->trigger_delay, 157 hrtimer_start(&data->timer_trigger, data->trigger_delay,
169 HRTIMER_MODE_REL)) 158 HRTIMER_MODE_REL);
170 dev_err(data->dev, "unable to start the wait timer\n");
171 } else { 159 } else {
172 hrtimer_cancel(&data->timer_trigger); 160 hrtimer_cancel(&data->timer_trigger);
173 /* omitting return value check, timer should have been valid */ 161 /* omitting return value check, timer should have been valid */
diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
index 476171a768d6..8a029f9bc18c 100644
--- a/drivers/pwm/pwm-img.c
+++ b/drivers/pwm/pwm-img.c
@@ -16,6 +16,7 @@
16#include <linux/mfd/syscon.h> 16#include <linux/mfd/syscon.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_device.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/pwm.h> 21#include <linux/pwm.h>
21#include <linux/regmap.h> 22#include <linux/regmap.h>
@@ -38,7 +39,22 @@
38#define PERIP_PWM_PDM_CONTROL_CH_MASK 0x1 39#define PERIP_PWM_PDM_CONTROL_CH_MASK 0x1
39#define PERIP_PWM_PDM_CONTROL_CH_SHIFT(ch) ((ch) * 4) 40#define PERIP_PWM_PDM_CONTROL_CH_SHIFT(ch) ((ch) * 4)
40 41
41#define MAX_TMBASE_STEPS 65536 42/*
43 * PWM period is specified with a timebase register,
44 * in number of step periods. The PWM duty cycle is also
45 * specified in step periods, in the [0, $timebase] range.
46 * In other words, the timebase imposes the duty cycle
47 * resolution. Therefore, let's constraint the timebase to
48 * a minimum value to allow a sane range of duty cycle values.
49 * Imposing a minimum timebase, will impose a maximum PWM frequency.
50 *
51 * The value chosen is completely arbitrary.
52 */
53#define MIN_TMBASE_STEPS 16
54
55struct img_pwm_soc_data {
56 u32 max_timebase;
57};
42 58
43struct img_pwm_chip { 59struct img_pwm_chip {
44 struct device *dev; 60 struct device *dev;
@@ -47,6 +63,9 @@ struct img_pwm_chip {
47 struct clk *sys_clk; 63 struct clk *sys_clk;
48 void __iomem *base; 64 void __iomem *base;
49 struct regmap *periph_regs; 65 struct regmap *periph_regs;
66 int max_period_ns;
67 int min_period_ns;
68 const struct img_pwm_soc_data *data;
50}; 69};
51 70
52static inline struct img_pwm_chip *to_img_pwm_chip(struct pwm_chip *chip) 71static inline struct img_pwm_chip *to_img_pwm_chip(struct pwm_chip *chip)
@@ -72,24 +91,31 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
72 u32 val, div, duty, timebase; 91 u32 val, div, duty, timebase;
73 unsigned long mul, output_clk_hz, input_clk_hz; 92 unsigned long mul, output_clk_hz, input_clk_hz;
74 struct img_pwm_chip *pwm_chip = to_img_pwm_chip(chip); 93 struct img_pwm_chip *pwm_chip = to_img_pwm_chip(chip);
94 unsigned int max_timebase = pwm_chip->data->max_timebase;
95
96 if (period_ns < pwm_chip->min_period_ns ||
97 period_ns > pwm_chip->max_period_ns) {
98 dev_err(chip->dev, "configured period not in range\n");
99 return -ERANGE;
100 }
75 101
76 input_clk_hz = clk_get_rate(pwm_chip->pwm_clk); 102 input_clk_hz = clk_get_rate(pwm_chip->pwm_clk);
77 output_clk_hz = DIV_ROUND_UP(NSEC_PER_SEC, period_ns); 103 output_clk_hz = DIV_ROUND_UP(NSEC_PER_SEC, period_ns);
78 104
79 mul = DIV_ROUND_UP(input_clk_hz, output_clk_hz); 105 mul = DIV_ROUND_UP(input_clk_hz, output_clk_hz);
80 if (mul <= MAX_TMBASE_STEPS) { 106 if (mul <= max_timebase) {
81 div = PWM_CTRL_CFG_NO_SUB_DIV; 107 div = PWM_CTRL_CFG_NO_SUB_DIV;
82 timebase = DIV_ROUND_UP(mul, 1); 108 timebase = DIV_ROUND_UP(mul, 1);
83 } else if (mul <= MAX_TMBASE_STEPS * 8) { 109 } else if (mul <= max_timebase * 8) {
84 div = PWM_CTRL_CFG_SUB_DIV0; 110 div = PWM_CTRL_CFG_SUB_DIV0;
85 timebase = DIV_ROUND_UP(mul, 8); 111 timebase = DIV_ROUND_UP(mul, 8);
86 } else if (mul <= MAX_TMBASE_STEPS * 64) { 112 } else if (mul <= max_timebase * 64) {
87 div = PWM_CTRL_CFG_SUB_DIV1; 113 div = PWM_CTRL_CFG_SUB_DIV1;
88 timebase = DIV_ROUND_UP(mul, 64); 114 timebase = DIV_ROUND_UP(mul, 64);
89 } else if (mul <= MAX_TMBASE_STEPS * 512) { 115 } else if (mul <= max_timebase * 512) {
90 div = PWM_CTRL_CFG_SUB_DIV0_DIV1; 116 div = PWM_CTRL_CFG_SUB_DIV0_DIV1;
91 timebase = DIV_ROUND_UP(mul, 512); 117 timebase = DIV_ROUND_UP(mul, 512);
92 } else if (mul > MAX_TMBASE_STEPS * 512) { 118 } else if (mul > max_timebase * 512) {
93 dev_err(chip->dev, 119 dev_err(chip->dev,
94 "failed to configure timebase steps/divider value\n"); 120 "failed to configure timebase steps/divider value\n");
95 return -EINVAL; 121 return -EINVAL;
@@ -143,11 +169,27 @@ static const struct pwm_ops img_pwm_ops = {
143 .owner = THIS_MODULE, 169 .owner = THIS_MODULE,
144}; 170};
145 171
172static const struct img_pwm_soc_data pistachio_pwm = {
173 .max_timebase = 255,
174};
175
176static const struct of_device_id img_pwm_of_match[] = {
177 {
178 .compatible = "img,pistachio-pwm",
179 .data = &pistachio_pwm,
180 },
181 { }
182};
183MODULE_DEVICE_TABLE(of, img_pwm_of_match);
184
146static int img_pwm_probe(struct platform_device *pdev) 185static int img_pwm_probe(struct platform_device *pdev)
147{ 186{
148 int ret; 187 int ret;
188 u64 val;
189 unsigned long clk_rate;
149 struct resource *res; 190 struct resource *res;
150 struct img_pwm_chip *pwm; 191 struct img_pwm_chip *pwm;
192 const struct of_device_id *of_dev_id;
151 193
152 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 194 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
153 if (!pwm) 195 if (!pwm)
@@ -160,6 +202,11 @@ static int img_pwm_probe(struct platform_device *pdev)
160 if (IS_ERR(pwm->base)) 202 if (IS_ERR(pwm->base))
161 return PTR_ERR(pwm->base); 203 return PTR_ERR(pwm->base);
162 204
205 of_dev_id = of_match_device(img_pwm_of_match, &pdev->dev);
206 if (!of_dev_id)
207 return -ENODEV;
208 pwm->data = of_dev_id->data;
209
163 pwm->periph_regs = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 210 pwm->periph_regs = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
164 "img,cr-periph"); 211 "img,cr-periph");
165 if (IS_ERR(pwm->periph_regs)) 212 if (IS_ERR(pwm->periph_regs))
@@ -189,6 +236,17 @@ static int img_pwm_probe(struct platform_device *pdev)
189 goto disable_sysclk; 236 goto disable_sysclk;
190 } 237 }
191 238
239 clk_rate = clk_get_rate(pwm->pwm_clk);
240
241 /* The maximum input clock divider is 512 */
242 val = (u64)NSEC_PER_SEC * 512 * pwm->data->max_timebase;
243 do_div(val, clk_rate);
244 pwm->max_period_ns = val;
245
246 val = (u64)NSEC_PER_SEC * MIN_TMBASE_STEPS;
247 do_div(val, clk_rate);
248 pwm->min_period_ns = val;
249
192 pwm->chip.dev = &pdev->dev; 250 pwm->chip.dev = &pdev->dev;
193 pwm->chip.ops = &img_pwm_ops; 251 pwm->chip.ops = &img_pwm_ops;
194 pwm->chip.base = -1; 252 pwm->chip.base = -1;
@@ -228,12 +286,6 @@ static int img_pwm_remove(struct platform_device *pdev)
228 return pwmchip_remove(&pwm_chip->chip); 286 return pwmchip_remove(&pwm_chip->chip);
229} 287}
230 288
231static const struct of_device_id img_pwm_of_match[] = {
232 { .compatible = "img,pistachio-pwm", },
233 { }
234};
235MODULE_DEVICE_TABLE(of, img_pwm_of_match);
236
237static struct platform_driver img_pwm_driver = { 289static struct platform_driver img_pwm_driver = {
238 .driver = { 290 .driver = {
239 .name = "img-pwm", 291 .name = "img-pwm",
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index a1d07d347c20..1e492feaa9c6 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -78,11 +78,6 @@ static int arizona_ldo1_hc_set_voltage_sel(struct regulator_dev *rdev,
78 if (ret != 0) 78 if (ret != 0)
79 return ret; 79 return ret;
80 80
81 ret = regmap_update_bits(regmap, ARIZONA_DYNAMIC_FREQUENCY_SCALING_1,
82 ARIZONA_SUBSYS_MAX_FREQ, val);
83 if (ret != 0)
84 return ret;
85
86 if (val) 81 if (val)
87 return 0; 82 return 0;
88 83
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 8a4df7a1f2ee..e628d4c2f2ae 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -394,6 +394,7 @@ static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id,
394 394
395static int da9052_regulator_probe(struct platform_device *pdev) 395static int da9052_regulator_probe(struct platform_device *pdev)
396{ 396{
397 const struct mfd_cell *cell = mfd_get_cell(pdev);
397 struct regulator_config config = { }; 398 struct regulator_config config = { };
398 struct da9052_regulator *regulator; 399 struct da9052_regulator *regulator;
399 struct da9052 *da9052; 400 struct da9052 *da9052;
@@ -409,7 +410,7 @@ static int da9052_regulator_probe(struct platform_device *pdev)
409 regulator->da9052 = da9052; 410 regulator->da9052 = da9052;
410 411
411 regulator->info = find_regulator_info(regulator->da9052->chip_id, 412 regulator->info = find_regulator_info(regulator->da9052->chip_id,
412 pdev->id); 413 cell->id);
413 if (regulator->info == NULL) { 414 if (regulator->info == NULL) {
414 dev_err(&pdev->dev, "invalid regulator ID specified\n"); 415 dev_err(&pdev->dev, "invalid regulator ID specified\n");
415 return -EINVAL; 416 return -EINVAL;
@@ -419,7 +420,7 @@ static int da9052_regulator_probe(struct platform_device *pdev)
419 config.driver_data = regulator; 420 config.driver_data = regulator;
420 config.regmap = da9052->regmap; 421 config.regmap = da9052->regmap;
421 if (pdata && pdata->regulators) { 422 if (pdata && pdata->regulators) {
422 config.init_data = pdata->regulators[pdev->id]; 423 config.init_data = pdata->regulators[cell->id];
423 } else { 424 } else {
424#ifdef CONFIG_OF 425#ifdef CONFIG_OF
425 struct device_node *nproot = da9052->dev->of_node; 426 struct device_node *nproot = da9052->dev->of_node;
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 6149ae01e11f..0fe4ad8826b2 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -164,6 +164,16 @@ config RTC_DRV_ABB5ZES3
164 This driver can also be built as a module. If so, the module 164 This driver can also be built as a module. If so, the module
165 will be called rtc-ab-b5ze-s3. 165 will be called rtc-ab-b5ze-s3.
166 166
167config RTC_DRV_ABX80X
168 tristate "Abracon ABx80x"
169 help
170 If you say yes here you get support for Abracon AB080X and AB180X
171 families of ultra-low-power battery- and capacitor-backed real-time
172 clock chips.
173
174 This driver can also be built as a module. If so, the module
175 will be called rtc-abx80x.
176
167config RTC_DRV_AS3722 177config RTC_DRV_AS3722
168 tristate "ams AS3722 RTC driver" 178 tristate "ams AS3722 RTC driver"
169 depends on MFD_AS3722 179 depends on MFD_AS3722
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c31731c29762..2b82e2b0311b 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o
25obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o 25obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o
26obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o 26obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o
27obj-$(CONFIG_RTC_DRV_ABB5ZES3) += rtc-ab-b5ze-s3.o 27obj-$(CONFIG_RTC_DRV_ABB5ZES3) += rtc-ab-b5ze-s3.o
28obj-$(CONFIG_RTC_DRV_ABX80X) += rtc-abx80x.o
28obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o 29obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o
29obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o 30obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
30obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o 31obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
new file mode 100644
index 000000000000..4337c3bc6ace
--- /dev/null
+++ b/drivers/rtc/rtc-abx80x.c
@@ -0,0 +1,307 @@
1/*
2 * A driver for the I2C members of the Abracon AB x8xx RTC family,
3 * and compatible: AB 1805 and AB 0805
4 *
5 * Copyright 2014-2015 Macq S.A.
6 *
7 * Author: Philippe De Muyter <phdm@macqel.be>
8 * Author: Alexandre Belloni <alexandre.belloni@free-electrons.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/bcd.h>
17#include <linux/i2c.h>
18#include <linux/module.h>
19#include <linux/rtc.h>
20
21#define ABX8XX_REG_HTH 0x00
22#define ABX8XX_REG_SC 0x01
23#define ABX8XX_REG_MN 0x02
24#define ABX8XX_REG_HR 0x03
25#define ABX8XX_REG_DA 0x04
26#define ABX8XX_REG_MO 0x05
27#define ABX8XX_REG_YR 0x06
28#define ABX8XX_REG_WD 0x07
29
30#define ABX8XX_REG_CTRL1 0x10
31#define ABX8XX_CTRL_WRITE BIT(1)
32#define ABX8XX_CTRL_12_24 BIT(6)
33
34#define ABX8XX_REG_CFG_KEY 0x1f
35#define ABX8XX_CFG_KEY_MISC 0x9d
36
37#define ABX8XX_REG_ID0 0x28
38
39#define ABX8XX_REG_TRICKLE 0x20
40#define ABX8XX_TRICKLE_CHARGE_ENABLE 0xa0
41#define ABX8XX_TRICKLE_STANDARD_DIODE 0x8
42#define ABX8XX_TRICKLE_SCHOTTKY_DIODE 0x4
43
44static u8 trickle_resistors[] = {0, 3, 6, 11};
45
46enum abx80x_chip {AB0801, AB0803, AB0804, AB0805,
47 AB1801, AB1803, AB1804, AB1805, ABX80X};
48
49struct abx80x_cap {
50 u16 pn;
51 bool has_tc;
52};
53
54static struct abx80x_cap abx80x_caps[] = {
55 [AB0801] = {.pn = 0x0801},
56 [AB0803] = {.pn = 0x0803},
57 [AB0804] = {.pn = 0x0804, .has_tc = true},
58 [AB0805] = {.pn = 0x0805, .has_tc = true},
59 [AB1801] = {.pn = 0x1801},
60 [AB1803] = {.pn = 0x1803},
61 [AB1804] = {.pn = 0x1804, .has_tc = true},
62 [AB1805] = {.pn = 0x1805, .has_tc = true},
63 [ABX80X] = {.pn = 0}
64};
65
66static struct i2c_driver abx80x_driver;
67
68static int abx80x_enable_trickle_charger(struct i2c_client *client,
69 u8 trickle_cfg)
70{
71 int err;
72
73 /*
74 * Write the configuration key register to enable access to the Trickle
75 * register
76 */
77 err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY,
78 ABX8XX_CFG_KEY_MISC);
79 if (err < 0) {
80 dev_err(&client->dev, "Unable to write configuration key\n");
81 return -EIO;
82 }
83
84 err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE,
85 ABX8XX_TRICKLE_CHARGE_ENABLE |
86 trickle_cfg);
87 if (err < 0) {
88 dev_err(&client->dev, "Unable to write trickle register\n");
89 return -EIO;
90 }
91
92 return 0;
93}
94
95static int abx80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
96{
97 struct i2c_client *client = to_i2c_client(dev);
98 unsigned char buf[8];
99 int err;
100
101 err = i2c_smbus_read_i2c_block_data(client, ABX8XX_REG_HTH,
102 sizeof(buf), buf);
103 if (err < 0) {
104 dev_err(&client->dev, "Unable to read date\n");
105 return -EIO;
106 }
107
108 tm->tm_sec = bcd2bin(buf[ABX8XX_REG_SC] & 0x7F);
109 tm->tm_min = bcd2bin(buf[ABX8XX_REG_MN] & 0x7F);
110 tm->tm_hour = bcd2bin(buf[ABX8XX_REG_HR] & 0x3F);
111 tm->tm_wday = buf[ABX8XX_REG_WD] & 0x7;
112 tm->tm_mday = bcd2bin(buf[ABX8XX_REG_DA] & 0x3F);
113 tm->tm_mon = bcd2bin(buf[ABX8XX_REG_MO] & 0x1F) - 1;
114 tm->tm_year = bcd2bin(buf[ABX8XX_REG_YR]) + 100;
115
116 err = rtc_valid_tm(tm);
117 if (err < 0)
118 dev_err(&client->dev, "retrieved date/time is not valid.\n");
119
120 return err;
121}
122
123static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
124{
125 struct i2c_client *client = to_i2c_client(dev);
126 unsigned char buf[8];
127 int err;
128
129 if (tm->tm_year < 100)
130 return -EINVAL;
131
132 buf[ABX8XX_REG_HTH] = 0;
133 buf[ABX8XX_REG_SC] = bin2bcd(tm->tm_sec);
134 buf[ABX8XX_REG_MN] = bin2bcd(tm->tm_min);
135 buf[ABX8XX_REG_HR] = bin2bcd(tm->tm_hour);
136 buf[ABX8XX_REG_DA] = bin2bcd(tm->tm_mday);
137 buf[ABX8XX_REG_MO] = bin2bcd(tm->tm_mon + 1);
138 buf[ABX8XX_REG_YR] = bin2bcd(tm->tm_year - 100);
139 buf[ABX8XX_REG_WD] = tm->tm_wday;
140
141 err = i2c_smbus_write_i2c_block_data(client, ABX8XX_REG_HTH,
142 sizeof(buf), buf);
143 if (err < 0) {
144 dev_err(&client->dev, "Unable to write to date registers\n");
145 return -EIO;
146 }
147
148 return 0;
149}
150
151static const struct rtc_class_ops abx80x_rtc_ops = {
152 .read_time = abx80x_rtc_read_time,
153 .set_time = abx80x_rtc_set_time,
154};
155
156static int abx80x_dt_trickle_cfg(struct device_node *np)
157{
158 const char *diode;
159 int trickle_cfg = 0;
160 int i, ret;
161 u32 tmp;
162
163 ret = of_property_read_string(np, "abracon,tc-diode", &diode);
164 if (ret)
165 return ret;
166
167 if (!strcmp(diode, "standard"))
168 trickle_cfg |= ABX8XX_TRICKLE_STANDARD_DIODE;
169 else if (!strcmp(diode, "schottky"))
170 trickle_cfg |= ABX8XX_TRICKLE_SCHOTTKY_DIODE;
171 else
172 return -EINVAL;
173
174 ret = of_property_read_u32(np, "abracon,tc-resistor", &tmp);
175 if (ret)
176 return ret;
177
178 for (i = 0; i < sizeof(trickle_resistors); i++)
179 if (trickle_resistors[i] == tmp)
180 break;
181
182 if (i == sizeof(trickle_resistors))
183 return -EINVAL;
184
185 return (trickle_cfg | i);
186}
187
188static int abx80x_probe(struct i2c_client *client,
189 const struct i2c_device_id *id)
190{
191 struct device_node *np = client->dev.of_node;
192 struct rtc_device *rtc;
193 int i, data, err, trickle_cfg = -EINVAL;
194 char buf[7];
195 unsigned int part = id->driver_data;
196 unsigned int partnumber;
197 unsigned int majrev, minrev;
198 unsigned int lot;
199 unsigned int wafer;
200 unsigned int uid;
201
202 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
203 return -ENODEV;
204
205 err = i2c_smbus_read_i2c_block_data(client, ABX8XX_REG_ID0,
206 sizeof(buf), buf);
207 if (err < 0) {
208 dev_err(&client->dev, "Unable to read partnumber\n");
209 return -EIO;
210 }
211
212 partnumber = (buf[0] << 8) | buf[1];
213 majrev = buf[2] >> 3;
214 minrev = buf[2] & 0x7;
215 lot = ((buf[4] & 0x80) << 2) | ((buf[6] & 0x80) << 1) | buf[3];
216 uid = ((buf[4] & 0x7f) << 8) | buf[5];
217 wafer = (buf[6] & 0x7c) >> 2;
218 dev_info(&client->dev, "model %04x, revision %u.%u, lot %x, wafer %x, uid %x\n",
219 partnumber, majrev, minrev, lot, wafer, uid);
220
221 data = i2c_smbus_read_byte_data(client, ABX8XX_REG_CTRL1);
222 if (data < 0) {
223 dev_err(&client->dev, "Unable to read control register\n");
224 return -EIO;
225 }
226
227 err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CTRL1,
228 ((data & ~ABX8XX_CTRL_12_24) |
229 ABX8XX_CTRL_WRITE));
230 if (err < 0) {
231 dev_err(&client->dev, "Unable to write control register\n");
232 return -EIO;
233 }
234
235 /* part autodetection */
236 if (part == ABX80X) {
237 for (i = 0; abx80x_caps[i].pn; i++)
238 if (partnumber == abx80x_caps[i].pn)
239 break;
240 if (abx80x_caps[i].pn == 0) {
241 dev_err(&client->dev, "Unknown part: %04x\n",
242 partnumber);
243 return -EINVAL;
244 }
245 part = i;
246 }
247
248 if (partnumber != abx80x_caps[part].pn) {
249 dev_err(&client->dev, "partnumber mismatch %04x != %04x\n",
250 partnumber, abx80x_caps[part].pn);
251 return -EINVAL;
252 }
253
254 if (np && abx80x_caps[part].has_tc)
255 trickle_cfg = abx80x_dt_trickle_cfg(np);
256
257 if (trickle_cfg > 0) {
258 dev_info(&client->dev, "Enabling trickle charger: %02x\n",
259 trickle_cfg);
260 abx80x_enable_trickle_charger(client, trickle_cfg);
261 }
262
263 rtc = devm_rtc_device_register(&client->dev, abx80x_driver.driver.name,
264 &abx80x_rtc_ops, THIS_MODULE);
265
266 if (IS_ERR(rtc))
267 return PTR_ERR(rtc);
268
269 i2c_set_clientdata(client, rtc);
270
271 return 0;
272}
273
274static int abx80x_remove(struct i2c_client *client)
275{
276 return 0;
277}
278
279static const struct i2c_device_id abx80x_id[] = {
280 { "abx80x", ABX80X },
281 { "ab0801", AB0801 },
282 { "ab0803", AB0803 },
283 { "ab0804", AB0804 },
284 { "ab0805", AB0805 },
285 { "ab1801", AB1801 },
286 { "ab1803", AB1803 },
287 { "ab1804", AB1804 },
288 { "ab1805", AB1805 },
289 { }
290};
291MODULE_DEVICE_TABLE(i2c, abx80x_id);
292
293static struct i2c_driver abx80x_driver = {
294 .driver = {
295 .name = "rtc-abx80x",
296 },
297 .probe = abx80x_probe,
298 .remove = abx80x_remove,
299 .id_table = abx80x_id,
300};
301
302module_i2c_driver(abx80x_driver);
303
304MODULE_AUTHOR("Philippe De Muyter <phdm@macqel.be>");
305MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@free-electrons.com>");
306MODULE_DESCRIPTION("Abracon ABX80X RTC driver");
307MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
index 43e04af39e09..4b62d1a875e4 100644
--- a/drivers/rtc/rtc-armada38x.c
+++ b/drivers/rtc/rtc-armada38x.c
@@ -40,6 +40,13 @@ struct armada38x_rtc {
40 void __iomem *regs; 40 void __iomem *regs;
41 void __iomem *regs_soc; 41 void __iomem *regs_soc;
42 spinlock_t lock; 42 spinlock_t lock;
43 /*
44 * While setting the time, the RTC TIME register should not be
45 * accessed. Setting the RTC time involves sleeping during
46 * 100ms, so a mutex instead of a spinlock is used to protect
47 * it
48 */
49 struct mutex mutex_time;
43 int irq; 50 int irq;
44}; 51};
45 52
@@ -57,10 +64,9 @@ static void rtc_delayed_write(u32 val, struct armada38x_rtc *rtc, int offset)
57static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm) 64static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
58{ 65{
59 struct armada38x_rtc *rtc = dev_get_drvdata(dev); 66 struct armada38x_rtc *rtc = dev_get_drvdata(dev);
60 unsigned long time, time_check, flags; 67 unsigned long time, time_check;
61
62 spin_lock_irqsave(&rtc->lock, flags);
63 68
69 mutex_lock(&rtc->mutex_time);
64 time = readl(rtc->regs + RTC_TIME); 70 time = readl(rtc->regs + RTC_TIME);
65 /* 71 /*
66 * WA for failing time set attempts. As stated in HW ERRATA if 72 * WA for failing time set attempts. As stated in HW ERRATA if
@@ -71,7 +77,7 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
71 if ((time_check - time) > 1) 77 if ((time_check - time) > 1)
72 time_check = readl(rtc->regs + RTC_TIME); 78 time_check = readl(rtc->regs + RTC_TIME);
73 79
74 spin_unlock_irqrestore(&rtc->lock, flags); 80 mutex_unlock(&rtc->mutex_time);
75 81
76 rtc_time_to_tm(time_check, tm); 82 rtc_time_to_tm(time_check, tm);
77 83
@@ -94,19 +100,12 @@ static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
94 * then wait for 100ms before writing to the time register to be 100 * then wait for 100ms before writing to the time register to be
95 * sure that the data will be taken into account. 101 * sure that the data will be taken into account.
96 */ 102 */
97 spin_lock_irqsave(&rtc->lock, flags); 103 mutex_lock(&rtc->mutex_time);
98
99 rtc_delayed_write(0, rtc, RTC_STATUS); 104 rtc_delayed_write(0, rtc, RTC_STATUS);
100
101 spin_unlock_irqrestore(&rtc->lock, flags);
102
103 msleep(100); 105 msleep(100);
104
105 spin_lock_irqsave(&rtc->lock, flags);
106
107 rtc_delayed_write(time, rtc, RTC_TIME); 106 rtc_delayed_write(time, rtc, RTC_TIME);
107 mutex_unlock(&rtc->mutex_time);
108 108
109 spin_unlock_irqrestore(&rtc->lock, flags);
110out: 109out:
111 return ret; 110 return ret;
112} 111}
@@ -230,6 +229,7 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
230 return -ENOMEM; 229 return -ENOMEM;
231 230
232 spin_lock_init(&rtc->lock); 231 spin_lock_init(&rtc->lock);
232 mutex_init(&rtc->mutex_time);
233 233
234 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc"); 234 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc");
235 rtc->regs = devm_ioremap_resource(&pdev->dev, res); 235 rtc->regs = devm_ioremap_resource(&pdev->dev, res);
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index c43aca69fb30..0fc3fe5fd5b8 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -667,6 +667,8 @@ static struct raw3215_info *raw3215_alloc_info(void)
667 info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); 667 info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
668 info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA); 668 info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA);
669 if (!info->buffer || !info->inbuf) { 669 if (!info->buffer || !info->inbuf) {
670 kfree(info->inbuf);
671 kfree(info->buffer);
670 kfree(info); 672 kfree(info);
671 return NULL; 673 return NULL;
672 } 674 }
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index f0b9871a4bbd..3ba611419759 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -1158,11 +1158,12 @@ static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
1158 poll_timeout = time; 1158 poll_timeout = time;
1159 hr_time = ktime_set(0, poll_timeout); 1159 hr_time = ktime_set(0, poll_timeout);
1160 1160
1161 if (!hrtimer_is_queued(&ap_poll_timer) || 1161 spin_lock_bh(&ap_poll_timer_lock);
1162 !hrtimer_forward(&ap_poll_timer, hrtimer_get_expires(&ap_poll_timer), hr_time)) { 1162 hrtimer_cancel(&ap_poll_timer);
1163 hrtimer_set_expires(&ap_poll_timer, hr_time); 1163 hrtimer_set_expires(&ap_poll_timer, hr_time);
1164 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS); 1164 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
1165 } 1165 spin_unlock_bh(&ap_poll_timer_lock);
1166
1166 return count; 1167 return count;
1167} 1168}
1168 1169
@@ -1528,14 +1529,11 @@ static inline void __ap_schedule_poll_timer(void)
1528 ktime_t hr_time; 1529 ktime_t hr_time;
1529 1530
1530 spin_lock_bh(&ap_poll_timer_lock); 1531 spin_lock_bh(&ap_poll_timer_lock);
1531 if (hrtimer_is_queued(&ap_poll_timer) || ap_suspend_flag) 1532 if (!hrtimer_is_queued(&ap_poll_timer) && !ap_suspend_flag) {
1532 goto out;
1533 if (ktime_to_ns(hrtimer_expires_remaining(&ap_poll_timer)) <= 0) {
1534 hr_time = ktime_set(0, poll_timeout); 1533 hr_time = ktime_set(0, poll_timeout);
1535 hrtimer_forward_now(&ap_poll_timer, hr_time); 1534 hrtimer_forward_now(&ap_poll_timer, hr_time);
1536 hrtimer_restart(&ap_poll_timer); 1535 hrtimer_restart(&ap_poll_timer);
1537 } 1536 }
1538out:
1539 spin_unlock_bh(&ap_poll_timer_lock); 1537 spin_unlock_bh(&ap_poll_timer_lock);
1540} 1538}
1541 1539
@@ -1952,7 +1950,7 @@ static void ap_reset_domain(void)
1952{ 1950{
1953 int i; 1951 int i;
1954 1952
1955 if (ap_domain_index != -1) 1953 if ((ap_domain_index != -1) && (ap_test_config_domain(ap_domain_index)))
1956 for (i = 0; i < AP_DEVICES; i++) 1954 for (i = 0; i < AP_DEVICES; i++)
1957 ap_reset_queue(AP_MKQID(i, ap_domain_index)); 1955 ap_reset_queue(AP_MKQID(i, ap_domain_index));
1958} 1956}
@@ -2097,7 +2095,6 @@ void ap_module_exit(void)
2097 hrtimer_cancel(&ap_poll_timer); 2095 hrtimer_cancel(&ap_poll_timer);
2098 destroy_workqueue(ap_work_queue); 2096 destroy_workqueue(ap_work_queue);
2099 tasklet_kill(&ap_tasklet); 2097 tasklet_kill(&ap_tasklet);
2100 root_device_unregister(ap_root_device);
2101 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL, 2098 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
2102 __ap_match_all))) 2099 __ap_match_all)))
2103 { 2100 {
@@ -2106,6 +2103,7 @@ void ap_module_exit(void)
2106 } 2103 }
2107 for (i = 0; ap_bus_attrs[i]; i++) 2104 for (i = 0; ap_bus_attrs[i]; i++)
2108 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); 2105 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
2106 root_device_unregister(ap_root_device);
2109 bus_unregister(&ap_bus_type); 2107 bus_unregister(&ap_bus_type);
2110 unregister_reset_call(&ap_reset_call); 2108 unregister_reset_call(&ap_reset_call);
2111 if (ap_using_interrupts()) 2109 if (ap_using_interrupts())
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 7600639db4c4..add419d6ff34 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -149,7 +149,6 @@ static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset);
149static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry *sglistarg); 149static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry *sglistarg);
150static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id); 150static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id);
151static char *twa_string_lookup(twa_message_type *table, unsigned int aen_code); 151static char *twa_string_lookup(twa_message_type *table, unsigned int aen_code);
152static void twa_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id);
153 152
154/* Functions */ 153/* Functions */
155 154
@@ -1340,11 +1339,11 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance)
1340 } 1339 }
1341 1340
1342 /* Now complete the io */ 1341 /* Now complete the io */
1342 scsi_dma_unmap(cmd);
1343 cmd->scsi_done(cmd);
1343 tw_dev->state[request_id] = TW_S_COMPLETED; 1344 tw_dev->state[request_id] = TW_S_COMPLETED;
1344 twa_free_request_id(tw_dev, request_id); 1345 twa_free_request_id(tw_dev, request_id);
1345 tw_dev->posted_request_count--; 1346 tw_dev->posted_request_count--;
1346 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
1347 twa_unmap_scsi_data(tw_dev, request_id);
1348 } 1347 }
1349 1348
1350 /* Check for valid status after each drain */ 1349 /* Check for valid status after each drain */
@@ -1402,26 +1401,6 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm
1402 } 1401 }
1403} /* End twa_load_sgl() */ 1402} /* End twa_load_sgl() */
1404 1403
1405/* This function will perform a pci-dma mapping for a scatter gather list */
1406static int twa_map_scsi_sg_data(TW_Device_Extension *tw_dev, int request_id)
1407{
1408 int use_sg;
1409 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1410
1411 use_sg = scsi_dma_map(cmd);
1412 if (!use_sg)
1413 return 0;
1414 else if (use_sg < 0) {
1415 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1c, "Failed to map scatter gather list");
1416 return 0;
1417 }
1418
1419 cmd->SCp.phase = TW_PHASE_SGLIST;
1420 cmd->SCp.have_data_in = use_sg;
1421
1422 return use_sg;
1423} /* End twa_map_scsi_sg_data() */
1424
1425/* This function will poll for a response interrupt of a request */ 1404/* This function will poll for a response interrupt of a request */
1426static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds) 1405static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds)
1427{ 1406{
@@ -1600,9 +1579,11 @@ static int twa_reset_device_extension(TW_Device_Extension *tw_dev)
1600 (tw_dev->state[i] != TW_S_INITIAL) && 1579 (tw_dev->state[i] != TW_S_INITIAL) &&
1601 (tw_dev->state[i] != TW_S_COMPLETED)) { 1580 (tw_dev->state[i] != TW_S_COMPLETED)) {
1602 if (tw_dev->srb[i]) { 1581 if (tw_dev->srb[i]) {
1603 tw_dev->srb[i]->result = (DID_RESET << 16); 1582 struct scsi_cmnd *cmd = tw_dev->srb[i];
1604 tw_dev->srb[i]->scsi_done(tw_dev->srb[i]); 1583
1605 twa_unmap_scsi_data(tw_dev, i); 1584 cmd->result = (DID_RESET << 16);
1585 scsi_dma_unmap(cmd);
1586 cmd->scsi_done(cmd);
1606 } 1587 }
1607 } 1588 }
1608 } 1589 }
@@ -1781,21 +1762,18 @@ static int twa_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_
1781 /* Save the scsi command for use by the ISR */ 1762 /* Save the scsi command for use by the ISR */
1782 tw_dev->srb[request_id] = SCpnt; 1763 tw_dev->srb[request_id] = SCpnt;
1783 1764
1784 /* Initialize phase to zero */
1785 SCpnt->SCp.phase = TW_PHASE_INITIAL;
1786
1787 retval = twa_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL); 1765 retval = twa_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL);
1788 switch (retval) { 1766 switch (retval) {
1789 case SCSI_MLQUEUE_HOST_BUSY: 1767 case SCSI_MLQUEUE_HOST_BUSY:
1768 scsi_dma_unmap(SCpnt);
1790 twa_free_request_id(tw_dev, request_id); 1769 twa_free_request_id(tw_dev, request_id);
1791 twa_unmap_scsi_data(tw_dev, request_id);
1792 break; 1770 break;
1793 case 1: 1771 case 1:
1794 tw_dev->state[request_id] = TW_S_COMPLETED;
1795 twa_free_request_id(tw_dev, request_id);
1796 twa_unmap_scsi_data(tw_dev, request_id);
1797 SCpnt->result = (DID_ERROR << 16); 1772 SCpnt->result = (DID_ERROR << 16);
1773 scsi_dma_unmap(SCpnt);
1798 done(SCpnt); 1774 done(SCpnt);
1775 tw_dev->state[request_id] = TW_S_COMPLETED;
1776 twa_free_request_id(tw_dev, request_id);
1799 retval = 0; 1777 retval = 0;
1800 } 1778 }
1801out: 1779out:
@@ -1863,8 +1841,8 @@ static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
1863 command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); 1841 command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
1864 command_packet->sg_list[0].length = cpu_to_le32(TW_MIN_SGL_LENGTH); 1842 command_packet->sg_list[0].length = cpu_to_le32(TW_MIN_SGL_LENGTH);
1865 } else { 1843 } else {
1866 sg_count = twa_map_scsi_sg_data(tw_dev, request_id); 1844 sg_count = scsi_dma_map(srb);
1867 if (sg_count == 0) 1845 if (sg_count < 0)
1868 goto out; 1846 goto out;
1869 1847
1870 scsi_for_each_sg(srb, sg, sg_count, i) { 1848 scsi_for_each_sg(srb, sg, sg_count, i) {
@@ -1979,15 +1957,6 @@ static char *twa_string_lookup(twa_message_type *table, unsigned int code)
1979 return(table[index].text); 1957 return(table[index].text);
1980} /* End twa_string_lookup() */ 1958} /* End twa_string_lookup() */
1981 1959
1982/* This function will perform a pci-dma unmap */
1983static void twa_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id)
1984{
1985 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1986
1987 if (cmd->SCp.phase == TW_PHASE_SGLIST)
1988 scsi_dma_unmap(cmd);
1989} /* End twa_unmap_scsi_data() */
1990
1991/* This function gets called when a disk is coming on-line */ 1960/* This function gets called when a disk is coming on-line */
1992static int twa_slave_configure(struct scsi_device *sdev) 1961static int twa_slave_configure(struct scsi_device *sdev)
1993{ 1962{
diff --git a/drivers/scsi/3w-9xxx.h b/drivers/scsi/3w-9xxx.h
index 040f7214e5b7..0fdc83cfa0e1 100644
--- a/drivers/scsi/3w-9xxx.h
+++ b/drivers/scsi/3w-9xxx.h
@@ -324,11 +324,6 @@ static twa_message_type twa_error_table[] = {
324#define TW_CURRENT_DRIVER_BUILD 0 324#define TW_CURRENT_DRIVER_BUILD 0
325#define TW_CURRENT_DRIVER_BRANCH 0 325#define TW_CURRENT_DRIVER_BRANCH 0
326 326
327/* Phase defines */
328#define TW_PHASE_INITIAL 0
329#define TW_PHASE_SINGLE 1
330#define TW_PHASE_SGLIST 2
331
332/* Misc defines */ 327/* Misc defines */
333#define TW_9550SX_DRAIN_COMPLETED 0xFFFF 328#define TW_9550SX_DRAIN_COMPLETED 0xFFFF
334#define TW_SECTOR_SIZE 512 329#define TW_SECTOR_SIZE 512
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 2361772d5909..f8374850f714 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -290,26 +290,6 @@ static int twl_post_command_packet(TW_Device_Extension *tw_dev, int request_id)
290 return 0; 290 return 0;
291} /* End twl_post_command_packet() */ 291} /* End twl_post_command_packet() */
292 292
293/* This function will perform a pci-dma mapping for a scatter gather list */
294static int twl_map_scsi_sg_data(TW_Device_Extension *tw_dev, int request_id)
295{
296 int use_sg;
297 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
298
299 use_sg = scsi_dma_map(cmd);
300 if (!use_sg)
301 return 0;
302 else if (use_sg < 0) {
303 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Failed to map scatter gather list");
304 return 0;
305 }
306
307 cmd->SCp.phase = TW_PHASE_SGLIST;
308 cmd->SCp.have_data_in = use_sg;
309
310 return use_sg;
311} /* End twl_map_scsi_sg_data() */
312
313/* This function hands scsi cdb's to the firmware */ 293/* This function hands scsi cdb's to the firmware */
314static int twl_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry_ISO *sglistarg) 294static int twl_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry_ISO *sglistarg)
315{ 295{
@@ -357,8 +337,8 @@ static int twl_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
357 if (!sglistarg) { 337 if (!sglistarg) {
358 /* Map sglist from scsi layer to cmd packet */ 338 /* Map sglist from scsi layer to cmd packet */
359 if (scsi_sg_count(srb)) { 339 if (scsi_sg_count(srb)) {
360 sg_count = twl_map_scsi_sg_data(tw_dev, request_id); 340 sg_count = scsi_dma_map(srb);
361 if (sg_count == 0) 341 if (sg_count <= 0)
362 goto out; 342 goto out;
363 343
364 scsi_for_each_sg(srb, sg, sg_count, i) { 344 scsi_for_each_sg(srb, sg, sg_count, i) {
@@ -1102,15 +1082,6 @@ out:
1102 return retval; 1082 return retval;
1103} /* End twl_initialize_device_extension() */ 1083} /* End twl_initialize_device_extension() */
1104 1084
1105/* This function will perform a pci-dma unmap */
1106static void twl_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id)
1107{
1108 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1109
1110 if (cmd->SCp.phase == TW_PHASE_SGLIST)
1111 scsi_dma_unmap(cmd);
1112} /* End twl_unmap_scsi_data() */
1113
1114/* This function will handle attention interrupts */ 1085/* This function will handle attention interrupts */
1115static int twl_handle_attention_interrupt(TW_Device_Extension *tw_dev) 1086static int twl_handle_attention_interrupt(TW_Device_Extension *tw_dev)
1116{ 1087{
@@ -1251,11 +1222,11 @@ static irqreturn_t twl_interrupt(int irq, void *dev_instance)
1251 } 1222 }
1252 1223
1253 /* Now complete the io */ 1224 /* Now complete the io */
1225 scsi_dma_unmap(cmd);
1226 cmd->scsi_done(cmd);
1254 tw_dev->state[request_id] = TW_S_COMPLETED; 1227 tw_dev->state[request_id] = TW_S_COMPLETED;
1255 twl_free_request_id(tw_dev, request_id); 1228 twl_free_request_id(tw_dev, request_id);
1256 tw_dev->posted_request_count--; 1229 tw_dev->posted_request_count--;
1257 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
1258 twl_unmap_scsi_data(tw_dev, request_id);
1259 } 1230 }
1260 1231
1261 /* Check for another response interrupt */ 1232 /* Check for another response interrupt */
@@ -1400,10 +1371,12 @@ static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_res
1400 if ((tw_dev->state[i] != TW_S_FINISHED) && 1371 if ((tw_dev->state[i] != TW_S_FINISHED) &&
1401 (tw_dev->state[i] != TW_S_INITIAL) && 1372 (tw_dev->state[i] != TW_S_INITIAL) &&
1402 (tw_dev->state[i] != TW_S_COMPLETED)) { 1373 (tw_dev->state[i] != TW_S_COMPLETED)) {
1403 if (tw_dev->srb[i]) { 1374 struct scsi_cmnd *cmd = tw_dev->srb[i];
1404 tw_dev->srb[i]->result = (DID_RESET << 16); 1375
1405 tw_dev->srb[i]->scsi_done(tw_dev->srb[i]); 1376 if (cmd) {
1406 twl_unmap_scsi_data(tw_dev, i); 1377 cmd->result = (DID_RESET << 16);
1378 scsi_dma_unmap(cmd);
1379 cmd->scsi_done(cmd);
1407 } 1380 }
1408 } 1381 }
1409 } 1382 }
@@ -1507,9 +1480,6 @@ static int twl_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_
1507 /* Save the scsi command for use by the ISR */ 1480 /* Save the scsi command for use by the ISR */
1508 tw_dev->srb[request_id] = SCpnt; 1481 tw_dev->srb[request_id] = SCpnt;
1509 1482
1510 /* Initialize phase to zero */
1511 SCpnt->SCp.phase = TW_PHASE_INITIAL;
1512
1513 retval = twl_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL); 1483 retval = twl_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL);
1514 if (retval) { 1484 if (retval) {
1515 tw_dev->state[request_id] = TW_S_COMPLETED; 1485 tw_dev->state[request_id] = TW_S_COMPLETED;
diff --git a/drivers/scsi/3w-sas.h b/drivers/scsi/3w-sas.h
index d474892701d4..fec6449c7595 100644
--- a/drivers/scsi/3w-sas.h
+++ b/drivers/scsi/3w-sas.h
@@ -103,10 +103,6 @@ static char *twl_aen_severity_table[] =
103#define TW_CURRENT_DRIVER_BUILD 0 103#define TW_CURRENT_DRIVER_BUILD 0
104#define TW_CURRENT_DRIVER_BRANCH 0 104#define TW_CURRENT_DRIVER_BRANCH 0
105 105
106/* Phase defines */
107#define TW_PHASE_INITIAL 0
108#define TW_PHASE_SGLIST 2
109
110/* Misc defines */ 106/* Misc defines */
111#define TW_SECTOR_SIZE 512 107#define TW_SECTOR_SIZE 512
112#define TW_MAX_UNITS 32 108#define TW_MAX_UNITS 32
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index c75f2048319f..2940bd769936 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1271,32 +1271,6 @@ static int tw_initialize_device_extension(TW_Device_Extension *tw_dev)
1271 return 0; 1271 return 0;
1272} /* End tw_initialize_device_extension() */ 1272} /* End tw_initialize_device_extension() */
1273 1273
1274static int tw_map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
1275{
1276 int use_sg;
1277
1278 dprintk(KERN_WARNING "3w-xxxx: tw_map_scsi_sg_data()\n");
1279
1280 use_sg = scsi_dma_map(cmd);
1281 if (use_sg < 0) {
1282 printk(KERN_WARNING "3w-xxxx: tw_map_scsi_sg_data(): pci_map_sg() failed.\n");
1283 return 0;
1284 }
1285
1286 cmd->SCp.phase = TW_PHASE_SGLIST;
1287 cmd->SCp.have_data_in = use_sg;
1288
1289 return use_sg;
1290} /* End tw_map_scsi_sg_data() */
1291
1292static void tw_unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
1293{
1294 dprintk(KERN_WARNING "3w-xxxx: tw_unmap_scsi_data()\n");
1295
1296 if (cmd->SCp.phase == TW_PHASE_SGLIST)
1297 scsi_dma_unmap(cmd);
1298} /* End tw_unmap_scsi_data() */
1299
1300/* This function will reset a device extension */ 1274/* This function will reset a device extension */
1301static int tw_reset_device_extension(TW_Device_Extension *tw_dev) 1275static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
1302{ 1276{
@@ -1319,8 +1293,8 @@ static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
1319 srb = tw_dev->srb[i]; 1293 srb = tw_dev->srb[i];
1320 if (srb != NULL) { 1294 if (srb != NULL) {
1321 srb->result = (DID_RESET << 16); 1295 srb->result = (DID_RESET << 16);
1322 tw_dev->srb[i]->scsi_done(tw_dev->srb[i]); 1296 scsi_dma_unmap(srb);
1323 tw_unmap_scsi_data(tw_dev->tw_pci_dev, tw_dev->srb[i]); 1297 srb->scsi_done(srb);
1324 } 1298 }
1325 } 1299 }
1326 } 1300 }
@@ -1767,8 +1741,8 @@ static int tw_scsiop_read_write(TW_Device_Extension *tw_dev, int request_id)
1767 command_packet->byte8.io.lba = lba; 1741 command_packet->byte8.io.lba = lba;
1768 command_packet->byte6.block_count = num_sectors; 1742 command_packet->byte6.block_count = num_sectors;
1769 1743
1770 use_sg = tw_map_scsi_sg_data(tw_dev->tw_pci_dev, tw_dev->srb[request_id]); 1744 use_sg = scsi_dma_map(srb);
1771 if (!use_sg) 1745 if (use_sg <= 0)
1772 return 1; 1746 return 1;
1773 1747
1774 scsi_for_each_sg(tw_dev->srb[request_id], sg, use_sg, i) { 1748 scsi_for_each_sg(tw_dev->srb[request_id], sg, use_sg, i) {
@@ -1955,9 +1929,6 @@ static int tw_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_c
1955 /* Save the scsi command for use by the ISR */ 1929 /* Save the scsi command for use by the ISR */
1956 tw_dev->srb[request_id] = SCpnt; 1930 tw_dev->srb[request_id] = SCpnt;
1957 1931
1958 /* Initialize phase to zero */
1959 SCpnt->SCp.phase = TW_PHASE_INITIAL;
1960
1961 switch (*command) { 1932 switch (*command) {
1962 case READ_10: 1933 case READ_10:
1963 case READ_6: 1934 case READ_6:
@@ -2185,12 +2156,11 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance)
2185 2156
2186 /* Now complete the io */ 2157 /* Now complete the io */
2187 if ((error != TW_ISR_DONT_COMPLETE)) { 2158 if ((error != TW_ISR_DONT_COMPLETE)) {
2159 scsi_dma_unmap(tw_dev->srb[request_id]);
2160 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
2188 tw_dev->state[request_id] = TW_S_COMPLETED; 2161 tw_dev->state[request_id] = TW_S_COMPLETED;
2189 tw_state_request_finish(tw_dev, request_id); 2162 tw_state_request_finish(tw_dev, request_id);
2190 tw_dev->posted_request_count--; 2163 tw_dev->posted_request_count--;
2191 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
2192
2193 tw_unmap_scsi_data(tw_dev->tw_pci_dev, tw_dev->srb[request_id]);
2194 } 2164 }
2195 } 2165 }
2196 2166
diff --git a/drivers/scsi/3w-xxxx.h b/drivers/scsi/3w-xxxx.h
index 29b0b84ed69e..6f65e663d393 100644
--- a/drivers/scsi/3w-xxxx.h
+++ b/drivers/scsi/3w-xxxx.h
@@ -195,11 +195,6 @@ static unsigned char tw_sense_table[][4] =
195#define TW_AEN_SMART_FAIL 0x000F 195#define TW_AEN_SMART_FAIL 0x000F
196#define TW_AEN_SBUF_FAIL 0x0024 196#define TW_AEN_SBUF_FAIL 0x0024
197 197
198/* Phase defines */
199#define TW_PHASE_INITIAL 0
200#define TW_PHASE_SINGLE 1
201#define TW_PHASE_SGLIST 2
202
203/* Misc defines */ 198/* Misc defines */
204#define TW_ALIGNMENT_6000 64 /* 64 bytes */ 199#define TW_ALIGNMENT_6000 64 /* 64 bytes */
205#define TW_ALIGNMENT_7000 4 /* 4 bytes */ 200#define TW_ALIGNMENT_7000 4 /* 4 bytes */
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index ec432763a29a..b95d2779f467 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -375,9 +375,10 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
375 u8 lun = cmd->device->lun; 375 u8 lun = cmd->device->lun;
376 unsigned long flags; 376 unsigned long flags;
377 int bufflen = scsi_bufflen(cmd); 377 int bufflen = scsi_bufflen(cmd);
378 int mbo; 378 int mbo, sg_count;
379 struct mailbox *mb = aha1542->mb; 379 struct mailbox *mb = aha1542->mb;
380 struct ccb *ccb = aha1542->ccb; 380 struct ccb *ccb = aha1542->ccb;
381 struct chain *cptr;
381 382
382 if (*cmd->cmnd == REQUEST_SENSE) { 383 if (*cmd->cmnd == REQUEST_SENSE) {
383 /* Don't do the command - we have the sense data already */ 384 /* Don't do the command - we have the sense data already */
@@ -397,6 +398,13 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
397 print_hex_dump_bytes("command: ", DUMP_PREFIX_NONE, cmd->cmnd, cmd->cmd_len); 398 print_hex_dump_bytes("command: ", DUMP_PREFIX_NONE, cmd->cmnd, cmd->cmd_len);
398 } 399 }
399#endif 400#endif
401 if (bufflen) { /* allocate memory before taking host_lock */
402 sg_count = scsi_sg_count(cmd);
403 cptr = kmalloc(sizeof(*cptr) * sg_count, GFP_KERNEL | GFP_DMA);
404 if (!cptr)
405 return SCSI_MLQUEUE_HOST_BUSY;
406 }
407
400 /* Use the outgoing mailboxes in a round-robin fashion, because this 408 /* Use the outgoing mailboxes in a round-robin fashion, because this
401 is how the host adapter will scan for them */ 409 is how the host adapter will scan for them */
402 410
@@ -441,19 +449,10 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
441 449
442 if (bufflen) { 450 if (bufflen) {
443 struct scatterlist *sg; 451 struct scatterlist *sg;
444 struct chain *cptr; 452 int i;
445 int i, sg_count = scsi_sg_count(cmd);
446 453
447 ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */ 454 ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */
448 cmd->host_scribble = kmalloc(sizeof(*cptr)*sg_count, 455 cmd->host_scribble = (void *)cptr;
449 GFP_KERNEL | GFP_DMA);
450 cptr = (struct chain *) cmd->host_scribble;
451 if (cptr == NULL) {
452 /* free the claimed mailbox slot */
453 aha1542->int_cmds[mbo] = NULL;
454 spin_unlock_irqrestore(sh->host_lock, flags);
455 return SCSI_MLQUEUE_HOST_BUSY;
456 }
457 scsi_for_each_sg(cmd, sg, sg_count, i) { 456 scsi_for_each_sg(cmd, sg, sg_count, i) {
458 any2scsi(cptr[i].dataptr, isa_page_to_bus(sg_page(sg)) 457 any2scsi(cptr[i].dataptr, isa_page_to_bus(sg_page(sg))
459 + sg->offset); 458 + sg->offset);
diff --git a/drivers/scsi/be2iscsi/be.h b/drivers/scsi/be2iscsi/be.h
index 81e83a65a193..32070099c333 100644
--- a/drivers/scsi/be2iscsi/be.h
+++ b/drivers/scsi/be2iscsi/be.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -8,9 +8,9 @@
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Contact Information: 10 * Contact Information:
11 * linux-drivers@emulex.com 11 * linux-drivers@avagotech.com
12 * 12 *
13 * Emulex 13 * Avago Technologies
14 * 3333 Susan Street 14 * 3333 Susan Street
15 * Costa Mesa, CA 92626 15 * Costa Mesa, CA 92626
16 */ 16 */
diff --git a/drivers/scsi/be2iscsi/be_cmds.c b/drivers/scsi/be2iscsi/be_cmds.c
index 1028760b8a22..447cf7ce606e 100644
--- a/drivers/scsi/be2iscsi/be_cmds.c
+++ b/drivers/scsi/be2iscsi/be_cmds.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -8,9 +8,9 @@
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Contact Information: 10 * Contact Information:
11 * linux-drivers@emulex.com 11 * linux-drivers@avagotech.com
12 * 12 *
13 * Emulex 13 * Avago Technologies
14 * 3333 Susan Street 14 * 3333 Susan Street
15 * Costa Mesa, CA 92626 15 * Costa Mesa, CA 92626
16 */ 16 */
diff --git a/drivers/scsi/be2iscsi/be_cmds.h b/drivers/scsi/be2iscsi/be_cmds.h
index 98897434bcb4..f11d325fe696 100644
--- a/drivers/scsi/be2iscsi/be_cmds.h
+++ b/drivers/scsi/be2iscsi/be_cmds.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -8,9 +8,9 @@
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Contact Information: 10 * Contact Information:
11 * linux-drivers@emulex.com 11 * linux-drivers@avagotech.com
12 * 12 *
13 * Emulex 13 * Avago Technologies
14 * 3333 Susan Street 14 * 3333 Susan Street
15 * Costa Mesa, CA 92626 15 * Costa Mesa, CA 92626
16 */ 16 */
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index b7391a3f9f0b..2f0700796842 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -7,12 +7,12 @@
7 * as published by the Free Software Foundation. The full GNU General 7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * linux-drivers@emulex.com 13 * linux-drivers@avagotech.com
14 * 14 *
15 * Emulex 15 * Avago Technologies
16 * 3333 Susan Street 16 * 3333 Susan Street
17 * Costa Mesa, CA 92626 17 * Costa Mesa, CA 92626
18 */ 18 */
diff --git a/drivers/scsi/be2iscsi/be_iscsi.h b/drivers/scsi/be2iscsi/be_iscsi.h
index e0b3b2d1f27a..0c84e1c0763a 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.h
+++ b/drivers/scsi/be2iscsi/be_iscsi.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -7,12 +7,12 @@
7 * as published by the Free Software Foundation. The full GNU General 7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * linux-drivers@emulex.com 13 * linux-drivers@avagotech.com
14 * 14 *
15 * Emulex 15 * Avago Technologies
16 * 3333 Susan Street 16 * 3333 Susan Street
17 * Costa Mesa, CA 92626 17 * Costa Mesa, CA 92626
18 */ 18 */
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 923a2b5a2439..1f74760ce86c 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -7,12 +7,12 @@
7 * as published by the Free Software Foundation. The full GNU General 7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * linux-drivers@emulex.com 13 * linux-drivers@avagotech.com
14 * 14 *
15 * Emulex 15 * Avago Technologies
16 * 3333 Susan Street 16 * 3333 Susan Street
17 * Costa Mesa, CA 92626 17 * Costa Mesa, CA 92626
18 */ 18 */
@@ -50,7 +50,7 @@ static unsigned int enable_msix = 1;
50 50
51MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); 51MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
52MODULE_VERSION(BUILD_STR); 52MODULE_VERSION(BUILD_STR);
53MODULE_AUTHOR("Emulex Corporation"); 53MODULE_AUTHOR("Avago Technologies");
54MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
55module_param(be_iopoll_budget, int, 0); 55module_param(be_iopoll_budget, int, 0);
56module_param(enable_msix, int, 0); 56module_param(enable_msix, int, 0);
@@ -552,7 +552,7 @@ MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
552 552
553static struct scsi_host_template beiscsi_sht = { 553static struct scsi_host_template beiscsi_sht = {
554 .module = THIS_MODULE, 554 .module = THIS_MODULE,
555 .name = "Emulex 10Gbe open-iscsi Initiator Driver", 555 .name = "Avago Technologies 10Gbe open-iscsi Initiator Driver",
556 .proc_name = DRV_NAME, 556 .proc_name = DRV_NAME,
557 .queuecommand = iscsi_queuecommand, 557 .queuecommand = iscsi_queuecommand,
558 .change_queue_depth = scsi_change_queue_depth, 558 .change_queue_depth = scsi_change_queue_depth,
diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
index 7ee0ffc38514..e70ea26bbc2b 100644
--- a/drivers/scsi/be2iscsi/be_main.h
+++ b/drivers/scsi/be2iscsi/be_main.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -7,12 +7,12 @@
7 * as published by the Free Software Foundation. The full GNU General 7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * linux-drivers@emulex.com 13 * linux-drivers@avagotech.com
14 * 14 *
15 * Emulex 15 * Avago Technologies
16 * 3333 Susan Street 16 * 3333 Susan Street
17 * Costa Mesa, CA 92626 17 * Costa Mesa, CA 92626
18 */ 18 */
@@ -37,7 +37,7 @@
37 37
38#define DRV_NAME "be2iscsi" 38#define DRV_NAME "be2iscsi"
39#define BUILD_STR "10.4.114.0" 39#define BUILD_STR "10.4.114.0"
40#define BE_NAME "Emulex OneConnect" \ 40#define BE_NAME "Avago Technologies OneConnect" \
41 "Open-iSCSI Driver version" BUILD_STR 41 "Open-iSCSI Driver version" BUILD_STR
42#define DRV_DESC BE_NAME " " "Driver" 42#define DRV_DESC BE_NAME " " "Driver"
43 43
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 681d4e8f003a..c2c4d6975fb7 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -7,12 +7,12 @@
7 * as published by the Free Software Foundation. The full GNU General 7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * linux-drivers@emulex.com 13 * linux-drivers@avagotech.com
14 * 14 *
15 * Emulex 15 * Avago Technologies
16 * 3333 Susan Street 16 * 3333 Susan Street
17 * Costa Mesa, CA 92626 17 * Costa Mesa, CA 92626
18 */ 18 */
diff --git a/drivers/scsi/be2iscsi/be_mgmt.h b/drivers/scsi/be2iscsi/be_mgmt.h
index bd81446936fc..9356b9a86b66 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.h
+++ b/drivers/scsi/be2iscsi/be_mgmt.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2014 Emulex 2 * Copyright (C) 2005 - 2015 Avago Technologies
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -7,12 +7,12 @@
7 * as published by the Free Software Foundation. The full GNU General 7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING. 8 * Public License is included in this distribution in the file called COPYING.
9 * 9 *
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com) 10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * linux-drivers@emulex.com 13 * linux-drivers@avagotech.com
14 * 14 *
15 * Emulex 15 * Avago Technologies
16 * 3333 Susan Street 16 * 3333 Susan Street
17 * Costa Mesa, CA 92626 17 * Costa Mesa, CA 92626
18 */ 18 */
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index cb73cf9e9ba5..c140f99772ca 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -1130,25 +1130,6 @@ lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
1130} 1130}
1131 1131
1132/** 1132/**
1133 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
1134 * @data: A pointer to the immediate command data portion of the IOCB.
1135 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
1136 *
1137 * The routine copies the entire FCP command from @fcp_cmnd to @data while
1138 * byte swapping the data to big endian format for transmission on the wire.
1139 **/
1140static void
1141lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
1142{
1143 int i, j;
1144
1145 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
1146 i += sizeof(uint32_t), j++) {
1147 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
1148 }
1149}
1150
1151/**
1152 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec 1133 * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
1153 * @phba: The Hba for which this call is being executed. 1134 * @phba: The Hba for which this call is being executed.
1154 * @lpfc_cmd: The scsi buffer which is going to be mapped. 1135 * @lpfc_cmd: The scsi buffer which is going to be mapped.
@@ -1283,7 +1264,6 @@ lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1283 * we need to set word 4 of IOCB here 1264 * we need to set word 4 of IOCB here
1284 */ 1265 */
1285 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd); 1266 iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
1286 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
1287 return 0; 1267 return 0;
1288} 1268}
1289 1269
@@ -4147,6 +4127,24 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
4147} 4127}
4148 4128
4149/** 4129/**
4130 * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
4131 * @data: A pointer to the immediate command data portion of the IOCB.
4132 * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
4133 *
4134 * The routine copies the entire FCP command from @fcp_cmnd to @data while
4135 * byte swapping the data to big endian format for transmission on the wire.
4136 **/
4137static void
4138lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
4139{
4140 int i, j;
4141 for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
4142 i += sizeof(uint32_t), j++) {
4143 ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
4144 }
4145}
4146
4147/**
4150 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit 4148 * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
4151 * @vport: The virtual port for which this call is being executed. 4149 * @vport: The virtual port for which this call is being executed.
4152 * @lpfc_cmd: The scsi command which needs to send. 4150 * @lpfc_cmd: The scsi command which needs to send.
@@ -4225,6 +4223,9 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4225 fcp_cmnd->fcpCntl3 = 0; 4223 fcp_cmnd->fcpCntl3 = 0;
4226 phba->fc4ControlRequests++; 4224 phba->fc4ControlRequests++;
4227 } 4225 }
4226 if (phba->sli_rev == 3 &&
4227 !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
4228 lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
4228 /* 4229 /*
4229 * Finish initializing those IOCB fields that are independent 4230 * Finish initializing those IOCB fields that are independent
4230 * of the scsi_cmnd request_buffer 4231 * of the scsi_cmnd request_buffer
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 68c2002e78bf..5c9e680aa375 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1020,8 +1020,7 @@ static void tcm_qla2xxx_depend_tpg(struct work_struct *work)
1020 struct se_portal_group *se_tpg = &base_tpg->se_tpg; 1020 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
1021 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha; 1021 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
1022 1022
1023 if (!configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys, 1023 if (!target_depend_item(&se_tpg->tpg_group.cg_item)) {
1024 &se_tpg->tpg_group.cg_item)) {
1025 atomic_set(&base_tpg->lport_tpg_enabled, 1); 1024 atomic_set(&base_tpg->lport_tpg_enabled, 1);
1026 qlt_enable_vha(base_vha); 1025 qlt_enable_vha(base_vha);
1027 } 1026 }
@@ -1037,8 +1036,7 @@ static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
1037 1036
1038 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) { 1037 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) {
1039 atomic_set(&base_tpg->lport_tpg_enabled, 0); 1038 atomic_set(&base_tpg->lport_tpg_enabled, 0);
1040 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys, 1039 target_undepend_item(&se_tpg->tpg_group.cg_item);
1041 &se_tpg->tpg_group.cg_item);
1042 } 1040 }
1043 complete(&base_tpg->tpg_base_comp); 1041 complete(&base_tpg->tpg_base_comp);
1044} 1042}
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 262ab837a704..9f77d23239a2 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -226,6 +226,7 @@ static struct {
226 {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, 226 {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
227 {"Promise", "VTrak E610f", NULL, BLIST_SPARSELUN | BLIST_NO_RSOC}, 227 {"Promise", "VTrak E610f", NULL, BLIST_SPARSELUN | BLIST_NO_RSOC},
228 {"Promise", "", NULL, BLIST_SPARSELUN}, 228 {"Promise", "", NULL, BLIST_SPARSELUN},
229 {"QNAP", "iSCSI Storage", NULL, BLIST_MAX_1024},
229 {"QUANTUM", "XP34301", "1071", BLIST_NOTQ}, 230 {"QUANTUM", "XP34301", "1071", BLIST_NOTQ},
230 {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN}, 231 {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
231 {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN}, 232 {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 60aae01caa89..6efab1c455e1 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -897,6 +897,12 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
897 */ 897 */
898 if (*bflags & BLIST_MAX_512) 898 if (*bflags & BLIST_MAX_512)
899 blk_queue_max_hw_sectors(sdev->request_queue, 512); 899 blk_queue_max_hw_sectors(sdev->request_queue, 512);
900 /*
901 * Max 1024 sector transfer length for targets that report incorrect
902 * max/optimal lengths and relied on the old block layer safe default
903 */
904 else if (*bflags & BLIST_MAX_1024)
905 blk_queue_max_hw_sectors(sdev->request_queue, 1024);
900 906
901 /* 907 /*
902 * Some devices may not want to have a start command automatically 908 * Some devices may not want to have a start command automatically
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 79beebf53302..7f9d65fe4fd9 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1600,6 +1600,7 @@ static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
1600{ 1600{
1601 u64 start_lba = blk_rq_pos(scmd->request); 1601 u64 start_lba = blk_rq_pos(scmd->request);
1602 u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512); 1602 u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512);
1603 u64 factor = scmd->device->sector_size / 512;
1603 u64 bad_lba; 1604 u64 bad_lba;
1604 int info_valid; 1605 int info_valid;
1605 /* 1606 /*
@@ -1621,16 +1622,9 @@ static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
1621 if (scsi_bufflen(scmd) <= scmd->device->sector_size) 1622 if (scsi_bufflen(scmd) <= scmd->device->sector_size)
1622 return 0; 1623 return 0;
1623 1624
1624 if (scmd->device->sector_size < 512) { 1625 /* be careful ... don't want any overflows */
1625 /* only legitimate sector_size here is 256 */ 1626 do_div(start_lba, factor);
1626 start_lba <<= 1; 1627 do_div(end_lba, factor);
1627 end_lba <<= 1;
1628 } else {
1629 /* be careful ... don't want any overflows */
1630 unsigned int factor = scmd->device->sector_size / 512;
1631 do_div(start_lba, factor);
1632 do_div(end_lba, factor);
1633 }
1634 1628
1635 /* The bad lba was reported incorrectly, we have no idea where 1629 /* The bad lba was reported incorrectly, we have no idea where
1636 * the error is. 1630 * the error is.
@@ -2188,8 +2182,7 @@ got_data:
2188 if (sector_size != 512 && 2182 if (sector_size != 512 &&
2189 sector_size != 1024 && 2183 sector_size != 1024 &&
2190 sector_size != 2048 && 2184 sector_size != 2048 &&
2191 sector_size != 4096 && 2185 sector_size != 4096) {
2192 sector_size != 256) {
2193 sd_printk(KERN_NOTICE, sdkp, "Unsupported sector size %d.\n", 2186 sd_printk(KERN_NOTICE, sdkp, "Unsupported sector size %d.\n",
2194 sector_size); 2187 sector_size);
2195 /* 2188 /*
@@ -2244,8 +2237,6 @@ got_data:
2244 sdkp->capacity <<= 2; 2237 sdkp->capacity <<= 2;
2245 else if (sector_size == 1024) 2238 else if (sector_size == 1024)
2246 sdkp->capacity <<= 1; 2239 sdkp->capacity <<= 1;
2247 else if (sector_size == 256)
2248 sdkp->capacity >>= 1;
2249 2240
2250 blk_queue_physical_block_size(sdp->request_queue, 2241 blk_queue_physical_block_size(sdp->request_queue,
2251 sdkp->physical_block_size); 2242 sdkp->physical_block_size);
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index d9dad90344d5..3c6584ff65c1 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1600,8 +1600,7 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1600 break; 1600 break;
1601 default: 1601 default:
1602 vm_srb->data_in = UNKNOWN_TYPE; 1602 vm_srb->data_in = UNKNOWN_TYPE;
1603 vm_srb->win8_extension.srb_flags |= (SRB_FLAGS_DATA_IN | 1603 vm_srb->win8_extension.srb_flags |= SRB_FLAGS_NO_DATA_TRANSFER;
1604 SRB_FLAGS_DATA_OUT);
1605 break; 1604 break;
1606 } 1605 }
1607 1606
diff --git a/drivers/sh/pm_runtime.c b/drivers/sh/pm_runtime.c
index cd4c293f0dd0..fe8875f0d7be 100644
--- a/drivers/sh/pm_runtime.c
+++ b/drivers/sh/pm_runtime.c
@@ -80,9 +80,10 @@ static int __init sh_pm_runtime_init(void)
80 if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) { 80 if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
81 if (!of_machine_is_compatible("renesas,emev2") && 81 if (!of_machine_is_compatible("renesas,emev2") &&
82 !of_machine_is_compatible("renesas,r7s72100") && 82 !of_machine_is_compatible("renesas,r7s72100") &&
83 !of_machine_is_compatible("renesas,r8a73a4") &&
84#ifndef CONFIG_PM_GENERIC_DOMAINS_OF 83#ifndef CONFIG_PM_GENERIC_DOMAINS_OF
84 !of_machine_is_compatible("renesas,r8a73a4") &&
85 !of_machine_is_compatible("renesas,r8a7740") && 85 !of_machine_is_compatible("renesas,r8a7740") &&
86 !of_machine_is_compatible("renesas,sh73a0") &&
86#endif 87#endif
87 !of_machine_is_compatible("renesas,r8a7778") && 88 !of_machine_is_compatible("renesas,r8a7778") &&
88 !of_machine_is_compatible("renesas,r8a7779") && 89 !of_machine_is_compatible("renesas,r8a7779") &&
@@ -90,9 +91,7 @@ static int __init sh_pm_runtime_init(void)
90 !of_machine_is_compatible("renesas,r8a7791") && 91 !of_machine_is_compatible("renesas,r8a7791") &&
91 !of_machine_is_compatible("renesas,r8a7792") && 92 !of_machine_is_compatible("renesas,r8a7792") &&
92 !of_machine_is_compatible("renesas,r8a7793") && 93 !of_machine_is_compatible("renesas,r8a7793") &&
93 !of_machine_is_compatible("renesas,r8a7794") && 94 !of_machine_is_compatible("renesas,r8a7794"))
94 !of_machine_is_compatible("renesas,sh7372") &&
95 !of_machine_is_compatible("renesas,sh73a0"))
96 return 0; 95 return 0;
97 } 96 }
98 97
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 198f96b7fb45..72b059081559 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -78,6 +78,7 @@ config SPI_ATMEL
78config SPI_BCM2835 78config SPI_BCM2835
79 tristate "BCM2835 SPI controller" 79 tristate "BCM2835 SPI controller"
80 depends on ARCH_BCM2835 || COMPILE_TEST 80 depends on ARCH_BCM2835 || COMPILE_TEST
81 depends on GPIOLIB
81 help 82 help
82 This selects a driver for the Broadcom BCM2835 SPI master. 83 This selects a driver for the Broadcom BCM2835 SPI master.
83 84
@@ -302,7 +303,7 @@ config SPI_FSL_SPI
302config SPI_FSL_DSPI 303config SPI_FSL_DSPI
303 tristate "Freescale DSPI controller" 304 tristate "Freescale DSPI controller"
304 select REGMAP_MMIO 305 select REGMAP_MMIO
305 depends on SOC_VF610 || COMPILE_TEST 306 depends on SOC_VF610 || SOC_LS1021A || COMPILE_TEST
306 help 307 help
307 This enables support for the Freescale DSPI controller in master 308 This enables support for the Freescale DSPI controller in master
308 mode. VF610 platform uses the controller. 309 mode. VF610 platform uses the controller.
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index f63864a893c5..37875cf942f7 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -164,13 +164,12 @@ static int bcm2835_spi_transfer_one_poll(struct spi_master *master,
164 unsigned long xfer_time_us) 164 unsigned long xfer_time_us)
165{ 165{
166 struct bcm2835_spi *bs = spi_master_get_devdata(master); 166 struct bcm2835_spi *bs = spi_master_get_devdata(master);
167 unsigned long timeout = jiffies + 167 /* set timeout to 1 second of maximum polling */
168 max(4 * xfer_time_us * HZ / 1000000, 2uL); 168 unsigned long timeout = jiffies + HZ;
169 169
170 /* enable HW block without interrupts */ 170 /* enable HW block without interrupts */
171 bcm2835_wr(bs, BCM2835_SPI_CS, cs | BCM2835_SPI_CS_TA); 171 bcm2835_wr(bs, BCM2835_SPI_CS, cs | BCM2835_SPI_CS_TA);
172 172
173 /* set timeout to 4x the expected time, or 2 jiffies */
174 /* loop until finished the transfer */ 173 /* loop until finished the transfer */
175 while (bs->rx_len) { 174 while (bs->rx_len) {
176 /* read from fifo as much as possible */ 175 /* read from fifo as much as possible */
diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
index 5ef6638d5e8a..840a4984d365 100644
--- a/drivers/spi/spi-bitbang.c
+++ b/drivers/spi/spi-bitbang.c
@@ -180,7 +180,6 @@ int spi_bitbang_setup(struct spi_device *spi)
180{ 180{
181 struct spi_bitbang_cs *cs = spi->controller_state; 181 struct spi_bitbang_cs *cs = spi->controller_state;
182 struct spi_bitbang *bitbang; 182 struct spi_bitbang *bitbang;
183 int retval;
184 unsigned long flags; 183 unsigned long flags;
185 184
186 bitbang = spi_master_get_devdata(spi->master); 185 bitbang = spi_master_get_devdata(spi->master);
@@ -197,9 +196,11 @@ int spi_bitbang_setup(struct spi_device *spi)
197 if (!cs->txrx_word) 196 if (!cs->txrx_word)
198 return -EINVAL; 197 return -EINVAL;
199 198
200 retval = bitbang->setup_transfer(spi, NULL); 199 if (bitbang->setup_transfer) {
201 if (retval < 0) 200 int retval = bitbang->setup_transfer(spi, NULL);
202 return retval; 201 if (retval < 0)
202 return retval;
203 }
203 204
204 dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs); 205 dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);
205 206
@@ -295,9 +296,11 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
295 296
296 /* init (-1) or override (1) transfer params */ 297 /* init (-1) or override (1) transfer params */
297 if (do_setup != 0) { 298 if (do_setup != 0) {
298 status = bitbang->setup_transfer(spi, t); 299 if (bitbang->setup_transfer) {
299 if (status < 0) 300 status = bitbang->setup_transfer(spi, t);
300 break; 301 if (status < 0)
302 break;
303 }
301 if (do_setup == -1) 304 if (do_setup == -1)
302 do_setup = 0; 305 do_setup = 0;
303 } 306 }
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c
index 9c46a3058743..896add8cfd3b 100644
--- a/drivers/spi/spi-fsl-cpm.c
+++ b/drivers/spi/spi-fsl-cpm.c
@@ -24,6 +24,7 @@
24#include <linux/of_address.h> 24#include <linux/of_address.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/platform_device.h>
27 28
28#include "spi-fsl-cpm.h" 29#include "spi-fsl-cpm.h"
29#include "spi-fsl-lib.h" 30#include "spi-fsl-lib.h"
@@ -269,17 +270,6 @@ static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
269 if (mspi->flags & SPI_CPM2) { 270 if (mspi->flags & SPI_CPM2) {
270 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); 271 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
271 out_be16(spi_base, pram_ofs); 272 out_be16(spi_base, pram_ofs);
272 } else {
273 struct spi_pram __iomem *pram = spi_base;
274 u16 rpbase = in_be16(&pram->rpbase);
275
276 /* Microcode relocation patch applied? */
277 if (rpbase) {
278 pram_ofs = rpbase;
279 } else {
280 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
281 out_be16(spi_base, pram_ofs);
282 }
283 } 273 }
284 274
285 iounmap(spi_base); 275 iounmap(spi_base);
@@ -292,7 +282,6 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
292 struct device_node *np = dev->of_node; 282 struct device_node *np = dev->of_node;
293 const u32 *iprop; 283 const u32 *iprop;
294 int size; 284 int size;
295 unsigned long pram_ofs;
296 unsigned long bds_ofs; 285 unsigned long bds_ofs;
297 286
298 if (!(mspi->flags & SPI_CPM_MODE)) 287 if (!(mspi->flags & SPI_CPM_MODE))
@@ -319,8 +308,26 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
319 } 308 }
320 } 309 }
321 310
322 pram_ofs = fsl_spi_cpm_get_pram(mspi); 311 if (mspi->flags & SPI_CPM1) {
323 if (IS_ERR_VALUE(pram_ofs)) { 312 struct resource *res;
313 void *pram;
314
315 res = platform_get_resource(to_platform_device(dev),
316 IORESOURCE_MEM, 1);
317 pram = devm_ioremap_resource(dev, res);
318 if (IS_ERR(pram))
319 mspi->pram = NULL;
320 else
321 mspi->pram = pram;
322 } else {
323 unsigned long pram_ofs = fsl_spi_cpm_get_pram(mspi);
324
325 if (IS_ERR_VALUE(pram_ofs))
326 mspi->pram = NULL;
327 else
328 mspi->pram = cpm_muram_addr(pram_ofs);
329 }
330 if (mspi->pram == NULL) {
324 dev_err(dev, "can't allocate spi parameter ram\n"); 331 dev_err(dev, "can't allocate spi parameter ram\n");
325 goto err_pram; 332 goto err_pram;
326 } 333 }
@@ -346,8 +353,6 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
346 goto err_dummy_rx; 353 goto err_dummy_rx;
347 } 354 }
348 355
349 mspi->pram = cpm_muram_addr(pram_ofs);
350
351 mspi->tx_bd = cpm_muram_addr(bds_ofs); 356 mspi->tx_bd = cpm_muram_addr(bds_ofs);
352 mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); 357 mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd));
353 358
@@ -375,7 +380,8 @@ err_dummy_rx:
375err_dummy_tx: 380err_dummy_tx:
376 cpm_muram_free(bds_ofs); 381 cpm_muram_free(bds_ofs);
377err_bds: 382err_bds:
378 cpm_muram_free(pram_ofs); 383 if (!(mspi->flags & SPI_CPM1))
384 cpm_muram_free(cpm_muram_offset(mspi->pram));
379err_pram: 385err_pram:
380 fsl_spi_free_dummy_rx(); 386 fsl_spi_free_dummy_rx();
381 return -ENOMEM; 387 return -ENOMEM;
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index d0a73a09a9bd..80d245ac846f 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -359,14 +359,16 @@ static void fsl_espi_rw_trans(struct spi_message *m,
359 struct fsl_espi_transfer *trans, u8 *rx_buff) 359 struct fsl_espi_transfer *trans, u8 *rx_buff)
360{ 360{
361 struct fsl_espi_transfer *espi_trans = trans; 361 struct fsl_espi_transfer *espi_trans = trans;
362 unsigned int n_tx = espi_trans->n_tx; 362 unsigned int total_len = espi_trans->len;
363 unsigned int n_rx = espi_trans->n_rx;
364 struct spi_transfer *t; 363 struct spi_transfer *t;
365 u8 *local_buf; 364 u8 *local_buf;
366 u8 *rx_buf = rx_buff; 365 u8 *rx_buf = rx_buff;
367 unsigned int trans_len; 366 unsigned int trans_len;
368 unsigned int addr; 367 unsigned int addr;
369 int i, pos, loop; 368 unsigned int tx_only;
369 unsigned int rx_pos = 0;
370 unsigned int pos;
371 int i, loop;
370 372
371 local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL); 373 local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
372 if (!local_buf) { 374 if (!local_buf) {
@@ -374,36 +376,48 @@ static void fsl_espi_rw_trans(struct spi_message *m,
374 return; 376 return;
375 } 377 }
376 378
377 for (pos = 0, loop = 0; pos < n_rx; pos += trans_len, loop++) { 379 for (pos = 0, loop = 0; pos < total_len; pos += trans_len, loop++) {
378 trans_len = n_rx - pos; 380 trans_len = total_len - pos;
379 if (trans_len > SPCOM_TRANLEN_MAX - n_tx)
380 trans_len = SPCOM_TRANLEN_MAX - n_tx;
381 381
382 i = 0; 382 i = 0;
383 tx_only = 0;
383 list_for_each_entry(t, &m->transfers, transfer_list) { 384 list_for_each_entry(t, &m->transfers, transfer_list) {
384 if (t->tx_buf) { 385 if (t->tx_buf) {
385 memcpy(local_buf + i, t->tx_buf, t->len); 386 memcpy(local_buf + i, t->tx_buf, t->len);
386 i += t->len; 387 i += t->len;
388 if (!t->rx_buf)
389 tx_only += t->len;
387 } 390 }
388 } 391 }
389 392
393 /* Add additional TX bytes to compensate SPCOM_TRANLEN_MAX */
394 if (loop > 0)
395 trans_len += tx_only;
396
397 if (trans_len > SPCOM_TRANLEN_MAX)
398 trans_len = SPCOM_TRANLEN_MAX;
399
400 /* Update device offset */
390 if (pos > 0) { 401 if (pos > 0) {
391 addr = fsl_espi_cmd2addr(local_buf); 402 addr = fsl_espi_cmd2addr(local_buf);
392 addr += pos; 403 addr += rx_pos;
393 fsl_espi_addr2cmd(addr, local_buf); 404 fsl_espi_addr2cmd(addr, local_buf);
394 } 405 }
395 406
396 espi_trans->n_tx = n_tx; 407 espi_trans->len = trans_len;
397 espi_trans->n_rx = trans_len;
398 espi_trans->len = trans_len + n_tx;
399 espi_trans->tx_buf = local_buf; 408 espi_trans->tx_buf = local_buf;
400 espi_trans->rx_buf = local_buf; 409 espi_trans->rx_buf = local_buf;
401 fsl_espi_do_trans(m, espi_trans); 410 fsl_espi_do_trans(m, espi_trans);
402 411
403 memcpy(rx_buf + pos, espi_trans->rx_buf + n_tx, trans_len); 412 /* If there is at least one RX byte then copy it to rx_buf */
413 if (tx_only < SPCOM_TRANLEN_MAX)
414 memcpy(rx_buf + rx_pos, espi_trans->rx_buf + tx_only,
415 trans_len - tx_only);
416
417 rx_pos += trans_len - tx_only;
404 418
405 if (loop > 0) 419 if (loop > 0)
406 espi_trans->actual_length += espi_trans->len - n_tx; 420 espi_trans->actual_length += espi_trans->len - tx_only;
407 else 421 else
408 espi_trans->actual_length += espi_trans->len; 422 espi_trans->actual_length += espi_trans->len;
409 } 423 }
@@ -418,6 +432,7 @@ static int fsl_espi_do_one_msg(struct spi_master *master,
418 u8 *rx_buf = NULL; 432 u8 *rx_buf = NULL;
419 unsigned int n_tx = 0; 433 unsigned int n_tx = 0;
420 unsigned int n_rx = 0; 434 unsigned int n_rx = 0;
435 unsigned int xfer_len = 0;
421 struct fsl_espi_transfer espi_trans; 436 struct fsl_espi_transfer espi_trans;
422 437
423 list_for_each_entry(t, &m->transfers, transfer_list) { 438 list_for_each_entry(t, &m->transfers, transfer_list) {
@@ -427,11 +442,13 @@ static int fsl_espi_do_one_msg(struct spi_master *master,
427 n_rx += t->len; 442 n_rx += t->len;
428 rx_buf = t->rx_buf; 443 rx_buf = t->rx_buf;
429 } 444 }
445 if ((t->tx_buf) || (t->rx_buf))
446 xfer_len += t->len;
430 } 447 }
431 448
432 espi_trans.n_tx = n_tx; 449 espi_trans.n_tx = n_tx;
433 espi_trans.n_rx = n_rx; 450 espi_trans.n_rx = n_rx;
434 espi_trans.len = n_tx + n_rx; 451 espi_trans.len = xfer_len;
435 espi_trans.actual_length = 0; 452 espi_trans.actual_length = 0;
436 espi_trans.status = 0; 453 espi_trans.status = 0;
437 454
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 4df8942058de..d1a5b9fc3eba 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -1210,6 +1210,7 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1210 struct omap2_mcspi *mcspi; 1210 struct omap2_mcspi *mcspi;
1211 struct omap2_mcspi_dma *mcspi_dma; 1211 struct omap2_mcspi_dma *mcspi_dma;
1212 struct spi_transfer *t; 1212 struct spi_transfer *t;
1213 int status;
1213 1214
1214 spi = m->spi; 1215 spi = m->spi;
1215 mcspi = spi_master_get_devdata(master); 1216 mcspi = spi_master_get_devdata(master);
@@ -1229,7 +1230,8 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1229 tx_buf ? "tx" : "", 1230 tx_buf ? "tx" : "",
1230 rx_buf ? "rx" : "", 1231 rx_buf ? "rx" : "",
1231 t->bits_per_word); 1232 t->bits_per_word);
1232 return -EINVAL; 1233 status = -EINVAL;
1234 goto out;
1233 } 1235 }
1234 1236
1235 if (m->is_dma_mapped || len < DMA_MIN_BYTES) 1237 if (m->is_dma_mapped || len < DMA_MIN_BYTES)
@@ -1241,7 +1243,8 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1241 if (dma_mapping_error(mcspi->dev, t->tx_dma)) { 1243 if (dma_mapping_error(mcspi->dev, t->tx_dma)) {
1242 dev_dbg(mcspi->dev, "dma %cX %d bytes error\n", 1244 dev_dbg(mcspi->dev, "dma %cX %d bytes error\n",
1243 'T', len); 1245 'T', len);
1244 return -EINVAL; 1246 status = -EINVAL;
1247 goto out;
1245 } 1248 }
1246 } 1249 }
1247 if (mcspi_dma->dma_rx && rx_buf != NULL) { 1250 if (mcspi_dma->dma_rx && rx_buf != NULL) {
@@ -1253,14 +1256,19 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,
1253 if (tx_buf != NULL) 1256 if (tx_buf != NULL)
1254 dma_unmap_single(mcspi->dev, t->tx_dma, 1257 dma_unmap_single(mcspi->dev, t->tx_dma,
1255 len, DMA_TO_DEVICE); 1258 len, DMA_TO_DEVICE);
1256 return -EINVAL; 1259 status = -EINVAL;
1260 goto out;
1257 } 1261 }
1258 } 1262 }
1259 } 1263 }
1260 1264
1261 omap2_mcspi_work(mcspi, m); 1265 omap2_mcspi_work(mcspi, m);
1266 /* spi_finalize_current_message() changes the status inside the
1267 * spi_message, save the status here. */
1268 status = m->status;
1269out:
1262 spi_finalize_current_message(master); 1270 spi_finalize_current_message(master);
1263 return 0; 1271 return status;
1264} 1272}
1265 1273
1266static int omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) 1274static int omap2_mcspi_master_setup(struct omap2_mcspi *mcspi)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index d5d7d2235163..50910d85df5a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -583,6 +583,15 @@ static int spi_unmap_msg(struct spi_master *master, struct spi_message *msg)
583 rx_dev = master->dma_rx->device->dev; 583 rx_dev = master->dma_rx->device->dev;
584 584
585 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 585 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
586 /*
587 * Restore the original value of tx_buf or rx_buf if they are
588 * NULL.
589 */
590 if (xfer->tx_buf == master->dummy_tx)
591 xfer->tx_buf = NULL;
592 if (xfer->rx_buf == master->dummy_rx)
593 xfer->rx_buf = NULL;
594
586 if (!master->can_dma(master, msg->spi, xfer)) 595 if (!master->can_dma(master, msg->spi, xfer))
587 continue; 596 continue;
588 597
diff --git a/drivers/ssb/driver_pcicore.c b/drivers/ssb/driver_pcicore.c
index 15a7ee3859dd..5fe1c22e289b 100644
--- a/drivers/ssb/driver_pcicore.c
+++ b/drivers/ssb/driver_pcicore.c
@@ -359,12 +359,13 @@ static void ssb_pcicore_init_hostmode(struct ssb_pcicore *pc)
359 359
360 /* 360 /*
361 * Accessing PCI config without a proper delay after devices reset (not 361 * Accessing PCI config without a proper delay after devices reset (not
362 * GPIO reset) was causing reboots on WRT300N v1.0. 362 * GPIO reset) was causing reboots on WRT300N v1.0 (BCM4704).
363 * Tested delay 850 us lowered reboot chance to 50-80%, 1000 us fixed it 363 * Tested delay 850 us lowered reboot chance to 50-80%, 1000 us fixed it
364 * completely. Flushing all writes was also tested but with no luck. 364 * completely. Flushing all writes was also tested but with no luck.
365 * The same problem was reported for WRT350N v1 (BCM4705), so we just
366 * sleep here unconditionally.
365 */ 367 */
366 if (pc->dev->bus->chip_id == 0x4704) 368 usleep_range(1000, 2000);
367 usleep_range(1000, 2000);
368 369
369 /* Enable PCI bridge BAR0 prefetch and burst */ 370 /* Enable PCI bridge BAR0 prefetch and burst */
370 val = PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; 371 val = PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
diff --git a/drivers/staging/gdm724x/gdm_mux.c b/drivers/staging/gdm724x/gdm_mux.c
index 8199b0a697bb..1cf24e4edf25 100644
--- a/drivers/staging/gdm724x/gdm_mux.c
+++ b/drivers/staging/gdm724x/gdm_mux.c
@@ -158,7 +158,7 @@ static int up_to_host(struct mux_rx *r)
158 unsigned int start_flag; 158 unsigned int start_flag;
159 unsigned int payload_size; 159 unsigned int payload_size;
160 unsigned short packet_type; 160 unsigned short packet_type;
161 int dummy_cnt; 161 int total_len;
162 u32 packet_size_sum = r->offset; 162 u32 packet_size_sum = r->offset;
163 int index; 163 int index;
164 int ret = TO_HOST_INVALID_PACKET; 164 int ret = TO_HOST_INVALID_PACKET;
@@ -176,10 +176,10 @@ static int up_to_host(struct mux_rx *r)
176 break; 176 break;
177 } 177 }
178 178
179 dummy_cnt = ALIGN(MUX_HEADER_SIZE + payload_size, 4); 179 total_len = ALIGN(MUX_HEADER_SIZE + payload_size, 4);
180 180
181 if (len - packet_size_sum < 181 if (len - packet_size_sum <
182 MUX_HEADER_SIZE + payload_size + dummy_cnt) { 182 total_len) {
183 pr_err("invalid payload : %d %d %04x\n", 183 pr_err("invalid payload : %d %d %04x\n",
184 payload_size, len, packet_type); 184 payload_size, len, packet_type);
185 break; 185 break;
@@ -202,7 +202,7 @@ static int up_to_host(struct mux_rx *r)
202 break; 202 break;
203 } 203 }
204 204
205 packet_size_sum += MUX_HEADER_SIZE + payload_size + dummy_cnt; 205 packet_size_sum += total_len;
206 if (len - packet_size_sum <= MUX_HEADER_SIZE + 2) { 206 if (len - packet_size_sum <= MUX_HEADER_SIZE + 2) {
207 ret = r->callback(NULL, 207 ret = r->callback(NULL,
208 0, 208 0,
@@ -361,7 +361,6 @@ static int gdm_mux_send(void *priv_dev, void *data, int len, int tty_index,
361 struct mux_pkt_header *mux_header; 361 struct mux_pkt_header *mux_header;
362 struct mux_tx *t = NULL; 362 struct mux_tx *t = NULL;
363 static u32 seq_num = 1; 363 static u32 seq_num = 1;
364 int dummy_cnt;
365 int total_len; 364 int total_len;
366 int ret; 365 int ret;
367 unsigned long flags; 366 unsigned long flags;
@@ -374,9 +373,7 @@ static int gdm_mux_send(void *priv_dev, void *data, int len, int tty_index,
374 373
375 spin_lock_irqsave(&mux_dev->write_lock, flags); 374 spin_lock_irqsave(&mux_dev->write_lock, flags);
376 375
377 dummy_cnt = ALIGN(MUX_HEADER_SIZE + len, 4); 376 total_len = ALIGN(MUX_HEADER_SIZE + len, 4);
378
379 total_len = len + MUX_HEADER_SIZE + dummy_cnt;
380 377
381 t = alloc_mux_tx(total_len); 378 t = alloc_mux_tx(total_len);
382 if (!t) { 379 if (!t) {
@@ -392,7 +389,8 @@ static int gdm_mux_send(void *priv_dev, void *data, int len, int tty_index,
392 mux_header->packet_type = __cpu_to_le16(packet_type[tty_index]); 389 mux_header->packet_type = __cpu_to_le16(packet_type[tty_index]);
393 390
394 memcpy(t->buf+MUX_HEADER_SIZE, data, len); 391 memcpy(t->buf+MUX_HEADER_SIZE, data, len);
395 memset(t->buf+MUX_HEADER_SIZE+len, 0, dummy_cnt); 392 memset(t->buf+MUX_HEADER_SIZE+len, 0, total_len - MUX_HEADER_SIZE -
393 len);
396 394
397 t->len = total_len; 395 t->len = total_len;
398 t->callback = cb; 396 t->callback = cb;
diff --git a/drivers/staging/media/omap4iss/Kconfig b/drivers/staging/media/omap4iss/Kconfig
index b78643f907e7..072dac04a750 100644
--- a/drivers/staging/media/omap4iss/Kconfig
+++ b/drivers/staging/media/omap4iss/Kconfig
@@ -2,6 +2,7 @@ config VIDEO_OMAP4
2 bool "OMAP 4 Camera support" 2 bool "OMAP 4 Camera support"
3 depends on VIDEO_V4L2=y && VIDEO_V4L2_SUBDEV_API && I2C=y && ARCH_OMAP4 3 depends on VIDEO_V4L2=y && VIDEO_V4L2_SUBDEV_API && I2C=y && ARCH_OMAP4
4 depends on HAS_DMA 4 depends on HAS_DMA
5 select MFD_SYSCON
5 select VIDEOBUF2_DMA_CONTIG 6 select VIDEOBUF2_DMA_CONTIG
6 ---help--- 7 ---help---
7 Driver for an OMAP 4 ISS controller. 8 Driver for an OMAP 4 ISS controller.
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index e0ad5e520e2d..7ced940bd807 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -17,6 +17,7 @@
17#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/mfd/syscon.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
@@ -1386,6 +1387,16 @@ static int iss_probe(struct platform_device *pdev)
1386 1387
1387 platform_set_drvdata(pdev, iss); 1388 platform_set_drvdata(pdev, iss);
1388 1389
1390 /*
1391 * TODO: When implementing DT support switch to syscon regmap lookup by
1392 * phandle.
1393 */
1394 iss->syscon = syscon_regmap_lookup_by_compatible("syscon");
1395 if (IS_ERR(iss->syscon)) {
1396 ret = PTR_ERR(iss->syscon);
1397 goto error;
1398 }
1399
1389 /* Clocks */ 1400 /* Clocks */
1390 ret = iss_map_mem_resource(pdev, iss, OMAP4_ISS_MEM_TOP); 1401 ret = iss_map_mem_resource(pdev, iss, OMAP4_ISS_MEM_TOP);
1391 if (ret < 0) 1402 if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.h b/drivers/staging/media/omap4iss/iss.h
index 734cfeeb0314..35df8b4709e6 100644
--- a/drivers/staging/media/omap4iss/iss.h
+++ b/drivers/staging/media/omap4iss/iss.h
@@ -29,6 +29,8 @@
29#include "iss_ipipe.h" 29#include "iss_ipipe.h"
30#include "iss_resizer.h" 30#include "iss_resizer.h"
31 31
32struct regmap;
33
32#define to_iss_device(ptr_module) \ 34#define to_iss_device(ptr_module) \
33 container_of(ptr_module, struct iss_device, ptr_module) 35 container_of(ptr_module, struct iss_device, ptr_module)
34#define to_device(ptr_module) \ 36#define to_device(ptr_module) \
@@ -79,6 +81,7 @@ struct iss_reg {
79 81
80/* 82/*
81 * struct iss_device - ISS device structure. 83 * struct iss_device - ISS device structure.
84 * @syscon: Regmap for the syscon register space
82 * @crashed: Bitmask of crashed entities (indexed by entity ID) 85 * @crashed: Bitmask of crashed entities (indexed by entity ID)
83 */ 86 */
84struct iss_device { 87struct iss_device {
@@ -93,6 +96,7 @@ struct iss_device {
93 96
94 struct resource *res[OMAP4_ISS_MEM_LAST]; 97 struct resource *res[OMAP4_ISS_MEM_LAST];
95 void __iomem *regs[OMAP4_ISS_MEM_LAST]; 98 void __iomem *regs[OMAP4_ISS_MEM_LAST];
99 struct regmap *syscon;
96 100
97 u64 raw_dmamask; 101 u64 raw_dmamask;
98 102
diff --git a/drivers/staging/media/omap4iss/iss_csiphy.c b/drivers/staging/media/omap4iss/iss_csiphy.c
index 7c3d55d811ef..748607f8918f 100644
--- a/drivers/staging/media/omap4iss/iss_csiphy.c
+++ b/drivers/staging/media/omap4iss/iss_csiphy.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/regmap.h>
16 17
17#include "../../../../arch/arm/mach-omap2/control.h" 18#include "../../../../arch/arm/mach-omap2/control.h"
18 19
@@ -140,9 +141,11 @@ int omap4iss_csiphy_config(struct iss_device *iss,
140 * - bit [18] : CSIPHY1 CTRLCLK enable 141 * - bit [18] : CSIPHY1 CTRLCLK enable
141 * - bit [17:16] : CSIPHY1 config: 00 d-phy, 01/10 ccp2 142 * - bit [17:16] : CSIPHY1 config: 00 d-phy, 01/10 ccp2
142 */ 143 */
143 cam_rx_ctrl = omap4_ctrl_pad_readl( 144 /*
144 OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_CAMERA_RX); 145 * TODO: When implementing DT support specify the CONTROL_CAMERA_RX
145 146 * register offset in the syscon property instead of hardcoding it.
147 */
148 regmap_read(iss->syscon, 0x68, &cam_rx_ctrl);
146 149
147 if (subdevs->interface == ISS_INTERFACE_CSI2A_PHY1) { 150 if (subdevs->interface == ISS_INTERFACE_CSI2A_PHY1) {
148 cam_rx_ctrl &= ~(OMAP4_CAMERARX_CSI21_LANEENABLE_MASK | 151 cam_rx_ctrl &= ~(OMAP4_CAMERARX_CSI21_LANEENABLE_MASK |
@@ -166,8 +169,7 @@ int omap4iss_csiphy_config(struct iss_device *iss,
166 cam_rx_ctrl |= OMAP4_CAMERARX_CSI22_CTRLCLKEN_MASK; 169 cam_rx_ctrl |= OMAP4_CAMERARX_CSI22_CTRLCLKEN_MASK;
167 } 170 }
168 171
169 omap4_ctrl_pad_writel(cam_rx_ctrl, 172 regmap_write(iss->syscon, 0x68, cam_rx_ctrl);
170 OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_CAMERA_RX);
171 173
172 /* Reset used lane count */ 174 /* Reset used lane count */
173 csi2->phy->used_data_lanes = 0; 175 csi2->phy->used_data_lanes = 0;
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 42fba3f5b593..cb0b6387789f 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -1900,23 +1900,20 @@ static int r871x_mp_ioctl_hdl(struct net_device *dev,
1900 struct mp_ioctl_handler *phandler; 1900 struct mp_ioctl_handler *phandler;
1901 struct mp_ioctl_param *poidparam; 1901 struct mp_ioctl_param *poidparam;
1902 unsigned long BytesRead, BytesWritten, BytesNeeded; 1902 unsigned long BytesRead, BytesWritten, BytesNeeded;
1903 u8 *pparmbuf = NULL, bset; 1903 u8 *pparmbuf, bset;
1904 u16 len; 1904 u16 len;
1905 uint status; 1905 uint status;
1906 int ret = 0; 1906 int ret = 0;
1907 1907
1908 if ((!p->length) || (!p->pointer)) { 1908 if ((!p->length) || (!p->pointer))
1909 ret = -EINVAL; 1909 return -EINVAL;
1910 goto _r871x_mp_ioctl_hdl_exit; 1910
1911 }
1912 bset = (u8)(p->flags & 0xFFFF); 1911 bset = (u8)(p->flags & 0xFFFF);
1913 len = p->length; 1912 len = p->length;
1914 pparmbuf = NULL;
1915 pparmbuf = memdup_user(p->pointer, len); 1913 pparmbuf = memdup_user(p->pointer, len);
1916 if (IS_ERR(pparmbuf)) { 1914 if (IS_ERR(pparmbuf))
1917 ret = PTR_ERR(pparmbuf); 1915 return PTR_ERR(pparmbuf);
1918 goto _r871x_mp_ioctl_hdl_exit; 1916
1919 }
1920 poidparam = (struct mp_ioctl_param *)pparmbuf; 1917 poidparam = (struct mp_ioctl_param *)pparmbuf;
1921 if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) { 1918 if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
1922 ret = -EINVAL; 1919 ret = -EINVAL;
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 3c7ea95dd9f9..dbbb2f879a29 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -1250,7 +1250,7 @@ err_enable:
1250 return -ENODEV; 1250 return -ENODEV;
1251} 1251}
1252 1252
1253static void __exit lynxfb_pci_remove(struct pci_dev *pdev) 1253static void lynxfb_pci_remove(struct pci_dev *pdev)
1254{ 1254{
1255 struct fb_info *info; 1255 struct fb_info *info;
1256 struct lynx_share *share; 1256 struct lynx_share *share;
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
index 1cdcf49b2445..e00c0605d154 100644
--- a/drivers/staging/vt6655/card.c
+++ b/drivers/staging/vt6655/card.c
@@ -362,12 +362,16 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
362 * Return Value: none 362 * Return Value: none
363 */ 363 */
364bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate, 364bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
365 u64 qwBSSTimestamp, u64 qwLocalTSF) 365 u64 qwBSSTimestamp)
366{ 366{
367 u64 local_tsf;
367 u64 qwTSFOffset = 0; 368 u64 qwTSFOffset = 0;
368 369
369 if (qwBSSTimestamp != qwLocalTSF) { 370 CARDbGetCurrentTSF(pDevice, &local_tsf);
370 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); 371
372 if (qwBSSTimestamp != local_tsf) {
373 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp,
374 local_tsf);
371 /* adjust TSF, HW's TSF add TSF Offset reg */ 375 /* adjust TSF, HW's TSF add TSF Offset reg */
372 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset); 376 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
373 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32)); 377 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
diff --git a/drivers/staging/vt6655/card.h b/drivers/staging/vt6655/card.h
index 2dfc41952271..16cca49e680a 100644
--- a/drivers/staging/vt6655/card.h
+++ b/drivers/staging/vt6655/card.h
@@ -83,7 +83,7 @@ bool CARDbRadioPowerOff(struct vnt_private *);
83bool CARDbRadioPowerOn(struct vnt_private *); 83bool CARDbRadioPowerOn(struct vnt_private *);
84bool CARDbSetPhyParameter(struct vnt_private *, u8); 84bool CARDbSetPhyParameter(struct vnt_private *, u8);
85bool CARDbUpdateTSF(struct vnt_private *, unsigned char byRxRate, 85bool CARDbUpdateTSF(struct vnt_private *, unsigned char byRxRate,
86 u64 qwBSSTimestamp, u64 qwLocalTSF); 86 u64 qwBSSTimestamp);
87bool CARDbSetBeaconPeriod(struct vnt_private *, unsigned short wBeaconInterval); 87bool CARDbSetBeaconPeriod(struct vnt_private *, unsigned short wBeaconInterval);
88 88
89#endif /* __CARD_H__ */ 89#endif /* __CARD_H__ */
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 4bb4f8ee4132..0343ae386f03 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -912,7 +912,11 @@ static int vnt_int_report_rate(struct vnt_private *priv,
912 912
913 if (!(tsr1 & TSR1_TERR)) { 913 if (!(tsr1 & TSR1_TERR)) {
914 info->status.rates[0].idx = idx; 914 info->status.rates[0].idx = idx;
915 info->flags |= IEEE80211_TX_STAT_ACK; 915
916 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
917 info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
918 else
919 info->flags |= IEEE80211_TX_STAT_ACK;
916 } 920 }
917 921
918 return 0; 922 return 0;
@@ -937,9 +941,6 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
937 /* Only the status of first TD in the chain is correct */ 941 /* Only the status of first TD in the chain is correct */
938 if (pTD->m_td1TD1.byTCR & TCR_STP) { 942 if (pTD->m_td1TD1.byTCR & TCR_STP) {
939 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) { 943 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
940
941 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
942
943 if (!(byTsr1 & TSR1_TERR)) { 944 if (!(byTsr1 & TSR1_TERR)) {
944 if (byTsr0 != 0) { 945 if (byTsr0 != 0) {
945 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n", 946 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
@@ -958,6 +959,9 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
958 (int)uIdx, byTsr1, byTsr0); 959 (int)uIdx, byTsr1, byTsr0);
959 } 960 }
960 } 961 }
962
963 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
964
961 device_free_tx_buf(pDevice, pTD); 965 device_free_tx_buf(pDevice, pTD);
962 pDevice->iTDUsed[uIdx]--; 966 pDevice->iTDUsed[uIdx]--;
963 } 967 }
@@ -989,10 +993,8 @@ static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
989 skb->len, DMA_TO_DEVICE); 993 skb->len, DMA_TO_DEVICE);
990 } 994 }
991 995
992 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) 996 if (skb)
993 ieee80211_tx_status_irqsafe(pDevice->hw, skb); 997 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
994 else
995 dev_kfree_skb_irq(skb);
996 998
997 pTDInfo->skb_dma = 0; 999 pTDInfo->skb_dma = 0;
998 pTDInfo->skb = NULL; 1000 pTDInfo->skb = NULL;
@@ -1204,14 +1206,6 @@ static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1204 if (dma_idx == TYPE_AC0DMA) 1206 if (dma_idx == TYPE_AC0DMA)
1205 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB; 1207 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
1206 1208
1207 priv->iTDUsed[dma_idx]++;
1208
1209 /* Take ownership */
1210 wmb();
1211 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1212
1213 /* get Next */
1214 wmb();
1215 priv->apCurrTD[dma_idx] = head_td->next; 1209 priv->apCurrTD[dma_idx] = head_td->next;
1216 1210
1217 spin_unlock_irqrestore(&priv->lock, flags); 1211 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1232,11 +1226,18 @@ static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1232 1226
1233 head_td->buff_addr = cpu_to_le32(head_td->pTDInfo->skb_dma); 1227 head_td->buff_addr = cpu_to_le32(head_td->pTDInfo->skb_dma);
1234 1228
1229 /* Poll Transmit the adapter */
1230 wmb();
1231 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1232 wmb(); /* second memory barrier */
1233
1235 if (head_td->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) 1234 if (head_td->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1236 MACvTransmitAC0(priv->PortOffset); 1235 MACvTransmitAC0(priv->PortOffset);
1237 else 1236 else
1238 MACvTransmit0(priv->PortOffset); 1237 MACvTransmit0(priv->PortOffset);
1239 1238
1239 priv->iTDUsed[dma_idx]++;
1240
1240 spin_unlock_irqrestore(&priv->lock, flags); 1241 spin_unlock_irqrestore(&priv->lock, flags);
1241 1242
1242 return 0; 1243 return 0;
@@ -1416,9 +1417,16 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1416 1417
1417 priv->current_aid = conf->aid; 1418 priv->current_aid = conf->aid;
1418 1419
1419 if (changed & BSS_CHANGED_BSSID) 1420 if (changed & BSS_CHANGED_BSSID) {
1421 unsigned long flags;
1422
1423 spin_lock_irqsave(&priv->lock, flags);
1424
1420 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid); 1425 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1421 1426
1427 spin_unlock_irqrestore(&priv->lock, flags);
1428 }
1429
1422 if (changed & BSS_CHANGED_BASIC_RATES) { 1430 if (changed & BSS_CHANGED_BASIC_RATES) {
1423 priv->basic_rates = conf->basic_rates; 1431 priv->basic_rates = conf->basic_rates;
1424 1432
@@ -1477,7 +1485,7 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1477 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) { 1485 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
1478 if (conf->assoc) { 1486 if (conf->assoc) {
1479 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value, 1487 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1480 conf->sync_device_ts, conf->sync_tsf); 1488 conf->sync_tsf);
1481 1489
1482 CARDbSetBeaconPeriod(priv, conf->beacon_int); 1490 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1483 1491
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index f6c2cf8590c4..5c589962a1e8 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -805,10 +805,18 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
805 vnt_schedule_command(priv, WLAN_CMD_SETPOWER); 805 vnt_schedule_command(priv, WLAN_CMD_SETPOWER);
806 } 806 }
807 807
808 if (current_rate > RATE_11M) 808 if (current_rate > RATE_11M) {
809 pkt_type = priv->packet_type; 809 if (info->band == IEEE80211_BAND_5GHZ) {
810 else 810 pkt_type = PK_TYPE_11A;
811 } else {
812 if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
813 pkt_type = PK_TYPE_11GB;
814 else
815 pkt_type = PK_TYPE_11GA;
816 }
817 } else {
811 pkt_type = PK_TYPE_11B; 818 pkt_type = PK_TYPE_11B;
819 }
812 820
813 spin_lock_irqsave(&priv->lock, flags); 821 spin_lock_irqsave(&priv->lock, flags);
814 822
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 34871a628b11..74e6114ff18f 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -230,7 +230,7 @@ int iscsit_access_np(struct iscsi_np *np, struct iscsi_portal_group *tpg)
230 * Here we serialize access across the TIQN+TPG Tuple. 230 * Here we serialize access across the TIQN+TPG Tuple.
231 */ 231 */
232 ret = down_interruptible(&tpg->np_login_sem); 232 ret = down_interruptible(&tpg->np_login_sem);
233 if ((ret != 0) || signal_pending(current)) 233 if (ret != 0)
234 return -1; 234 return -1;
235 235
236 spin_lock_bh(&tpg->tpg_state_lock); 236 spin_lock_bh(&tpg->tpg_state_lock);
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
index 8ce94ff744e6..70d799dfab03 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -346,6 +346,7 @@ static int iscsi_login_zero_tsih_s1(
346 if (IS_ERR(sess->se_sess)) { 346 if (IS_ERR(sess->se_sess)) {
347 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 347 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
348 ISCSI_LOGIN_STATUS_NO_RESOURCES); 348 ISCSI_LOGIN_STATUS_NO_RESOURCES);
349 kfree(sess->sess_ops);
349 kfree(sess); 350 kfree(sess);
350 return -ENOMEM; 351 return -ENOMEM;
351 } 352 }
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c
index e8a240818353..5e3295fe404d 100644
--- a/drivers/target/iscsi/iscsi_target_tpg.c
+++ b/drivers/target/iscsi/iscsi_target_tpg.c
@@ -161,10 +161,7 @@ struct iscsi_portal_group *iscsit_get_tpg_from_np(
161int iscsit_get_tpg( 161int iscsit_get_tpg(
162 struct iscsi_portal_group *tpg) 162 struct iscsi_portal_group *tpg)
163{ 163{
164 int ret; 164 return mutex_lock_interruptible(&tpg->tpg_access_lock);
165
166 ret = mutex_lock_interruptible(&tpg->tpg_access_lock);
167 return ((ret != 0) || signal_pending(current)) ? -1 : 0;
168} 165}
169 166
170void iscsit_put_tpg(struct iscsi_portal_group *tpg) 167void iscsit_put_tpg(struct iscsi_portal_group *tpg)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 75cbde1f7c5b..4f8d4d459aa4 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -704,7 +704,7 @@ target_alua_state_check(struct se_cmd *cmd)
704 704
705 if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE) 705 if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)
706 return 0; 706 return 0;
707 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 707 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
708 return 0; 708 return 0;
709 709
710 if (!port) 710 if (!port)
@@ -2377,7 +2377,7 @@ ssize_t core_alua_store_secondary_write_metadata(
2377 2377
2378int core_setup_alua(struct se_device *dev) 2378int core_setup_alua(struct se_device *dev)
2379{ 2379{
2380 if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV && 2380 if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) &&
2381 !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) { 2381 !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) {
2382 struct t10_alua_lu_gp_member *lu_gp_mem; 2382 struct t10_alua_lu_gp_member *lu_gp_mem;
2383 2383
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index ddaf76a4ac2a..e7b0430a0575 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -212,10 +212,6 @@ static struct config_group *target_core_register_fabric(
212 212
213 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" 213 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
214 " %s\n", tf->tf_group.cg_item.ci_name); 214 " %s\n", tf->tf_group.cg_item.ci_name);
215 /*
216 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
217 */
218 tf->tf_ops.tf_subsys = tf->tf_subsys;
219 tf->tf_fabric = &tf->tf_group.cg_item; 215 tf->tf_fabric = &tf->tf_group.cg_item;
220 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric" 216 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
221 " for %s\n", name); 217 " for %s\n", name);
@@ -291,10 +287,17 @@ static struct configfs_subsystem target_core_fabrics = {
291 }, 287 },
292}; 288};
293 289
294struct configfs_subsystem *target_core_subsystem[] = { 290int target_depend_item(struct config_item *item)
295 &target_core_fabrics, 291{
296 NULL, 292 return configfs_depend_item(&target_core_fabrics, item);
297}; 293}
294EXPORT_SYMBOL(target_depend_item);
295
296void target_undepend_item(struct config_item *item)
297{
298 return configfs_undepend_item(&target_core_fabrics, item);
299}
300EXPORT_SYMBOL(target_undepend_item);
298 301
299/*############################################################################## 302/*##############################################################################
300// Start functions called by external Target Fabrics Modules 303// Start functions called by external Target Fabrics Modules
@@ -467,7 +470,6 @@ int target_register_template(const struct target_core_fabric_ops *fo)
467 * struct target_fabric_configfs->tf_cit_tmpl 470 * struct target_fabric_configfs->tf_cit_tmpl
468 */ 471 */
469 tf->tf_module = fo->module; 472 tf->tf_module = fo->module;
470 tf->tf_subsys = target_core_subsystem[0];
471 snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", fo->name); 473 snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", fo->name);
472 474
473 tf->tf_ops = *fo; 475 tf->tf_ops = *fo;
@@ -809,7 +811,7 @@ static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev,
809{ 811{
810 int ret; 812 int ret;
811 813
812 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 814 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
813 return sprintf(page, "Passthrough\n"); 815 return sprintf(page, "Passthrough\n");
814 816
815 spin_lock(&dev->dev_reservation_lock); 817 spin_lock(&dev->dev_reservation_lock);
@@ -960,7 +962,7 @@ SE_DEV_PR_ATTR_RO(res_pr_type);
960static ssize_t target_core_dev_pr_show_attr_res_type( 962static ssize_t target_core_dev_pr_show_attr_res_type(
961 struct se_device *dev, char *page) 963 struct se_device *dev, char *page)
962{ 964{
963 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 965 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
964 return sprintf(page, "SPC_PASSTHROUGH\n"); 966 return sprintf(page, "SPC_PASSTHROUGH\n");
965 else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 967 else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)
966 return sprintf(page, "SPC2_RESERVATIONS\n"); 968 return sprintf(page, "SPC2_RESERVATIONS\n");
@@ -973,7 +975,7 @@ SE_DEV_PR_ATTR_RO(res_type);
973static ssize_t target_core_dev_pr_show_attr_res_aptpl_active( 975static ssize_t target_core_dev_pr_show_attr_res_aptpl_active(
974 struct se_device *dev, char *page) 976 struct se_device *dev, char *page)
975{ 977{
976 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 978 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
977 return 0; 979 return 0;
978 980
979 return sprintf(page, "APTPL Bit Status: %s\n", 981 return sprintf(page, "APTPL Bit Status: %s\n",
@@ -988,7 +990,7 @@ SE_DEV_PR_ATTR_RO(res_aptpl_active);
988static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata( 990static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata(
989 struct se_device *dev, char *page) 991 struct se_device *dev, char *page)
990{ 992{
991 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 993 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
992 return 0; 994 return 0;
993 995
994 return sprintf(page, "Ready to process PR APTPL metadata..\n"); 996 return sprintf(page, "Ready to process PR APTPL metadata..\n");
@@ -1035,7 +1037,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
1035 u16 port_rpti = 0, tpgt = 0; 1037 u16 port_rpti = 0, tpgt = 0;
1036 u8 type = 0, scope; 1038 u8 type = 0, scope;
1037 1039
1038 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1040 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1039 return 0; 1041 return 0;
1040 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1042 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)
1041 return 0; 1043 return 0;
@@ -2870,7 +2872,7 @@ static int __init target_core_init_configfs(void)
2870{ 2872{
2871 struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL; 2873 struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL;
2872 struct config_group *lu_gp_cg = NULL; 2874 struct config_group *lu_gp_cg = NULL;
2873 struct configfs_subsystem *subsys; 2875 struct configfs_subsystem *subsys = &target_core_fabrics;
2874 struct t10_alua_lu_gp *lu_gp; 2876 struct t10_alua_lu_gp *lu_gp;
2875 int ret; 2877 int ret;
2876 2878
@@ -2878,7 +2880,6 @@ static int __init target_core_init_configfs(void)
2878 " Engine: %s on %s/%s on "UTS_RELEASE"\n", 2880 " Engine: %s on %s/%s on "UTS_RELEASE"\n",
2879 TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); 2881 TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine);
2880 2882
2881 subsys = target_core_subsystem[0];
2882 config_group_init(&subsys->su_group); 2883 config_group_init(&subsys->su_group);
2883 mutex_init(&subsys->su_mutex); 2884 mutex_init(&subsys->su_mutex);
2884 2885
@@ -3008,13 +3009,10 @@ out_global:
3008 3009
3009static void __exit target_core_exit_configfs(void) 3010static void __exit target_core_exit_configfs(void)
3010{ 3011{
3011 struct configfs_subsystem *subsys;
3012 struct config_group *hba_cg, *alua_cg, *lu_gp_cg; 3012 struct config_group *hba_cg, *alua_cg, *lu_gp_cg;
3013 struct config_item *item; 3013 struct config_item *item;
3014 int i; 3014 int i;
3015 3015
3016 subsys = target_core_subsystem[0];
3017
3018 lu_gp_cg = &alua_lu_gps_group; 3016 lu_gp_cg = &alua_lu_gps_group;
3019 for (i = 0; lu_gp_cg->default_groups[i]; i++) { 3017 for (i = 0; lu_gp_cg->default_groups[i]; i++) {
3020 item = &lu_gp_cg->default_groups[i]->cg_item; 3018 item = &lu_gp_cg->default_groups[i]->cg_item;
@@ -3045,8 +3043,8 @@ static void __exit target_core_exit_configfs(void)
3045 * We expect subsys->su_group.default_groups to be released 3043 * We expect subsys->su_group.default_groups to be released
3046 * by configfs subsystem provider logic.. 3044 * by configfs subsystem provider logic..
3047 */ 3045 */
3048 configfs_unregister_subsystem(subsys); 3046 configfs_unregister_subsystem(&target_core_fabrics);
3049 kfree(subsys->su_group.default_groups); 3047 kfree(target_core_fabrics.su_group.default_groups);
3050 3048
3051 core_alua_free_lu_gp(default_lu_gp); 3049 core_alua_free_lu_gp(default_lu_gp);
3052 default_lu_gp = NULL; 3050 default_lu_gp = NULL;
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 7faa6aef9a4d..ce5f768181ff 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -33,6 +33,7 @@
33#include <linux/kthread.h> 33#include <linux/kthread.h>
34#include <linux/in.h> 34#include <linux/in.h>
35#include <linux/export.h> 35#include <linux/export.h>
36#include <asm/unaligned.h>
36#include <net/sock.h> 37#include <net/sock.h>
37#include <net/tcp.h> 38#include <net/tcp.h>
38#include <scsi/scsi.h> 39#include <scsi/scsi.h>
@@ -527,7 +528,7 @@ static void core_export_port(
527 list_add_tail(&port->sep_list, &dev->dev_sep_list); 528 list_add_tail(&port->sep_list, &dev->dev_sep_list);
528 spin_unlock(&dev->se_port_lock); 529 spin_unlock(&dev->se_port_lock);
529 530
530 if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV && 531 if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) &&
531 !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) { 532 !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) {
532 tg_pt_gp_mem = core_alua_allocate_tg_pt_gp_mem(port); 533 tg_pt_gp_mem = core_alua_allocate_tg_pt_gp_mem(port);
533 if (IS_ERR(tg_pt_gp_mem) || !tg_pt_gp_mem) { 534 if (IS_ERR(tg_pt_gp_mem) || !tg_pt_gp_mem) {
@@ -1603,7 +1604,7 @@ int target_configure_device(struct se_device *dev)
1603 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI 1604 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
1604 * passthrough because this is being provided by the backend LLD. 1605 * passthrough because this is being provided by the backend LLD.
1605 */ 1606 */
1606 if (dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) { 1607 if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
1607 strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", 8); 1608 strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", 8);
1608 strncpy(&dev->t10_wwn.model[0], 1609 strncpy(&dev->t10_wwn.model[0],
1609 dev->transport->inquiry_prod, 16); 1610 dev->transport->inquiry_prod, 16);
@@ -1707,3 +1708,76 @@ void core_dev_release_virtual_lun0(void)
1707 target_free_device(g_lun0_dev); 1708 target_free_device(g_lun0_dev);
1708 core_delete_hba(hba); 1709 core_delete_hba(hba);
1709} 1710}
1711
1712/*
1713 * Common CDB parsing for kernel and user passthrough.
1714 */
1715sense_reason_t
1716passthrough_parse_cdb(struct se_cmd *cmd,
1717 sense_reason_t (*exec_cmd)(struct se_cmd *cmd))
1718{
1719 unsigned char *cdb = cmd->t_task_cdb;
1720
1721 /*
1722 * Clear a lun set in the cdb if the initiator talking to use spoke
1723 * and old standards version, as we can't assume the underlying device
1724 * won't choke up on it.
1725 */
1726 switch (cdb[0]) {
1727 case READ_10: /* SBC - RDProtect */
1728 case READ_12: /* SBC - RDProtect */
1729 case READ_16: /* SBC - RDProtect */
1730 case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
1731 case VERIFY: /* SBC - VRProtect */
1732 case VERIFY_16: /* SBC - VRProtect */
1733 case WRITE_VERIFY: /* SBC - VRProtect */
1734 case WRITE_VERIFY_12: /* SBC - VRProtect */
1735 case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
1736 break;
1737 default:
1738 cdb[1] &= 0x1f; /* clear logical unit number */
1739 break;
1740 }
1741
1742 /*
1743 * For REPORT LUNS we always need to emulate the response, for everything
1744 * else, pass it up.
1745 */
1746 if (cdb[0] == REPORT_LUNS) {
1747 cmd->execute_cmd = spc_emulate_report_luns;
1748 return TCM_NO_SENSE;
1749 }
1750
1751 /* Set DATA_CDB flag for ops that should have it */
1752 switch (cdb[0]) {
1753 case READ_6:
1754 case READ_10:
1755 case READ_12:
1756 case READ_16:
1757 case WRITE_6:
1758 case WRITE_10:
1759 case WRITE_12:
1760 case WRITE_16:
1761 case WRITE_VERIFY:
1762 case WRITE_VERIFY_12:
1763 case 0x8e: /* WRITE_VERIFY_16 */
1764 case COMPARE_AND_WRITE:
1765 case XDWRITEREAD_10:
1766 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
1767 break;
1768 case VARIABLE_LENGTH_CMD:
1769 switch (get_unaligned_be16(&cdb[8])) {
1770 case READ_32:
1771 case WRITE_32:
1772 case 0x0c: /* WRITE_VERIFY_32 */
1773 case XDWRITEREAD_32:
1774 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
1775 break;
1776 }
1777 }
1778
1779 cmd->execute_cmd = exec_cmd;
1780
1781 return TCM_NO_SENSE;
1782}
1783EXPORT_SYMBOL(passthrough_parse_cdb);
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index f7e6e51aed36..3f27bfd816d8 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -958,7 +958,6 @@ static struct se_subsystem_api fileio_template = {
958 .inquiry_prod = "FILEIO", 958 .inquiry_prod = "FILEIO",
959 .inquiry_rev = FD_VERSION, 959 .inquiry_rev = FD_VERSION,
960 .owner = THIS_MODULE, 960 .owner = THIS_MODULE,
961 .transport_type = TRANSPORT_PLUGIN_VHBA_PDEV,
962 .attach_hba = fd_attach_hba, 961 .attach_hba = fd_attach_hba,
963 .detach_hba = fd_detach_hba, 962 .detach_hba = fd_detach_hba,
964 .alloc_device = fd_alloc_device, 963 .alloc_device = fd_alloc_device,
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 1b7947c2510f..8c965683789f 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -904,7 +904,6 @@ static struct se_subsystem_api iblock_template = {
904 .inquiry_prod = "IBLOCK", 904 .inquiry_prod = "IBLOCK",
905 .inquiry_rev = IBLOCK_VERSION, 905 .inquiry_rev = IBLOCK_VERSION,
906 .owner = THIS_MODULE, 906 .owner = THIS_MODULE,
907 .transport_type = TRANSPORT_PLUGIN_VHBA_PDEV,
908 .attach_hba = iblock_attach_hba, 907 .attach_hba = iblock_attach_hba,
909 .detach_hba = iblock_detach_hba, 908 .detach_hba = iblock_detach_hba,
910 .alloc_device = iblock_alloc_device, 909 .alloc_device = iblock_alloc_device,
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 874a9bc988d8..68bd7f5d9f73 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -4,9 +4,6 @@
4/* target_core_alua.c */ 4/* target_core_alua.c */
5extern struct t10_alua_lu_gp *default_lu_gp; 5extern struct t10_alua_lu_gp *default_lu_gp;
6 6
7/* target_core_configfs.c */
8extern struct configfs_subsystem *target_core_subsystem[];
9
10/* target_core_device.c */ 7/* target_core_device.c */
11extern struct mutex g_device_mutex; 8extern struct mutex g_device_mutex;
12extern struct list_head g_device_list; 9extern struct list_head g_device_list;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index c1aa9655e96e..a15411c79ae9 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1367,41 +1367,26 @@ void core_scsi3_free_all_registrations(
1367 1367
1368static int core_scsi3_tpg_depend_item(struct se_portal_group *tpg) 1368static int core_scsi3_tpg_depend_item(struct se_portal_group *tpg)
1369{ 1369{
1370 return configfs_depend_item(tpg->se_tpg_tfo->tf_subsys, 1370 return target_depend_item(&tpg->tpg_group.cg_item);
1371 &tpg->tpg_group.cg_item);
1372} 1371}
1373 1372
1374static void core_scsi3_tpg_undepend_item(struct se_portal_group *tpg) 1373static void core_scsi3_tpg_undepend_item(struct se_portal_group *tpg)
1375{ 1374{
1376 configfs_undepend_item(tpg->se_tpg_tfo->tf_subsys, 1375 target_undepend_item(&tpg->tpg_group.cg_item);
1377 &tpg->tpg_group.cg_item);
1378
1379 atomic_dec_mb(&tpg->tpg_pr_ref_count); 1376 atomic_dec_mb(&tpg->tpg_pr_ref_count);
1380} 1377}
1381 1378
1382static int core_scsi3_nodeacl_depend_item(struct se_node_acl *nacl) 1379static int core_scsi3_nodeacl_depend_item(struct se_node_acl *nacl)
1383{ 1380{
1384 struct se_portal_group *tpg = nacl->se_tpg;
1385
1386 if (nacl->dynamic_node_acl) 1381 if (nacl->dynamic_node_acl)
1387 return 0; 1382 return 0;
1388 1383 return target_depend_item(&nacl->acl_group.cg_item);
1389 return configfs_depend_item(tpg->se_tpg_tfo->tf_subsys,
1390 &nacl->acl_group.cg_item);
1391} 1384}
1392 1385
1393static void core_scsi3_nodeacl_undepend_item(struct se_node_acl *nacl) 1386static void core_scsi3_nodeacl_undepend_item(struct se_node_acl *nacl)
1394{ 1387{
1395 struct se_portal_group *tpg = nacl->se_tpg; 1388 if (!nacl->dynamic_node_acl)
1396 1389 target_undepend_item(&nacl->acl_group.cg_item);
1397 if (nacl->dynamic_node_acl) {
1398 atomic_dec_mb(&nacl->acl_pr_ref_count);
1399 return;
1400 }
1401
1402 configfs_undepend_item(tpg->se_tpg_tfo->tf_subsys,
1403 &nacl->acl_group.cg_item);
1404
1405 atomic_dec_mb(&nacl->acl_pr_ref_count); 1390 atomic_dec_mb(&nacl->acl_pr_ref_count);
1406} 1391}
1407 1392
@@ -1419,8 +1404,7 @@ static int core_scsi3_lunacl_depend_item(struct se_dev_entry *se_deve)
1419 nacl = lun_acl->se_lun_nacl; 1404 nacl = lun_acl->se_lun_nacl;
1420 tpg = nacl->se_tpg; 1405 tpg = nacl->se_tpg;
1421 1406
1422 return configfs_depend_item(tpg->se_tpg_tfo->tf_subsys, 1407 return target_depend_item(&lun_acl->se_lun_group.cg_item);
1423 &lun_acl->se_lun_group.cg_item);
1424} 1408}
1425 1409
1426static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) 1410static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
@@ -1438,9 +1422,7 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
1438 nacl = lun_acl->se_lun_nacl; 1422 nacl = lun_acl->se_lun_nacl;
1439 tpg = nacl->se_tpg; 1423 tpg = nacl->se_tpg;
1440 1424
1441 configfs_undepend_item(tpg->se_tpg_tfo->tf_subsys, 1425 target_undepend_item(&lun_acl->se_lun_group.cg_item);
1442 &lun_acl->se_lun_group.cg_item);
1443
1444 atomic_dec_mb(&se_deve->pr_ref_count); 1426 atomic_dec_mb(&se_deve->pr_ref_count);
1445} 1427}
1446 1428
@@ -4111,7 +4093,7 @@ target_check_reservation(struct se_cmd *cmd)
4111 return 0; 4093 return 0;
4112 if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE) 4094 if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)
4113 return 0; 4095 return 0;
4114 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 4096 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
4115 return 0; 4097 return 0;
4116 4098
4117 spin_lock(&dev->dev_reservation_lock); 4099 spin_lock(&dev->dev_reservation_lock);
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index f6c954c4635f..ecc5eaef13d6 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -521,6 +521,7 @@ static int pscsi_configure_device(struct se_device *dev)
521 " pdv_host_id: %d\n", pdv->pdv_host_id); 521 " pdv_host_id: %d\n", pdv->pdv_host_id);
522 return -EINVAL; 522 return -EINVAL;
523 } 523 }
524 pdv->pdv_lld_host = sh;
524 } 525 }
525 } else { 526 } else {
526 if (phv->phv_mode == PHV_VIRTUAL_HOST_ID) { 527 if (phv->phv_mode == PHV_VIRTUAL_HOST_ID) {
@@ -603,6 +604,8 @@ static void pscsi_free_device(struct se_device *dev)
603 if ((phv->phv_mode == PHV_LLD_SCSI_HOST_NO) && 604 if ((phv->phv_mode == PHV_LLD_SCSI_HOST_NO) &&
604 (phv->phv_lld_host != NULL)) 605 (phv->phv_lld_host != NULL))
605 scsi_host_put(phv->phv_lld_host); 606 scsi_host_put(phv->phv_lld_host);
607 else if (pdv->pdv_lld_host)
608 scsi_host_put(pdv->pdv_lld_host);
606 609
607 if ((sd->type == TYPE_DISK) || (sd->type == TYPE_ROM)) 610 if ((sd->type == TYPE_DISK) || (sd->type == TYPE_ROM))
608 scsi_device_put(sd); 611 scsi_device_put(sd);
@@ -970,64 +973,13 @@ fail:
970 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 973 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
971} 974}
972 975
973/*
974 * Clear a lun set in the cdb if the initiator talking to use spoke
975 * and old standards version, as we can't assume the underlying device
976 * won't choke up on it.
977 */
978static inline void pscsi_clear_cdb_lun(unsigned char *cdb)
979{
980 switch (cdb[0]) {
981 case READ_10: /* SBC - RDProtect */
982 case READ_12: /* SBC - RDProtect */
983 case READ_16: /* SBC - RDProtect */
984 case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
985 case VERIFY: /* SBC - VRProtect */
986 case VERIFY_16: /* SBC - VRProtect */
987 case WRITE_VERIFY: /* SBC - VRProtect */
988 case WRITE_VERIFY_12: /* SBC - VRProtect */
989 case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
990 break;
991 default:
992 cdb[1] &= 0x1f; /* clear logical unit number */
993 break;
994 }
995}
996
997static sense_reason_t 976static sense_reason_t
998pscsi_parse_cdb(struct se_cmd *cmd) 977pscsi_parse_cdb(struct se_cmd *cmd)
999{ 978{
1000 unsigned char *cdb = cmd->t_task_cdb;
1001
1002 if (cmd->se_cmd_flags & SCF_BIDI) 979 if (cmd->se_cmd_flags & SCF_BIDI)
1003 return TCM_UNSUPPORTED_SCSI_OPCODE; 980 return TCM_UNSUPPORTED_SCSI_OPCODE;
1004 981
1005 pscsi_clear_cdb_lun(cdb); 982 return passthrough_parse_cdb(cmd, pscsi_execute_cmd);
1006
1007 /*
1008 * For REPORT LUNS we always need to emulate the response, for everything
1009 * else the default for pSCSI is to pass the command to the underlying
1010 * LLD / physical hardware.
1011 */
1012 switch (cdb[0]) {
1013 case REPORT_LUNS:
1014 cmd->execute_cmd = spc_emulate_report_luns;
1015 return 0;
1016 case READ_6:
1017 case READ_10:
1018 case READ_12:
1019 case READ_16:
1020 case WRITE_6:
1021 case WRITE_10:
1022 case WRITE_12:
1023 case WRITE_16:
1024 case WRITE_VERIFY:
1025 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
1026 /* FALLTHROUGH*/
1027 default:
1028 cmd->execute_cmd = pscsi_execute_cmd;
1029 return 0;
1030 }
1031} 983}
1032 984
1033static sense_reason_t 985static sense_reason_t
@@ -1189,7 +1141,7 @@ static struct configfs_attribute *pscsi_backend_dev_attrs[] = {
1189static struct se_subsystem_api pscsi_template = { 1141static struct se_subsystem_api pscsi_template = {
1190 .name = "pscsi", 1142 .name = "pscsi",
1191 .owner = THIS_MODULE, 1143 .owner = THIS_MODULE,
1192 .transport_type = TRANSPORT_PLUGIN_PHBA_PDEV, 1144 .transport_flags = TRANSPORT_FLAG_PASSTHROUGH,
1193 .attach_hba = pscsi_attach_hba, 1145 .attach_hba = pscsi_attach_hba,
1194 .detach_hba = pscsi_detach_hba, 1146 .detach_hba = pscsi_detach_hba,
1195 .pmode_enable_hba = pscsi_pmode_enable_hba, 1147 .pmode_enable_hba = pscsi_pmode_enable_hba,
diff --git a/drivers/target/target_core_pscsi.h b/drivers/target/target_core_pscsi.h
index 1bd757dff8ee..820d3052b775 100644
--- a/drivers/target/target_core_pscsi.h
+++ b/drivers/target/target_core_pscsi.h
@@ -45,6 +45,7 @@ struct pscsi_dev_virt {
45 int pdv_lun_id; 45 int pdv_lun_id;
46 struct block_device *pdv_bd; 46 struct block_device *pdv_bd;
47 struct scsi_device *pdv_sd; 47 struct scsi_device *pdv_sd;
48 struct Scsi_Host *pdv_lld_host;
48} ____cacheline_aligned; 49} ____cacheline_aligned;
49 50
50typedef enum phv_modes { 51typedef enum phv_modes {
diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index a263bf5fab8d..d16489b6a1a4 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -733,7 +733,6 @@ static struct se_subsystem_api rd_mcp_template = {
733 .name = "rd_mcp", 733 .name = "rd_mcp",
734 .inquiry_prod = "RAMDISK-MCP", 734 .inquiry_prod = "RAMDISK-MCP",
735 .inquiry_rev = RD_MCP_VERSION, 735 .inquiry_rev = RD_MCP_VERSION,
736 .transport_type = TRANSPORT_PLUGIN_VHBA_VDEV,
737 .attach_hba = rd_attach_hba, 736 .attach_hba = rd_attach_hba,
738 .detach_hba = rd_detach_hba, 737 .detach_hba = rd_detach_hba,
739 .alloc_device = rd_alloc_device, 738 .alloc_device = rd_alloc_device,
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 8855781ac653..733824e3825f 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -568,7 +568,7 @@ sbc_compare_and_write(struct se_cmd *cmd)
568 * comparision using SGLs at cmd->t_bidi_data_sg.. 568 * comparision using SGLs at cmd->t_bidi_data_sg..
569 */ 569 */
570 rc = down_interruptible(&dev->caw_sem); 570 rc = down_interruptible(&dev->caw_sem);
571 if ((rc != 0) || signal_pending(current)) { 571 if (rc != 0) {
572 cmd->transport_complete_callback = NULL; 572 cmd->transport_complete_callback = NULL;
573 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 573 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
574 } 574 }
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 3fe5cb240b6f..675f2d9d1f14 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1196,7 +1196,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
1196 * Check if SAM Task Attribute emulation is enabled for this 1196 * Check if SAM Task Attribute emulation is enabled for this
1197 * struct se_device storage object 1197 * struct se_device storage object
1198 */ 1198 */
1199 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1199 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1200 return 0; 1200 return 0;
1201 1201
1202 if (cmd->sam_task_attr == TCM_ACA_TAG) { 1202 if (cmd->sam_task_attr == TCM_ACA_TAG) {
@@ -1770,7 +1770,7 @@ static int target_write_prot_action(struct se_cmd *cmd)
1770 sectors, 0, NULL, 0); 1770 sectors, 0, NULL, 0);
1771 if (unlikely(cmd->pi_err)) { 1771 if (unlikely(cmd->pi_err)) {
1772 spin_lock_irq(&cmd->t_state_lock); 1772 spin_lock_irq(&cmd->t_state_lock);
1773 cmd->transport_state &= ~CMD_T_BUSY|CMD_T_SENT; 1773 cmd->transport_state &= ~(CMD_T_BUSY|CMD_T_SENT);
1774 spin_unlock_irq(&cmd->t_state_lock); 1774 spin_unlock_irq(&cmd->t_state_lock);
1775 transport_generic_request_failure(cmd, cmd->pi_err); 1775 transport_generic_request_failure(cmd, cmd->pi_err);
1776 return -1; 1776 return -1;
@@ -1787,7 +1787,7 @@ static bool target_handle_task_attr(struct se_cmd *cmd)
1787{ 1787{
1788 struct se_device *dev = cmd->se_dev; 1788 struct se_device *dev = cmd->se_dev;
1789 1789
1790 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1790 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1791 return false; 1791 return false;
1792 1792
1793 /* 1793 /*
@@ -1868,7 +1868,7 @@ void target_execute_cmd(struct se_cmd *cmd)
1868 1868
1869 if (target_handle_task_attr(cmd)) { 1869 if (target_handle_task_attr(cmd)) {
1870 spin_lock_irq(&cmd->t_state_lock); 1870 spin_lock_irq(&cmd->t_state_lock);
1871 cmd->transport_state &= ~CMD_T_BUSY|CMD_T_SENT; 1871 cmd->transport_state &= ~(CMD_T_BUSY | CMD_T_SENT);
1872 spin_unlock_irq(&cmd->t_state_lock); 1872 spin_unlock_irq(&cmd->t_state_lock);
1873 return; 1873 return;
1874 } 1874 }
@@ -1912,7 +1912,7 @@ static void transport_complete_task_attr(struct se_cmd *cmd)
1912{ 1912{
1913 struct se_device *dev = cmd->se_dev; 1913 struct se_device *dev = cmd->se_dev;
1914 1914
1915 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1915 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1916 return; 1916 return;
1917 1917
1918 if (cmd->sam_task_attr == TCM_SIMPLE_TAG) { 1918 if (cmd->sam_task_attr == TCM_SIMPLE_TAG) {
@@ -1957,8 +1957,7 @@ static void transport_complete_qf(struct se_cmd *cmd)
1957 case DMA_TO_DEVICE: 1957 case DMA_TO_DEVICE:
1958 if (cmd->se_cmd_flags & SCF_BIDI) { 1958 if (cmd->se_cmd_flags & SCF_BIDI) {
1959 ret = cmd->se_tfo->queue_data_in(cmd); 1959 ret = cmd->se_tfo->queue_data_in(cmd);
1960 if (ret < 0) 1960 break;
1961 break;
1962 } 1961 }
1963 /* Fall through for DMA_TO_DEVICE */ 1962 /* Fall through for DMA_TO_DEVICE */
1964 case DMA_NONE: 1963 case DMA_NONE:
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index dbc872a6c981..07d2996d8c1f 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -71,13 +71,6 @@ struct tcmu_hba {
71 u32 host_id; 71 u32 host_id;
72}; 72};
73 73
74/* User wants all cmds or just some */
75enum passthru_level {
76 TCMU_PASS_ALL = 0,
77 TCMU_PASS_IO,
78 TCMU_PASS_INVALID,
79};
80
81#define TCMU_CONFIG_LEN 256 74#define TCMU_CONFIG_LEN 256
82 75
83struct tcmu_dev { 76struct tcmu_dev {
@@ -89,7 +82,6 @@ struct tcmu_dev {
89#define TCMU_DEV_BIT_OPEN 0 82#define TCMU_DEV_BIT_OPEN 0
90#define TCMU_DEV_BIT_BROKEN 1 83#define TCMU_DEV_BIT_BROKEN 1
91 unsigned long flags; 84 unsigned long flags;
92 enum passthru_level pass_level;
93 85
94 struct uio_info uio_info; 86 struct uio_info uio_info;
95 87
@@ -683,8 +675,6 @@ static struct se_device *tcmu_alloc_device(struct se_hba *hba, const char *name)
683 setup_timer(&udev->timeout, tcmu_device_timedout, 675 setup_timer(&udev->timeout, tcmu_device_timedout,
684 (unsigned long)udev); 676 (unsigned long)udev);
685 677
686 udev->pass_level = TCMU_PASS_ALL;
687
688 return &udev->se_dev; 678 return &udev->se_dev;
689} 679}
690 680
@@ -948,13 +938,13 @@ static void tcmu_free_device(struct se_device *dev)
948} 938}
949 939
950enum { 940enum {
951 Opt_dev_config, Opt_dev_size, Opt_err, Opt_pass_level, 941 Opt_dev_config, Opt_dev_size, Opt_hw_block_size, Opt_err,
952}; 942};
953 943
954static match_table_t tokens = { 944static match_table_t tokens = {
955 {Opt_dev_config, "dev_config=%s"}, 945 {Opt_dev_config, "dev_config=%s"},
956 {Opt_dev_size, "dev_size=%u"}, 946 {Opt_dev_size, "dev_size=%u"},
957 {Opt_pass_level, "pass_level=%u"}, 947 {Opt_hw_block_size, "hw_block_size=%u"},
958 {Opt_err, NULL} 948 {Opt_err, NULL}
959}; 949};
960 950
@@ -965,7 +955,7 @@ static ssize_t tcmu_set_configfs_dev_params(struct se_device *dev,
965 char *orig, *ptr, *opts, *arg_p; 955 char *orig, *ptr, *opts, *arg_p;
966 substring_t args[MAX_OPT_ARGS]; 956 substring_t args[MAX_OPT_ARGS];
967 int ret = 0, token; 957 int ret = 0, token;
968 int arg; 958 unsigned long tmp_ul;
969 959
970 opts = kstrdup(page, GFP_KERNEL); 960 opts = kstrdup(page, GFP_KERNEL);
971 if (!opts) 961 if (!opts)
@@ -998,15 +988,23 @@ static ssize_t tcmu_set_configfs_dev_params(struct se_device *dev,
998 if (ret < 0) 988 if (ret < 0)
999 pr_err("kstrtoul() failed for dev_size=\n"); 989 pr_err("kstrtoul() failed for dev_size=\n");
1000 break; 990 break;
1001 case Opt_pass_level: 991 case Opt_hw_block_size:
1002 match_int(args, &arg); 992 arg_p = match_strdup(&args[0]);
1003 if (arg >= TCMU_PASS_INVALID) { 993 if (!arg_p) {
1004 pr_warn("TCMU: Invalid pass_level: %d\n", arg); 994 ret = -ENOMEM;
1005 break; 995 break;
1006 } 996 }
1007 997 ret = kstrtoul(arg_p, 0, &tmp_ul);
1008 pr_debug("TCMU: Setting pass_level to %d\n", arg); 998 kfree(arg_p);
1009 udev->pass_level = arg; 999 if (ret < 0) {
1000 pr_err("kstrtoul() failed for hw_block_size=\n");
1001 break;
1002 }
1003 if (!tmp_ul) {
1004 pr_err("hw_block_size must be nonzero\n");
1005 break;
1006 }
1007 dev->dev_attrib.hw_block_size = tmp_ul;
1010 break; 1008 break;
1011 default: 1009 default:
1012 break; 1010 break;
@@ -1024,8 +1022,7 @@ static ssize_t tcmu_show_configfs_dev_params(struct se_device *dev, char *b)
1024 1022
1025 bl = sprintf(b + bl, "Config: %s ", 1023 bl = sprintf(b + bl, "Config: %s ",
1026 udev->dev_config[0] ? udev->dev_config : "NULL"); 1024 udev->dev_config[0] ? udev->dev_config : "NULL");
1027 bl += sprintf(b + bl, "Size: %zu PassLevel: %u\n", 1025 bl += sprintf(b + bl, "Size: %zu\n", udev->dev_size);
1028 udev->dev_size, udev->pass_level);
1029 1026
1030 return bl; 1027 return bl;
1031} 1028}
@@ -1039,20 +1036,6 @@ static sector_t tcmu_get_blocks(struct se_device *dev)
1039} 1036}
1040 1037
1041static sense_reason_t 1038static sense_reason_t
1042tcmu_execute_rw(struct se_cmd *se_cmd, struct scatterlist *sgl, u32 sgl_nents,
1043 enum dma_data_direction data_direction)
1044{
1045 int ret;
1046
1047 ret = tcmu_queue_cmd(se_cmd);
1048
1049 if (ret != 0)
1050 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
1051 else
1052 return TCM_NO_SENSE;
1053}
1054
1055static sense_reason_t
1056tcmu_pass_op(struct se_cmd *se_cmd) 1039tcmu_pass_op(struct se_cmd *se_cmd)
1057{ 1040{
1058 int ret = tcmu_queue_cmd(se_cmd); 1041 int ret = tcmu_queue_cmd(se_cmd);
@@ -1063,91 +1046,29 @@ tcmu_pass_op(struct se_cmd *se_cmd)
1063 return TCM_NO_SENSE; 1046 return TCM_NO_SENSE;
1064} 1047}
1065 1048
1066static struct sbc_ops tcmu_sbc_ops = {
1067 .execute_rw = tcmu_execute_rw,
1068 .execute_sync_cache = tcmu_pass_op,
1069 .execute_write_same = tcmu_pass_op,
1070 .execute_write_same_unmap = tcmu_pass_op,
1071 .execute_unmap = tcmu_pass_op,
1072};
1073
1074static sense_reason_t 1049static sense_reason_t
1075tcmu_parse_cdb(struct se_cmd *cmd) 1050tcmu_parse_cdb(struct se_cmd *cmd)
1076{ 1051{
1077 unsigned char *cdb = cmd->t_task_cdb; 1052 return passthrough_parse_cdb(cmd, tcmu_pass_op);
1078 struct tcmu_dev *udev = TCMU_DEV(cmd->se_dev);
1079 sense_reason_t ret;
1080
1081 switch (udev->pass_level) {
1082 case TCMU_PASS_ALL:
1083 /* We're just like pscsi, then */
1084 /*
1085 * For REPORT LUNS we always need to emulate the response, for everything
1086 * else, pass it up.
1087 */
1088 switch (cdb[0]) {
1089 case REPORT_LUNS:
1090 cmd->execute_cmd = spc_emulate_report_luns;
1091 break;
1092 case READ_6:
1093 case READ_10:
1094 case READ_12:
1095 case READ_16:
1096 case WRITE_6:
1097 case WRITE_10:
1098 case WRITE_12:
1099 case WRITE_16:
1100 case WRITE_VERIFY:
1101 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
1102 /* FALLTHROUGH */
1103 default:
1104 cmd->execute_cmd = tcmu_pass_op;
1105 }
1106 ret = TCM_NO_SENSE;
1107 break;
1108 case TCMU_PASS_IO:
1109 ret = sbc_parse_cdb(cmd, &tcmu_sbc_ops);
1110 break;
1111 default:
1112 pr_err("Unknown tcm-user pass level %d\n", udev->pass_level);
1113 ret = TCM_CHECK_CONDITION_ABORT_CMD;
1114 }
1115
1116 return ret;
1117} 1053}
1118 1054
1119DEF_TB_DEFAULT_ATTRIBS(tcmu); 1055DEF_TB_DEV_ATTRIB_RO(tcmu, hw_pi_prot_type);
1056TB_DEV_ATTR_RO(tcmu, hw_pi_prot_type);
1057
1058DEF_TB_DEV_ATTRIB_RO(tcmu, hw_block_size);
1059TB_DEV_ATTR_RO(tcmu, hw_block_size);
1060
1061DEF_TB_DEV_ATTRIB_RO(tcmu, hw_max_sectors);
1062TB_DEV_ATTR_RO(tcmu, hw_max_sectors);
1063
1064DEF_TB_DEV_ATTRIB_RO(tcmu, hw_queue_depth);
1065TB_DEV_ATTR_RO(tcmu, hw_queue_depth);
1120 1066
1121static struct configfs_attribute *tcmu_backend_dev_attrs[] = { 1067static struct configfs_attribute *tcmu_backend_dev_attrs[] = {
1122 &tcmu_dev_attrib_emulate_model_alias.attr,
1123 &tcmu_dev_attrib_emulate_dpo.attr,
1124 &tcmu_dev_attrib_emulate_fua_write.attr,
1125 &tcmu_dev_attrib_emulate_fua_read.attr,
1126 &tcmu_dev_attrib_emulate_write_cache.attr,
1127 &tcmu_dev_attrib_emulate_ua_intlck_ctrl.attr,
1128 &tcmu_dev_attrib_emulate_tas.attr,
1129 &tcmu_dev_attrib_emulate_tpu.attr,
1130 &tcmu_dev_attrib_emulate_tpws.attr,
1131 &tcmu_dev_attrib_emulate_caw.attr,
1132 &tcmu_dev_attrib_emulate_3pc.attr,
1133 &tcmu_dev_attrib_pi_prot_type.attr,
1134 &tcmu_dev_attrib_hw_pi_prot_type.attr, 1068 &tcmu_dev_attrib_hw_pi_prot_type.attr,
1135 &tcmu_dev_attrib_pi_prot_format.attr,
1136 &tcmu_dev_attrib_enforce_pr_isids.attr,
1137 &tcmu_dev_attrib_is_nonrot.attr,
1138 &tcmu_dev_attrib_emulate_rest_reord.attr,
1139 &tcmu_dev_attrib_force_pr_aptpl.attr,
1140 &tcmu_dev_attrib_hw_block_size.attr, 1069 &tcmu_dev_attrib_hw_block_size.attr,
1141 &tcmu_dev_attrib_block_size.attr,
1142 &tcmu_dev_attrib_hw_max_sectors.attr, 1070 &tcmu_dev_attrib_hw_max_sectors.attr,
1143 &tcmu_dev_attrib_optimal_sectors.attr,
1144 &tcmu_dev_attrib_hw_queue_depth.attr, 1071 &tcmu_dev_attrib_hw_queue_depth.attr,
1145 &tcmu_dev_attrib_queue_depth.attr,
1146 &tcmu_dev_attrib_max_unmap_lba_count.attr,
1147 &tcmu_dev_attrib_max_unmap_block_desc_count.attr,
1148 &tcmu_dev_attrib_unmap_granularity.attr,
1149 &tcmu_dev_attrib_unmap_granularity_alignment.attr,
1150 &tcmu_dev_attrib_max_write_same_len.attr,
1151 NULL, 1072 NULL,
1152}; 1073};
1153 1074
@@ -1156,7 +1077,7 @@ static struct se_subsystem_api tcmu_template = {
1156 .inquiry_prod = "USER", 1077 .inquiry_prod = "USER",
1157 .inquiry_rev = TCMU_VERSION, 1078 .inquiry_rev = TCMU_VERSION,
1158 .owner = THIS_MODULE, 1079 .owner = THIS_MODULE,
1159 .transport_type = TRANSPORT_PLUGIN_VHBA_PDEV, 1080 .transport_flags = TRANSPORT_FLAG_PASSTHROUGH,
1160 .attach_hba = tcmu_attach_hba, 1081 .attach_hba = tcmu_attach_hba,
1161 .detach_hba = tcmu_detach_hba, 1082 .detach_hba = tcmu_detach_hba,
1162 .alloc_device = tcmu_alloc_device, 1083 .alloc_device = tcmu_alloc_device,
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index a600ff15dcfd..8fd680ac941b 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -58,7 +58,6 @@ static int target_xcopy_locate_se_dev_e4(struct se_cmd *se_cmd, struct xcopy_op
58 bool src) 58 bool src)
59{ 59{
60 struct se_device *se_dev; 60 struct se_device *se_dev;
61 struct configfs_subsystem *subsys = target_core_subsystem[0];
62 unsigned char tmp_dev_wwn[XCOPY_NAA_IEEE_REGEX_LEN], *dev_wwn; 61 unsigned char tmp_dev_wwn[XCOPY_NAA_IEEE_REGEX_LEN], *dev_wwn;
63 int rc; 62 int rc;
64 63
@@ -90,8 +89,7 @@ static int target_xcopy_locate_se_dev_e4(struct se_cmd *se_cmd, struct xcopy_op
90 " se_dev\n", xop->src_dev); 89 " se_dev\n", xop->src_dev);
91 } 90 }
92 91
93 rc = configfs_depend_item(subsys, 92 rc = target_depend_item(&se_dev->dev_group.cg_item);
94 &se_dev->dev_group.cg_item);
95 if (rc != 0) { 93 if (rc != 0) {
96 pr_err("configfs_depend_item attempt failed:" 94 pr_err("configfs_depend_item attempt failed:"
97 " %d for se_dev: %p\n", rc, se_dev); 95 " %d for se_dev: %p\n", rc, se_dev);
@@ -99,8 +97,8 @@ static int target_xcopy_locate_se_dev_e4(struct se_cmd *se_cmd, struct xcopy_op
99 return rc; 97 return rc;
100 } 98 }
101 99
102 pr_debug("Called configfs_depend_item for subsys: %p se_dev: %p" 100 pr_debug("Called configfs_depend_item for se_dev: %p"
103 " se_dev->se_dev_group: %p\n", subsys, se_dev, 101 " se_dev->se_dev_group: %p\n", se_dev,
104 &se_dev->dev_group); 102 &se_dev->dev_group);
105 103
106 mutex_unlock(&g_device_mutex); 104 mutex_unlock(&g_device_mutex);
@@ -373,7 +371,6 @@ static int xcopy_pt_get_cmd_state(struct se_cmd *se_cmd)
373 371
374static void xcopy_pt_undepend_remotedev(struct xcopy_op *xop) 372static void xcopy_pt_undepend_remotedev(struct xcopy_op *xop)
375{ 373{
376 struct configfs_subsystem *subsys = target_core_subsystem[0];
377 struct se_device *remote_dev; 374 struct se_device *remote_dev;
378 375
379 if (xop->op_origin == XCOL_SOURCE_RECV_OP) 376 if (xop->op_origin == XCOL_SOURCE_RECV_OP)
@@ -381,11 +378,11 @@ static void xcopy_pt_undepend_remotedev(struct xcopy_op *xop)
381 else 378 else
382 remote_dev = xop->src_dev; 379 remote_dev = xop->src_dev;
383 380
384 pr_debug("Calling configfs_undepend_item for subsys: %p" 381 pr_debug("Calling configfs_undepend_item for"
385 " remote_dev: %p remote_dev->dev_group: %p\n", 382 " remote_dev: %p remote_dev->dev_group: %p\n",
386 subsys, remote_dev, &remote_dev->dev_group.cg_item); 383 remote_dev, &remote_dev->dev_group.cg_item);
387 384
388 configfs_undepend_item(subsys, &remote_dev->dev_group.cg_item); 385 target_undepend_item(&remote_dev->dev_group.cg_item);
389} 386}
390 387
391static void xcopy_pt_release_cmd(struct se_cmd *se_cmd) 388static void xcopy_pt_release_cmd(struct se_cmd *se_cmd)
diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index c2556cf5186b..01255fd65135 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -224,9 +224,9 @@ static const struct armada_thermal_data armada380_data = {
224 .is_valid_shift = 10, 224 .is_valid_shift = 10,
225 .temp_shift = 0, 225 .temp_shift = 0,
226 .temp_mask = 0x3ff, 226 .temp_mask = 0x3ff,
227 .coef_b = 1169498786UL, 227 .coef_b = 2931108200UL,
228 .coef_m = 2000000UL, 228 .coef_m = 5000000UL,
229 .coef_div = 4289, 229 .coef_div = 10502,
230 .inverted = true, 230 .inverted = true,
231}; 231};
232 232
diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 12623bc02f46..725718e97a0b 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -206,51 +206,57 @@ static void find_target_mwait(void)
206 206
207} 207}
208 208
209struct pkg_cstate_info {
210 bool skip;
211 int msr_index;
212 int cstate_id;
213};
214
215#define PKG_CSTATE_INIT(id) { \
216 .msr_index = MSR_PKG_C##id##_RESIDENCY, \
217 .cstate_id = id \
218 }
219
220static struct pkg_cstate_info pkg_cstates[] = {
221 PKG_CSTATE_INIT(2),
222 PKG_CSTATE_INIT(3),
223 PKG_CSTATE_INIT(6),
224 PKG_CSTATE_INIT(7),
225 PKG_CSTATE_INIT(8),
226 PKG_CSTATE_INIT(9),
227 PKG_CSTATE_INIT(10),
228 {NULL},
229};
230
209static bool has_pkg_state_counter(void) 231static bool has_pkg_state_counter(void)
210{ 232{
211 u64 tmp; 233 u64 val;
212 return !rdmsrl_safe(MSR_PKG_C2_RESIDENCY, &tmp) || 234 struct pkg_cstate_info *info = pkg_cstates;
213 !rdmsrl_safe(MSR_PKG_C3_RESIDENCY, &tmp) || 235
214 !rdmsrl_safe(MSR_PKG_C6_RESIDENCY, &tmp) || 236 /* check if any one of the counter msrs exists */
215 !rdmsrl_safe(MSR_PKG_C7_RESIDENCY, &tmp); 237 while (info->msr_index) {
238 if (!rdmsrl_safe(info->msr_index, &val))
239 return true;
240 info++;
241 }
242
243 return false;
216} 244}
217 245
218static u64 pkg_state_counter(void) 246static u64 pkg_state_counter(void)
219{ 247{
220 u64 val; 248 u64 val;
221 u64 count = 0; 249 u64 count = 0;
222 250 struct pkg_cstate_info *info = pkg_cstates;
223 static bool skip_c2; 251
224 static bool skip_c3; 252 while (info->msr_index) {
225 static bool skip_c6; 253 if (!info->skip) {
226 static bool skip_c7; 254 if (!rdmsrl_safe(info->msr_index, &val))
227 255 count += val;
228 if (!skip_c2) { 256 else
229 if (!rdmsrl_safe(MSR_PKG_C2_RESIDENCY, &val)) 257 info->skip = true;
230 count += val; 258 }
231 else 259 info++;
232 skip_c2 = true;
233 }
234
235 if (!skip_c3) {
236 if (!rdmsrl_safe(MSR_PKG_C3_RESIDENCY, &val))
237 count += val;
238 else
239 skip_c3 = true;
240 }
241
242 if (!skip_c6) {
243 if (!rdmsrl_safe(MSR_PKG_C6_RESIDENCY, &val))
244 count += val;
245 else
246 skip_c6 = true;
247 }
248
249 if (!skip_c7) {
250 if (!rdmsrl_safe(MSR_PKG_C7_RESIDENCY, &val))
251 count += val;
252 else
253 skip_c7 = true;
254 } 260 }
255 261
256 return count; 262 return count;
@@ -667,7 +673,7 @@ static struct thermal_cooling_device_ops powerclamp_cooling_ops = {
667}; 673};
668 674
669/* runs on Nehalem and later */ 675/* runs on Nehalem and later */
670static const struct x86_cpu_id intel_powerclamp_ids[] = { 676static const struct x86_cpu_id intel_powerclamp_ids[] __initconst = {
671 { X86_VENDOR_INTEL, 6, 0x1a}, 677 { X86_VENDOR_INTEL, 6, 0x1a},
672 { X86_VENDOR_INTEL, 6, 0x1c}, 678 { X86_VENDOR_INTEL, 6, 0x1c},
673 { X86_VENDOR_INTEL, 6, 0x1e}, 679 { X86_VENDOR_INTEL, 6, 0x1e},
@@ -689,12 +695,13 @@ static const struct x86_cpu_id intel_powerclamp_ids[] = {
689 { X86_VENDOR_INTEL, 6, 0x46}, 695 { X86_VENDOR_INTEL, 6, 0x46},
690 { X86_VENDOR_INTEL, 6, 0x4c}, 696 { X86_VENDOR_INTEL, 6, 0x4c},
691 { X86_VENDOR_INTEL, 6, 0x4d}, 697 { X86_VENDOR_INTEL, 6, 0x4d},
698 { X86_VENDOR_INTEL, 6, 0x4f},
692 { X86_VENDOR_INTEL, 6, 0x56}, 699 { X86_VENDOR_INTEL, 6, 0x56},
693 {} 700 {}
694}; 701};
695MODULE_DEVICE_TABLE(x86cpu, intel_powerclamp_ids); 702MODULE_DEVICE_TABLE(x86cpu, intel_powerclamp_ids);
696 703
697static int powerclamp_probe(void) 704static int __init powerclamp_probe(void)
698{ 705{
699 if (!x86_match_cpu(intel_powerclamp_ids)) { 706 if (!x86_match_cpu(intel_powerclamp_ids)) {
700 pr_err("Intel powerclamp does not run on family %d model %d\n", 707 pr_err("Intel powerclamp does not run on family %d model %d\n",
@@ -760,7 +767,7 @@ file_error:
760 debugfs_remove_recursive(debug_dir); 767 debugfs_remove_recursive(debug_dir);
761} 768}
762 769
763static int powerclamp_init(void) 770static int __init powerclamp_init(void)
764{ 771{
765 int retval; 772 int retval;
766 int bitmap_size; 773 int bitmap_size;
@@ -809,7 +816,7 @@ exit_free:
809} 816}
810module_init(powerclamp_init); 817module_init(powerclamp_init);
811 818
812static void powerclamp_exit(void) 819static void __exit powerclamp_exit(void)
813{ 820{
814 unregister_hotcpu_notifier(&powerclamp_cpu_notifier); 821 unregister_hotcpu_notifier(&powerclamp_cpu_notifier);
815 end_power_clamp(); 822 end_power_clamp();
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index 3aa46ac7cdbc..cd8f5f93b42c 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -529,7 +529,7 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
529 529
530 thermal->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); 530 thermal->pclk = devm_clk_get(&pdev->dev, "apb_pclk");
531 if (IS_ERR(thermal->pclk)) { 531 if (IS_ERR(thermal->pclk)) {
532 error = PTR_ERR(thermal->clk); 532 error = PTR_ERR(thermal->pclk);
533 dev_err(&pdev->dev, "failed to get apb_pclk clock: %d\n", 533 dev_err(&pdev->dev, "failed to get apb_pclk clock: %d\n",
534 error); 534 error);
535 return error; 535 return error;
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 0531c752fbbb..8e391812e503 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -103,7 +103,7 @@ static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
103static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, 103static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
104 int trip) 104 int trip)
105{ 105{
106 return 0; 106 return false;
107} 107}
108static inline const struct thermal_trip * 108static inline const struct thermal_trip *
109of_thermal_get_trip_points(struct thermal_zone_device *tz) 109of_thermal_get_trip_points(struct thermal_zone_device *tz)
diff --git a/drivers/thermal/ti-soc-thermal/dra752-thermal-data.c b/drivers/thermal/ti-soc-thermal/dra752-thermal-data.c
index a4929272074f..58b5c6694cd4 100644
--- a/drivers/thermal/ti-soc-thermal/dra752-thermal-data.c
+++ b/drivers/thermal/ti-soc-thermal/dra752-thermal-data.c
@@ -420,7 +420,8 @@ const struct ti_bandgap_data dra752_data = {
420 TI_BANDGAP_FEATURE_FREEZE_BIT | 420 TI_BANDGAP_FEATURE_FREEZE_BIT |
421 TI_BANDGAP_FEATURE_TALERT | 421 TI_BANDGAP_FEATURE_TALERT |
422 TI_BANDGAP_FEATURE_COUNTER_DELAY | 422 TI_BANDGAP_FEATURE_COUNTER_DELAY |
423 TI_BANDGAP_FEATURE_HISTORY_BUFFER, 423 TI_BANDGAP_FEATURE_HISTORY_BUFFER |
424 TI_BANDGAP_FEATURE_ERRATA_814,
424 .fclock_name = "l3instr_ts_gclk_div", 425 .fclock_name = "l3instr_ts_gclk_div",
425 .div_ck_name = "l3instr_ts_gclk_div", 426 .div_ck_name = "l3instr_ts_gclk_div",
426 .conv_table = dra752_adc_to_temp, 427 .conv_table = dra752_adc_to_temp,
diff --git a/drivers/thermal/ti-soc-thermal/omap5-thermal-data.c b/drivers/thermal/ti-soc-thermal/omap5-thermal-data.c
index eff0c80fd4af..79ff70c446ba 100644
--- a/drivers/thermal/ti-soc-thermal/omap5-thermal-data.c
+++ b/drivers/thermal/ti-soc-thermal/omap5-thermal-data.c
@@ -319,7 +319,8 @@ const struct ti_bandgap_data omap5430_data = {
319 TI_BANDGAP_FEATURE_FREEZE_BIT | 319 TI_BANDGAP_FEATURE_FREEZE_BIT |
320 TI_BANDGAP_FEATURE_TALERT | 320 TI_BANDGAP_FEATURE_TALERT |
321 TI_BANDGAP_FEATURE_COUNTER_DELAY | 321 TI_BANDGAP_FEATURE_COUNTER_DELAY |
322 TI_BANDGAP_FEATURE_HISTORY_BUFFER, 322 TI_BANDGAP_FEATURE_HISTORY_BUFFER |
323 TI_BANDGAP_FEATURE_ERRATA_813,
323 .fclock_name = "l3instr_ts_gclk_div", 324 .fclock_name = "l3instr_ts_gclk_div",
324 .div_ck_name = "l3instr_ts_gclk_div", 325 .div_ck_name = "l3instr_ts_gclk_div",
325 .conv_table = omap5430_adc_to_temp, 326 .conv_table = omap5430_adc_to_temp,
diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
index 62a5d449c388..bc14dc874594 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
@@ -119,6 +119,37 @@ exit:
119} 119}
120 120
121/** 121/**
122 * ti_errata814_bandgap_read_temp() - helper function to read dra7 sensor temperature
123 * @bgp: pointer to ti_bandgap structure
124 * @reg: desired register (offset) to be read
125 *
126 * Function to read dra7 bandgap sensor temperature. This is done separately
127 * so as to workaround the errata "Bandgap Temperature read Dtemp can be
128 * corrupted" - Errata ID: i814".
129 * Read accesses to registers listed below can be corrupted due to incorrect
130 * resynchronization between clock domains.
131 * Read access to registers below can be corrupted :
132 * CTRL_CORE_DTEMP_MPU/GPU/CORE/DSPEVE/IVA_n (n = 0 to 4)
133 * CTRL_CORE_TEMP_SENSOR_MPU/GPU/CORE/DSPEVE/IVA_n
134 *
135 * Return: the register value.
136 */
137static u32 ti_errata814_bandgap_read_temp(struct ti_bandgap *bgp, u32 reg)
138{
139 u32 val1, val2;
140
141 val1 = ti_bandgap_readl(bgp, reg);
142 val2 = ti_bandgap_readl(bgp, reg);
143
144 /* If both times we read the same value then that is right */
145 if (val1 == val2)
146 return val1;
147
148 /* if val1 and val2 are different read it third time */
149 return ti_bandgap_readl(bgp, reg);
150}
151
152/**
122 * ti_bandgap_read_temp() - helper function to read sensor temperature 153 * ti_bandgap_read_temp() - helper function to read sensor temperature
123 * @bgp: pointer to ti_bandgap structure 154 * @bgp: pointer to ti_bandgap structure
124 * @id: bandgap sensor id 155 * @id: bandgap sensor id
@@ -148,7 +179,11 @@ static u32 ti_bandgap_read_temp(struct ti_bandgap *bgp, int id)
148 } 179 }
149 180
150 /* read temperature */ 181 /* read temperature */
151 temp = ti_bandgap_readl(bgp, reg); 182 if (TI_BANDGAP_HAS(bgp, ERRATA_814))
183 temp = ti_errata814_bandgap_read_temp(bgp, reg);
184 else
185 temp = ti_bandgap_readl(bgp, reg);
186
152 temp &= tsr->bgap_dtemp_mask; 187 temp &= tsr->bgap_dtemp_mask;
153 188
154 if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) 189 if (TI_BANDGAP_HAS(bgp, FREEZE_BIT))
@@ -410,7 +445,7 @@ static int ti_bandgap_update_alert_threshold(struct ti_bandgap *bgp, int id,
410{ 445{
411 struct temp_sensor_data *ts_data = bgp->conf->sensors[id].ts_data; 446 struct temp_sensor_data *ts_data = bgp->conf->sensors[id].ts_data;
412 struct temp_sensor_registers *tsr; 447 struct temp_sensor_registers *tsr;
413 u32 thresh_val, reg_val, t_hot, t_cold; 448 u32 thresh_val, reg_val, t_hot, t_cold, ctrl;
414 int err = 0; 449 int err = 0;
415 450
416 tsr = bgp->conf->sensors[id].registers; 451 tsr = bgp->conf->sensors[id].registers;
@@ -442,8 +477,47 @@ static int ti_bandgap_update_alert_threshold(struct ti_bandgap *bgp, int id,
442 ~(tsr->threshold_thot_mask | tsr->threshold_tcold_mask); 477 ~(tsr->threshold_thot_mask | tsr->threshold_tcold_mask);
443 reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask)) | 478 reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask)) |
444 (t_cold << __ffs(tsr->threshold_tcold_mask)); 479 (t_cold << __ffs(tsr->threshold_tcold_mask));
480
481 /**
482 * Errata i813:
483 * Spurious Thermal Alert: Talert can happen randomly while the device
484 * remains under the temperature limit defined for this event to trig.
485 * This spurious event is caused by a incorrect re-synchronization
486 * between clock domains. The comparison between configured threshold
487 * and current temperature value can happen while the value is
488 * transitioning (metastable), thus causing inappropriate event
489 * generation. No spurious event occurs as long as the threshold value
490 * stays unchanged. Spurious event can be generated while a thermal
491 * alert threshold is modified in
492 * CONTROL_BANDGAP_THRESHOLD_MPU/GPU/CORE/DSPEVE/IVA_n.
493 */
494
495 if (TI_BANDGAP_HAS(bgp, ERRATA_813)) {
496 /* Mask t_hot and t_cold events at the IP Level */
497 ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
498
499 if (hot)
500 ctrl &= ~tsr->mask_hot_mask;
501 else
502 ctrl &= ~tsr->mask_cold_mask;
503
504 ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);
505 }
506
507 /* Write the threshold value */
445 ti_bandgap_writel(bgp, reg_val, tsr->bgap_threshold); 508 ti_bandgap_writel(bgp, reg_val, tsr->bgap_threshold);
446 509
510 if (TI_BANDGAP_HAS(bgp, ERRATA_813)) {
511 /* Unmask t_hot and t_cold events at the IP Level */
512 ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
513 if (hot)
514 ctrl |= tsr->mask_hot_mask;
515 else
516 ctrl |= tsr->mask_cold_mask;
517
518 ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);
519 }
520
447 if (err) { 521 if (err) {
448 dev_err(bgp->dev, "failed to reprogram thot threshold\n"); 522 dev_err(bgp->dev, "failed to reprogram thot threshold\n");
449 err = -EIO; 523 err = -EIO;
diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.h b/drivers/thermal/ti-soc-thermal/ti-bandgap.h
index b3adf72f252d..0c52f7afba00 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.h
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.h
@@ -318,6 +318,10 @@ struct ti_temp_sensor {
318 * TI_BANDGAP_FEATURE_HISTORY_BUFFER - used when the bandgap device features 318 * TI_BANDGAP_FEATURE_HISTORY_BUFFER - used when the bandgap device features
319 * a history buffer of temperatures. 319 * a history buffer of temperatures.
320 * 320 *
321 * TI_BANDGAP_FEATURE_ERRATA_814 - used to workaorund when the bandgap device
322 * has Errata 814
323 * TI_BANDGAP_FEATURE_ERRATA_813 - used to workaorund when the bandgap device
324 * has Errata 813
321 * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a 325 * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a
322 * specific feature (above) or not. Return non-zero, if yes. 326 * specific feature (above) or not. Return non-zero, if yes.
323 */ 327 */
@@ -331,6 +335,8 @@ struct ti_temp_sensor {
331#define TI_BANDGAP_FEATURE_FREEZE_BIT BIT(7) 335#define TI_BANDGAP_FEATURE_FREEZE_BIT BIT(7)
332#define TI_BANDGAP_FEATURE_COUNTER_DELAY BIT(8) 336#define TI_BANDGAP_FEATURE_COUNTER_DELAY BIT(8)
333#define TI_BANDGAP_FEATURE_HISTORY_BUFFER BIT(9) 337#define TI_BANDGAP_FEATURE_HISTORY_BUFFER BIT(9)
338#define TI_BANDGAP_FEATURE_ERRATA_814 BIT(10)
339#define TI_BANDGAP_FEATURE_ERRATA_813 BIT(11)
334#define TI_BANDGAP_HAS(b, f) \ 340#define TI_BANDGAP_HAS(b, f) \
335 ((b)->conf->features & TI_BANDGAP_FEATURE_ ## f) 341 ((b)->conf->features & TI_BANDGAP_FEATURE_ ## f)
336 342
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index f1e57425e39f..7a3d146a5f0e 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -289,7 +289,7 @@ static int xen_initial_domain_console_init(void)
289 return -ENOMEM; 289 return -ENOMEM;
290 } 290 }
291 291
292 info->irq = bind_virq_to_irq(VIRQ_CONSOLE, 0); 292 info->irq = bind_virq_to_irq(VIRQ_CONSOLE, 0, false);
293 info->vtermno = HVC_COOKIE; 293 info->vtermno = HVC_COOKIE;
294 294
295 spin_lock(&xencons_lock); 295 spin_lock(&xencons_lock);
@@ -299,11 +299,27 @@ static int xen_initial_domain_console_init(void)
299 return 0; 299 return 0;
300} 300}
301 301
302static void xen_console_update_evtchn(struct xencons_info *info)
303{
304 if (xen_hvm_domain()) {
305 uint64_t v;
306 int err;
307
308 err = hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
309 if (!err && v)
310 info->evtchn = v;
311 } else
312 info->evtchn = xen_start_info->console.domU.evtchn;
313}
314
302void xen_console_resume(void) 315void xen_console_resume(void)
303{ 316{
304 struct xencons_info *info = vtermno_to_xencons(HVC_COOKIE); 317 struct xencons_info *info = vtermno_to_xencons(HVC_COOKIE);
305 if (info != NULL && info->irq) 318 if (info != NULL && info->irq) {
319 if (!xen_initial_domain())
320 xen_console_update_evtchn(info);
306 rebind_evtchn_irq(info->evtchn, info->irq); 321 rebind_evtchn_irq(info->evtchn, info->irq);
322 }
307} 323}
308 324
309static void xencons_disconnect_backend(struct xencons_info *info) 325static void xencons_disconnect_backend(struct xencons_info *info)
diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
index 04d9e23d1ee1..358323c83b4f 100644
--- a/drivers/tty/mips_ejtag_fdc.c
+++ b/drivers/tty/mips_ejtag_fdc.c
@@ -174,13 +174,13 @@ struct mips_ejtag_fdc_tty {
174static inline void mips_ejtag_fdc_write(struct mips_ejtag_fdc_tty *priv, 174static inline void mips_ejtag_fdc_write(struct mips_ejtag_fdc_tty *priv,
175 unsigned int offs, unsigned int data) 175 unsigned int offs, unsigned int data)
176{ 176{
177 iowrite32(data, priv->reg + offs); 177 __raw_writel(data, priv->reg + offs);
178} 178}
179 179
180static inline unsigned int mips_ejtag_fdc_read(struct mips_ejtag_fdc_tty *priv, 180static inline unsigned int mips_ejtag_fdc_read(struct mips_ejtag_fdc_tty *priv,
181 unsigned int offs) 181 unsigned int offs)
182{ 182{
183 return ioread32(priv->reg + offs); 183 return __raw_readl(priv->reg + offs);
184} 184}
185 185
186/* Encoding of byte stream in FDC words */ 186/* Encoding of byte stream in FDC words */
@@ -347,9 +347,9 @@ static void mips_ejtag_fdc_console_write(struct console *c, const char *s,
347 s += inc[word.bytes - 1]; 347 s += inc[word.bytes - 1];
348 348
349 /* Busy wait until there's space in fifo */ 349 /* Busy wait until there's space in fifo */
350 while (ioread32(regs + REG_FDSTAT) & REG_FDSTAT_TXF) 350 while (__raw_readl(regs + REG_FDSTAT) & REG_FDSTAT_TXF)
351 ; 351 ;
352 iowrite32(word.word, regs + REG_FDTX(c->index)); 352 __raw_writel(word.word, regs + REG_FDTX(c->index));
353 } 353 }
354out: 354out:
355 local_irq_restore(flags); 355 local_irq_restore(flags);
@@ -1227,7 +1227,7 @@ static int kgdbfdc_read_char(void)
1227 1227
1228 /* Read next word from KGDB channel */ 1228 /* Read next word from KGDB channel */
1229 do { 1229 do {
1230 stat = ioread32(regs + REG_FDSTAT); 1230 stat = __raw_readl(regs + REG_FDSTAT);
1231 1231
1232 /* No data waiting? */ 1232 /* No data waiting? */
1233 if (stat & REG_FDSTAT_RXE) 1233 if (stat & REG_FDSTAT_RXE)
@@ -1236,7 +1236,7 @@ static int kgdbfdc_read_char(void)
1236 /* Read next word */ 1236 /* Read next word */
1237 channel = (stat & REG_FDSTAT_RXCHAN) >> 1237 channel = (stat & REG_FDSTAT_RXCHAN) >>
1238 REG_FDSTAT_RXCHAN_SHIFT; 1238 REG_FDSTAT_RXCHAN_SHIFT;
1239 data = ioread32(regs + REG_FDRX); 1239 data = __raw_readl(regs + REG_FDRX);
1240 } while (channel != CONFIG_MIPS_EJTAG_FDC_KGDB_CHAN); 1240 } while (channel != CONFIG_MIPS_EJTAG_FDC_KGDB_CHAN);
1241 1241
1242 /* Decode into rbuf */ 1242 /* Decode into rbuf */
@@ -1266,9 +1266,10 @@ static void kgdbfdc_push_one(void)
1266 return; 1266 return;
1267 1267
1268 /* Busy wait until there's space in fifo */ 1268 /* Busy wait until there's space in fifo */
1269 while (ioread32(regs + REG_FDSTAT) & REG_FDSTAT_TXF) 1269 while (__raw_readl(regs + REG_FDSTAT) & REG_FDSTAT_TXF)
1270 ; 1270 ;
1271 iowrite32(word.word, regs + REG_FDTX(CONFIG_MIPS_EJTAG_FDC_KGDB_CHAN)); 1271 __raw_writel(word.word,
1272 regs + REG_FDTX(CONFIG_MIPS_EJTAG_FDC_KGDB_CHAN));
1272} 1273}
1273 1274
1274/* flush the whole write buffer to the TX FIFO */ 1275/* flush the whole write buffer to the TX FIFO */
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 91abc00aa833..2c34c3249972 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3170,7 +3170,7 @@ static int gsmtty_break_ctl(struct tty_struct *tty, int state)
3170 return gsmtty_modem_update(dlci, encode); 3170 return gsmtty_modem_update(dlci, encode);
3171} 3171}
3172 3172
3173static void gsmtty_remove(struct tty_driver *driver, struct tty_struct *tty) 3173static void gsmtty_cleanup(struct tty_struct *tty)
3174{ 3174{
3175 struct gsm_dlci *dlci = tty->driver_data; 3175 struct gsm_dlci *dlci = tty->driver_data;
3176 struct gsm_mux *gsm = dlci->gsm; 3176 struct gsm_mux *gsm = dlci->gsm;
@@ -3178,7 +3178,6 @@ static void gsmtty_remove(struct tty_driver *driver, struct tty_struct *tty)
3178 dlci_put(dlci); 3178 dlci_put(dlci);
3179 dlci_put(gsm->dlci[0]); 3179 dlci_put(gsm->dlci[0]);
3180 mux_put(gsm); 3180 mux_put(gsm);
3181 driver->ttys[tty->index] = NULL;
3182} 3181}
3183 3182
3184/* Virtual ttys for the demux */ 3183/* Virtual ttys for the demux */
@@ -3199,7 +3198,7 @@ static const struct tty_operations gsmtty_ops = {
3199 .tiocmget = gsmtty_tiocmget, 3198 .tiocmget = gsmtty_tiocmget,
3200 .tiocmset = gsmtty_tiocmset, 3199 .tiocmset = gsmtty_tiocmset,
3201 .break_ctl = gsmtty_break_ctl, 3200 .break_ctl = gsmtty_break_ctl,
3202 .remove = gsmtty_remove, 3201 .cleanup = gsmtty_cleanup,
3203}; 3202};
3204 3203
3205 3204
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 644ddb841d9f..bbc4ce66c2c1 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -600,7 +600,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
600 add_wait_queue(&tty->read_wait, &wait); 600 add_wait_queue(&tty->read_wait, &wait);
601 601
602 for (;;) { 602 for (;;) {
603 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 603 if (test_bit(TTY_OTHER_DONE, &tty->flags)) {
604 ret = -EIO; 604 ret = -EIO;
605 break; 605 break;
606 } 606 }
@@ -828,7 +828,7 @@ static unsigned int n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp,
828 /* set bits for operations that won't block */ 828 /* set bits for operations that won't block */
829 if (n_hdlc->rx_buf_list.head) 829 if (n_hdlc->rx_buf_list.head)
830 mask |= POLLIN | POLLRDNORM; /* readable */ 830 mask |= POLLIN | POLLRDNORM; /* readable */
831 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 831 if (test_bit(TTY_OTHER_DONE, &tty->flags))
832 mask |= POLLHUP; 832 mask |= POLLHUP;
833 if (tty_hung_up_p(filp)) 833 if (tty_hung_up_p(filp))
834 mask |= POLLHUP; 834 mask |= POLLHUP;
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index cf6e0f2e1331..cc57a3a6b02b 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1949,6 +1949,18 @@ static inline int input_available_p(struct tty_struct *tty, int poll)
1949 return ldata->commit_head - ldata->read_tail >= amt; 1949 return ldata->commit_head - ldata->read_tail >= amt;
1950} 1950}
1951 1951
1952static inline int check_other_done(struct tty_struct *tty)
1953{
1954 int done = test_bit(TTY_OTHER_DONE, &tty->flags);
1955 if (done) {
1956 /* paired with cmpxchg() in check_other_closed(); ensures
1957 * read buffer head index is not stale
1958 */
1959 smp_mb__after_atomic();
1960 }
1961 return done;
1962}
1963
1952/** 1964/**
1953 * copy_from_read_buf - copy read data directly 1965 * copy_from_read_buf - copy read data directly
1954 * @tty: terminal device 1966 * @tty: terminal device
@@ -2167,7 +2179,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
2167 struct n_tty_data *ldata = tty->disc_data; 2179 struct n_tty_data *ldata = tty->disc_data;
2168 unsigned char __user *b = buf; 2180 unsigned char __user *b = buf;
2169 DEFINE_WAIT_FUNC(wait, woken_wake_function); 2181 DEFINE_WAIT_FUNC(wait, woken_wake_function);
2170 int c; 2182 int c, done;
2171 int minimum, time; 2183 int minimum, time;
2172 ssize_t retval = 0; 2184 ssize_t retval = 0;
2173 long timeout; 2185 long timeout;
@@ -2235,8 +2247,10 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
2235 ((minimum - (b - buf)) >= 1)) 2247 ((minimum - (b - buf)) >= 1))
2236 ldata->minimum_to_wake = (minimum - (b - buf)); 2248 ldata->minimum_to_wake = (minimum - (b - buf));
2237 2249
2250 done = check_other_done(tty);
2251
2238 if (!input_available_p(tty, 0)) { 2252 if (!input_available_p(tty, 0)) {
2239 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2253 if (done) {
2240 retval = -EIO; 2254 retval = -EIO;
2241 break; 2255 break;
2242 } 2256 }
@@ -2443,12 +2457,12 @@ static unsigned int n_tty_poll(struct tty_struct *tty, struct file *file,
2443 2457
2444 poll_wait(file, &tty->read_wait, wait); 2458 poll_wait(file, &tty->read_wait, wait);
2445 poll_wait(file, &tty->write_wait, wait); 2459 poll_wait(file, &tty->write_wait, wait);
2460 if (check_other_done(tty))
2461 mask |= POLLHUP;
2446 if (input_available_p(tty, 1)) 2462 if (input_available_p(tty, 1))
2447 mask |= POLLIN | POLLRDNORM; 2463 mask |= POLLIN | POLLRDNORM;
2448 if (tty->packet && tty->link->ctrl_status) 2464 if (tty->packet && tty->link->ctrl_status)
2449 mask |= POLLPRI | POLLIN | POLLRDNORM; 2465 mask |= POLLPRI | POLLIN | POLLRDNORM;
2450 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
2451 mask |= POLLHUP;
2452 if (tty_hung_up_p(file)) 2466 if (tty_hung_up_p(file))
2453 mask |= POLLHUP; 2467 mask |= POLLHUP;
2454 if (!(mask & (POLLHUP | POLLIN | POLLRDNORM))) { 2468 if (!(mask & (POLLHUP | POLLIN | POLLRDNORM))) {
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index e72ee629cead..4d5e8409769c 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -53,9 +53,8 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
53 /* Review - krefs on tty_link ?? */ 53 /* Review - krefs on tty_link ?? */
54 if (!tty->link) 54 if (!tty->link)
55 return; 55 return;
56 tty_flush_to_ldisc(tty->link);
57 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); 56 set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
58 wake_up_interruptible(&tty->link->read_wait); 57 tty_flip_buffer_push(tty->link->port);
59 wake_up_interruptible(&tty->link->write_wait); 58 wake_up_interruptible(&tty->link->write_wait);
60 if (tty->driver->subtype == PTY_TYPE_MASTER) { 59 if (tty->driver->subtype == PTY_TYPE_MASTER) {
61 set_bit(TTY_OTHER_CLOSED, &tty->flags); 60 set_bit(TTY_OTHER_CLOSED, &tty->flags);
@@ -243,7 +242,9 @@ static int pty_open(struct tty_struct *tty, struct file *filp)
243 goto out; 242 goto out;
244 243
245 clear_bit(TTY_IO_ERROR, &tty->flags); 244 clear_bit(TTY_IO_ERROR, &tty->flags);
245 /* TTY_OTHER_CLOSED must be cleared before TTY_OTHER_DONE */
246 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); 246 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
247 clear_bit(TTY_OTHER_DONE, &tty->link->flags);
247 set_bit(TTY_THROTTLED, &tty->flags); 248 set_bit(TTY_THROTTLED, &tty->flags);
248 return 0; 249 return 0;
249 250
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 08da4d3e2162..46bcebba54b2 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1998,6 +1998,8 @@ pci_wch_ch38x_setup(struct serial_private *priv,
1998#define PCIE_DEVICE_ID_WCH_CH382_2S1P 0x3250 1998#define PCIE_DEVICE_ID_WCH_CH382_2S1P 0x3250
1999#define PCIE_DEVICE_ID_WCH_CH384_4S 0x3470 1999#define PCIE_DEVICE_ID_WCH_CH384_4S 0x3470
2000 2000
2001#define PCI_DEVICE_ID_EXAR_XR17V8358 0x8358
2002
2001/* Unknown vendors/cards - this should not be in linux/pci_ids.h */ 2003/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
2002#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584 2004#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
2003#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588 0x1588 2005#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588 0x1588
@@ -2520,6 +2522,13 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
2520 .subdevice = PCI_ANY_ID, 2522 .subdevice = PCI_ANY_ID,
2521 .setup = pci_xr17v35x_setup, 2523 .setup = pci_xr17v35x_setup,
2522 }, 2524 },
2525 {
2526 .vendor = PCI_VENDOR_ID_EXAR,
2527 .device = PCI_DEVICE_ID_EXAR_XR17V8358,
2528 .subvendor = PCI_ANY_ID,
2529 .subdevice = PCI_ANY_ID,
2530 .setup = pci_xr17v35x_setup,
2531 },
2523 /* 2532 /*
2524 * Xircom cards 2533 * Xircom cards
2525 */ 2534 */
@@ -2999,6 +3008,7 @@ enum pci_board_num_t {
2999 pbn_exar_XR17V352, 3008 pbn_exar_XR17V352,
3000 pbn_exar_XR17V354, 3009 pbn_exar_XR17V354,
3001 pbn_exar_XR17V358, 3010 pbn_exar_XR17V358,
3011 pbn_exar_XR17V8358,
3002 pbn_exar_ibm_saturn, 3012 pbn_exar_ibm_saturn,
3003 pbn_pasemi_1682M, 3013 pbn_pasemi_1682M,
3004 pbn_ni8430_2, 3014 pbn_ni8430_2,
@@ -3685,6 +3695,14 @@ static struct pciserial_board pci_boards[] = {
3685 .reg_shift = 0, 3695 .reg_shift = 0,
3686 .first_offset = 0, 3696 .first_offset = 0,
3687 }, 3697 },
3698 [pbn_exar_XR17V8358] = {
3699 .flags = FL_BASE0,
3700 .num_ports = 16,
3701 .base_baud = 7812500,
3702 .uart_offset = 0x400,
3703 .reg_shift = 0,
3704 .first_offset = 0,
3705 },
3688 [pbn_exar_ibm_saturn] = { 3706 [pbn_exar_ibm_saturn] = {
3689 .flags = FL_BASE0, 3707 .flags = FL_BASE0,
3690 .num_ports = 1, 3708 .num_ports = 1,
@@ -5080,7 +5098,7 @@ static struct pci_device_id serial_pci_tbl[] = {
5080 0, 5098 0,
5081 0, pbn_exar_XR17C158 }, 5099 0, pbn_exar_XR17C158 },
5082 /* 5100 /*
5083 * Exar Corp. XR17V35[248] Dual/Quad/Octal PCIe UARTs 5101 * Exar Corp. XR17V[48]35[248] Dual/Quad/Octal/Hexa PCIe UARTs
5084 */ 5102 */
5085 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V352, 5103 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V352,
5086 PCI_ANY_ID, PCI_ANY_ID, 5104 PCI_ANY_ID, PCI_ANY_ID,
@@ -5094,7 +5112,10 @@ static struct pci_device_id serial_pci_tbl[] = {
5094 PCI_ANY_ID, PCI_ANY_ID, 5112 PCI_ANY_ID, PCI_ANY_ID,
5095 0, 5113 0,
5096 0, pbn_exar_XR17V358 }, 5114 0, pbn_exar_XR17V358 },
5097 5115 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V8358,
5116 PCI_ANY_ID, PCI_ANY_ID,
5117 0,
5118 0, pbn_exar_XR17V8358 },
5098 /* 5119 /*
5099 * Topic TP560 Data/Fax/Voice 56k modem (reported by Evan Clarke) 5120 * Topic TP560 Data/Fax/Voice 56k modem (reported by Evan Clarke)
5100 */ 5121 */
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 5a4e9d579585..6f5a0720a8c8 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1639,6 +1639,9 @@ static int pl011_startup(struct uart_port *port)
1639 1639
1640 writew(uap->vendor->ifls, uap->port.membase + UART011_IFLS); 1640 writew(uap->vendor->ifls, uap->port.membase + UART011_IFLS);
1641 1641
1642 /* Assume that TX IRQ doesn't work until we see one: */
1643 uap->tx_irq_seen = 0;
1644
1642 spin_lock_irq(&uap->port.lock); 1645 spin_lock_irq(&uap->port.lock);
1643 1646
1644 /* restore RTS and DTR */ 1647 /* restore RTS and DTR */
@@ -1702,7 +1705,7 @@ static void pl011_shutdown(struct uart_port *port)
1702 spin_lock_irq(&uap->port.lock); 1705 spin_lock_irq(&uap->port.lock);
1703 uap->im = 0; 1706 uap->im = 0;
1704 writew(uap->im, uap->port.membase + UART011_IMSC); 1707 writew(uap->im, uap->port.membase + UART011_IMSC);
1705 writew(0xffff & ~UART011_TXIS, uap->port.membase + UART011_ICR); 1708 writew(0xffff, uap->port.membase + UART011_ICR);
1706 spin_unlock_irq(&uap->port.lock); 1709 spin_unlock_irq(&uap->port.lock);
1707 1710
1708 pl011_dma_shutdown(uap); 1711 pl011_dma_shutdown(uap);
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d58fe4763d9e..27dade29646b 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -880,6 +880,7 @@ static int atmel_prepare_tx_dma(struct uart_port *port)
880 config.direction = DMA_MEM_TO_DEV; 880 config.direction = DMA_MEM_TO_DEV;
881 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 881 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
882 config.dst_addr = port->mapbase + ATMEL_US_THR; 882 config.dst_addr = port->mapbase + ATMEL_US_THR;
883 config.dst_maxburst = 1;
883 884
884 ret = dmaengine_slave_config(atmel_port->chan_tx, 885 ret = dmaengine_slave_config(atmel_port->chan_tx,
885 &config); 886 &config);
@@ -1059,6 +1060,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port)
1059 config.direction = DMA_DEV_TO_MEM; 1060 config.direction = DMA_DEV_TO_MEM;
1060 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1061 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
1061 config.src_addr = port->mapbase + ATMEL_US_RHR; 1062 config.src_addr = port->mapbase + ATMEL_US_RHR;
1063 config.src_maxburst = 1;
1062 1064
1063 ret = dmaengine_slave_config(atmel_port->chan_rx, 1065 ret = dmaengine_slave_config(atmel_port->chan_rx,
1064 &config); 1066 &config);
diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 5fdc9f3ecd64..6dc471e30e79 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -187,13 +187,8 @@ static int __init param_setup_earlycon(char *buf)
187 return 0; 187 return 0;
188 188
189 err = setup_earlycon(buf); 189 err = setup_earlycon(buf);
190 if (err == -ENOENT) { 190 if (err == -ENOENT || err == -EALREADY)
191 pr_warn("no match for %s\n", buf); 191 return 0;
192 err = 0;
193 } else if (err == -EALREADY) {
194 pr_warn("already registered\n");
195 err = 0;
196 }
197 return err; 192 return err;
198} 193}
199early_param("earlycon", param_setup_earlycon); 194early_param("earlycon", param_setup_earlycon);
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 5b73afb9f9f3..137381e649e5 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -346,7 +346,6 @@ static const struct of_device_id of_platform_serial_table[] = {
346 { .compatible = "ibm,qpace-nwp-serial", 346 { .compatible = "ibm,qpace-nwp-serial",
347 .data = (void *)PORT_NWPSERIAL, }, 347 .data = (void *)PORT_NWPSERIAL, },
348#endif 348#endif
349 { .type = "serial", .data = (void *)PORT_UNKNOWN, },
350 { /* end of list */ }, 349 { /* end of list */ },
351}; 350};
352 351
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 211479aa34bb..7f49172ccd86 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1735,6 +1735,8 @@ static int serial_omap_probe(struct platform_device *pdev)
1735err_add_port: 1735err_add_port:
1736 pm_runtime_put(&pdev->dev); 1736 pm_runtime_put(&pdev->dev);
1737 pm_runtime_disable(&pdev->dev); 1737 pm_runtime_disable(&pdev->dev);
1738 pm_qos_remove_request(&up->pm_qos_request);
1739 device_init_wakeup(up->dev, false);
1738err_rs485: 1740err_rs485:
1739err_port_line: 1741err_port_line:
1740 return ret; 1742 return ret;
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index cf08876922f1..a0ae942d9562 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -1068,8 +1068,9 @@ static int s3c64xx_serial_startup(struct uart_port *port)
1068 spin_lock_irqsave(&port->lock, flags); 1068 spin_lock_irqsave(&port->lock, flags);
1069 1069
1070 ufcon = rd_regl(port, S3C2410_UFCON); 1070 ufcon = rd_regl(port, S3C2410_UFCON);
1071 ufcon |= S3C2410_UFCON_RESETRX | S3C2410_UFCON_RESETTX | 1071 ufcon |= S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8;
1072 S5PV210_UFCON_RXTRIG8; 1072 if (!uart_console(port))
1073 ufcon |= S3C2410_UFCON_RESETTX;
1073 wr_regl(port, S3C2410_UFCON, ufcon); 1074 wr_regl(port, S3C2410_UFCON, ufcon);
1074 1075
1075 enable_rx_pio(ourport); 1076 enable_rx_pio(ourport);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index eb5b03be9dfd..0b7bb12dfc68 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1770,7 +1770,7 @@ static const struct file_operations uart_proc_fops = {
1770 * @port: the port to write the message 1770 * @port: the port to write the message
1771 * @s: array of characters 1771 * @s: array of characters
1772 * @count: number of characters in string to write 1772 * @count: number of characters in string to write
1773 * @write: function to write character to port 1773 * @putchar: function to write character to port
1774 */ 1774 */
1775void uart_console_write(struct uart_port *port, const char *s, 1775void uart_console_write(struct uart_port *port, const char *s,
1776 unsigned int count, 1776 unsigned int count,
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index 708eead850b0..b1c6bd3d483f 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -632,7 +632,8 @@ MODULE_DEVICE_TABLE(of, ulite_of_match);
632 632
633static int ulite_probe(struct platform_device *pdev) 633static int ulite_probe(struct platform_device *pdev)
634{ 634{
635 struct resource *res, *res2; 635 struct resource *res;
636 int irq;
636 int id = pdev->id; 637 int id = pdev->id;
637#ifdef CONFIG_OF 638#ifdef CONFIG_OF
638 const __be32 *prop; 639 const __be32 *prop;
@@ -646,11 +647,11 @@ static int ulite_probe(struct platform_device *pdev)
646 if (!res) 647 if (!res)
647 return -ENODEV; 648 return -ENODEV;
648 649
649 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 650 irq = platform_get_irq(pdev, 0);
650 if (!res2) 651 if (irq <= 0)
651 return -ENODEV; 652 return -ENXIO;
652 653
653 return ulite_assign(&pdev->dev, id, res->start, res2->start); 654 return ulite_assign(&pdev->dev, id, res->start, irq);
654} 655}
655 656
656static int ulite_remove(struct platform_device *pdev) 657static int ulite_remove(struct platform_device *pdev)
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index f218ec658f5d..3ddbac767db3 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1331,9 +1331,9 @@ static SIMPLE_DEV_PM_OPS(cdns_uart_dev_pm_ops, cdns_uart_suspend,
1331 */ 1331 */
1332static int cdns_uart_probe(struct platform_device *pdev) 1332static int cdns_uart_probe(struct platform_device *pdev)
1333{ 1333{
1334 int rc, id; 1334 int rc, id, irq;
1335 struct uart_port *port; 1335 struct uart_port *port;
1336 struct resource *res, *res2; 1336 struct resource *res;
1337 struct cdns_uart *cdns_uart_data; 1337 struct cdns_uart *cdns_uart_data;
1338 1338
1339 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), 1339 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data),
@@ -1380,9 +1380,9 @@ static int cdns_uart_probe(struct platform_device *pdev)
1380 goto err_out_clk_disable; 1380 goto err_out_clk_disable;
1381 } 1381 }
1382 1382
1383 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1383 irq = platform_get_irq(pdev, 0);
1384 if (!res2) { 1384 if (irq <= 0) {
1385 rc = -ENODEV; 1385 rc = -ENXIO;
1386 goto err_out_clk_disable; 1386 goto err_out_clk_disable;
1387 } 1387 }
1388 1388
@@ -1411,7 +1411,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1411 * and triggers invocation of the config_port() entry point. 1411 * and triggers invocation of the config_port() entry point.
1412 */ 1412 */
1413 port->mapbase = res->start; 1413 port->mapbase = res->start;
1414 port->irq = res2->start; 1414 port->irq = irq;
1415 port->dev = &pdev->dev; 1415 port->dev = &pdev->dev;
1416 port->uartclk = clk_get_rate(cdns_uart_data->uartclk); 1416 port->uartclk = clk_get_rate(cdns_uart_data->uartclk);
1417 port->private_data = cdns_uart_data; 1417 port->private_data = cdns_uart_data;
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 75661641f5fe..2f78b77f0f81 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -37,6 +37,28 @@
37 37
38#define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF) 38#define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF)
39 39
40/*
41 * If all tty flip buffers have been processed by flush_to_ldisc() or
42 * dropped by tty_buffer_flush(), check if the linked pty has been closed.
43 * If so, wake the reader/poll to process
44 */
45static inline void check_other_closed(struct tty_struct *tty)
46{
47 unsigned long flags, old;
48
49 /* transition from TTY_OTHER_CLOSED => TTY_OTHER_DONE must be atomic */
50 for (flags = ACCESS_ONCE(tty->flags);
51 test_bit(TTY_OTHER_CLOSED, &flags);
52 ) {
53 old = flags;
54 __set_bit(TTY_OTHER_DONE, &flags);
55 flags = cmpxchg(&tty->flags, old, flags);
56 if (old == flags) {
57 wake_up_interruptible(&tty->read_wait);
58 break;
59 }
60 }
61}
40 62
41/** 63/**
42 * tty_buffer_lock_exclusive - gain exclusive access to buffer 64 * tty_buffer_lock_exclusive - gain exclusive access to buffer
@@ -229,6 +251,8 @@ void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld)
229 if (ld && ld->ops->flush_buffer) 251 if (ld && ld->ops->flush_buffer)
230 ld->ops->flush_buffer(tty); 252 ld->ops->flush_buffer(tty);
231 253
254 check_other_closed(tty);
255
232 atomic_dec(&buf->priority); 256 atomic_dec(&buf->priority);
233 mutex_unlock(&buf->lock); 257 mutex_unlock(&buf->lock);
234} 258}
@@ -471,8 +495,10 @@ static void flush_to_ldisc(struct work_struct *work)
471 smp_rmb(); 495 smp_rmb();
472 count = head->commit - head->read; 496 count = head->commit - head->read;
473 if (!count) { 497 if (!count) {
474 if (next == NULL) 498 if (next == NULL) {
499 check_other_closed(tty);
475 break; 500 break;
501 }
476 buf->head = next; 502 buf->head = next;
477 tty_buffer_free(port, head); 503 tty_buffer_free(port, head);
478 continue; 504 continue;
@@ -489,19 +515,6 @@ static void flush_to_ldisc(struct work_struct *work)
489} 515}
490 516
491/** 517/**
492 * tty_flush_to_ldisc
493 * @tty: tty to push
494 *
495 * Push the terminal flip buffers to the line discipline.
496 *
497 * Must not be called from IRQ context.
498 */
499void tty_flush_to_ldisc(struct tty_struct *tty)
500{
501 flush_work(&tty->port->buf.work);
502}
503
504/**
505 * tty_flip_buffer_push - terminal 518 * tty_flip_buffer_push - terminal
506 * @port: tty port to push 519 * @port: tty port to push
507 * 520 *
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 632fc8152061..8e53fe469664 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -536,7 +536,7 @@ EXPORT_SYMBOL(tty_termios_hw_change);
536 * Locking: termios_rwsem 536 * Locking: termios_rwsem
537 */ 537 */
538 538
539static int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) 539int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
540{ 540{
541 struct ktermios old_termios; 541 struct ktermios old_termios;
542 struct tty_ldisc *ld; 542 struct tty_ldisc *ld;
@@ -569,6 +569,7 @@ static int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
569 up_write(&tty->termios_rwsem); 569 up_write(&tty->termios_rwsem);
570 return 0; 570 return 0;
571} 571}
572EXPORT_SYMBOL_GPL(tty_set_termios);
572 573
573/** 574/**
574 * set_termios - set termios values for a tty 575 * set_termios - set termios values for a tty
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index dfb05edcdb96..5b7061a33103 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -88,9 +88,13 @@ static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
88 char buf[32]; 88 char buf[32];
89 int ret; 89 int ret;
90 90
91 if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 91 count = min_t(size_t, sizeof(buf) - 1, count);
92 if (copy_from_user(buf, ubuf, count))
92 return -EFAULT; 93 return -EFAULT;
93 94
95 /* sscanf requires a zero terminated string */
96 buf[count] = '\0';
97
94 if (sscanf(buf, "%u", &mode) != 1) 98 if (sscanf(buf, "%u", &mode) != 1)
95 return -EINVAL; 99 return -EINVAL;
96 100
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index 083acf45ad5a..19d655a743b5 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -520,7 +520,6 @@ static int ci_otg_start_host(struct otg_fsm *fsm, int on)
520{ 520{
521 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); 521 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm);
522 522
523 mutex_unlock(&fsm->lock);
524 if (on) { 523 if (on) {
525 ci_role_stop(ci); 524 ci_role_stop(ci);
526 ci_role_start(ci, CI_ROLE_HOST); 525 ci_role_start(ci, CI_ROLE_HOST);
@@ -529,7 +528,6 @@ static int ci_otg_start_host(struct otg_fsm *fsm, int on)
529 hw_device_reset(ci); 528 hw_device_reset(ci);
530 ci_role_start(ci, CI_ROLE_GADGET); 529 ci_role_start(ci, CI_ROLE_GADGET);
531 } 530 }
532 mutex_lock(&fsm->lock);
533 return 0; 531 return 0;
534} 532}
535 533
@@ -537,12 +535,10 @@ static int ci_otg_start_gadget(struct otg_fsm *fsm, int on)
537{ 535{
538 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); 536 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm);
539 537
540 mutex_unlock(&fsm->lock);
541 if (on) 538 if (on)
542 usb_gadget_vbus_connect(&ci->gadget); 539 usb_gadget_vbus_connect(&ci->gadget);
543 else 540 else
544 usb_gadget_vbus_disconnect(&ci->gadget); 541 usb_gadget_vbus_disconnect(&ci->gadget);
545 mutex_lock(&fsm->lock);
546 542
547 return 0; 543 return 0;
548} 544}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 3e15add665e2..5c8f58114677 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1142,11 +1142,16 @@ static int acm_probe(struct usb_interface *intf,
1142 } 1142 }
1143 1143
1144 while (buflen > 0) { 1144 while (buflen > 0) {
1145 elength = buffer[0];
1146 if (!elength) {
1147 dev_err(&intf->dev, "skipping garbage byte\n");
1148 elength = 1;
1149 goto next_desc;
1150 }
1145 if (buffer[1] != USB_DT_CS_INTERFACE) { 1151 if (buffer[1] != USB_DT_CS_INTERFACE) {
1146 dev_err(&intf->dev, "skipping garbage\n"); 1152 dev_err(&intf->dev, "skipping garbage\n");
1147 goto next_desc; 1153 goto next_desc;
1148 } 1154 }
1149 elength = buffer[0];
1150 1155
1151 switch (buffer[2]) { 1156 switch (buffer[2]) {
1152 case USB_CDC_UNION_TYPE: /* we've found it */ 1157 case USB_CDC_UNION_TYPE: /* we've found it */
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 41e510ae8c83..d85abfed84cc 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -106,6 +106,9 @@ static const struct usb_device_id usb_quirk_list[] = {
106 { USB_DEVICE(0x04f3, 0x010c), .driver_info = 106 { USB_DEVICE(0x04f3, 0x010c), .driver_info =
107 USB_QUIRK_DEVICE_QUALIFIER }, 107 USB_QUIRK_DEVICE_QUALIFIER },
108 108
109 { USB_DEVICE(0x04f3, 0x0125), .driver_info =
110 USB_QUIRK_DEVICE_QUALIFIER },
111
109 { USB_DEVICE(0x04f3, 0x016f), .driver_info = 112 { USB_DEVICE(0x04f3, 0x016f), .driver_info =
110 USB_QUIRK_DEVICE_QUALIFIER }, 113 USB_QUIRK_DEVICE_QUALIFIER },
111 114
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index edba5348be18..6b486a36863c 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -65,8 +65,8 @@
65#define USBOTGSS_IRQENABLE_SET_MISC 0x003c 65#define USBOTGSS_IRQENABLE_SET_MISC 0x003c
66#define USBOTGSS_IRQENABLE_CLR_MISC 0x0040 66#define USBOTGSS_IRQENABLE_CLR_MISC 0x0040
67#define USBOTGSS_IRQMISC_OFFSET 0x03fc 67#define USBOTGSS_IRQMISC_OFFSET 0x03fc
68#define USBOTGSS_UTMI_OTG_CTRL 0x0080 68#define USBOTGSS_UTMI_OTG_STATUS 0x0080
69#define USBOTGSS_UTMI_OTG_STATUS 0x0084 69#define USBOTGSS_UTMI_OTG_CTRL 0x0084
70#define USBOTGSS_UTMI_OTG_OFFSET 0x0480 70#define USBOTGSS_UTMI_OTG_OFFSET 0x0480
71#define USBOTGSS_TXFIFO_DEPTH 0x0508 71#define USBOTGSS_TXFIFO_DEPTH 0x0508
72#define USBOTGSS_RXFIFO_DEPTH 0x050c 72#define USBOTGSS_RXFIFO_DEPTH 0x050c
@@ -98,20 +98,20 @@
98#define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL (1 << 3) 98#define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL (1 << 3)
99#define USBOTGSS_IRQMISC_IDPULLUP_FALL (1 << 0) 99#define USBOTGSS_IRQMISC_IDPULLUP_FALL (1 << 0)
100 100
101/* UTMI_OTG_CTRL REGISTER */
102#define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5)
103#define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4)
104#define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3)
105#define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0)
106
107/* UTMI_OTG_STATUS REGISTER */ 101/* UTMI_OTG_STATUS REGISTER */
108#define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31) 102#define USBOTGSS_UTMI_OTG_STATUS_DRVVBUS (1 << 5)
109#define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9) 103#define USBOTGSS_UTMI_OTG_STATUS_CHRGVBUS (1 << 4)
110#define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8) 104#define USBOTGSS_UTMI_OTG_STATUS_DISCHRGVBUS (1 << 3)
111#define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4) 105#define USBOTGSS_UTMI_OTG_STATUS_IDPULLUP (1 << 0)
112#define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3) 106
113#define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2) 107/* UTMI_OTG_CTRL REGISTER */
114#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) 108#define USBOTGSS_UTMI_OTG_CTRL_SW_MODE (1 << 31)
109#define USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT (1 << 9)
110#define USBOTGSS_UTMI_OTG_CTRL_TXBITSTUFFENABLE (1 << 8)
111#define USBOTGSS_UTMI_OTG_CTRL_IDDIG (1 << 4)
112#define USBOTGSS_UTMI_OTG_CTRL_SESSEND (1 << 3)
113#define USBOTGSS_UTMI_OTG_CTRL_SESSVALID (1 << 2)
114#define USBOTGSS_UTMI_OTG_CTRL_VBUSVALID (1 << 1)
115 115
116struct dwc3_omap { 116struct dwc3_omap {
117 struct device *dev; 117 struct device *dev;
@@ -119,7 +119,7 @@ struct dwc3_omap {
119 int irq; 119 int irq;
120 void __iomem *base; 120 void __iomem *base;
121 121
122 u32 utmi_otg_status; 122 u32 utmi_otg_ctrl;
123 u32 utmi_otg_offset; 123 u32 utmi_otg_offset;
124 u32 irqmisc_offset; 124 u32 irqmisc_offset;
125 u32 irq_eoi_offset; 125 u32 irq_eoi_offset;
@@ -153,15 +153,15 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
153 writel(value, base + offset); 153 writel(value, base + offset);
154} 154}
155 155
156static u32 dwc3_omap_read_utmi_status(struct dwc3_omap *omap) 156static u32 dwc3_omap_read_utmi_ctrl(struct dwc3_omap *omap)
157{ 157{
158 return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS + 158 return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_CTRL +
159 omap->utmi_otg_offset); 159 omap->utmi_otg_offset);
160} 160}
161 161
162static void dwc3_omap_write_utmi_status(struct dwc3_omap *omap, u32 value) 162static void dwc3_omap_write_utmi_ctrl(struct dwc3_omap *omap, u32 value)
163{ 163{
164 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS + 164 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_CTRL +
165 omap->utmi_otg_offset, value); 165 omap->utmi_otg_offset, value);
166 166
167} 167}
@@ -235,25 +235,25 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
235 } 235 }
236 } 236 }
237 237
238 val = dwc3_omap_read_utmi_status(omap); 238 val = dwc3_omap_read_utmi_ctrl(omap);
239 val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG 239 val &= ~(USBOTGSS_UTMI_OTG_CTRL_IDDIG
240 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 240 | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID
241 | USBOTGSS_UTMI_OTG_STATUS_SESSEND); 241 | USBOTGSS_UTMI_OTG_CTRL_SESSEND);
242 val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID 242 val |= USBOTGSS_UTMI_OTG_CTRL_SESSVALID
243 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; 243 | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT;
244 dwc3_omap_write_utmi_status(omap, val); 244 dwc3_omap_write_utmi_ctrl(omap, val);
245 break; 245 break;
246 246
247 case OMAP_DWC3_VBUS_VALID: 247 case OMAP_DWC3_VBUS_VALID:
248 dev_dbg(omap->dev, "VBUS Connect\n"); 248 dev_dbg(omap->dev, "VBUS Connect\n");
249 249
250 val = dwc3_omap_read_utmi_status(omap); 250 val = dwc3_omap_read_utmi_ctrl(omap);
251 val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND; 251 val &= ~USBOTGSS_UTMI_OTG_CTRL_SESSEND;
252 val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG 252 val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG
253 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 253 | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID
254 | USBOTGSS_UTMI_OTG_STATUS_SESSVALID 254 | USBOTGSS_UTMI_OTG_CTRL_SESSVALID
255 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; 255 | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT;
256 dwc3_omap_write_utmi_status(omap, val); 256 dwc3_omap_write_utmi_ctrl(omap, val);
257 break; 257 break;
258 258
259 case OMAP_DWC3_ID_FLOAT: 259 case OMAP_DWC3_ID_FLOAT:
@@ -263,13 +263,13 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
263 case OMAP_DWC3_VBUS_OFF: 263 case OMAP_DWC3_VBUS_OFF:
264 dev_dbg(omap->dev, "VBUS Disconnect\n"); 264 dev_dbg(omap->dev, "VBUS Disconnect\n");
265 265
266 val = dwc3_omap_read_utmi_status(omap); 266 val = dwc3_omap_read_utmi_ctrl(omap);
267 val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID 267 val &= ~(USBOTGSS_UTMI_OTG_CTRL_SESSVALID
268 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID 268 | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID
269 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT); 269 | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT);
270 val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND 270 val |= USBOTGSS_UTMI_OTG_CTRL_SESSEND
271 | USBOTGSS_UTMI_OTG_STATUS_IDDIG; 271 | USBOTGSS_UTMI_OTG_CTRL_IDDIG;
272 dwc3_omap_write_utmi_status(omap, val); 272 dwc3_omap_write_utmi_ctrl(omap, val);
273 break; 273 break;
274 274
275 default: 275 default:
@@ -422,22 +422,22 @@ static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
422 struct device_node *node = omap->dev->of_node; 422 struct device_node *node = omap->dev->of_node;
423 int utmi_mode = 0; 423 int utmi_mode = 0;
424 424
425 reg = dwc3_omap_read_utmi_status(omap); 425 reg = dwc3_omap_read_utmi_ctrl(omap);
426 426
427 of_property_read_u32(node, "utmi-mode", &utmi_mode); 427 of_property_read_u32(node, "utmi-mode", &utmi_mode);
428 428
429 switch (utmi_mode) { 429 switch (utmi_mode) {
430 case DWC3_OMAP_UTMI_MODE_SW: 430 case DWC3_OMAP_UTMI_MODE_SW:
431 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; 431 reg |= USBOTGSS_UTMI_OTG_CTRL_SW_MODE;
432 break; 432 break;
433 case DWC3_OMAP_UTMI_MODE_HW: 433 case DWC3_OMAP_UTMI_MODE_HW:
434 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; 434 reg &= ~USBOTGSS_UTMI_OTG_CTRL_SW_MODE;
435 break; 435 break;
436 default: 436 default:
437 dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode); 437 dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode);
438 } 438 }
439 439
440 dwc3_omap_write_utmi_status(omap, reg); 440 dwc3_omap_write_utmi_ctrl(omap, reg);
441} 441}
442 442
443static int dwc3_omap_extcon_register(struct dwc3_omap *omap) 443static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
@@ -614,7 +614,7 @@ static int dwc3_omap_suspend(struct device *dev)
614{ 614{
615 struct dwc3_omap *omap = dev_get_drvdata(dev); 615 struct dwc3_omap *omap = dev_get_drvdata(dev);
616 616
617 omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap); 617 omap->utmi_otg_ctrl = dwc3_omap_read_utmi_ctrl(omap);
618 dwc3_omap_disable_irqs(omap); 618 dwc3_omap_disable_irqs(omap);
619 619
620 return 0; 620 return 0;
@@ -624,7 +624,7 @@ static int dwc3_omap_resume(struct device *dev)
624{ 624{
625 struct dwc3_omap *omap = dev_get_drvdata(dev); 625 struct dwc3_omap *omap = dev_get_drvdata(dev);
626 626
627 dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status); 627 dwc3_omap_write_utmi_ctrl(omap, omap->utmi_otg_ctrl);
628 dwc3_omap_enable_irqs(omap); 628 dwc3_omap_enable_irqs(omap);
629 629
630 pm_runtime_disable(dev); 630 pm_runtime_disable(dev);
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index c42765b3a060..0495c94a23d7 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1295,6 +1295,7 @@ static void purge_configs_funcs(struct gadget_info *gi)
1295 } 1295 }
1296 } 1296 }
1297 c->next_interface_id = 0; 1297 c->next_interface_id = 0;
1298 memset(c->interface, 0, sizeof(c->interface));
1298 c->superspeed = 0; 1299 c->superspeed = 0;
1299 c->highspeed = 0; 1300 c->highspeed = 0;
1300 c->fullspeed = 0; 1301 c->fullspeed = 0;
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 13dfc9915b1d..f7f35a36c09a 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -437,12 +437,20 @@ static int hidg_setup(struct usb_function *f,
437 | USB_REQ_GET_DESCRIPTOR): 437 | USB_REQ_GET_DESCRIPTOR):
438 switch (value >> 8) { 438 switch (value >> 8) {
439 case HID_DT_HID: 439 case HID_DT_HID:
440 {
441 struct hid_descriptor hidg_desc_copy = hidg_desc;
442
440 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n"); 443 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n");
444 hidg_desc_copy.desc[0].bDescriptorType = HID_DT_REPORT;
445 hidg_desc_copy.desc[0].wDescriptorLength =
446 cpu_to_le16(hidg->report_desc_length);
447
441 length = min_t(unsigned short, length, 448 length = min_t(unsigned short, length,
442 hidg_desc.bLength); 449 hidg_desc_copy.bLength);
443 memcpy(req->buf, &hidg_desc, length); 450 memcpy(req->buf, &hidg_desc_copy, length);
444 goto respond; 451 goto respond;
445 break; 452 break;
453 }
446 case HID_DT_REPORT: 454 case HID_DT_REPORT:
447 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n"); 455 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n");
448 length = min_t(unsigned short, length, 456 length = min_t(unsigned short, length,
@@ -632,6 +640,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
632 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 640 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
633 hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 641 hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
634 hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 642 hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
643 /*
644 * We can use hidg_desc struct here but we should not relay
645 * that its content won't change after returning from this function.
646 */
635 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT; 647 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT;
636 hidg_desc.desc[0].wDescriptorLength = 648 hidg_desc.desc[0].wDescriptorLength =
637 cpu_to_le16(hidg->report_desc_length); 649 cpu_to_le16(hidg->report_desc_length);
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 89179ab20c10..7ee057930ae7 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -113,6 +113,7 @@ struct gs_port {
113 int write_allocated; 113 int write_allocated;
114 struct gs_buf port_write_buf; 114 struct gs_buf port_write_buf;
115 wait_queue_head_t drain_wait; /* wait while writes drain */ 115 wait_queue_head_t drain_wait; /* wait while writes drain */
116 bool write_busy;
116 117
117 /* REVISIT this state ... */ 118 /* REVISIT this state ... */
118 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ 119 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
@@ -363,7 +364,7 @@ __acquires(&port->port_lock)
363 int status = 0; 364 int status = 0;
364 bool do_tty_wake = false; 365 bool do_tty_wake = false;
365 366
366 while (!list_empty(pool)) { 367 while (!port->write_busy && !list_empty(pool)) {
367 struct usb_request *req; 368 struct usb_request *req;
368 int len; 369 int len;
369 370
@@ -393,9 +394,11 @@ __acquires(&port->port_lock)
393 * NOTE that we may keep sending data for a while after 394 * NOTE that we may keep sending data for a while after
394 * the TTY closed (dev->ioport->port_tty is NULL). 395 * the TTY closed (dev->ioport->port_tty is NULL).
395 */ 396 */
397 port->write_busy = true;
396 spin_unlock(&port->port_lock); 398 spin_unlock(&port->port_lock);
397 status = usb_ep_queue(in, req, GFP_ATOMIC); 399 status = usb_ep_queue(in, req, GFP_ATOMIC);
398 spin_lock(&port->port_lock); 400 spin_lock(&port->port_lock);
401 port->write_busy = false;
399 402
400 if (status) { 403 if (status) {
401 pr_debug("%s: %s %s err %d\n", 404 pr_debug("%s: %s %s err %d\n",
diff --git a/drivers/usb/gadget/legacy/acm_ms.c b/drivers/usb/gadget/legacy/acm_ms.c
index c30b7b572465..1194b09ae746 100644
--- a/drivers/usb/gadget/legacy/acm_ms.c
+++ b/drivers/usb/gadget/legacy/acm_ms.c
@@ -121,7 +121,7 @@ static struct usb_function *f_msg;
121/* 121/*
122 * We _always_ have both ACM and mass storage functions. 122 * We _always_ have both ACM and mass storage functions.
123 */ 123 */
124static int __init acm_ms_do_config(struct usb_configuration *c) 124static int acm_ms_do_config(struct usb_configuration *c)
125{ 125{
126 struct fsg_opts *opts; 126 struct fsg_opts *opts;
127 int status; 127 int status;
@@ -174,7 +174,7 @@ static struct usb_configuration acm_ms_config_driver = {
174 174
175/*-------------------------------------------------------------------------*/ 175/*-------------------------------------------------------------------------*/
176 176
177static int __init acm_ms_bind(struct usb_composite_dev *cdev) 177static int acm_ms_bind(struct usb_composite_dev *cdev)
178{ 178{
179 struct usb_gadget *gadget = cdev->gadget; 179 struct usb_gadget *gadget = cdev->gadget;
180 struct fsg_opts *opts; 180 struct fsg_opts *opts;
@@ -249,7 +249,7 @@ fail_get_msg:
249 return status; 249 return status;
250} 250}
251 251
252static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 252static int acm_ms_unbind(struct usb_composite_dev *cdev)
253{ 253{
254 usb_put_function(f_msg); 254 usb_put_function(f_msg);
255 usb_put_function_instance(fi_msg); 255 usb_put_function_instance(fi_msg);
@@ -258,13 +258,13 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
258 return 0; 258 return 0;
259} 259}
260 260
261static __refdata struct usb_composite_driver acm_ms_driver = { 261static struct usb_composite_driver acm_ms_driver = {
262 .name = "g_acm_ms", 262 .name = "g_acm_ms",
263 .dev = &device_desc, 263 .dev = &device_desc,
264 .max_speed = USB_SPEED_SUPER, 264 .max_speed = USB_SPEED_SUPER,
265 .strings = dev_strings, 265 .strings = dev_strings,
266 .bind = acm_ms_bind, 266 .bind = acm_ms_bind,
267 .unbind = __exit_p(acm_ms_unbind), 267 .unbind = acm_ms_unbind,
268}; 268};
269 269
270module_usb_composite_driver(acm_ms_driver); 270module_usb_composite_driver(acm_ms_driver);
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c
index f46a3956e43d..f289caf18a45 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -167,7 +167,7 @@ static const struct usb_descriptor_header *otg_desc[] = {
167 167
168/*-------------------------------------------------------------------------*/ 168/*-------------------------------------------------------------------------*/
169 169
170static int __init audio_do_config(struct usb_configuration *c) 170static int audio_do_config(struct usb_configuration *c)
171{ 171{
172 int status; 172 int status;
173 173
@@ -216,7 +216,7 @@ static struct usb_configuration audio_config_driver = {
216 216
217/*-------------------------------------------------------------------------*/ 217/*-------------------------------------------------------------------------*/
218 218
219static int __init audio_bind(struct usb_composite_dev *cdev) 219static int audio_bind(struct usb_composite_dev *cdev)
220{ 220{
221#ifndef CONFIG_GADGET_UAC1 221#ifndef CONFIG_GADGET_UAC1
222 struct f_uac2_opts *uac2_opts; 222 struct f_uac2_opts *uac2_opts;
@@ -276,7 +276,7 @@ fail:
276 return status; 276 return status;
277} 277}
278 278
279static int __exit audio_unbind(struct usb_composite_dev *cdev) 279static int audio_unbind(struct usb_composite_dev *cdev)
280{ 280{
281#ifdef CONFIG_GADGET_UAC1 281#ifdef CONFIG_GADGET_UAC1
282 if (!IS_ERR_OR_NULL(f_uac1)) 282 if (!IS_ERR_OR_NULL(f_uac1))
@@ -292,13 +292,13 @@ static int __exit audio_unbind(struct usb_composite_dev *cdev)
292 return 0; 292 return 0;
293} 293}
294 294
295static __refdata struct usb_composite_driver audio_driver = { 295static struct usb_composite_driver audio_driver = {
296 .name = "g_audio", 296 .name = "g_audio",
297 .dev = &device_desc, 297 .dev = &device_desc,
298 .strings = audio_strings, 298 .strings = audio_strings,
299 .max_speed = USB_SPEED_HIGH, 299 .max_speed = USB_SPEED_HIGH,
300 .bind = audio_bind, 300 .bind = audio_bind,
301 .unbind = __exit_p(audio_unbind), 301 .unbind = audio_unbind,
302}; 302};
303 303
304module_usb_composite_driver(audio_driver); 304module_usb_composite_driver(audio_driver);
diff --git a/drivers/usb/gadget/legacy/cdc2.c b/drivers/usb/gadget/legacy/cdc2.c
index 2e85d9473478..afd3e37921a7 100644
--- a/drivers/usb/gadget/legacy/cdc2.c
+++ b/drivers/usb/gadget/legacy/cdc2.c
@@ -104,7 +104,7 @@ static struct usb_function_instance *fi_ecm;
104/* 104/*
105 * We _always_ have both CDC ECM and CDC ACM functions. 105 * We _always_ have both CDC ECM and CDC ACM functions.
106 */ 106 */
107static int __init cdc_do_config(struct usb_configuration *c) 107static int cdc_do_config(struct usb_configuration *c)
108{ 108{
109 int status; 109 int status;
110 110
@@ -153,7 +153,7 @@ static struct usb_configuration cdc_config_driver = {
153 153
154/*-------------------------------------------------------------------------*/ 154/*-------------------------------------------------------------------------*/
155 155
156static int __init cdc_bind(struct usb_composite_dev *cdev) 156static int cdc_bind(struct usb_composite_dev *cdev)
157{ 157{
158 struct usb_gadget *gadget = cdev->gadget; 158 struct usb_gadget *gadget = cdev->gadget;
159 struct f_ecm_opts *ecm_opts; 159 struct f_ecm_opts *ecm_opts;
@@ -211,7 +211,7 @@ fail:
211 return status; 211 return status;
212} 212}
213 213
214static int __exit cdc_unbind(struct usb_composite_dev *cdev) 214static int cdc_unbind(struct usb_composite_dev *cdev)
215{ 215{
216 usb_put_function(f_acm); 216 usb_put_function(f_acm);
217 usb_put_function_instance(fi_serial); 217 usb_put_function_instance(fi_serial);
@@ -222,13 +222,13 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
222 return 0; 222 return 0;
223} 223}
224 224
225static __refdata struct usb_composite_driver cdc_driver = { 225static struct usb_composite_driver cdc_driver = {
226 .name = "g_cdc", 226 .name = "g_cdc",
227 .dev = &device_desc, 227 .dev = &device_desc,
228 .strings = dev_strings, 228 .strings = dev_strings,
229 .max_speed = USB_SPEED_HIGH, 229 .max_speed = USB_SPEED_HIGH,
230 .bind = cdc_bind, 230 .bind = cdc_bind,
231 .unbind = __exit_p(cdc_unbind), 231 .unbind = cdc_unbind,
232}; 232};
233 233
234module_usb_composite_driver(cdc_driver); 234module_usb_composite_driver(cdc_driver);
diff --git a/drivers/usb/gadget/legacy/dbgp.c b/drivers/usb/gadget/legacy/dbgp.c
index 633683a72a11..204b10b1a7e7 100644
--- a/drivers/usb/gadget/legacy/dbgp.c
+++ b/drivers/usb/gadget/legacy/dbgp.c
@@ -284,7 +284,7 @@ fail_1:
284 return -ENODEV; 284 return -ENODEV;
285} 285}
286 286
287static int __init dbgp_bind(struct usb_gadget *gadget, 287static int dbgp_bind(struct usb_gadget *gadget,
288 struct usb_gadget_driver *driver) 288 struct usb_gadget_driver *driver)
289{ 289{
290 int err, stp; 290 int err, stp;
@@ -406,7 +406,7 @@ fail:
406 return err; 406 return err;
407} 407}
408 408
409static __refdata struct usb_gadget_driver dbgp_driver = { 409static struct usb_gadget_driver dbgp_driver = {
410 .function = "dbgp", 410 .function = "dbgp",
411 .max_speed = USB_SPEED_HIGH, 411 .max_speed = USB_SPEED_HIGH,
412 .bind = dbgp_bind, 412 .bind = dbgp_bind,
diff --git a/drivers/usb/gadget/legacy/ether.c b/drivers/usb/gadget/legacy/ether.c
index c5fdc61cdc4a..a3323dca218f 100644
--- a/drivers/usb/gadget/legacy/ether.c
+++ b/drivers/usb/gadget/legacy/ether.c
@@ -222,7 +222,7 @@ static struct usb_function *f_rndis;
222 * the first one present. That's to make Microsoft's drivers happy, 222 * the first one present. That's to make Microsoft's drivers happy,
223 * and to follow DOCSIS 1.0 (cable modem standard). 223 * and to follow DOCSIS 1.0 (cable modem standard).
224 */ 224 */
225static int __init rndis_do_config(struct usb_configuration *c) 225static int rndis_do_config(struct usb_configuration *c)
226{ 226{
227 int status; 227 int status;
228 228
@@ -264,7 +264,7 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
264/* 264/*
265 * We _always_ have an ECM, CDC Subset, or EEM configuration. 265 * We _always_ have an ECM, CDC Subset, or EEM configuration.
266 */ 266 */
267static int __init eth_do_config(struct usb_configuration *c) 267static int eth_do_config(struct usb_configuration *c)
268{ 268{
269 int status = 0; 269 int status = 0;
270 270
@@ -318,7 +318,7 @@ static struct usb_configuration eth_config_driver = {
318 318
319/*-------------------------------------------------------------------------*/ 319/*-------------------------------------------------------------------------*/
320 320
321static int __init eth_bind(struct usb_composite_dev *cdev) 321static int eth_bind(struct usb_composite_dev *cdev)
322{ 322{
323 struct usb_gadget *gadget = cdev->gadget; 323 struct usb_gadget *gadget = cdev->gadget;
324 struct f_eem_opts *eem_opts = NULL; 324 struct f_eem_opts *eem_opts = NULL;
@@ -447,7 +447,7 @@ fail:
447 return status; 447 return status;
448} 448}
449 449
450static int __exit eth_unbind(struct usb_composite_dev *cdev) 450static int eth_unbind(struct usb_composite_dev *cdev)
451{ 451{
452 if (has_rndis()) { 452 if (has_rndis()) {
453 usb_put_function(f_rndis); 453 usb_put_function(f_rndis);
@@ -466,13 +466,13 @@ static int __exit eth_unbind(struct usb_composite_dev *cdev)
466 return 0; 466 return 0;
467} 467}
468 468
469static __refdata struct usb_composite_driver eth_driver = { 469static struct usb_composite_driver eth_driver = {
470 .name = "g_ether", 470 .name = "g_ether",
471 .dev = &device_desc, 471 .dev = &device_desc,
472 .strings = dev_strings, 472 .strings = dev_strings,
473 .max_speed = USB_SPEED_SUPER, 473 .max_speed = USB_SPEED_SUPER,
474 .bind = eth_bind, 474 .bind = eth_bind,
475 .unbind = __exit_p(eth_unbind), 475 .unbind = eth_unbind,
476}; 476};
477 477
478module_usb_composite_driver(eth_driver); 478module_usb_composite_driver(eth_driver);
diff --git a/drivers/usb/gadget/legacy/g_ffs.c b/drivers/usb/gadget/legacy/g_ffs.c
index b01b88e1b716..7b9ef7e257d2 100644
--- a/drivers/usb/gadget/legacy/g_ffs.c
+++ b/drivers/usb/gadget/legacy/g_ffs.c
@@ -163,7 +163,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev);
163static int gfs_do_config(struct usb_configuration *c); 163static int gfs_do_config(struct usb_configuration *c);
164 164
165 165
166static __refdata struct usb_composite_driver gfs_driver = { 166static struct usb_composite_driver gfs_driver = {
167 .name = DRIVER_NAME, 167 .name = DRIVER_NAME,
168 .dev = &gfs_dev_desc, 168 .dev = &gfs_dev_desc,
169 .strings = gfs_dev_strings, 169 .strings = gfs_dev_strings,
diff --git a/drivers/usb/gadget/legacy/gmidi.c b/drivers/usb/gadget/legacy/gmidi.c
index e02a095294ac..da19c486b61e 100644
--- a/drivers/usb/gadget/legacy/gmidi.c
+++ b/drivers/usb/gadget/legacy/gmidi.c
@@ -118,7 +118,7 @@ static struct usb_gadget_strings *dev_strings[] = {
118static struct usb_function_instance *fi_midi; 118static struct usb_function_instance *fi_midi;
119static struct usb_function *f_midi; 119static struct usb_function *f_midi;
120 120
121static int __exit midi_unbind(struct usb_composite_dev *dev) 121static int midi_unbind(struct usb_composite_dev *dev)
122{ 122{
123 usb_put_function(f_midi); 123 usb_put_function(f_midi);
124 usb_put_function_instance(fi_midi); 124 usb_put_function_instance(fi_midi);
@@ -133,7 +133,7 @@ static struct usb_configuration midi_config = {
133 .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW, 133 .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW,
134}; 134};
135 135
136static int __init midi_bind_config(struct usb_configuration *c) 136static int midi_bind_config(struct usb_configuration *c)
137{ 137{
138 int status; 138 int status;
139 139
@@ -150,7 +150,7 @@ static int __init midi_bind_config(struct usb_configuration *c)
150 return 0; 150 return 0;
151} 151}
152 152
153static int __init midi_bind(struct usb_composite_dev *cdev) 153static int midi_bind(struct usb_composite_dev *cdev)
154{ 154{
155 struct f_midi_opts *midi_opts; 155 struct f_midi_opts *midi_opts;
156 int status; 156 int status;
@@ -185,13 +185,13 @@ put:
185 return status; 185 return status;
186} 186}
187 187
188static __refdata struct usb_composite_driver midi_driver = { 188static struct usb_composite_driver midi_driver = {
189 .name = (char *) longname, 189 .name = (char *) longname,
190 .dev = &device_desc, 190 .dev = &device_desc,
191 .strings = dev_strings, 191 .strings = dev_strings,
192 .max_speed = USB_SPEED_HIGH, 192 .max_speed = USB_SPEED_HIGH,
193 .bind = midi_bind, 193 .bind = midi_bind,
194 .unbind = __exit_p(midi_unbind), 194 .unbind = midi_unbind,
195}; 195};
196 196
197module_usb_composite_driver(midi_driver); 197module_usb_composite_driver(midi_driver);
diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
index 614b06d80b41..2baa572686c6 100644
--- a/drivers/usb/gadget/legacy/hid.c
+++ b/drivers/usb/gadget/legacy/hid.c
@@ -106,7 +106,7 @@ static struct usb_gadget_strings *dev_strings[] = {
106 106
107/****************************** Configurations ******************************/ 107/****************************** Configurations ******************************/
108 108
109static int __init do_config(struct usb_configuration *c) 109static int do_config(struct usb_configuration *c)
110{ 110{
111 struct hidg_func_node *e, *n; 111 struct hidg_func_node *e, *n;
112 int status = 0; 112 int status = 0;
@@ -147,7 +147,7 @@ static struct usb_configuration config_driver = {
147 147
148/****************************** Gadget Bind ******************************/ 148/****************************** Gadget Bind ******************************/
149 149
150static int __init hid_bind(struct usb_composite_dev *cdev) 150static int hid_bind(struct usb_composite_dev *cdev)
151{ 151{
152 struct usb_gadget *gadget = cdev->gadget; 152 struct usb_gadget *gadget = cdev->gadget;
153 struct list_head *tmp; 153 struct list_head *tmp;
@@ -205,7 +205,7 @@ put:
205 return status; 205 return status;
206} 206}
207 207
208static int __exit hid_unbind(struct usb_composite_dev *cdev) 208static int hid_unbind(struct usb_composite_dev *cdev)
209{ 209{
210 struct hidg_func_node *n; 210 struct hidg_func_node *n;
211 211
@@ -216,7 +216,7 @@ static int __exit hid_unbind(struct usb_composite_dev *cdev)
216 return 0; 216 return 0;
217} 217}
218 218
219static int __init hidg_plat_driver_probe(struct platform_device *pdev) 219static int hidg_plat_driver_probe(struct platform_device *pdev)
220{ 220{
221 struct hidg_func_descriptor *func = dev_get_platdata(&pdev->dev); 221 struct hidg_func_descriptor *func = dev_get_platdata(&pdev->dev);
222 struct hidg_func_node *entry; 222 struct hidg_func_node *entry;
@@ -252,13 +252,13 @@ static int hidg_plat_driver_remove(struct platform_device *pdev)
252/****************************** Some noise ******************************/ 252/****************************** Some noise ******************************/
253 253
254 254
255static __refdata struct usb_composite_driver hidg_driver = { 255static struct usb_composite_driver hidg_driver = {
256 .name = "g_hid", 256 .name = "g_hid",
257 .dev = &device_desc, 257 .dev = &device_desc,
258 .strings = dev_strings, 258 .strings = dev_strings,
259 .max_speed = USB_SPEED_HIGH, 259 .max_speed = USB_SPEED_HIGH,
260 .bind = hid_bind, 260 .bind = hid_bind,
261 .unbind = __exit_p(hid_unbind), 261 .unbind = hid_unbind,
262}; 262};
263 263
264static struct platform_driver hidg_plat_driver = { 264static struct platform_driver hidg_plat_driver = {
diff --git a/drivers/usb/gadget/legacy/mass_storage.c b/drivers/usb/gadget/legacy/mass_storage.c
index 8e27a8c96444..e7bfb081f111 100644
--- a/drivers/usb/gadget/legacy/mass_storage.c
+++ b/drivers/usb/gadget/legacy/mass_storage.c
@@ -130,7 +130,7 @@ static int msg_thread_exits(struct fsg_common *common)
130 return 0; 130 return 0;
131} 131}
132 132
133static int __init msg_do_config(struct usb_configuration *c) 133static int msg_do_config(struct usb_configuration *c)
134{ 134{
135 struct fsg_opts *opts; 135 struct fsg_opts *opts;
136 int ret; 136 int ret;
@@ -170,7 +170,7 @@ static struct usb_configuration msg_config_driver = {
170 170
171/****************************** Gadget Bind ******************************/ 171/****************************** Gadget Bind ******************************/
172 172
173static int __init msg_bind(struct usb_composite_dev *cdev) 173static int msg_bind(struct usb_composite_dev *cdev)
174{ 174{
175 static const struct fsg_operations ops = { 175 static const struct fsg_operations ops = {
176 .thread_exits = msg_thread_exits, 176 .thread_exits = msg_thread_exits,
@@ -248,7 +248,7 @@ static int msg_unbind(struct usb_composite_dev *cdev)
248 248
249/****************************** Some noise ******************************/ 249/****************************** Some noise ******************************/
250 250
251static __refdata struct usb_composite_driver msg_driver = { 251static struct usb_composite_driver msg_driver = {
252 .name = "g_mass_storage", 252 .name = "g_mass_storage",
253 .dev = &msg_device_desc, 253 .dev = &msg_device_desc,
254 .max_speed = USB_SPEED_SUPER, 254 .max_speed = USB_SPEED_SUPER,
diff --git a/drivers/usb/gadget/legacy/multi.c b/drivers/usb/gadget/legacy/multi.c
index 39d27bb343b4..b21b51f0c9fa 100644
--- a/drivers/usb/gadget/legacy/multi.c
+++ b/drivers/usb/gadget/legacy/multi.c
@@ -149,7 +149,7 @@ static struct usb_function *f_acm_rndis;
149static struct usb_function *f_rndis; 149static struct usb_function *f_rndis;
150static struct usb_function *f_msg_rndis; 150static struct usb_function *f_msg_rndis;
151 151
152static __init int rndis_do_config(struct usb_configuration *c) 152static int rndis_do_config(struct usb_configuration *c)
153{ 153{
154 struct fsg_opts *fsg_opts; 154 struct fsg_opts *fsg_opts;
155 int ret; 155 int ret;
@@ -237,7 +237,7 @@ static struct usb_function *f_acm_multi;
237static struct usb_function *f_ecm; 237static struct usb_function *f_ecm;
238static struct usb_function *f_msg_multi; 238static struct usb_function *f_msg_multi;
239 239
240static __init int cdc_do_config(struct usb_configuration *c) 240static int cdc_do_config(struct usb_configuration *c)
241{ 241{
242 struct fsg_opts *fsg_opts; 242 struct fsg_opts *fsg_opts;
243 int ret; 243 int ret;
@@ -466,7 +466,7 @@ fail:
466 return status; 466 return status;
467} 467}
468 468
469static int __exit multi_unbind(struct usb_composite_dev *cdev) 469static int multi_unbind(struct usb_composite_dev *cdev)
470{ 470{
471#ifdef CONFIG_USB_G_MULTI_CDC 471#ifdef CONFIG_USB_G_MULTI_CDC
472 usb_put_function(f_msg_multi); 472 usb_put_function(f_msg_multi);
@@ -497,13 +497,13 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
497/****************************** Some noise ******************************/ 497/****************************** Some noise ******************************/
498 498
499 499
500static __refdata struct usb_composite_driver multi_driver = { 500static struct usb_composite_driver multi_driver = {
501 .name = "g_multi", 501 .name = "g_multi",
502 .dev = &device_desc, 502 .dev = &device_desc,
503 .strings = dev_strings, 503 .strings = dev_strings,
504 .max_speed = USB_SPEED_HIGH, 504 .max_speed = USB_SPEED_HIGH,
505 .bind = multi_bind, 505 .bind = multi_bind,
506 .unbind = __exit_p(multi_unbind), 506 .unbind = multi_unbind,
507 .needs_serial = 1, 507 .needs_serial = 1,
508}; 508};
509 509
diff --git a/drivers/usb/gadget/legacy/ncm.c b/drivers/usb/gadget/legacy/ncm.c
index e90e23db2acb..6ce7421412e9 100644
--- a/drivers/usb/gadget/legacy/ncm.c
+++ b/drivers/usb/gadget/legacy/ncm.c
@@ -107,7 +107,7 @@ static struct usb_function *f_ncm;
107 107
108/*-------------------------------------------------------------------------*/ 108/*-------------------------------------------------------------------------*/
109 109
110static int __init ncm_do_config(struct usb_configuration *c) 110static int ncm_do_config(struct usb_configuration *c)
111{ 111{
112 int status; 112 int status;
113 113
@@ -143,7 +143,7 @@ static struct usb_configuration ncm_config_driver = {
143 143
144/*-------------------------------------------------------------------------*/ 144/*-------------------------------------------------------------------------*/
145 145
146static int __init gncm_bind(struct usb_composite_dev *cdev) 146static int gncm_bind(struct usb_composite_dev *cdev)
147{ 147{
148 struct usb_gadget *gadget = cdev->gadget; 148 struct usb_gadget *gadget = cdev->gadget;
149 struct f_ncm_opts *ncm_opts; 149 struct f_ncm_opts *ncm_opts;
@@ -186,7 +186,7 @@ fail:
186 return status; 186 return status;
187} 187}
188 188
189static int __exit gncm_unbind(struct usb_composite_dev *cdev) 189static int gncm_unbind(struct usb_composite_dev *cdev)
190{ 190{
191 if (!IS_ERR_OR_NULL(f_ncm)) 191 if (!IS_ERR_OR_NULL(f_ncm))
192 usb_put_function(f_ncm); 192 usb_put_function(f_ncm);
@@ -195,13 +195,13 @@ static int __exit gncm_unbind(struct usb_composite_dev *cdev)
195 return 0; 195 return 0;
196} 196}
197 197
198static __refdata struct usb_composite_driver ncm_driver = { 198static struct usb_composite_driver ncm_driver = {
199 .name = "g_ncm", 199 .name = "g_ncm",
200 .dev = &device_desc, 200 .dev = &device_desc,
201 .strings = dev_strings, 201 .strings = dev_strings,
202 .max_speed = USB_SPEED_HIGH, 202 .max_speed = USB_SPEED_HIGH,
203 .bind = gncm_bind, 203 .bind = gncm_bind,
204 .unbind = __exit_p(gncm_unbind), 204 .unbind = gncm_unbind,
205}; 205};
206 206
207module_usb_composite_driver(ncm_driver); 207module_usb_composite_driver(ncm_driver);
diff --git a/drivers/usb/gadget/legacy/nokia.c b/drivers/usb/gadget/legacy/nokia.c
index 9b8fd701648c..4bb498a38a1c 100644
--- a/drivers/usb/gadget/legacy/nokia.c
+++ b/drivers/usb/gadget/legacy/nokia.c
@@ -118,7 +118,7 @@ static struct usb_function_instance *fi_obex1;
118static struct usb_function_instance *fi_obex2; 118static struct usb_function_instance *fi_obex2;
119static struct usb_function_instance *fi_phonet; 119static struct usb_function_instance *fi_phonet;
120 120
121static int __init nokia_bind_config(struct usb_configuration *c) 121static int nokia_bind_config(struct usb_configuration *c)
122{ 122{
123 struct usb_function *f_acm; 123 struct usb_function *f_acm;
124 struct usb_function *f_phonet = NULL; 124 struct usb_function *f_phonet = NULL;
@@ -224,7 +224,7 @@ err_get_acm:
224 return status; 224 return status;
225} 225}
226 226
227static int __init nokia_bind(struct usb_composite_dev *cdev) 227static int nokia_bind(struct usb_composite_dev *cdev)
228{ 228{
229 struct usb_gadget *gadget = cdev->gadget; 229 struct usb_gadget *gadget = cdev->gadget;
230 int status; 230 int status;
@@ -307,7 +307,7 @@ err_usb:
307 return status; 307 return status;
308} 308}
309 309
310static int __exit nokia_unbind(struct usb_composite_dev *cdev) 310static int nokia_unbind(struct usb_composite_dev *cdev)
311{ 311{
312 if (!IS_ERR_OR_NULL(f_obex1_cfg2)) 312 if (!IS_ERR_OR_NULL(f_obex1_cfg2))
313 usb_put_function(f_obex1_cfg2); 313 usb_put_function(f_obex1_cfg2);
@@ -338,13 +338,13 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev)
338 return 0; 338 return 0;
339} 339}
340 340
341static __refdata struct usb_composite_driver nokia_driver = { 341static struct usb_composite_driver nokia_driver = {
342 .name = "g_nokia", 342 .name = "g_nokia",
343 .dev = &device_desc, 343 .dev = &device_desc,
344 .strings = dev_strings, 344 .strings = dev_strings,
345 .max_speed = USB_SPEED_HIGH, 345 .max_speed = USB_SPEED_HIGH,
346 .bind = nokia_bind, 346 .bind = nokia_bind,
347 .unbind = __exit_p(nokia_unbind), 347 .unbind = nokia_unbind,
348}; 348};
349 349
350module_usb_composite_driver(nokia_driver); 350module_usb_composite_driver(nokia_driver);
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
index d5b6ee725a2a..1ce7df1060a5 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -126,7 +126,7 @@ static struct usb_configuration printer_cfg_driver = {
126 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 126 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
127}; 127};
128 128
129static int __init printer_do_config(struct usb_configuration *c) 129static int printer_do_config(struct usb_configuration *c)
130{ 130{
131 struct usb_gadget *gadget = c->cdev->gadget; 131 struct usb_gadget *gadget = c->cdev->gadget;
132 int status = 0; 132 int status = 0;
@@ -152,7 +152,7 @@ static int __init printer_do_config(struct usb_configuration *c)
152 return status; 152 return status;
153} 153}
154 154
155static int __init printer_bind(struct usb_composite_dev *cdev) 155static int printer_bind(struct usb_composite_dev *cdev)
156{ 156{
157 struct f_printer_opts *opts; 157 struct f_printer_opts *opts;
158 int ret, len; 158 int ret, len;
@@ -191,7 +191,7 @@ static int __init printer_bind(struct usb_composite_dev *cdev)
191 return ret; 191 return ret;
192} 192}
193 193
194static int __exit printer_unbind(struct usb_composite_dev *cdev) 194static int printer_unbind(struct usb_composite_dev *cdev)
195{ 195{
196 usb_put_function(f_printer); 196 usb_put_function(f_printer);
197 usb_put_function_instance(fi_printer); 197 usb_put_function_instance(fi_printer);
@@ -199,7 +199,7 @@ static int __exit printer_unbind(struct usb_composite_dev *cdev)
199 return 0; 199 return 0;
200} 200}
201 201
202static __refdata struct usb_composite_driver printer_driver = { 202static struct usb_composite_driver printer_driver = {
203 .name = shortname, 203 .name = shortname,
204 .dev = &device_desc, 204 .dev = &device_desc,
205 .strings = dev_strings, 205 .strings = dev_strings,
diff --git a/drivers/usb/gadget/legacy/serial.c b/drivers/usb/gadget/legacy/serial.c
index 1f5f978d35d5..8b7528f9b78e 100644
--- a/drivers/usb/gadget/legacy/serial.c
+++ b/drivers/usb/gadget/legacy/serial.c
@@ -174,7 +174,7 @@ out:
174 return ret; 174 return ret;
175} 175}
176 176
177static int __init gs_bind(struct usb_composite_dev *cdev) 177static int gs_bind(struct usb_composite_dev *cdev)
178{ 178{
179 int status; 179 int status;
180 180
@@ -230,7 +230,7 @@ static int gs_unbind(struct usb_composite_dev *cdev)
230 return 0; 230 return 0;
231} 231}
232 232
233static __refdata struct usb_composite_driver gserial_driver = { 233static struct usb_composite_driver gserial_driver = {
234 .name = "g_serial", 234 .name = "g_serial",
235 .dev = &device_desc, 235 .dev = &device_desc,
236 .strings = dev_strings, 236 .strings = dev_strings,
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index 8b80addc4ce6..f9b4882fce52 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -2397,7 +2397,7 @@ static int usb_target_bind(struct usb_composite_dev *cdev)
2397 return 0; 2397 return 0;
2398} 2398}
2399 2399
2400static __refdata struct usb_composite_driver usbg_driver = { 2400static struct usb_composite_driver usbg_driver = {
2401 .name = "g_target", 2401 .name = "g_target",
2402 .dev = &usbg_device_desc, 2402 .dev = &usbg_device_desc,
2403 .strings = usbg_strings, 2403 .strings = usbg_strings,
diff --git a/drivers/usb/gadget/legacy/webcam.c b/drivers/usb/gadget/legacy/webcam.c
index 04a3da20f742..72c976bf3530 100644
--- a/drivers/usb/gadget/legacy/webcam.c
+++ b/drivers/usb/gadget/legacy/webcam.c
@@ -334,7 +334,7 @@ static const struct uvc_descriptor_header * const uvc_ss_streaming_cls[] = {
334 * USB configuration 334 * USB configuration
335 */ 335 */
336 336
337static int __init 337static int
338webcam_config_bind(struct usb_configuration *c) 338webcam_config_bind(struct usb_configuration *c)
339{ 339{
340 int status = 0; 340 int status = 0;
@@ -358,7 +358,7 @@ static struct usb_configuration webcam_config_driver = {
358 .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW, 358 .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW,
359}; 359};
360 360
361static int /* __init_or_exit */ 361static int
362webcam_unbind(struct usb_composite_dev *cdev) 362webcam_unbind(struct usb_composite_dev *cdev)
363{ 363{
364 if (!IS_ERR_OR_NULL(f_uvc)) 364 if (!IS_ERR_OR_NULL(f_uvc))
@@ -368,7 +368,7 @@ webcam_unbind(struct usb_composite_dev *cdev)
368 return 0; 368 return 0;
369} 369}
370 370
371static int __init 371static int
372webcam_bind(struct usb_composite_dev *cdev) 372webcam_bind(struct usb_composite_dev *cdev)
373{ 373{
374 struct f_uvc_opts *uvc_opts; 374 struct f_uvc_opts *uvc_opts;
@@ -422,7 +422,7 @@ error:
422 * Driver 422 * Driver
423 */ 423 */
424 424
425static __refdata struct usb_composite_driver webcam_driver = { 425static struct usb_composite_driver webcam_driver = {
426 .name = "g_webcam", 426 .name = "g_webcam",
427 .dev = &webcam_device_descriptor, 427 .dev = &webcam_device_descriptor,
428 .strings = webcam_device_strings, 428 .strings = webcam_device_strings,
diff --git a/drivers/usb/gadget/legacy/zero.c b/drivers/usb/gadget/legacy/zero.c
index 5ee95152493c..c986e8addb90 100644
--- a/drivers/usb/gadget/legacy/zero.c
+++ b/drivers/usb/gadget/legacy/zero.c
@@ -272,7 +272,7 @@ static struct usb_function_instance *func_inst_lb;
272module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR); 272module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR);
273MODULE_PARM_DESC(qlen, "depth of loopback queue"); 273MODULE_PARM_DESC(qlen, "depth of loopback queue");
274 274
275static int __init zero_bind(struct usb_composite_dev *cdev) 275static int zero_bind(struct usb_composite_dev *cdev)
276{ 276{
277 struct f_ss_opts *ss_opts; 277 struct f_ss_opts *ss_opts;
278 struct f_lb_opts *lb_opts; 278 struct f_lb_opts *lb_opts;
@@ -400,7 +400,7 @@ static int zero_unbind(struct usb_composite_dev *cdev)
400 return 0; 400 return 0;
401} 401}
402 402
403static __refdata struct usb_composite_driver zero_driver = { 403static struct usb_composite_driver zero_driver = {
404 .name = "zero", 404 .name = "zero",
405 .dev = &device_desc, 405 .dev = &device_desc,
406 .strings = dev_strings, 406 .strings = dev_strings,
diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c
index 2fbedca3c2b4..fc4226462f8f 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1942,7 +1942,7 @@ err_unprepare_fclk:
1942 return retval; 1942 return retval;
1943} 1943}
1944 1944
1945static int __exit at91udc_remove(struct platform_device *pdev) 1945static int at91udc_remove(struct platform_device *pdev)
1946{ 1946{
1947 struct at91_udc *udc = platform_get_drvdata(pdev); 1947 struct at91_udc *udc = platform_get_drvdata(pdev);
1948 unsigned long flags; 1948 unsigned long flags;
@@ -2018,7 +2018,7 @@ static int at91udc_resume(struct platform_device *pdev)
2018#endif 2018#endif
2019 2019
2020static struct platform_driver at91_udc_driver = { 2020static struct platform_driver at91_udc_driver = {
2021 .remove = __exit_p(at91udc_remove), 2021 .remove = at91udc_remove,
2022 .shutdown = at91udc_shutdown, 2022 .shutdown = at91udc_shutdown,
2023 .suspend = at91udc_suspend, 2023 .suspend = at91udc_suspend,
2024 .resume = at91udc_resume, 2024 .resume = at91udc_resume,
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 4c01953a0869..351d48550c33 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2186,7 +2186,7 @@ static int usba_udc_probe(struct platform_device *pdev)
2186 return 0; 2186 return 0;
2187} 2187}
2188 2188
2189static int __exit usba_udc_remove(struct platform_device *pdev) 2189static int usba_udc_remove(struct platform_device *pdev)
2190{ 2190{
2191 struct usba_udc *udc; 2191 struct usba_udc *udc;
2192 int i; 2192 int i;
@@ -2258,7 +2258,7 @@ static int usba_udc_resume(struct device *dev)
2258static SIMPLE_DEV_PM_OPS(usba_udc_pm_ops, usba_udc_suspend, usba_udc_resume); 2258static SIMPLE_DEV_PM_OPS(usba_udc_pm_ops, usba_udc_suspend, usba_udc_resume);
2259 2259
2260static struct platform_driver udc_driver = { 2260static struct platform_driver udc_driver = {
2261 .remove = __exit_p(usba_udc_remove), 2261 .remove = usba_udc_remove,
2262 .driver = { 2262 .driver = {
2263 .name = "atmel_usba_udc", 2263 .name = "atmel_usba_udc",
2264 .pm = &usba_udc_pm_ops, 2264 .pm = &usba_udc_pm_ops,
diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c
index 55fcb930f92e..c60022b46a48 100644
--- a/drivers/usb/gadget/udc/fsl_udc_core.c
+++ b/drivers/usb/gadget/udc/fsl_udc_core.c
@@ -2525,7 +2525,7 @@ err_kfree:
2525/* Driver removal function 2525/* Driver removal function
2526 * Free resources and finish pending transactions 2526 * Free resources and finish pending transactions
2527 */ 2527 */
2528static int __exit fsl_udc_remove(struct platform_device *pdev) 2528static int fsl_udc_remove(struct platform_device *pdev)
2529{ 2529{
2530 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2530 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2531 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev); 2531 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -2663,7 +2663,7 @@ static const struct platform_device_id fsl_udc_devtype[] = {
2663}; 2663};
2664MODULE_DEVICE_TABLE(platform, fsl_udc_devtype); 2664MODULE_DEVICE_TABLE(platform, fsl_udc_devtype);
2665static struct platform_driver udc_driver = { 2665static struct platform_driver udc_driver = {
2666 .remove = __exit_p(fsl_udc_remove), 2666 .remove = fsl_udc_remove,
2667 /* Just for FSL i.mx SoC currently */ 2667 /* Just for FSL i.mx SoC currently */
2668 .id_table = fsl_udc_devtype, 2668 .id_table = fsl_udc_devtype,
2669 /* these suspend and resume are not usb suspend and resume */ 2669 /* these suspend and resume are not usb suspend and resume */
diff --git a/drivers/usb/gadget/udc/fusb300_udc.c b/drivers/usb/gadget/udc/fusb300_udc.c
index fb4df159d32d..3970f453de49 100644
--- a/drivers/usb/gadget/udc/fusb300_udc.c
+++ b/drivers/usb/gadget/udc/fusb300_udc.c
@@ -1342,7 +1342,7 @@ static const struct usb_gadget_ops fusb300_gadget_ops = {
1342 .udc_stop = fusb300_udc_stop, 1342 .udc_stop = fusb300_udc_stop,
1343}; 1343};
1344 1344
1345static int __exit fusb300_remove(struct platform_device *pdev) 1345static int fusb300_remove(struct platform_device *pdev)
1346{ 1346{
1347 struct fusb300 *fusb300 = platform_get_drvdata(pdev); 1347 struct fusb300 *fusb300 = platform_get_drvdata(pdev);
1348 1348
@@ -1492,7 +1492,7 @@ clean_up:
1492} 1492}
1493 1493
1494static struct platform_driver fusb300_driver = { 1494static struct platform_driver fusb300_driver = {
1495 .remove = __exit_p(fusb300_remove), 1495 .remove = fusb300_remove,
1496 .driver = { 1496 .driver = {
1497 .name = (char *) udc_name, 1497 .name = (char *) udc_name,
1498 }, 1498 },
diff --git a/drivers/usb/gadget/udc/m66592-udc.c b/drivers/usb/gadget/udc/m66592-udc.c
index 8c7c83c93713..309706fe4bf0 100644
--- a/drivers/usb/gadget/udc/m66592-udc.c
+++ b/drivers/usb/gadget/udc/m66592-udc.c
@@ -1528,7 +1528,7 @@ static const struct usb_gadget_ops m66592_gadget_ops = {
1528 .pullup = m66592_pullup, 1528 .pullup = m66592_pullup,
1529}; 1529};
1530 1530
1531static int __exit m66592_remove(struct platform_device *pdev) 1531static int m66592_remove(struct platform_device *pdev)
1532{ 1532{
1533 struct m66592 *m66592 = platform_get_drvdata(pdev); 1533 struct m66592 *m66592 = platform_get_drvdata(pdev);
1534 1534
@@ -1695,7 +1695,7 @@ clean_up:
1695 1695
1696/*-------------------------------------------------------------------------*/ 1696/*-------------------------------------------------------------------------*/
1697static struct platform_driver m66592_driver = { 1697static struct platform_driver m66592_driver = {
1698 .remove = __exit_p(m66592_remove), 1698 .remove = m66592_remove,
1699 .driver = { 1699 .driver = {
1700 .name = (char *) udc_name, 1700 .name = (char *) udc_name,
1701 }, 1701 },
diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index 2495fe9c95c5..0293f7169dee 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -1820,7 +1820,7 @@ static const struct usb_gadget_ops r8a66597_gadget_ops = {
1820 .set_selfpowered = r8a66597_set_selfpowered, 1820 .set_selfpowered = r8a66597_set_selfpowered,
1821}; 1821};
1822 1822
1823static int __exit r8a66597_remove(struct platform_device *pdev) 1823static int r8a66597_remove(struct platform_device *pdev)
1824{ 1824{
1825 struct r8a66597 *r8a66597 = platform_get_drvdata(pdev); 1825 struct r8a66597 *r8a66597 = platform_get_drvdata(pdev);
1826 1826
@@ -1974,7 +1974,7 @@ clean_up2:
1974 1974
1975/*-------------------------------------------------------------------------*/ 1975/*-------------------------------------------------------------------------*/
1976static struct platform_driver r8a66597_driver = { 1976static struct platform_driver r8a66597_driver = {
1977 .remove = __exit_p(r8a66597_remove), 1977 .remove = r8a66597_remove,
1978 .driver = { 1978 .driver = {
1979 .name = (char *) udc_name, 1979 .name = (char *) udc_name,
1980 }, 1980 },
diff --git a/drivers/usb/gadget/udc/udc-xilinx.c b/drivers/usb/gadget/udc/udc-xilinx.c
index dd3e9fd31b80..1f24274477ab 100644
--- a/drivers/usb/gadget/udc/udc-xilinx.c
+++ b/drivers/usb/gadget/udc/udc-xilinx.c
@@ -2071,8 +2071,8 @@ static int xudc_probe(struct platform_device *pdev)
2071 /* Map the registers */ 2071 /* Map the registers */
2072 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2072 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2073 udc->addr = devm_ioremap_resource(&pdev->dev, res); 2073 udc->addr = devm_ioremap_resource(&pdev->dev, res);
2074 if (!udc->addr) 2074 if (IS_ERR(udc->addr))
2075 return -ENOMEM; 2075 return PTR_ERR(udc->addr);
2076 2076
2077 irq = platform_get_irq(pdev, 0); 2077 irq = platform_get_irq(pdev, 0);
2078 if (irq < 0) { 2078 if (irq < 0) {
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 9db74ca7e5b9..275c92e53a59 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -88,13 +88,20 @@ static int ehci_msm_probe(struct platform_device *pdev)
88 } 88 }
89 89
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 hcd->regs = devm_ioremap_resource(&pdev->dev, res); 91 if (!res) {
92 if (IS_ERR(hcd->regs)) { 92 dev_err(&pdev->dev, "Unable to get memory resource\n");
93 ret = PTR_ERR(hcd->regs); 93 ret = -ENODEV;
94 goto put_hcd; 94 goto put_hcd;
95 } 95 }
96
96 hcd->rsrc_start = res->start; 97 hcd->rsrc_start = res->start;
97 hcd->rsrc_len = resource_size(res); 98 hcd->rsrc_len = resource_size(res);
99 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
100 if (!hcd->regs) {
101 dev_err(&pdev->dev, "ioremap failed\n");
102 ret = -ENOMEM;
103 goto put_hcd;
104 }
98 105
99 /* 106 /*
100 * OTG driver takes care of PHY initialization, clock management, 107 * OTG driver takes care of PHY initialization, clock management,
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index f5397a517c54..7d34cbfaf373 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2026,8 +2026,13 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
2026 break; 2026 break;
2027 case COMP_DEV_ERR: 2027 case COMP_DEV_ERR:
2028 case COMP_STALL: 2028 case COMP_STALL:
2029 frame->status = -EPROTO;
2030 skip_td = true;
2031 break;
2029 case COMP_TX_ERR: 2032 case COMP_TX_ERR:
2030 frame->status = -EPROTO; 2033 frame->status = -EPROTO;
2034 if (event_trb != td->last_trb)
2035 return 0;
2031 skip_td = true; 2036 skip_td = true;
2032 break; 2037 break;
2033 case COMP_STOP: 2038 case COMP_STOP:
@@ -2640,7 +2645,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
2640 xhci_halt(xhci); 2645 xhci_halt(xhci);
2641hw_died: 2646hw_died:
2642 spin_unlock(&xhci->lock); 2647 spin_unlock(&xhci->lock);
2643 return -ESHUTDOWN; 2648 return IRQ_HANDLED;
2644 } 2649 }
2645 2650
2646 /* 2651 /*
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 8e421b89632d..ea75e8ccd3c1 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1267,7 +1267,7 @@ union xhci_trb {
1267 * since the command ring is 64-byte aligned. 1267 * since the command ring is 64-byte aligned.
1268 * It must also be greater than 16. 1268 * It must also be greater than 16.
1269 */ 1269 */
1270#define TRBS_PER_SEGMENT 64 1270#define TRBS_PER_SEGMENT 256
1271/* Allow two commands + a link TRB, along with any reserved command TRBs */ 1271/* Allow two commands + a link TRB, along with any reserved command TRBs */
1272#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) 1272#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
1273#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) 1273#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
diff --git a/drivers/usb/phy/phy-isp1301-omap.c b/drivers/usb/phy/phy-isp1301-omap.c
index 1e0e10dd6ba5..3af263cc0caa 100644
--- a/drivers/usb/phy/phy-isp1301-omap.c
+++ b/drivers/usb/phy/phy-isp1301-omap.c
@@ -94,7 +94,7 @@ struct isp1301 {
94 94
95#if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3) 95#if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
96 96
97#if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE) 97#if defined(CONFIG_TPS65010) || (defined(CONFIG_TPS65010_MODULE) && defined(MODULE))
98 98
99#include <linux/i2c/tps65010.h> 99#include <linux/i2c/tps65010.h>
100 100
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 84ce2d74894c..9031750e7404 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -127,6 +127,7 @@ static const struct usb_device_id id_table[] = {
127 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ 127 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
128 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */ 128 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
129 { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */ 129 { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */
130 { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */
130 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 131 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
131 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 132 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
132 { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */ 133 { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 829604d11f3f..f5257af33ecf 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -61,7 +61,6 @@ static const struct usb_device_id id_table[] = {
61 { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) }, 61 { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
62 { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) }, 62 { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) },
63 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) }, 63 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) },
64 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) },
65 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1), 64 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1),
66 .driver_info = PL2303_QUIRK_UART_STATE_IDX0 }, 65 .driver_info = PL2303_QUIRK_UART_STATE_IDX0 },
67 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65), 66 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65),
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 71fd9da1d6e7..e3b7af8adfb7 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -62,10 +62,6 @@
62#define ALCATEL_VENDOR_ID 0x11f7 62#define ALCATEL_VENDOR_ID 0x11f7
63#define ALCATEL_PRODUCT_ID 0x02df 63#define ALCATEL_PRODUCT_ID 0x02df
64 64
65/* Samsung I330 phone cradle */
66#define SAMSUNG_VENDOR_ID 0x04e8
67#define SAMSUNG_PRODUCT_ID 0x8001
68
69#define SIEMENS_VENDOR_ID 0x11f5 65#define SIEMENS_VENDOR_ID 0x11f5
70#define SIEMENS_PRODUCT_ID_SX1 0x0001 66#define SIEMENS_PRODUCT_ID_SX1 0x0001
71#define SIEMENS_PRODUCT_ID_X65 0x0003 67#define SIEMENS_PRODUCT_ID_X65 0x0003
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index bf2bd40e5f2a..60afb39eb73c 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -95,7 +95,7 @@ static const struct usb_device_id id_table[] = {
95 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 95 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
96 { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID), 96 { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID),
97 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 97 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
98 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID), 98 { USB_DEVICE_INTERFACE_CLASS(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID, 0xff),
99 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 99 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
100 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID), 100 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID),
101 .driver_info = (kernel_ulong_t)&palm_os_4_probe }, 101 .driver_info = (kernel_ulong_t)&palm_os_4_probe },
diff --git a/drivers/usb/storage/uas-detect.h b/drivers/usb/storage/uas-detect.h
index 9893d696fc97..f58caa9e6a27 100644
--- a/drivers/usb/storage/uas-detect.h
+++ b/drivers/usb/storage/uas-detect.h
@@ -51,7 +51,8 @@ static int uas_find_endpoints(struct usb_host_interface *alt,
51} 51}
52 52
53static int uas_use_uas_driver(struct usb_interface *intf, 53static int uas_use_uas_driver(struct usb_interface *intf,
54 const struct usb_device_id *id) 54 const struct usb_device_id *id,
55 unsigned long *flags_ret)
55{ 56{
56 struct usb_host_endpoint *eps[4] = { }; 57 struct usb_host_endpoint *eps[4] = { };
57 struct usb_device *udev = interface_to_usbdev(intf); 58 struct usb_device *udev = interface_to_usbdev(intf);
@@ -73,7 +74,7 @@ static int uas_use_uas_driver(struct usb_interface *intf,
73 * this writing the following versions exist: 74 * this writing the following versions exist:
74 * ASM1051 - no uas support version 75 * ASM1051 - no uas support version
75 * ASM1051 - with broken (*) uas support 76 * ASM1051 - with broken (*) uas support
76 * ASM1053 - with working uas support 77 * ASM1053 - with working uas support, but problems with large xfers
77 * ASM1153 - with working uas support 78 * ASM1153 - with working uas support
78 * 79 *
79 * Devices with these chips re-use a number of device-ids over the 80 * Devices with these chips re-use a number of device-ids over the
@@ -103,6 +104,9 @@ static int uas_use_uas_driver(struct usb_interface *intf,
103 } else if (usb_ss_max_streams(&eps[1]->ss_ep_comp) == 32) { 104 } else if (usb_ss_max_streams(&eps[1]->ss_ep_comp) == 32) {
104 /* Possibly an ASM1051, disable uas */ 105 /* Possibly an ASM1051, disable uas */
105 flags |= US_FL_IGNORE_UAS; 106 flags |= US_FL_IGNORE_UAS;
107 } else {
108 /* ASM1053, these have issues with large transfers */
109 flags |= US_FL_MAX_SECTORS_240;
106 } 110 }
107 } 111 }
108 112
@@ -132,5 +136,8 @@ static int uas_use_uas_driver(struct usb_interface *intf,
132 return 0; 136 return 0;
133 } 137 }
134 138
139 if (flags_ret)
140 *flags_ret = flags;
141
135 return 1; 142 return 1;
136} 143}
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 6cdabdc119a7..6d3122afeed3 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -759,7 +759,10 @@ static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd)
759 759
760static int uas_slave_alloc(struct scsi_device *sdev) 760static int uas_slave_alloc(struct scsi_device *sdev)
761{ 761{
762 sdev->hostdata = (void *)sdev->host->hostdata; 762 struct uas_dev_info *devinfo =
763 (struct uas_dev_info *)sdev->host->hostdata;
764
765 sdev->hostdata = devinfo;
763 766
764 /* USB has unusual DMA-alignment requirements: Although the 767 /* USB has unusual DMA-alignment requirements: Although the
765 * starting address of each scatter-gather element doesn't matter, 768 * starting address of each scatter-gather element doesn't matter,
@@ -778,6 +781,11 @@ static int uas_slave_alloc(struct scsi_device *sdev)
778 */ 781 */
779 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); 782 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
780 783
784 if (devinfo->flags & US_FL_MAX_SECTORS_64)
785 blk_queue_max_hw_sectors(sdev->request_queue, 64);
786 else if (devinfo->flags & US_FL_MAX_SECTORS_240)
787 blk_queue_max_hw_sectors(sdev->request_queue, 240);
788
781 return 0; 789 return 0;
782} 790}
783 791
@@ -887,8 +895,9 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
887 struct Scsi_Host *shost = NULL; 895 struct Scsi_Host *shost = NULL;
888 struct uas_dev_info *devinfo; 896 struct uas_dev_info *devinfo;
889 struct usb_device *udev = interface_to_usbdev(intf); 897 struct usb_device *udev = interface_to_usbdev(intf);
898 unsigned long dev_flags;
890 899
891 if (!uas_use_uas_driver(intf, id)) 900 if (!uas_use_uas_driver(intf, id, &dev_flags))
892 return -ENODEV; 901 return -ENODEV;
893 902
894 if (uas_switch_interface(udev, intf)) 903 if (uas_switch_interface(udev, intf))
@@ -910,8 +919,7 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
910 devinfo->udev = udev; 919 devinfo->udev = udev;
911 devinfo->resetting = 0; 920 devinfo->resetting = 0;
912 devinfo->shutdown = 0; 921 devinfo->shutdown = 0;
913 devinfo->flags = id->driver_info; 922 devinfo->flags = dev_flags;
914 usb_stor_adjust_quirks(udev, &devinfo->flags);
915 init_usb_anchor(&devinfo->cmd_urbs); 923 init_usb_anchor(&devinfo->cmd_urbs);
916 init_usb_anchor(&devinfo->sense_urbs); 924 init_usb_anchor(&devinfo->sense_urbs);
917 init_usb_anchor(&devinfo->data_urbs); 925 init_usb_anchor(&devinfo->data_urbs);
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index d684b4b8108f..caf188800c67 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -766,6 +766,13 @@ UNUSUAL_DEV( 0x059f, 0x0643, 0x0000, 0x0000,
766 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 766 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
767 US_FL_GO_SLOW ), 767 US_FL_GO_SLOW ),
768 768
769/* Reported by Christian Schaller <cschalle@redhat.com> */
770UNUSUAL_DEV( 0x059f, 0x0651, 0x0000, 0x0000,
771 "LaCie",
772 "External HDD",
773 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
774 US_FL_NO_WP_DETECT ),
775
769/* Submitted by Joel Bourquard <numlock@freesurf.ch> 776/* Submitted by Joel Bourquard <numlock@freesurf.ch>
770 * Some versions of this device need the SubClass and Protocol overrides 777 * Some versions of this device need the SubClass and Protocol overrides
771 * while others don't. 778 * while others don't.
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 5600c33fcadb..6c10c888f35f 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -479,7 +479,8 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)
479 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT | 479 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
480 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 | 480 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 |
481 US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE | 481 US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE |
482 US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES); 482 US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES |
483 US_FL_MAX_SECTORS_240);
483 484
484 p = quirks; 485 p = quirks;
485 while (*p) { 486 while (*p) {
@@ -520,6 +521,9 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)
520 case 'f': 521 case 'f':
521 f |= US_FL_NO_REPORT_OPCODES; 522 f |= US_FL_NO_REPORT_OPCODES;
522 break; 523 break;
524 case 'g':
525 f |= US_FL_MAX_SECTORS_240;
526 break;
523 case 'h': 527 case 'h':
524 f |= US_FL_CAPACITY_HEURISTICS; 528 f |= US_FL_CAPACITY_HEURISTICS;
525 break; 529 break;
@@ -1080,7 +1084,7 @@ static int storage_probe(struct usb_interface *intf,
1080 1084
1081 /* If uas is enabled and this device can do uas then ignore it. */ 1085 /* If uas is enabled and this device can do uas then ignore it. */
1082#if IS_ENABLED(CONFIG_USB_UAS) 1086#if IS_ENABLED(CONFIG_USB_UAS)
1083 if (uas_use_uas_driver(intf, id)) 1087 if (uas_use_uas_driver(intf, id, NULL))
1084 return -ENXIO; 1088 return -ENXIO;
1085#endif 1089#endif
1086 1090
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 69fab0fd15ae..e9851add6f4e 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -907,8 +907,14 @@ static void vfio_pci_request(void *device_data, unsigned int count)
907 mutex_lock(&vdev->igate); 907 mutex_lock(&vdev->igate);
908 908
909 if (vdev->req_trigger) { 909 if (vdev->req_trigger) {
910 dev_dbg(&vdev->pdev->dev, "Requesting device from user\n"); 910 if (!(count % 10))
911 dev_notice_ratelimited(&vdev->pdev->dev,
912 "Relaying device request to user (#%u)\n",
913 count);
911 eventfd_signal(vdev->req_trigger, 1); 914 eventfd_signal(vdev->req_trigger, 1);
915 } else if (count == 0) {
916 dev_warn(&vdev->pdev->dev,
917 "No device request channel registered, blocked until released by user\n");
912 } 918 }
913 919
914 mutex_unlock(&vdev->igate); 920 mutex_unlock(&vdev->igate);
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 0d336625ac71..e1278fe04b1e 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -710,6 +710,8 @@ void *vfio_del_group_dev(struct device *dev)
710 void *device_data = device->device_data; 710 void *device_data = device->device_data;
711 struct vfio_unbound_dev *unbound; 711 struct vfio_unbound_dev *unbound;
712 unsigned int i = 0; 712 unsigned int i = 0;
713 long ret;
714 bool interrupted = false;
713 715
714 /* 716 /*
715 * The group exists so long as we have a device reference. Get 717 * The group exists so long as we have a device reference. Get
@@ -755,9 +757,22 @@ void *vfio_del_group_dev(struct device *dev)
755 757
756 vfio_device_put(device); 758 vfio_device_put(device);
757 759
758 } while (wait_event_interruptible_timeout(vfio.release_q, 760 if (interrupted) {
759 !vfio_dev_present(group, dev), 761 ret = wait_event_timeout(vfio.release_q,
760 HZ * 10) <= 0); 762 !vfio_dev_present(group, dev), HZ * 10);
763 } else {
764 ret = wait_event_interruptible_timeout(vfio.release_q,
765 !vfio_dev_present(group, dev), HZ * 10);
766 if (ret == -ERESTARTSYS) {
767 interrupted = true;
768 dev_warn(dev,
769 "Device is currently in use, task"
770 " \"%s\" (%d) "
771 "blocked until device is released",
772 current->comm, task_pid_nr(current));
773 }
774 }
775 } while (ret <= 0);
761 776
762 vfio_group_put(group); 777 vfio_group_put(group);
763 778
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 5e19bb53b3a9..ea32b386797f 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1409,8 +1409,7 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
1409 * dependency now. 1409 * dependency now.
1410 */ 1410 */
1411 se_tpg = &tpg->se_tpg; 1411 se_tpg = &tpg->se_tpg;
1412 ret = configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys, 1412 ret = target_depend_item(&se_tpg->tpg_group.cg_item);
1413 &se_tpg->tpg_group.cg_item);
1414 if (ret) { 1413 if (ret) {
1415 pr_warn("configfs_depend_item() failed: %d\n", ret); 1414 pr_warn("configfs_depend_item() failed: %d\n", ret);
1416 kfree(vs_tpg); 1415 kfree(vs_tpg);
@@ -1513,8 +1512,7 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
1513 * to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur. 1512 * to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur.
1514 */ 1513 */
1515 se_tpg = &tpg->se_tpg; 1514 se_tpg = &tpg->se_tpg;
1516 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys, 1515 target_undepend_item(&se_tpg->tpg_group.cg_item);
1517 &se_tpg->tpg_group.cg_item);
1518 } 1516 }
1519 if (match) { 1517 if (match) {
1520 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) { 1518 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 3a145a643e0d..6897f1c1bc73 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -274,6 +274,10 @@ static int pwm_backlight_probe(struct platform_device *pdev)
274 274
275 pb->pwm = devm_pwm_get(&pdev->dev, NULL); 275 pb->pwm = devm_pwm_get(&pdev->dev, NULL);
276 if (IS_ERR(pb->pwm)) { 276 if (IS_ERR(pb->pwm)) {
277 ret = PTR_ERR(pb->pwm);
278 if (ret == -EPROBE_DEFER)
279 goto err_alloc;
280
277 dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); 281 dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n");
278 pb->legacy = true; 282 pb->legacy = true;
279 pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); 283 pb->pwm = pwm_request(data->pwm_id, "pwm-backlight");
diff --git a/drivers/xen/events/events_2l.c b/drivers/xen/events/events_2l.c
index 5db43fc100a4..7dd46312c180 100644
--- a/drivers/xen/events/events_2l.c
+++ b/drivers/xen/events/events_2l.c
@@ -345,6 +345,15 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
345 return IRQ_HANDLED; 345 return IRQ_HANDLED;
346} 346}
347 347
348static void evtchn_2l_resume(void)
349{
350 int i;
351
352 for_each_online_cpu(i)
353 memset(per_cpu(cpu_evtchn_mask, i), 0, sizeof(xen_ulong_t) *
354 EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD);
355}
356
348static const struct evtchn_ops evtchn_ops_2l = { 357static const struct evtchn_ops evtchn_ops_2l = {
349 .max_channels = evtchn_2l_max_channels, 358 .max_channels = evtchn_2l_max_channels,
350 .nr_channels = evtchn_2l_max_channels, 359 .nr_channels = evtchn_2l_max_channels,
@@ -356,6 +365,7 @@ static const struct evtchn_ops evtchn_ops_2l = {
356 .mask = evtchn_2l_mask, 365 .mask = evtchn_2l_mask,
357 .unmask = evtchn_2l_unmask, 366 .unmask = evtchn_2l_unmask,
358 .handle_events = evtchn_2l_handle_events, 367 .handle_events = evtchn_2l_handle_events,
368 .resume = evtchn_2l_resume,
359}; 369};
360 370
361void __init xen_evtchn_2l_init(void) 371void __init xen_evtchn_2l_init(void)
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 70fba973a107..38387950490e 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -529,8 +529,8 @@ static unsigned int __startup_pirq(unsigned int irq)
529 if (rc) 529 if (rc)
530 goto err; 530 goto err;
531 531
532 bind_evtchn_to_cpu(evtchn, 0);
533 info->evtchn = evtchn; 532 info->evtchn = evtchn;
533 bind_evtchn_to_cpu(evtchn, 0);
534 534
535 rc = xen_evtchn_port_setup(info); 535 rc = xen_evtchn_port_setup(info);
536 if (rc) 536 if (rc)
@@ -957,7 +957,7 @@ unsigned xen_evtchn_nr_channels(void)
957} 957}
958EXPORT_SYMBOL_GPL(xen_evtchn_nr_channels); 958EXPORT_SYMBOL_GPL(xen_evtchn_nr_channels);
959 959
960int bind_virq_to_irq(unsigned int virq, unsigned int cpu) 960int bind_virq_to_irq(unsigned int virq, unsigned int cpu, bool percpu)
961{ 961{
962 struct evtchn_bind_virq bind_virq; 962 struct evtchn_bind_virq bind_virq;
963 int evtchn, irq, ret; 963 int evtchn, irq, ret;
@@ -971,8 +971,12 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
971 if (irq < 0) 971 if (irq < 0)
972 goto out; 972 goto out;
973 973
974 irq_set_chip_and_handler_name(irq, &xen_percpu_chip, 974 if (percpu)
975 handle_percpu_irq, "virq"); 975 irq_set_chip_and_handler_name(irq, &xen_percpu_chip,
976 handle_percpu_irq, "virq");
977 else
978 irq_set_chip_and_handler_name(irq, &xen_dynamic_chip,
979 handle_edge_irq, "virq");
976 980
977 bind_virq.virq = virq; 981 bind_virq.virq = virq;
978 bind_virq.vcpu = cpu; 982 bind_virq.vcpu = cpu;
@@ -1062,7 +1066,7 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
1062{ 1066{
1063 int irq, retval; 1067 int irq, retval;
1064 1068
1065 irq = bind_virq_to_irq(virq, cpu); 1069 irq = bind_virq_to_irq(virq, cpu, irqflags & IRQF_PERCPU);
1066 if (irq < 0) 1070 if (irq < 0)
1067 return irq; 1071 return irq;
1068 retval = request_irq(irq, handler, irqflags, devname, dev_id); 1072 retval = request_irq(irq, handler, irqflags, devname, dev_id);
@@ -1279,8 +1283,9 @@ void rebind_evtchn_irq(int evtchn, int irq)
1279 1283
1280 mutex_unlock(&irq_mapping_update_lock); 1284 mutex_unlock(&irq_mapping_update_lock);
1281 1285
1282 /* new event channels are always bound to cpu 0 */ 1286 bind_evtchn_to_cpu(evtchn, info->cpu);
1283 irq_set_affinity(irq, cpumask_of(0)); 1287 /* This will be deferred until interrupt is processed */
1288 irq_set_affinity(irq, cpumask_of(info->cpu));
1284 1289
1285 /* Unmask the event channel. */ 1290 /* Unmask the event channel. */
1286 enable_irq(irq); 1291 enable_irq(irq);
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index d5bb1a33d0a3..89274850741b 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -327,30 +327,10 @@ static int map_grant_pages(struct grant_map *map)
327 return err; 327 return err;
328} 328}
329 329
330struct unmap_grant_pages_callback_data
331{
332 struct completion completion;
333 int result;
334};
335
336static void unmap_grant_callback(int result,
337 struct gntab_unmap_queue_data *data)
338{
339 struct unmap_grant_pages_callback_data* d = data->data;
340
341 d->result = result;
342 complete(&d->completion);
343}
344
345static int __unmap_grant_pages(struct grant_map *map, int offset, int pages) 330static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
346{ 331{
347 int i, err = 0; 332 int i, err = 0;
348 struct gntab_unmap_queue_data unmap_data; 333 struct gntab_unmap_queue_data unmap_data;
349 struct unmap_grant_pages_callback_data data;
350
351 init_completion(&data.completion);
352 unmap_data.data = &data;
353 unmap_data.done= &unmap_grant_callback;
354 334
355 if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) { 335 if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {
356 int pgno = (map->notify.addr >> PAGE_SHIFT); 336 int pgno = (map->notify.addr >> PAGE_SHIFT);
@@ -367,11 +347,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
367 unmap_data.pages = map->pages + offset; 347 unmap_data.pages = map->pages + offset;
368 unmap_data.count = pages; 348 unmap_data.count = pages;
369 349
370 gnttab_unmap_refs_async(&unmap_data); 350 err = gnttab_unmap_refs_sync(&unmap_data);
371 351 if (err)
372 wait_for_completion(&data.completion); 352 return err;
373 if (data.result)
374 return data.result;
375 353
376 for (i = 0; i < pages; i++) { 354 for (i = 0; i < pages; i++) {
377 if (map->unmap_ops[offset+i].status) 355 if (map->unmap_ops[offset+i].status)
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 17972fbacddc..b1c7170e5c9e 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -123,6 +123,11 @@ struct gnttab_ops {
123 int (*query_foreign_access)(grant_ref_t ref); 123 int (*query_foreign_access)(grant_ref_t ref);
124}; 124};
125 125
126struct unmap_refs_callback_data {
127 struct completion completion;
128 int result;
129};
130
126static struct gnttab_ops *gnttab_interface; 131static struct gnttab_ops *gnttab_interface;
127 132
128static int grant_table_version; 133static int grant_table_version;
@@ -863,6 +868,29 @@ void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item)
863} 868}
864EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async); 869EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async);
865 870
871static void unmap_refs_callback(int result,
872 struct gntab_unmap_queue_data *data)
873{
874 struct unmap_refs_callback_data *d = data->data;
875
876 d->result = result;
877 complete(&d->completion);
878}
879
880int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item)
881{
882 struct unmap_refs_callback_data data;
883
884 init_completion(&data.completion);
885 item->data = &data;
886 item->done = &unmap_refs_callback;
887 gnttab_unmap_refs_async(item);
888 wait_for_completion(&data.completion);
889
890 return data.result;
891}
892EXPORT_SYMBOL_GPL(gnttab_unmap_refs_sync);
893
866static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes) 894static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes)
867{ 895{
868 int rc; 896 int rc;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index bf1940706422..9e6a85104a20 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -131,6 +131,8 @@ static void do_suspend(void)
131 goto out_resume; 131 goto out_resume;
132 } 132 }
133 133
134 xen_arch_suspend();
135
134 si.cancelled = 1; 136 si.cancelled = 1;
135 137
136 err = stop_machine(xen_suspend, &si, cpumask_of(0)); 138 err = stop_machine(xen_suspend, &si, cpumask_of(0));
@@ -148,11 +150,12 @@ static void do_suspend(void)
148 si.cancelled = 1; 150 si.cancelled = 1;
149 } 151 }
150 152
153 xen_arch_resume();
154
151out_resume: 155out_resume:
152 if (!si.cancelled) { 156 if (!si.cancelled)
153 xen_arch_resume();
154 xs_resume(); 157 xs_resume();
155 } else 158 else
156 xs_suspend_cancel(); 159 xs_suspend_cancel();
157 160
158 dpm_resume_end(si.cancelled ? PMSG_THAW : PMSG_RESTORE); 161 dpm_resume_end(si.cancelled ? PMSG_THAW : PMSG_RESTORE);
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 810ad419e34c..4c549323c605 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -235,7 +235,7 @@ retry:
235#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) 235#define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT))
236#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) 236#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
237 while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { 237 while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
238 xen_io_tlb_start = (void *)__get_free_pages(__GFP_NOWARN, order); 238 xen_io_tlb_start = (void *)xen_get_swiotlb_free_pages(order);
239 if (xen_io_tlb_start) 239 if (xen_io_tlb_start)
240 break; 240 break;
241 order--; 241 order--;
diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c
index 75fe3d466515..9c234209d8b5 100644
--- a/drivers/xen/xen-pciback/conf_space.c
+++ b/drivers/xen/xen-pciback/conf_space.c
@@ -16,8 +16,8 @@
16#include "conf_space.h" 16#include "conf_space.h"
17#include "conf_space_quirks.h" 17#include "conf_space_quirks.h"
18 18
19bool permissive; 19bool xen_pcibk_permissive;
20module_param(permissive, bool, 0644); 20module_param_named(permissive, xen_pcibk_permissive, bool, 0644);
21 21
22/* This is where xen_pcibk_read_config_byte, xen_pcibk_read_config_word, 22/* This is where xen_pcibk_read_config_byte, xen_pcibk_read_config_word,
23 * xen_pcibk_write_config_word, and xen_pcibk_write_config_byte are created. */ 23 * xen_pcibk_write_config_word, and xen_pcibk_write_config_byte are created. */
@@ -262,7 +262,7 @@ int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size, u32 value)
262 * This means that some fields may still be read-only because 262 * This means that some fields may still be read-only because
263 * they have entries in the config_field list that intercept 263 * they have entries in the config_field list that intercept
264 * the write and do nothing. */ 264 * the write and do nothing. */
265 if (dev_data->permissive || permissive) { 265 if (dev_data->permissive || xen_pcibk_permissive) {
266 switch (size) { 266 switch (size) {
267 case 1: 267 case 1:
268 err = pci_write_config_byte(dev, offset, 268 err = pci_write_config_byte(dev, offset,
diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
index 2e1d73d1d5d0..62461a8ba1d6 100644
--- a/drivers/xen/xen-pciback/conf_space.h
+++ b/drivers/xen/xen-pciback/conf_space.h
@@ -64,7 +64,7 @@ struct config_field_entry {
64 void *data; 64 void *data;
65}; 65};
66 66
67extern bool permissive; 67extern bool xen_pcibk_permissive;
68 68
69#define OFFSET(cfg_entry) ((cfg_entry)->base_offset+(cfg_entry)->field->offset) 69#define OFFSET(cfg_entry) ((cfg_entry)->base_offset+(cfg_entry)->field->offset)
70 70
diff --git a/drivers/xen/xen-pciback/conf_space_header.c b/drivers/xen/xen-pciback/conf_space_header.c
index c2260a0456c9..ad3d17d29c81 100644
--- a/drivers/xen/xen-pciback/conf_space_header.c
+++ b/drivers/xen/xen-pciback/conf_space_header.c
@@ -118,7 +118,7 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data)
118 118
119 cmd->val = value; 119 cmd->val = value;
120 120
121 if (!permissive && (!dev_data || !dev_data->permissive)) 121 if (!xen_pcibk_permissive && (!dev_data || !dev_data->permissive))
122 return 0; 122 return 0;
123 123
124 /* Only allow the guest to control certain bits. */ 124 /* Only allow the guest to control certain bits. */
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 564b31584860..5390a674b5e3 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -57,6 +57,7 @@
57#include <xen/xen.h> 57#include <xen/xen.h>
58#include <xen/xenbus.h> 58#include <xen/xenbus.h>
59#include <xen/events.h> 59#include <xen/events.h>
60#include <xen/xen-ops.h>
60#include <xen/page.h> 61#include <xen/page.h>
61 62
62#include <xen/hvm.h> 63#include <xen/hvm.h>
@@ -735,6 +736,30 @@ static int __init xenstored_local_init(void)
735 return err; 736 return err;
736} 737}
737 738
739static int xenbus_resume_cb(struct notifier_block *nb,
740 unsigned long action, void *data)
741{
742 int err = 0;
743
744 if (xen_hvm_domain()) {
745 uint64_t v;
746
747 err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
748 if (!err && v)
749 xen_store_evtchn = v;
750 else
751 pr_warn("Cannot update xenstore event channel: %d\n",
752 err);
753 } else
754 xen_store_evtchn = xen_start_info->store_evtchn;
755
756 return err;
757}
758
759static struct notifier_block xenbus_resume_nb = {
760 .notifier_call = xenbus_resume_cb,
761};
762
738static int __init xenbus_init(void) 763static int __init xenbus_init(void)
739{ 764{
740 int err = 0; 765 int err = 0;
@@ -793,6 +818,10 @@ static int __init xenbus_init(void)
793 goto out_error; 818 goto out_error;
794 } 819 }
795 820
821 if ((xen_store_domain_type != XS_LOCAL) &&
822 (xen_store_domain_type != XS_UNKNOWN))
823 xen_resume_notifier_register(&xenbus_resume_nb);
824
796#ifdef CONFIG_XEN_COMPAT_XENFS 825#ifdef CONFIG_XEN_COMPAT_XENFS
797 /* 826 /*
798 * Create xenfs mountpoint in /proc for compatibility with 827 * Create xenfs mountpoint in /proc for compatibility with
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 241ef68d2893..cd46e4158830 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -918,7 +918,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
918 total_size = total_mapping_size(elf_phdata, 918 total_size = total_mapping_size(elf_phdata,
919 loc->elf_ex.e_phnum); 919 loc->elf_ex.e_phnum);
920 if (!total_size) { 920 if (!total_size) {
921 error = -EINVAL; 921 retval = -EINVAL;
922 goto out_free_dentry; 922 goto out_free_dentry;
923 } 923 }
924 } 924 }
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 9de772ee0031..614aaa1969bd 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -880,6 +880,8 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
880 * indirect refs to their parent bytenr. 880 * indirect refs to their parent bytenr.
881 * When roots are found, they're added to the roots list 881 * When roots are found, they're added to the roots list
882 * 882 *
883 * NOTE: This can return values > 0
884 *
883 * FIXME some caching might speed things up 885 * FIXME some caching might speed things up
884 */ 886 */
885static int find_parent_nodes(struct btrfs_trans_handle *trans, 887static int find_parent_nodes(struct btrfs_trans_handle *trans,
@@ -1198,6 +1200,19 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1198 return ret; 1200 return ret;
1199} 1201}
1200 1202
1203/**
1204 * btrfs_check_shared - tell us whether an extent is shared
1205 *
1206 * @trans: optional trans handle
1207 *
1208 * btrfs_check_shared uses the backref walking code but will short
1209 * circuit as soon as it finds a root or inode that doesn't match the
1210 * one passed in. This provides a significant performance benefit for
1211 * callers (such as fiemap) which want to know whether the extent is
1212 * shared but do not need a ref count.
1213 *
1214 * Return: 0 if extent is not shared, 1 if it is shared, < 0 on error.
1215 */
1201int btrfs_check_shared(struct btrfs_trans_handle *trans, 1216int btrfs_check_shared(struct btrfs_trans_handle *trans,
1202 struct btrfs_fs_info *fs_info, u64 root_objectid, 1217 struct btrfs_fs_info *fs_info, u64 root_objectid,
1203 u64 inum, u64 bytenr) 1218 u64 inum, u64 bytenr)
@@ -1226,11 +1241,13 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans,
1226 ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp, 1241 ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp,
1227 roots, NULL, root_objectid, inum); 1242 roots, NULL, root_objectid, inum);
1228 if (ret == BACKREF_FOUND_SHARED) { 1243 if (ret == BACKREF_FOUND_SHARED) {
1244 /* this is the only condition under which we return 1 */
1229 ret = 1; 1245 ret = 1;
1230 break; 1246 break;
1231 } 1247 }
1232 if (ret < 0 && ret != -ENOENT) 1248 if (ret < 0 && ret != -ENOENT)
1233 break; 1249 break;
1250 ret = 0;
1234 node = ulist_next(tmp, &uiter); 1251 node = ulist_next(tmp, &uiter);
1235 if (!node) 1252 if (!node)
1236 break; 1253 break;
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index cde698a07d21..a2ae42720a6a 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1802,6 +1802,8 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev)
1802 set_nlink(inode, btrfs_stack_inode_nlink(inode_item)); 1802 set_nlink(inode, btrfs_stack_inode_nlink(inode_item));
1803 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item)); 1803 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item));
1804 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item); 1804 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item);
1805 BTRFS_I(inode)->last_trans = btrfs_stack_inode_transid(inode_item);
1806
1805 inode->i_version = btrfs_stack_inode_sequence(inode_item); 1807 inode->i_version = btrfs_stack_inode_sequence(inode_item);
1806 inode->i_rdev = 0; 1808 inode->i_rdev = 0;
1807 *rdev = btrfs_stack_inode_rdev(inode_item); 1809 *rdev = btrfs_stack_inode_rdev(inode_item);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 1eef4ee01d1a..0ec3acd14cbf 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3178,10 +3178,8 @@ static int write_one_cache_group(struct btrfs_trans_handle *trans,
3178 bi = btrfs_item_ptr_offset(leaf, path->slots[0]); 3178 bi = btrfs_item_ptr_offset(leaf, path->slots[0]);
3179 write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item)); 3179 write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item));
3180 btrfs_mark_buffer_dirty(leaf); 3180 btrfs_mark_buffer_dirty(leaf);
3181 btrfs_release_path(path);
3182fail: 3181fail:
3183 if (ret) 3182 btrfs_release_path(path);
3184 btrfs_abort_transaction(trans, root, ret);
3185 return ret; 3183 return ret;
3186 3184
3187} 3185}
@@ -3305,8 +3303,7 @@ again:
3305 3303
3306 spin_lock(&block_group->lock); 3304 spin_lock(&block_group->lock);
3307 if (block_group->cached != BTRFS_CACHE_FINISHED || 3305 if (block_group->cached != BTRFS_CACHE_FINISHED ||
3308 !btrfs_test_opt(root, SPACE_CACHE) || 3306 !btrfs_test_opt(root, SPACE_CACHE)) {
3309 block_group->delalloc_bytes) {
3310 /* 3307 /*
3311 * don't bother trying to write stuff out _if_ 3308 * don't bother trying to write stuff out _if_
3312 * a) we're not cached, 3309 * a) we're not cached,
@@ -3408,17 +3405,14 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans,
3408 int loops = 0; 3405 int loops = 0;
3409 3406
3410 spin_lock(&cur_trans->dirty_bgs_lock); 3407 spin_lock(&cur_trans->dirty_bgs_lock);
3411 if (!list_empty(&cur_trans->dirty_bgs)) { 3408 if (list_empty(&cur_trans->dirty_bgs)) {
3412 list_splice_init(&cur_trans->dirty_bgs, &dirty); 3409 spin_unlock(&cur_trans->dirty_bgs_lock);
3410 return 0;
3413 } 3411 }
3412 list_splice_init(&cur_trans->dirty_bgs, &dirty);
3414 spin_unlock(&cur_trans->dirty_bgs_lock); 3413 spin_unlock(&cur_trans->dirty_bgs_lock);
3415 3414
3416again: 3415again:
3417 if (list_empty(&dirty)) {
3418 btrfs_free_path(path);
3419 return 0;
3420 }
3421
3422 /* 3416 /*
3423 * make sure all the block groups on our dirty list actually 3417 * make sure all the block groups on our dirty list actually
3424 * exist 3418 * exist
@@ -3431,18 +3425,16 @@ again:
3431 return -ENOMEM; 3425 return -ENOMEM;
3432 } 3426 }
3433 3427
3428 /*
3429 * cache_write_mutex is here only to save us from balance or automatic
3430 * removal of empty block groups deleting this block group while we are
3431 * writing out the cache
3432 */
3433 mutex_lock(&trans->transaction->cache_write_mutex);
3434 while (!list_empty(&dirty)) { 3434 while (!list_empty(&dirty)) {
3435 cache = list_first_entry(&dirty, 3435 cache = list_first_entry(&dirty,
3436 struct btrfs_block_group_cache, 3436 struct btrfs_block_group_cache,
3437 dirty_list); 3437 dirty_list);
3438
3439 /*
3440 * cache_write_mutex is here only to save us from balance
3441 * deleting this block group while we are writing out the
3442 * cache
3443 */
3444 mutex_lock(&trans->transaction->cache_write_mutex);
3445
3446 /* 3438 /*
3447 * this can happen if something re-dirties a block 3439 * this can happen if something re-dirties a block
3448 * group that is already under IO. Just wait for it to 3440 * group that is already under IO. Just wait for it to
@@ -3493,9 +3485,30 @@ again:
3493 ret = 0; 3485 ret = 0;
3494 } 3486 }
3495 } 3487 }
3496 if (!ret) 3488 if (!ret) {
3497 ret = write_one_cache_group(trans, root, path, cache); 3489 ret = write_one_cache_group(trans, root, path, cache);
3498 mutex_unlock(&trans->transaction->cache_write_mutex); 3490 /*
3491 * Our block group might still be attached to the list
3492 * of new block groups in the transaction handle of some
3493 * other task (struct btrfs_trans_handle->new_bgs). This
3494 * means its block group item isn't yet in the extent
3495 * tree. If this happens ignore the error, as we will
3496 * try again later in the critical section of the
3497 * transaction commit.
3498 */
3499 if (ret == -ENOENT) {
3500 ret = 0;
3501 spin_lock(&cur_trans->dirty_bgs_lock);
3502 if (list_empty(&cache->dirty_list)) {
3503 list_add_tail(&cache->dirty_list,
3504 &cur_trans->dirty_bgs);
3505 btrfs_get_block_group(cache);
3506 }
3507 spin_unlock(&cur_trans->dirty_bgs_lock);
3508 } else if (ret) {
3509 btrfs_abort_transaction(trans, root, ret);
3510 }
3511 }
3499 3512
3500 /* if its not on the io list, we need to put the block group */ 3513 /* if its not on the io list, we need to put the block group */
3501 if (should_put) 3514 if (should_put)
@@ -3503,7 +3516,16 @@ again:
3503 3516
3504 if (ret) 3517 if (ret)
3505 break; 3518 break;
3519
3520 /*
3521 * Avoid blocking other tasks for too long. It might even save
3522 * us from writing caches for block groups that are going to be
3523 * removed.
3524 */
3525 mutex_unlock(&trans->transaction->cache_write_mutex);
3526 mutex_lock(&trans->transaction->cache_write_mutex);
3506 } 3527 }
3528 mutex_unlock(&trans->transaction->cache_write_mutex);
3507 3529
3508 /* 3530 /*
3509 * go through delayed refs for all the stuff we've just kicked off 3531 * go through delayed refs for all the stuff we've just kicked off
@@ -3514,8 +3536,15 @@ again:
3514 loops++; 3536 loops++;
3515 spin_lock(&cur_trans->dirty_bgs_lock); 3537 spin_lock(&cur_trans->dirty_bgs_lock);
3516 list_splice_init(&cur_trans->dirty_bgs, &dirty); 3538 list_splice_init(&cur_trans->dirty_bgs, &dirty);
3539 /*
3540 * dirty_bgs_lock protects us from concurrent block group
3541 * deletes too (not just cache_write_mutex).
3542 */
3543 if (!list_empty(&dirty)) {
3544 spin_unlock(&cur_trans->dirty_bgs_lock);
3545 goto again;
3546 }
3517 spin_unlock(&cur_trans->dirty_bgs_lock); 3547 spin_unlock(&cur_trans->dirty_bgs_lock);
3518 goto again;
3519 } 3548 }
3520 3549
3521 btrfs_free_path(path); 3550 btrfs_free_path(path);
@@ -3588,8 +3617,11 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
3588 ret = 0; 3617 ret = 0;
3589 } 3618 }
3590 } 3619 }
3591 if (!ret) 3620 if (!ret) {
3592 ret = write_one_cache_group(trans, root, path, cache); 3621 ret = write_one_cache_group(trans, root, path, cache);
3622 if (ret)
3623 btrfs_abort_transaction(trans, root, ret);
3624 }
3593 3625
3594 /* if its not on the io list, we need to put the block group */ 3626 /* if its not on the io list, we need to put the block group */
3595 if (should_put) 3627 if (should_put)
@@ -7537,7 +7569,7 @@ static void unuse_block_rsv(struct btrfs_fs_info *fs_info,
7537 * returns the key for the extent through ins, and a tree buffer for 7569 * returns the key for the extent through ins, and a tree buffer for
7538 * the first block of the extent through buf. 7570 * the first block of the extent through buf.
7539 * 7571 *
7540 * returns the tree buffer or NULL. 7572 * returns the tree buffer or an ERR_PTR on error.
7541 */ 7573 */
7542struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 7574struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
7543 struct btrfs_root *root, 7575 struct btrfs_root *root,
@@ -7548,6 +7580,7 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
7548 struct btrfs_key ins; 7580 struct btrfs_key ins;
7549 struct btrfs_block_rsv *block_rsv; 7581 struct btrfs_block_rsv *block_rsv;
7550 struct extent_buffer *buf; 7582 struct extent_buffer *buf;
7583 struct btrfs_delayed_extent_op *extent_op;
7551 u64 flags = 0; 7584 u64 flags = 0;
7552 int ret; 7585 int ret;
7553 u32 blocksize = root->nodesize; 7586 u32 blocksize = root->nodesize;
@@ -7568,13 +7601,14 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
7568 7601
7569 ret = btrfs_reserve_extent(root, blocksize, blocksize, 7602 ret = btrfs_reserve_extent(root, blocksize, blocksize,
7570 empty_size, hint, &ins, 0, 0); 7603 empty_size, hint, &ins, 0, 0);
7571 if (ret) { 7604 if (ret)
7572 unuse_block_rsv(root->fs_info, block_rsv, blocksize); 7605 goto out_unuse;
7573 return ERR_PTR(ret);
7574 }
7575 7606
7576 buf = btrfs_init_new_buffer(trans, root, ins.objectid, level); 7607 buf = btrfs_init_new_buffer(trans, root, ins.objectid, level);
7577 BUG_ON(IS_ERR(buf)); /* -ENOMEM */ 7608 if (IS_ERR(buf)) {
7609 ret = PTR_ERR(buf);
7610 goto out_free_reserved;
7611 }
7578 7612
7579 if (root_objectid == BTRFS_TREE_RELOC_OBJECTID) { 7613 if (root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
7580 if (parent == 0) 7614 if (parent == 0)
@@ -7584,9 +7618,11 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
7584 BUG_ON(parent > 0); 7618 BUG_ON(parent > 0);
7585 7619
7586 if (root_objectid != BTRFS_TREE_LOG_OBJECTID) { 7620 if (root_objectid != BTRFS_TREE_LOG_OBJECTID) {
7587 struct btrfs_delayed_extent_op *extent_op;
7588 extent_op = btrfs_alloc_delayed_extent_op(); 7621 extent_op = btrfs_alloc_delayed_extent_op();
7589 BUG_ON(!extent_op); /* -ENOMEM */ 7622 if (!extent_op) {
7623 ret = -ENOMEM;
7624 goto out_free_buf;
7625 }
7590 if (key) 7626 if (key)
7591 memcpy(&extent_op->key, key, sizeof(extent_op->key)); 7627 memcpy(&extent_op->key, key, sizeof(extent_op->key));
7592 else 7628 else
@@ -7601,13 +7637,24 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
7601 extent_op->level = level; 7637 extent_op->level = level;
7602 7638
7603 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, 7639 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans,
7604 ins.objectid, 7640 ins.objectid, ins.offset,
7605 ins.offset, parent, root_objectid, 7641 parent, root_objectid, level,
7606 level, BTRFS_ADD_DELAYED_EXTENT, 7642 BTRFS_ADD_DELAYED_EXTENT,
7607 extent_op, 0); 7643 extent_op, 0);
7608 BUG_ON(ret); /* -ENOMEM */ 7644 if (ret)
7645 goto out_free_delayed;
7609 } 7646 }
7610 return buf; 7647 return buf;
7648
7649out_free_delayed:
7650 btrfs_free_delayed_extent_op(extent_op);
7651out_free_buf:
7652 free_extent_buffer(buf);
7653out_free_reserved:
7654 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 0);
7655out_unuse:
7656 unuse_block_rsv(root->fs_info, block_rsv, blocksize);
7657 return ERR_PTR(ret);
7611} 7658}
7612 7659
7613struct walk_control { 7660struct walk_control {
@@ -8782,6 +8829,24 @@ again:
8782 goto again; 8829 goto again;
8783 } 8830 }
8784 8831
8832 /*
8833 * if we are changing raid levels, try to allocate a corresponding
8834 * block group with the new raid level.
8835 */
8836 alloc_flags = update_block_group_flags(root, cache->flags);
8837 if (alloc_flags != cache->flags) {
8838 ret = do_chunk_alloc(trans, root, alloc_flags,
8839 CHUNK_ALLOC_FORCE);
8840 /*
8841 * ENOSPC is allowed here, we may have enough space
8842 * already allocated at the new raid level to
8843 * carry on
8844 */
8845 if (ret == -ENOSPC)
8846 ret = 0;
8847 if (ret < 0)
8848 goto out;
8849 }
8785 8850
8786 ret = set_block_group_ro(cache, 0); 8851 ret = set_block_group_ro(cache, 0);
8787 if (!ret) 8852 if (!ret)
@@ -8795,7 +8860,9 @@ again:
8795out: 8860out:
8796 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { 8861 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) {
8797 alloc_flags = update_block_group_flags(root, cache->flags); 8862 alloc_flags = update_block_group_flags(root, cache->flags);
8863 lock_chunks(root->fs_info->chunk_root);
8798 check_system_chunk(trans, root, alloc_flags); 8864 check_system_chunk(trans, root, alloc_flags);
8865 unlock_chunks(root->fs_info->chunk_root);
8799 } 8866 }
8800 mutex_unlock(&root->fs_info->ro_block_group_mutex); 8867 mutex_unlock(&root->fs_info->ro_block_group_mutex);
8801 8868
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 782f3bc4651d..c32d226bfecc 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4560,36 +4560,37 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb)
4560 do { 4560 do {
4561 index--; 4561 index--;
4562 page = eb->pages[index]; 4562 page = eb->pages[index];
4563 if (page && mapped) { 4563 if (!page)
4564 continue;
4565 if (mapped)
4564 spin_lock(&page->mapping->private_lock); 4566 spin_lock(&page->mapping->private_lock);
4567 /*
4568 * We do this since we'll remove the pages after we've
4569 * removed the eb from the radix tree, so we could race
4570 * and have this page now attached to the new eb. So
4571 * only clear page_private if it's still connected to
4572 * this eb.
4573 */
4574 if (PagePrivate(page) &&
4575 page->private == (unsigned long)eb) {
4576 BUG_ON(test_bit(EXTENT_BUFFER_DIRTY, &eb->bflags));
4577 BUG_ON(PageDirty(page));
4578 BUG_ON(PageWriteback(page));
4565 /* 4579 /*
4566 * We do this since we'll remove the pages after we've 4580 * We need to make sure we haven't be attached
4567 * removed the eb from the radix tree, so we could race 4581 * to a new eb.
4568 * and have this page now attached to the new eb. So
4569 * only clear page_private if it's still connected to
4570 * this eb.
4571 */ 4582 */
4572 if (PagePrivate(page) && 4583 ClearPagePrivate(page);
4573 page->private == (unsigned long)eb) { 4584 set_page_private(page, 0);
4574 BUG_ON(test_bit(EXTENT_BUFFER_DIRTY, &eb->bflags)); 4585 /* One for the page private */
4575 BUG_ON(PageDirty(page));
4576 BUG_ON(PageWriteback(page));
4577 /*
4578 * We need to make sure we haven't be attached
4579 * to a new eb.
4580 */
4581 ClearPagePrivate(page);
4582 set_page_private(page, 0);
4583 /* One for the page private */
4584 page_cache_release(page);
4585 }
4586 spin_unlock(&page->mapping->private_lock);
4587
4588 }
4589 if (page) {
4590 /* One for when we alloced the page */
4591 page_cache_release(page); 4586 page_cache_release(page);
4592 } 4587 }
4588
4589 if (mapped)
4590 spin_unlock(&page->mapping->private_lock);
4591
4592 /* One for when we alloced the page */
4593 page_cache_release(page);
4593 } while (index != 0); 4594 } while (index != 0);
4594} 4595}
4595 4596
@@ -4771,6 +4772,25 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
4771 start >> PAGE_CACHE_SHIFT); 4772 start >> PAGE_CACHE_SHIFT);
4772 if (eb && atomic_inc_not_zero(&eb->refs)) { 4773 if (eb && atomic_inc_not_zero(&eb->refs)) {
4773 rcu_read_unlock(); 4774 rcu_read_unlock();
4775 /*
4776 * Lock our eb's refs_lock to avoid races with
4777 * free_extent_buffer. When we get our eb it might be flagged
4778 * with EXTENT_BUFFER_STALE and another task running
4779 * free_extent_buffer might have seen that flag set,
4780 * eb->refs == 2, that the buffer isn't under IO (dirty and
4781 * writeback flags not set) and it's still in the tree (flag
4782 * EXTENT_BUFFER_TREE_REF set), therefore being in the process
4783 * of decrementing the extent buffer's reference count twice.
4784 * So here we could race and increment the eb's reference count,
4785 * clear its stale flag, mark it as dirty and drop our reference
4786 * before the other task finishes executing free_extent_buffer,
4787 * which would later result in an attempt to free an extent
4788 * buffer that is dirty.
4789 */
4790 if (test_bit(EXTENT_BUFFER_STALE, &eb->bflags)) {
4791 spin_lock(&eb->refs_lock);
4792 spin_unlock(&eb->refs_lock);
4793 }
4774 mark_extent_buffer_accessed(eb, NULL); 4794 mark_extent_buffer_accessed(eb, NULL);
4775 return eb; 4795 return eb;
4776 } 4796 }
@@ -4870,6 +4890,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
4870 mark_extent_buffer_accessed(exists, p); 4890 mark_extent_buffer_accessed(exists, p);
4871 goto free_eb; 4891 goto free_eb;
4872 } 4892 }
4893 exists = NULL;
4873 4894
4874 /* 4895 /*
4875 * Do this so attach doesn't complain and we need to 4896 * Do this so attach doesn't complain and we need to
@@ -4933,12 +4954,12 @@ again:
4933 return eb; 4954 return eb;
4934 4955
4935free_eb: 4956free_eb:
4957 WARN_ON(!atomic_dec_and_test(&eb->refs));
4936 for (i = 0; i < num_pages; i++) { 4958 for (i = 0; i < num_pages; i++) {
4937 if (eb->pages[i]) 4959 if (eb->pages[i])
4938 unlock_page(eb->pages[i]); 4960 unlock_page(eb->pages[i]);
4939 } 4961 }
4940 4962
4941 WARN_ON(!atomic_dec_and_test(&eb->refs));
4942 btrfs_release_extent_buffer(eb); 4963 btrfs_release_extent_buffer(eb);
4943 return exists; 4964 return exists;
4944} 4965}
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 81fa75a8e1f3..9dbe5b548fa6 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -86,7 +86,7 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
86 86
87 mapping_set_gfp_mask(inode->i_mapping, 87 mapping_set_gfp_mask(inode->i_mapping,
88 mapping_gfp_mask(inode->i_mapping) & 88 mapping_gfp_mask(inode->i_mapping) &
89 ~(GFP_NOFS & ~__GFP_HIGHMEM)); 89 ~(__GFP_FS | __GFP_HIGHMEM));
90 90
91 return inode; 91 return inode;
92} 92}
@@ -1218,7 +1218,7 @@ out:
1218 * 1218 *
1219 * This function writes out a free space cache struct to disk for quick recovery 1219 * This function writes out a free space cache struct to disk for quick recovery
1220 * on mount. This will return 0 if it was successfull in writing the cache out, 1220 * on mount. This will return 0 if it was successfull in writing the cache out,
1221 * and -1 if it was not. 1221 * or an errno if it was not.
1222 */ 1222 */
1223static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, 1223static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
1224 struct btrfs_free_space_ctl *ctl, 1224 struct btrfs_free_space_ctl *ctl,
@@ -1235,12 +1235,12 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
1235 int must_iput = 0; 1235 int must_iput = 0;
1236 1236
1237 if (!i_size_read(inode)) 1237 if (!i_size_read(inode))
1238 return -1; 1238 return -EIO;
1239 1239
1240 WARN_ON(io_ctl->pages); 1240 WARN_ON(io_ctl->pages);
1241 ret = io_ctl_init(io_ctl, inode, root, 1); 1241 ret = io_ctl_init(io_ctl, inode, root, 1);
1242 if (ret) 1242 if (ret)
1243 return -1; 1243 return ret;
1244 1244
1245 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) { 1245 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) {
1246 down_write(&block_group->data_rwsem); 1246 down_write(&block_group->data_rwsem);
@@ -1258,7 +1258,9 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
1258 } 1258 }
1259 1259
1260 /* Lock all pages first so we can lock the extent safely. */ 1260 /* Lock all pages first so we can lock the extent safely. */
1261 io_ctl_prepare_pages(io_ctl, inode, 0); 1261 ret = io_ctl_prepare_pages(io_ctl, inode, 0);
1262 if (ret)
1263 goto out;
1262 1264
1263 lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, 1265 lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1,
1264 0, &cached_state); 1266 0, &cached_state);
@@ -3464,6 +3466,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
3464 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; 3466 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl;
3465 int ret; 3467 int ret;
3466 struct btrfs_io_ctl io_ctl; 3468 struct btrfs_io_ctl io_ctl;
3469 bool release_metadata = true;
3467 3470
3468 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) 3471 if (!btrfs_test_opt(root, INODE_MAP_CACHE))
3469 return 0; 3472 return 0;
@@ -3471,11 +3474,20 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
3471 memset(&io_ctl, 0, sizeof(io_ctl)); 3474 memset(&io_ctl, 0, sizeof(io_ctl));
3472 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, 3475 ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl,
3473 trans, path, 0); 3476 trans, path, 0);
3474 if (!ret) 3477 if (!ret) {
3478 /*
3479 * At this point writepages() didn't error out, so our metadata
3480 * reservation is released when the writeback finishes, at
3481 * inode.c:btrfs_finish_ordered_io(), regardless of it finishing
3482 * with or without an error.
3483 */
3484 release_metadata = false;
3475 ret = btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0); 3485 ret = btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0);
3486 }
3476 3487
3477 if (ret) { 3488 if (ret) {
3478 btrfs_delalloc_release_metadata(inode, inode->i_size); 3489 if (release_metadata)
3490 btrfs_delalloc_release_metadata(inode, inode->i_size);
3479#ifdef DEBUG 3491#ifdef DEBUG
3480 btrfs_err(root->fs_info, 3492 btrfs_err(root->fs_info,
3481 "failed to write free ino cache for root %llu", 3493 "failed to write free ino cache for root %llu",
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ada4d24ed11b..8bb013672aee 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3632,25 +3632,28 @@ static void btrfs_read_locked_inode(struct inode *inode)
3632 BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); 3632 BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item);
3633 BTRFS_I(inode)->last_trans = btrfs_inode_transid(leaf, inode_item); 3633 BTRFS_I(inode)->last_trans = btrfs_inode_transid(leaf, inode_item);
3634 3634
3635 inode->i_version = btrfs_inode_sequence(leaf, inode_item);
3636 inode->i_generation = BTRFS_I(inode)->generation;
3637 inode->i_rdev = 0;
3638 rdev = btrfs_inode_rdev(leaf, inode_item);
3639
3640 BTRFS_I(inode)->index_cnt = (u64)-1;
3641 BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item);
3642
3643cache_index:
3635 /* 3644 /*
3636 * If we were modified in the current generation and evicted from memory 3645 * If we were modified in the current generation and evicted from memory
3637 * and then re-read we need to do a full sync since we don't have any 3646 * and then re-read we need to do a full sync since we don't have any
3638 * idea about which extents were modified before we were evicted from 3647 * idea about which extents were modified before we were evicted from
3639 * cache. 3648 * cache.
3649 *
3650 * This is required for both inode re-read from disk and delayed inode
3651 * in delayed_nodes_tree.
3640 */ 3652 */
3641 if (BTRFS_I(inode)->last_trans == root->fs_info->generation) 3653 if (BTRFS_I(inode)->last_trans == root->fs_info->generation)
3642 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, 3654 set_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
3643 &BTRFS_I(inode)->runtime_flags); 3655 &BTRFS_I(inode)->runtime_flags);
3644 3656
3645 inode->i_version = btrfs_inode_sequence(leaf, inode_item);
3646 inode->i_generation = BTRFS_I(inode)->generation;
3647 inode->i_rdev = 0;
3648 rdev = btrfs_inode_rdev(leaf, inode_item);
3649
3650 BTRFS_I(inode)->index_cnt = (u64)-1;
3651 BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item);
3652
3653cache_index:
3654 path->slots[0]++; 3657 path->slots[0]++;
3655 if (inode->i_nlink != 1 || 3658 if (inode->i_nlink != 1 ||
3656 path->slots[0] >= btrfs_header_nritems(leaf)) 3659 path->slots[0] >= btrfs_header_nritems(leaf))
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index b05653f182c2..1c22c6518504 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2410,7 +2410,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
2410 "Attempt to delete subvolume %llu during send", 2410 "Attempt to delete subvolume %llu during send",
2411 dest->root_key.objectid); 2411 dest->root_key.objectid);
2412 err = -EPERM; 2412 err = -EPERM;
2413 goto out_dput; 2413 goto out_unlock_inode;
2414 } 2414 }
2415 2415
2416 d_invalidate(dentry); 2416 d_invalidate(dentry);
@@ -2505,6 +2505,7 @@ out_up_write:
2505 root_flags & ~BTRFS_ROOT_SUBVOL_DEAD); 2505 root_flags & ~BTRFS_ROOT_SUBVOL_DEAD);
2506 spin_unlock(&dest->root_item_lock); 2506 spin_unlock(&dest->root_item_lock);
2507 } 2507 }
2508out_unlock_inode:
2508 mutex_unlock(&inode->i_mutex); 2509 mutex_unlock(&inode->i_mutex);
2509 if (!err) { 2510 if (!err) {
2510 shrink_dcache_sb(root->fs_info->sb); 2511 shrink_dcache_sb(root->fs_info->sb);
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 157cc54fc634..760c4a5e096b 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -722,6 +722,7 @@ void btrfs_start_ordered_extent(struct inode *inode,
722int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len) 722int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
723{ 723{
724 int ret = 0; 724 int ret = 0;
725 int ret_wb = 0;
725 u64 end; 726 u64 end;
726 u64 orig_end; 727 u64 orig_end;
727 struct btrfs_ordered_extent *ordered; 728 struct btrfs_ordered_extent *ordered;
@@ -741,9 +742,14 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
741 if (ret) 742 if (ret)
742 return ret; 743 return ret;
743 744
744 ret = filemap_fdatawait_range(inode->i_mapping, start, orig_end); 745 /*
745 if (ret) 746 * If we have a writeback error don't return immediately. Wait first
746 return ret; 747 * for any ordered extents that haven't completed yet. This is to make
748 * sure no one can dirty the same page ranges and call writepages()
749 * before the ordered extents complete - to avoid failures (-EEXIST)
750 * when adding the new ordered extents to the ordered tree.
751 */
752 ret_wb = filemap_fdatawait_range(inode->i_mapping, start, orig_end);
747 753
748 end = orig_end; 754 end = orig_end;
749 while (1) { 755 while (1) {
@@ -767,7 +773,7 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
767 break; 773 break;
768 end--; 774 end--;
769 } 775 }
770 return ret; 776 return ret_wb ? ret_wb : ret;
771} 777}
772 778
773/* 779/*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8bcd2a007517..174f5e1e00ab 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1058,6 +1058,7 @@ static int contains_pending_extent(struct btrfs_trans_handle *trans,
1058 struct extent_map *em; 1058 struct extent_map *em;
1059 struct list_head *search_list = &trans->transaction->pending_chunks; 1059 struct list_head *search_list = &trans->transaction->pending_chunks;
1060 int ret = 0; 1060 int ret = 0;
1061 u64 physical_start = *start;
1061 1062
1062again: 1063again:
1063 list_for_each_entry(em, search_list, list) { 1064 list_for_each_entry(em, search_list, list) {
@@ -1068,9 +1069,9 @@ again:
1068 for (i = 0; i < map->num_stripes; i++) { 1069 for (i = 0; i < map->num_stripes; i++) {
1069 if (map->stripes[i].dev != device) 1070 if (map->stripes[i].dev != device)
1070 continue; 1071 continue;
1071 if (map->stripes[i].physical >= *start + len || 1072 if (map->stripes[i].physical >= physical_start + len ||
1072 map->stripes[i].physical + em->orig_block_len <= 1073 map->stripes[i].physical + em->orig_block_len <=
1073 *start) 1074 physical_start)
1074 continue; 1075 continue;
1075 *start = map->stripes[i].physical + 1076 *start = map->stripes[i].physical +
1076 em->orig_block_len; 1077 em->orig_block_len;
@@ -1193,8 +1194,14 @@ again:
1193 */ 1194 */
1194 if (contains_pending_extent(trans, device, 1195 if (contains_pending_extent(trans, device,
1195 &search_start, 1196 &search_start,
1196 hole_size)) 1197 hole_size)) {
1197 hole_size = 0; 1198 if (key.offset >= search_start) {
1199 hole_size = key.offset - search_start;
1200 } else {
1201 WARN_ON_ONCE(1);
1202 hole_size = 0;
1203 }
1204 }
1198 1205
1199 if (hole_size > max_hole_size) { 1206 if (hole_size > max_hole_size) {
1200 max_hole_start = search_start; 1207 max_hole_start = search_start;
@@ -4618,6 +4625,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
4618{ 4625{
4619 u64 chunk_offset; 4626 u64 chunk_offset;
4620 4627
4628 ASSERT(mutex_is_locked(&extent_root->fs_info->chunk_mutex));
4621 chunk_offset = find_next_chunk(extent_root->fs_info); 4629 chunk_offset = find_next_chunk(extent_root->fs_info);
4622 return __btrfs_alloc_chunk(trans, extent_root, chunk_offset, type); 4630 return __btrfs_alloc_chunk(trans, extent_root, chunk_offset, type);
4623} 4631}
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index 430e0348c99e..7dc886c9a78f 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -24,6 +24,7 @@
24#include "cifsfs.h" 24#include "cifsfs.h"
25#include "dns_resolve.h" 25#include "dns_resolve.h"
26#include "cifs_debug.h" 26#include "cifs_debug.h"
27#include "cifs_unicode.h"
27 28
28static LIST_HEAD(cifs_dfs_automount_list); 29static LIST_HEAD(cifs_dfs_automount_list);
29 30
@@ -312,7 +313,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
312 xid = get_xid(); 313 xid = get_xid();
313 rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls, 314 rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls,
314 &num_referrals, &referrals, 315 &num_referrals, &referrals,
315 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 316 cifs_remap(cifs_sb));
316 free_xid(xid); 317 free_xid(xid);
317 318
318 cifs_put_tlink(tlink); 319 cifs_put_tlink(tlink);
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 0303c6793d90..5a53ac6b1e02 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -27,41 +27,6 @@
27#include "cifsglob.h" 27#include "cifsglob.h"
28#include "cifs_debug.h" 28#include "cifs_debug.h"
29 29
30/*
31 * cifs_utf16_bytes - how long will a string be after conversion?
32 * @utf16 - pointer to input string
33 * @maxbytes - don't go past this many bytes of input string
34 * @codepage - destination codepage
35 *
36 * Walk a utf16le string and return the number of bytes that the string will
37 * be after being converted to the given charset, not including any null
38 * termination required. Don't walk past maxbytes in the source buffer.
39 */
40int
41cifs_utf16_bytes(const __le16 *from, int maxbytes,
42 const struct nls_table *codepage)
43{
44 int i;
45 int charlen, outlen = 0;
46 int maxwords = maxbytes / 2;
47 char tmp[NLS_MAX_CHARSET_SIZE];
48 __u16 ftmp;
49
50 for (i = 0; i < maxwords; i++) {
51 ftmp = get_unaligned_le16(&from[i]);
52 if (ftmp == 0)
53 break;
54
55 charlen = codepage->uni2char(ftmp, tmp, NLS_MAX_CHARSET_SIZE);
56 if (charlen > 0)
57 outlen += charlen;
58 else
59 outlen++;
60 }
61
62 return outlen;
63}
64
65int cifs_remap(struct cifs_sb_info *cifs_sb) 30int cifs_remap(struct cifs_sb_info *cifs_sb)
66{ 31{
67 int map_type; 32 int map_type;
@@ -155,10 +120,13 @@ convert_sfm_char(const __u16 src_char, char *target)
155 * enough to hold the result of the conversion (at least NLS_MAX_CHARSET_SIZE). 120 * enough to hold the result of the conversion (at least NLS_MAX_CHARSET_SIZE).
156 */ 121 */
157static int 122static int
158cifs_mapchar(char *target, const __u16 src_char, const struct nls_table *cp, 123cifs_mapchar(char *target, const __u16 *from, const struct nls_table *cp,
159 int maptype) 124 int maptype)
160{ 125{
161 int len = 1; 126 int len = 1;
127 __u16 src_char;
128
129 src_char = *from;
162 130
163 if ((maptype == SFM_MAP_UNI_RSVD) && convert_sfm_char(src_char, target)) 131 if ((maptype == SFM_MAP_UNI_RSVD) && convert_sfm_char(src_char, target))
164 return len; 132 return len;
@@ -168,10 +136,23 @@ cifs_mapchar(char *target, const __u16 src_char, const struct nls_table *cp,
168 136
169 /* if character not one of seven in special remap set */ 137 /* if character not one of seven in special remap set */
170 len = cp->uni2char(src_char, target, NLS_MAX_CHARSET_SIZE); 138 len = cp->uni2char(src_char, target, NLS_MAX_CHARSET_SIZE);
171 if (len <= 0) { 139 if (len <= 0)
172 *target = '?'; 140 goto surrogate_pair;
173 len = 1; 141
174 } 142 return len;
143
144surrogate_pair:
145 /* convert SURROGATE_PAIR and IVS */
146 if (strcmp(cp->charset, "utf8"))
147 goto unknown;
148 len = utf16s_to_utf8s(from, 3, UTF16_LITTLE_ENDIAN, target, 6);
149 if (len <= 0)
150 goto unknown;
151 return len;
152
153unknown:
154 *target = '?';
155 len = 1;
175 return len; 156 return len;
176} 157}
177 158
@@ -206,7 +187,7 @@ cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
206 int nullsize = nls_nullsize(codepage); 187 int nullsize = nls_nullsize(codepage);
207 int fromwords = fromlen / 2; 188 int fromwords = fromlen / 2;
208 char tmp[NLS_MAX_CHARSET_SIZE]; 189 char tmp[NLS_MAX_CHARSET_SIZE];
209 __u16 ftmp; 190 __u16 ftmp[3]; /* ftmp[3] = 3array x 2bytes = 6bytes UTF-16 */
210 191
211 /* 192 /*
212 * because the chars can be of varying widths, we need to take care 193 * because the chars can be of varying widths, we need to take care
@@ -217,9 +198,17 @@ cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
217 safelen = tolen - (NLS_MAX_CHARSET_SIZE + nullsize); 198 safelen = tolen - (NLS_MAX_CHARSET_SIZE + nullsize);
218 199
219 for (i = 0; i < fromwords; i++) { 200 for (i = 0; i < fromwords; i++) {
220 ftmp = get_unaligned_le16(&from[i]); 201 ftmp[0] = get_unaligned_le16(&from[i]);
221 if (ftmp == 0) 202 if (ftmp[0] == 0)
222 break; 203 break;
204 if (i + 1 < fromwords)
205 ftmp[1] = get_unaligned_le16(&from[i + 1]);
206 else
207 ftmp[1] = 0;
208 if (i + 2 < fromwords)
209 ftmp[2] = get_unaligned_le16(&from[i + 2]);
210 else
211 ftmp[2] = 0;
223 212
224 /* 213 /*
225 * check to see if converting this character might make the 214 * check to see if converting this character might make the
@@ -234,6 +223,17 @@ cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
234 /* put converted char into 'to' buffer */ 223 /* put converted char into 'to' buffer */
235 charlen = cifs_mapchar(&to[outlen], ftmp, codepage, map_type); 224 charlen = cifs_mapchar(&to[outlen], ftmp, codepage, map_type);
236 outlen += charlen; 225 outlen += charlen;
226
227 /* charlen (=bytes of UTF-8 for 1 character)
228 * 4bytes UTF-8(surrogate pair) is charlen=4
229 * (4bytes UTF-16 code)
230 * 7-8bytes UTF-8(IVS) is charlen=3+4 or 4+4
231 * (2 UTF-8 pairs divided to 2 UTF-16 pairs) */
232 if (charlen == 4)
233 i++;
234 else if (charlen >= 5)
235 /* 5-6bytes UTF-8 */
236 i += 2;
237 } 237 }
238 238
239 /* properly null-terminate string */ 239 /* properly null-terminate string */
@@ -296,6 +296,46 @@ success:
296} 296}
297 297
298/* 298/*
299 * cifs_utf16_bytes - how long will a string be after conversion?
300 * @utf16 - pointer to input string
301 * @maxbytes - don't go past this many bytes of input string
302 * @codepage - destination codepage
303 *
304 * Walk a utf16le string and return the number of bytes that the string will
305 * be after being converted to the given charset, not including any null
306 * termination required. Don't walk past maxbytes in the source buffer.
307 */
308int
309cifs_utf16_bytes(const __le16 *from, int maxbytes,
310 const struct nls_table *codepage)
311{
312 int i;
313 int charlen, outlen = 0;
314 int maxwords = maxbytes / 2;
315 char tmp[NLS_MAX_CHARSET_SIZE];
316 __u16 ftmp[3];
317
318 for (i = 0; i < maxwords; i++) {
319 ftmp[0] = get_unaligned_le16(&from[i]);
320 if (ftmp[0] == 0)
321 break;
322 if (i + 1 < maxwords)
323 ftmp[1] = get_unaligned_le16(&from[i + 1]);
324 else
325 ftmp[1] = 0;
326 if (i + 2 < maxwords)
327 ftmp[2] = get_unaligned_le16(&from[i + 2]);
328 else
329 ftmp[2] = 0;
330
331 charlen = cifs_mapchar(tmp, ftmp, codepage, NO_MAP_UNI_RSVD);
332 outlen += charlen;
333 }
334
335 return outlen;
336}
337
338/*
299 * cifs_strndup_from_utf16 - copy a string from wire format to the local 339 * cifs_strndup_from_utf16 - copy a string from wire format to the local
300 * codepage 340 * codepage
301 * @src - source string 341 * @src - source string
@@ -409,10 +449,15 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
409 char src_char; 449 char src_char;
410 __le16 dst_char; 450 __le16 dst_char;
411 wchar_t tmp; 451 wchar_t tmp;
452 wchar_t *wchar_to; /* UTF-16 */
453 int ret;
454 unicode_t u;
412 455
413 if (map_chars == NO_MAP_UNI_RSVD) 456 if (map_chars == NO_MAP_UNI_RSVD)
414 return cifs_strtoUTF16(target, source, PATH_MAX, cp); 457 return cifs_strtoUTF16(target, source, PATH_MAX, cp);
415 458
459 wchar_to = kzalloc(6, GFP_KERNEL);
460
416 for (i = 0; i < srclen; j++) { 461 for (i = 0; i < srclen; j++) {
417 src_char = source[i]; 462 src_char = source[i];
418 charlen = 1; 463 charlen = 1;
@@ -441,11 +486,55 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
441 * if no match, use question mark, which at least in 486 * if no match, use question mark, which at least in
442 * some cases serves as wild card 487 * some cases serves as wild card
443 */ 488 */
444 if (charlen < 1) { 489 if (charlen > 0)
445 dst_char = cpu_to_le16(0x003f); 490 goto ctoUTF16;
446 charlen = 1; 491
492 /* convert SURROGATE_PAIR */
493 if (strcmp(cp->charset, "utf8") || !wchar_to)
494 goto unknown;
495 if (*(source + i) & 0x80) {
496 charlen = utf8_to_utf32(source + i, 6, &u);
497 if (charlen < 0)
498 goto unknown;
499 } else
500 goto unknown;
501 ret = utf8s_to_utf16s(source + i, charlen,
502 UTF16_LITTLE_ENDIAN,
503 wchar_to, 6);
504 if (ret < 0)
505 goto unknown;
506
507 i += charlen;
508 dst_char = cpu_to_le16(*wchar_to);
509 if (charlen <= 3)
510 /* 1-3bytes UTF-8 to 2bytes UTF-16 */
511 put_unaligned(dst_char, &target[j]);
512 else if (charlen == 4) {
513 /* 4bytes UTF-8(surrogate pair) to 4bytes UTF-16
514 * 7-8bytes UTF-8(IVS) divided to 2 UTF-16
515 * (charlen=3+4 or 4+4) */
516 put_unaligned(dst_char, &target[j]);
517 dst_char = cpu_to_le16(*(wchar_to + 1));
518 j++;
519 put_unaligned(dst_char, &target[j]);
520 } else if (charlen >= 5) {
521 /* 5-6bytes UTF-8 to 6bytes UTF-16 */
522 put_unaligned(dst_char, &target[j]);
523 dst_char = cpu_to_le16(*(wchar_to + 1));
524 j++;
525 put_unaligned(dst_char, &target[j]);
526 dst_char = cpu_to_le16(*(wchar_to + 2));
527 j++;
528 put_unaligned(dst_char, &target[j]);
447 } 529 }
530 continue;
531
532unknown:
533 dst_char = cpu_to_le16(0x003f);
534 charlen = 1;
448 } 535 }
536
537ctoUTF16:
449 /* 538 /*
450 * character may take more than one byte in the source string, 539 * character may take more than one byte in the source string,
451 * but will take exactly two bytes in the target string 540 * but will take exactly two bytes in the target string
@@ -456,6 +545,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
456 545
457ctoUTF16_out: 546ctoUTF16_out:
458 put_unaligned(0, &target[j]); /* Null terminate target unicode string */ 547 put_unaligned(0, &target[j]); /* Null terminate target unicode string */
548 kfree(wchar_to);
459 return j; 549 return j;
460} 550}
461 551
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index f5089bde3635..0a9fb6b53126 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -469,6 +469,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
469 seq_puts(s, ",nouser_xattr"); 469 seq_puts(s, ",nouser_xattr");
470 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR) 470 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
471 seq_puts(s, ",mapchars"); 471 seq_puts(s, ",mapchars");
472 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SFM_CHR)
473 seq_puts(s, ",mapposix");
472 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) 474 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
473 seq_puts(s, ",sfu"); 475 seq_puts(s, ",sfu");
474 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) 476 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index c31ce98c1704..c63fd1dde25b 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -361,11 +361,11 @@ extern int CIFSUnixCreateHardLink(const unsigned int xid,
361extern int CIFSUnixCreateSymLink(const unsigned int xid, 361extern int CIFSUnixCreateSymLink(const unsigned int xid,
362 struct cifs_tcon *tcon, 362 struct cifs_tcon *tcon,
363 const char *fromName, const char *toName, 363 const char *fromName, const char *toName,
364 const struct nls_table *nls_codepage); 364 const struct nls_table *nls_codepage, int remap);
365extern int CIFSSMBUnixQuerySymLink(const unsigned int xid, 365extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,
366 struct cifs_tcon *tcon, 366 struct cifs_tcon *tcon,
367 const unsigned char *searchName, char **syminfo, 367 const unsigned char *searchName, char **syminfo,
368 const struct nls_table *nls_codepage); 368 const struct nls_table *nls_codepage, int remap);
369extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, 369extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
370 __u16 fid, char **symlinkinfo, 370 __u16 fid, char **symlinkinfo,
371 const struct nls_table *nls_codepage); 371 const struct nls_table *nls_codepage);
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 84650a51c7c4..f26ffbfc64d8 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -2784,7 +2784,7 @@ copyRetry:
2784int 2784int
2785CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, 2785CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon,
2786 const char *fromName, const char *toName, 2786 const char *fromName, const char *toName,
2787 const struct nls_table *nls_codepage) 2787 const struct nls_table *nls_codepage, int remap)
2788{ 2788{
2789 TRANSACTION2_SPI_REQ *pSMB = NULL; 2789 TRANSACTION2_SPI_REQ *pSMB = NULL;
2790 TRANSACTION2_SPI_RSP *pSMBr = NULL; 2790 TRANSACTION2_SPI_RSP *pSMBr = NULL;
@@ -2804,9 +2804,9 @@ createSymLinkRetry:
2804 2804
2805 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2805 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2806 name_len = 2806 name_len =
2807 cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, 2807 cifsConvertToUTF16((__le16 *) pSMB->FileName, fromName,
2808 /* find define for this maxpathcomponent */ 2808 /* find define for this maxpathcomponent */
2809 PATH_MAX, nls_codepage); 2809 PATH_MAX, nls_codepage, remap);
2810 name_len++; /* trailing null */ 2810 name_len++; /* trailing null */
2811 name_len *= 2; 2811 name_len *= 2;
2812 2812
@@ -2828,9 +2828,9 @@ createSymLinkRetry:
2828 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 2828 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
2829 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2829 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2830 name_len_target = 2830 name_len_target =
2831 cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX 2831 cifsConvertToUTF16((__le16 *) data_offset, toName,
2832 /* find define for this maxpathcomponent */ 2832 /* find define for this maxpathcomponent */
2833 , nls_codepage); 2833 PATH_MAX, nls_codepage, remap);
2834 name_len_target++; /* trailing null */ 2834 name_len_target++; /* trailing null */
2835 name_len_target *= 2; 2835 name_len_target *= 2;
2836 } else { /* BB improve the check for buffer overruns BB */ 2836 } else { /* BB improve the check for buffer overruns BB */
@@ -3034,7 +3034,7 @@ winCreateHardLinkRetry:
3034int 3034int
3035CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, 3035CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
3036 const unsigned char *searchName, char **symlinkinfo, 3036 const unsigned char *searchName, char **symlinkinfo,
3037 const struct nls_table *nls_codepage) 3037 const struct nls_table *nls_codepage, int remap)
3038{ 3038{
3039/* SMB_QUERY_FILE_UNIX_LINK */ 3039/* SMB_QUERY_FILE_UNIX_LINK */
3040 TRANSACTION2_QPI_REQ *pSMB = NULL; 3040 TRANSACTION2_QPI_REQ *pSMB = NULL;
@@ -3055,8 +3055,9 @@ querySymLinkRetry:
3055 3055
3056 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3056 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3057 name_len = 3057 name_len =
3058 cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, 3058 cifsConvertToUTF16((__le16 *) pSMB->FileName,
3059 PATH_MAX, nls_codepage); 3059 searchName, PATH_MAX, nls_codepage,
3060 remap);
3060 name_len++; /* trailing null */ 3061 name_len++; /* trailing null */
3061 name_len *= 2; 3062 name_len *= 2;
3062 } else { /* BB improve the check for buffer overruns BB */ 3063 } else { /* BB improve the check for buffer overruns BB */
@@ -4917,7 +4918,7 @@ getDFSRetry:
4917 strncpy(pSMB->RequestFileName, search_name, name_len); 4918 strncpy(pSMB->RequestFileName, search_name, name_len);
4918 } 4919 }
4919 4920
4920 if (ses->server && ses->server->sign) 4921 if (ses->server->sign)
4921 pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; 4922 pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
4922 4923
4923 pSMB->hdr.Uid = ses->Suid; 4924 pSMB->hdr.Uid = ses->Suid;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index f3bfe08e177b..8383d5ea4202 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -386,6 +386,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
386 rc = generic_ip_connect(server); 386 rc = generic_ip_connect(server);
387 if (rc) { 387 if (rc) {
388 cifs_dbg(FYI, "reconnect error %d\n", rc); 388 cifs_dbg(FYI, "reconnect error %d\n", rc);
389 mutex_unlock(&server->srv_mutex);
389 msleep(3000); 390 msleep(3000);
390 } else { 391 } else {
391 atomic_inc(&tcpSesReconnectCount); 392 atomic_inc(&tcpSesReconnectCount);
@@ -393,8 +394,8 @@ cifs_reconnect(struct TCP_Server_Info *server)
393 if (server->tcpStatus != CifsExiting) 394 if (server->tcpStatus != CifsExiting)
394 server->tcpStatus = CifsNeedNegotiate; 395 server->tcpStatus = CifsNeedNegotiate;
395 spin_unlock(&GlobalMid_Lock); 396 spin_unlock(&GlobalMid_Lock);
397 mutex_unlock(&server->srv_mutex);
396 } 398 }
397 mutex_unlock(&server->srv_mutex);
398 } while (server->tcpStatus == CifsNeedReconnect); 399 } while (server->tcpStatus == CifsNeedReconnect);
399 400
400 return rc; 401 return rc;
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 338d56936f6a..c3eb998a99bd 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -620,8 +620,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
620 } 620 }
621 rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args, 621 rc = CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
622 cifs_sb->local_nls, 622 cifs_sb->local_nls,
623 cifs_sb->mnt_cifs_flags & 623 cifs_remap(cifs_sb));
624 CIFS_MOUNT_MAP_SPECIAL_CHR);
625 if (rc) 624 if (rc)
626 goto mknod_out; 625 goto mknod_out;
627 626
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index cafbf10521d5..3f50cee79df9 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -140,8 +140,7 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
140 posix_flags = cifs_posix_convert_flags(f_flags); 140 posix_flags = cifs_posix_convert_flags(f_flags);
141 rc = CIFSPOSIXCreate(xid, tcon, posix_flags, mode, pnetfid, presp_data, 141 rc = CIFSPOSIXCreate(xid, tcon, posix_flags, mode, pnetfid, presp_data,
142 poplock, full_path, cifs_sb->local_nls, 142 poplock, full_path, cifs_sb->local_nls,
143 cifs_sb->mnt_cifs_flags & 143 cifs_remap(cifs_sb));
144 CIFS_MOUNT_MAP_SPECIAL_CHR);
145 cifs_put_tlink(tlink); 144 cifs_put_tlink(tlink);
146 145
147 if (rc) 146 if (rc)
@@ -1553,8 +1552,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
1553 rc = server->ops->mand_unlock_range(cfile, flock, xid); 1552 rc = server->ops->mand_unlock_range(cfile, flock, xid);
1554 1553
1555out: 1554out:
1556 if (flock->fl_flags & FL_POSIX) 1555 if (flock->fl_flags & FL_POSIX && !rc)
1557 posix_lock_file_wait(file, flock); 1556 rc = posix_lock_file_wait(file, flock);
1558 return rc; 1557 return rc;
1559} 1558}
1560 1559
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 55b58112d122..f621b44cb800 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -373,8 +373,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
373 373
374 /* could have done a find first instead but this returns more info */ 374 /* could have done a find first instead but this returns more info */
375 rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data, 375 rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data,
376 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 376 cifs_sb->local_nls, cifs_remap(cifs_sb));
377 CIFS_MOUNT_MAP_SPECIAL_CHR);
378 cifs_put_tlink(tlink); 377 cifs_put_tlink(tlink);
379 378
380 if (!rc) { 379 if (!rc) {
@@ -402,9 +401,25 @@ int cifs_get_inode_info_unix(struct inode **pinode,
402 rc = -ENOMEM; 401 rc = -ENOMEM;
403 } else { 402 } else {
404 /* we already have inode, update it */ 403 /* we already have inode, update it */
404
405 /* if uniqueid is different, return error */
406 if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
407 CIFS_I(*pinode)->uniqueid != fattr.cf_uniqueid)) {
408 rc = -ESTALE;
409 goto cgiiu_exit;
410 }
411
412 /* if filetype is different, return error */
413 if (unlikely(((*pinode)->i_mode & S_IFMT) !=
414 (fattr.cf_mode & S_IFMT))) {
415 rc = -ESTALE;
416 goto cgiiu_exit;
417 }
418
405 cifs_fattr_to_inode(*pinode, &fattr); 419 cifs_fattr_to_inode(*pinode, &fattr);
406 } 420 }
407 421
422cgiiu_exit:
408 return rc; 423 return rc;
409} 424}
410 425
@@ -839,6 +854,15 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
839 if (!*inode) 854 if (!*inode)
840 rc = -ENOMEM; 855 rc = -ENOMEM;
841 } else { 856 } else {
857 /* we already have inode, update it */
858
859 /* if filetype is different, return error */
860 if (unlikely(((*inode)->i_mode & S_IFMT) !=
861 (fattr.cf_mode & S_IFMT))) {
862 rc = -ESTALE;
863 goto cgii_exit;
864 }
865
842 cifs_fattr_to_inode(*inode, &fattr); 866 cifs_fattr_to_inode(*inode, &fattr);
843 } 867 }
844 868
@@ -2215,8 +2239,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
2215 pTcon = tlink_tcon(tlink); 2239 pTcon = tlink_tcon(tlink);
2216 rc = CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, args, 2240 rc = CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, args,
2217 cifs_sb->local_nls, 2241 cifs_sb->local_nls,
2218 cifs_sb->mnt_cifs_flags & 2242 cifs_remap(cifs_sb));
2219 CIFS_MOUNT_MAP_SPECIAL_CHR);
2220 cifs_put_tlink(tlink); 2243 cifs_put_tlink(tlink);
2221 } 2244 }
2222 2245
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 252e672d5604..e6c707cc62b3 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -717,7 +717,8 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
717 rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname); 717 rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname);
718 else if (pTcon->unix_ext) 718 else if (pTcon->unix_ext)
719 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname, 719 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
720 cifs_sb->local_nls); 720 cifs_sb->local_nls,
721 cifs_remap(cifs_sb));
721 /* else 722 /* else
722 rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName, 723 rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
723 cifs_sb_target->local_nls); */ 724 cifs_sb_target->local_nls); */
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index b4a47237486b..b1eede3678a9 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -90,6 +90,8 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
90 if (dentry) { 90 if (dentry) {
91 inode = d_inode(dentry); 91 inode = d_inode(dentry);
92 if (inode) { 92 if (inode) {
93 if (d_mountpoint(dentry))
94 goto out;
93 /* 95 /*
94 * If we're generating inode numbers, then we don't 96 * If we're generating inode numbers, then we don't
95 * want to clobber the existing one with the one that 97 * want to clobber the existing one with the one that
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index 7bfdd6066276..fc537c29044e 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -960,7 +960,8 @@ cifs_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
960 /* Check for unix extensions */ 960 /* Check for unix extensions */
961 if (cap_unix(tcon->ses)) { 961 if (cap_unix(tcon->ses)) {
962 rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, target_path, 962 rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, target_path,
963 cifs_sb->local_nls); 963 cifs_sb->local_nls,
964 cifs_remap(cifs_sb));
964 if (rc == -EREMOTE) 965 if (rc == -EREMOTE)
965 rc = cifs_unix_dfs_readlink(xid, tcon, full_path, 966 rc = cifs_unix_dfs_readlink(xid, tcon, full_path,
966 target_path, 967 target_path,
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 65cd7a84c8bc..54cbe19d9c08 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -110,7 +110,7 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
110 110
111 /* GLOBAL_CAP_LARGE_MTU will only be set if dialect > SMB2.02 */ 111 /* GLOBAL_CAP_LARGE_MTU will only be set if dialect > SMB2.02 */
112 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */ 112 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */
113 if ((tcon->ses) && 113 if ((tcon->ses) && (tcon->ses->server) &&
114 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) 114 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
115 hdr->CreditCharge = cpu_to_le16(1); 115 hdr->CreditCharge = cpu_to_le16(1);
116 /* else CreditCharge MBZ */ 116 /* else CreditCharge MBZ */
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index da94e41bdbf6..537356742091 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -173,5 +173,5 @@ MODULE_LICENSE("GPL");
173MODULE_VERSION("0.0.2"); 173MODULE_VERSION("0.0.2");
174MODULE_DESCRIPTION("Simple RAM filesystem for user driven kernel subsystem configuration."); 174MODULE_DESCRIPTION("Simple RAM filesystem for user driven kernel subsystem configuration.");
175 175
176module_init(configfs_init); 176core_initcall(configfs_init);
177module_exit(configfs_exit); 177module_exit(configfs_exit);
diff --git a/fs/dcache.c b/fs/dcache.c
index 656ce522a218..37b5afdaf698 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1239,13 +1239,13 @@ ascend:
1239 /* might go back up the wrong parent if we have had a rename. */ 1239 /* might go back up the wrong parent if we have had a rename. */
1240 if (need_seqretry(&rename_lock, seq)) 1240 if (need_seqretry(&rename_lock, seq))
1241 goto rename_retry; 1241 goto rename_retry;
1242 next = child->d_child.next; 1242 /* go into the first sibling still alive */
1243 while (unlikely(child->d_flags & DCACHE_DENTRY_KILLED)) { 1243 do {
1244 next = child->d_child.next;
1244 if (next == &this_parent->d_subdirs) 1245 if (next == &this_parent->d_subdirs)
1245 goto ascend; 1246 goto ascend;
1246 child = list_entry(next, struct dentry, d_child); 1247 child = list_entry(next, struct dentry, d_child);
1247 next = next->next; 1248 } while (unlikely(child->d_flags & DCACHE_DENTRY_KILLED));
1248 }
1249 rcu_read_unlock(); 1249 rcu_read_unlock();
1250 goto resume; 1250 goto resume;
1251 } 1251 }
diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c
index 59fedbcf8798..86a2121828c3 100644
--- a/fs/efivarfs/super.c
+++ b/fs/efivarfs/super.c
@@ -121,7 +121,7 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
121 int len, i; 121 int len, i;
122 int err = -ENOMEM; 122 int err = -ENOMEM;
123 123
124 entry = kmalloc(sizeof(*entry), GFP_KERNEL); 124 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
125 if (!entry) 125 if (!entry)
126 return err; 126 return err;
127 127
diff --git a/fs/exec.c b/fs/exec.c
index 49a1c61433b7..1977c2a553ac 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -659,6 +659,9 @@ int setup_arg_pages(struct linux_binprm *bprm,
659 if (stack_base > STACK_SIZE_MAX) 659 if (stack_base > STACK_SIZE_MAX)
660 stack_base = STACK_SIZE_MAX; 660 stack_base = STACK_SIZE_MAX;
661 661
662 /* Add space for stack randomization. */
663 stack_base += (STACK_RND_MASK << PAGE_SHIFT);
664
662 /* Make sure we didn't let the argument array grow too large. */ 665 /* Make sure we didn't let the argument array grow too large. */
663 if (vma->vm_end - vma->vm_start > stack_base) 666 if (vma->vm_end - vma->vm_start > stack_base)
664 return -ENOMEM; 667 return -ENOMEM;
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig
index 18228c201f7f..024f2284d3f6 100644
--- a/fs/ext4/Kconfig
+++ b/fs/ext4/Kconfig
@@ -64,8 +64,8 @@ config EXT4_FS_SECURITY
64 If you are not using a security module that requires using 64 If you are not using a security module that requires using
65 extended attributes for file security labels, say N. 65 extended attributes for file security labels, say N.
66 66
67config EXT4_FS_ENCRYPTION 67config EXT4_ENCRYPTION
68 bool "Ext4 Encryption" 68 tristate "Ext4 Encryption"
69 depends on EXT4_FS 69 depends on EXT4_FS
70 select CRYPTO_AES 70 select CRYPTO_AES
71 select CRYPTO_CBC 71 select CRYPTO_CBC
@@ -81,6 +81,11 @@ config EXT4_FS_ENCRYPTION
81 efficient since it avoids caching the encrypted and 81 efficient since it avoids caching the encrypted and
82 decrypted pages in the page cache. 82 decrypted pages in the page cache.
83 83
84config EXT4_FS_ENCRYPTION
85 bool
86 default y
87 depends on EXT4_ENCRYPTION
88
84config EXT4_DEBUG 89config EXT4_DEBUG
85 bool "EXT4 debugging support" 90 bool "EXT4 debugging support"
86 depends on EXT4_FS 91 depends on EXT4_FS
diff --git a/fs/ext4/crypto_fname.c b/fs/ext4/crypto_fname.c
index ca2f5948c1ac..fded02f72299 100644
--- a/fs/ext4/crypto_fname.c
+++ b/fs/ext4/crypto_fname.c
@@ -66,6 +66,7 @@ static int ext4_fname_encrypt(struct ext4_fname_crypto_ctx *ctx,
66 int res = 0; 66 int res = 0;
67 char iv[EXT4_CRYPTO_BLOCK_SIZE]; 67 char iv[EXT4_CRYPTO_BLOCK_SIZE];
68 struct scatterlist sg[1]; 68 struct scatterlist sg[1];
69 int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK);
69 char *workbuf; 70 char *workbuf;
70 71
71 if (iname->len <= 0 || iname->len > ctx->lim) 72 if (iname->len <= 0 || iname->len > ctx->lim)
@@ -73,6 +74,7 @@ static int ext4_fname_encrypt(struct ext4_fname_crypto_ctx *ctx,
73 74
74 ciphertext_len = (iname->len < EXT4_CRYPTO_BLOCK_SIZE) ? 75 ciphertext_len = (iname->len < EXT4_CRYPTO_BLOCK_SIZE) ?
75 EXT4_CRYPTO_BLOCK_SIZE : iname->len; 76 EXT4_CRYPTO_BLOCK_SIZE : iname->len;
77 ciphertext_len = ext4_fname_crypto_round_up(ciphertext_len, padding);
76 ciphertext_len = (ciphertext_len > ctx->lim) 78 ciphertext_len = (ciphertext_len > ctx->lim)
77 ? ctx->lim : ciphertext_len; 79 ? ctx->lim : ciphertext_len;
78 80
@@ -101,7 +103,7 @@ static int ext4_fname_encrypt(struct ext4_fname_crypto_ctx *ctx,
101 /* Create encryption request */ 103 /* Create encryption request */
102 sg_init_table(sg, 1); 104 sg_init_table(sg, 1);
103 sg_set_page(sg, ctx->workpage, PAGE_SIZE, 0); 105 sg_set_page(sg, ctx->workpage, PAGE_SIZE, 0);
104 ablkcipher_request_set_crypt(req, sg, sg, iname->len, iv); 106 ablkcipher_request_set_crypt(req, sg, sg, ciphertext_len, iv);
105 res = crypto_ablkcipher_encrypt(req); 107 res = crypto_ablkcipher_encrypt(req);
106 if (res == -EINPROGRESS || res == -EBUSY) { 108 if (res == -EINPROGRESS || res == -EBUSY) {
107 BUG_ON(req->base.data != &ecr); 109 BUG_ON(req->base.data != &ecr);
@@ -198,106 +200,57 @@ static int ext4_fname_decrypt(struct ext4_fname_crypto_ctx *ctx,
198 return oname->len; 200 return oname->len;
199} 201}
200 202
203static const char *lookup_table =
204 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
205
201/** 206/**
202 * ext4_fname_encode_digest() - 207 * ext4_fname_encode_digest() -
203 * 208 *
204 * Encodes the input digest using characters from the set [a-zA-Z0-9_+]. 209 * Encodes the input digest using characters from the set [a-zA-Z0-9_+].
205 * The encoded string is roughly 4/3 times the size of the input string. 210 * The encoded string is roughly 4/3 times the size of the input string.
206 */ 211 */
207int ext4_fname_encode_digest(char *dst, char *src, u32 len) 212static int digest_encode(const char *src, int len, char *dst)
208{ 213{
209 static const char *lookup_table = 214 int i = 0, bits = 0, ac = 0;
210 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+"; 215 char *cp = dst;
211 u32 current_chunk, num_chunks, i; 216
212 char tmp_buf[3]; 217 while (i < len) {
213 u32 c0, c1, c2, c3; 218 ac += (((unsigned char) src[i]) << bits);
214 219 bits += 8;
215 current_chunk = 0; 220 do {
216 num_chunks = len/3; 221 *cp++ = lookup_table[ac & 0x3f];
217 for (i = 0; i < num_chunks; i++) { 222 ac >>= 6;
218 c0 = src[3*i] & 0x3f; 223 bits -= 6;
219 c1 = (((src[3*i]>>6)&0x3) | ((src[3*i+1] & 0xf)<<2)) & 0x3f; 224 } while (bits >= 6);
220 c2 = (((src[3*i+1]>>4)&0xf) | ((src[3*i+2] & 0x3)<<4)) & 0x3f;
221 c3 = (src[3*i+2]>>2) & 0x3f;
222 dst[4*i] = lookup_table[c0];
223 dst[4*i+1] = lookup_table[c1];
224 dst[4*i+2] = lookup_table[c2];
225 dst[4*i+3] = lookup_table[c3];
226 }
227 if (i*3 < len) {
228 memset(tmp_buf, 0, 3);
229 memcpy(tmp_buf, &src[3*i], len-3*i);
230 c0 = tmp_buf[0] & 0x3f;
231 c1 = (((tmp_buf[0]>>6)&0x3) | ((tmp_buf[1] & 0xf)<<2)) & 0x3f;
232 c2 = (((tmp_buf[1]>>4)&0xf) | ((tmp_buf[2] & 0x3)<<4)) & 0x3f;
233 c3 = (tmp_buf[2]>>2) & 0x3f;
234 dst[4*i] = lookup_table[c0];
235 dst[4*i+1] = lookup_table[c1];
236 dst[4*i+2] = lookup_table[c2];
237 dst[4*i+3] = lookup_table[c3];
238 i++; 225 i++;
239 } 226 }
240 return (i * 4); 227 if (bits)
228 *cp++ = lookup_table[ac & 0x3f];
229 return cp - dst;
241} 230}
242 231
243/** 232static int digest_decode(const char *src, int len, char *dst)
244 * ext4_fname_hash() -
245 *
246 * This function computes the hash of the input filename, and sets the output
247 * buffer to the *encoded* digest. It returns the length of the digest as its
248 * return value. Errors are returned as negative numbers. We trust the caller
249 * to allocate sufficient memory to oname string.
250 */
251static int ext4_fname_hash(struct ext4_fname_crypto_ctx *ctx,
252 const struct ext4_str *iname,
253 struct ext4_str *oname)
254{ 233{
255 struct scatterlist sg; 234 int i = 0, bits = 0, ac = 0;
256 struct hash_desc desc = { 235 const char *p;
257 .tfm = (struct crypto_hash *)ctx->htfm, 236 char *cp = dst;
258 .flags = CRYPTO_TFM_REQ_MAY_SLEEP 237
259 }; 238 while (i < len) {
260 int res = 0; 239 p = strchr(lookup_table, src[i]);
261 240 if (p == NULL || src[i] == 0)
262 if (iname->len <= EXT4_FNAME_CRYPTO_DIGEST_SIZE) { 241 return -2;
263 res = ext4_fname_encode_digest(oname->name, iname->name, 242 ac += (p - lookup_table) << bits;
264 iname->len); 243 bits += 6;
265 oname->len = res; 244 if (bits >= 8) {
266 return res; 245 *cp++ = ac & 0xff;
267 } 246 ac >>= 8;
268 247 bits -= 8;
269 sg_init_one(&sg, iname->name, iname->len); 248 }
270 res = crypto_hash_init(&desc); 249 i++;
271 if (res) {
272 printk(KERN_ERR
273 "%s: Error initializing crypto hash; res = [%d]\n",
274 __func__, res);
275 goto out;
276 }
277 res = crypto_hash_update(&desc, &sg, iname->len);
278 if (res) {
279 printk(KERN_ERR
280 "%s: Error updating crypto hash; res = [%d]\n",
281 __func__, res);
282 goto out;
283 }
284 res = crypto_hash_final(&desc,
285 &oname->name[EXT4_FNAME_CRYPTO_DIGEST_SIZE]);
286 if (res) {
287 printk(KERN_ERR
288 "%s: Error finalizing crypto hash; res = [%d]\n",
289 __func__, res);
290 goto out;
291 } 250 }
292 /* Encode the digest as a printable string--this will increase the 251 if (ac)
293 * size of the digest */ 252 return -1;
294 oname->name[0] = 'I'; 253 return cp - dst;
295 res = ext4_fname_encode_digest(oname->name+1,
296 &oname->name[EXT4_FNAME_CRYPTO_DIGEST_SIZE],
297 EXT4_FNAME_CRYPTO_DIGEST_SIZE) + 1;
298 oname->len = res;
299out:
300 return res;
301} 254}
302 255
303/** 256/**
@@ -405,6 +358,7 @@ struct ext4_fname_crypto_ctx *ext4_get_fname_crypto_ctx(
405 if (IS_ERR(ctx)) 358 if (IS_ERR(ctx))
406 return ctx; 359 return ctx;
407 360
361 ctx->flags = ei->i_crypt_policy_flags;
408 if (ctx->has_valid_key) { 362 if (ctx->has_valid_key) {
409 if (ctx->key.mode != EXT4_ENCRYPTION_MODE_AES_256_CTS) { 363 if (ctx->key.mode != EXT4_ENCRYPTION_MODE_AES_256_CTS) {
410 printk_once(KERN_WARNING 364 printk_once(KERN_WARNING
@@ -517,6 +471,7 @@ int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx,
517 u32 namelen) 471 u32 namelen)
518{ 472{
519 u32 ciphertext_len; 473 u32 ciphertext_len;
474 int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK);
520 475
521 if (ctx == NULL) 476 if (ctx == NULL)
522 return -EIO; 477 return -EIO;
@@ -524,6 +479,7 @@ int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx,
524 return -EACCES; 479 return -EACCES;
525 ciphertext_len = (namelen < EXT4_CRYPTO_BLOCK_SIZE) ? 480 ciphertext_len = (namelen < EXT4_CRYPTO_BLOCK_SIZE) ?
526 EXT4_CRYPTO_BLOCK_SIZE : namelen; 481 EXT4_CRYPTO_BLOCK_SIZE : namelen;
482 ciphertext_len = ext4_fname_crypto_round_up(ciphertext_len, padding);
527 ciphertext_len = (ciphertext_len > ctx->lim) 483 ciphertext_len = (ciphertext_len > ctx->lim)
528 ? ctx->lim : ciphertext_len; 484 ? ctx->lim : ciphertext_len;
529 return (int) ciphertext_len; 485 return (int) ciphertext_len;
@@ -539,10 +495,13 @@ int ext4_fname_crypto_alloc_buffer(struct ext4_fname_crypto_ctx *ctx,
539 u32 ilen, struct ext4_str *crypto_str) 495 u32 ilen, struct ext4_str *crypto_str)
540{ 496{
541 unsigned int olen; 497 unsigned int olen;
498 int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK);
542 499
543 if (!ctx) 500 if (!ctx)
544 return -EIO; 501 return -EIO;
545 olen = ext4_fname_crypto_round_up(ilen, EXT4_CRYPTO_BLOCK_SIZE); 502 if (padding < EXT4_CRYPTO_BLOCK_SIZE)
503 padding = EXT4_CRYPTO_BLOCK_SIZE;
504 olen = ext4_fname_crypto_round_up(ilen, padding);
546 crypto_str->len = olen; 505 crypto_str->len = olen;
547 if (olen < EXT4_FNAME_CRYPTO_DIGEST_SIZE*2) 506 if (olen < EXT4_FNAME_CRYPTO_DIGEST_SIZE*2)
548 olen = EXT4_FNAME_CRYPTO_DIGEST_SIZE*2; 507 olen = EXT4_FNAME_CRYPTO_DIGEST_SIZE*2;
@@ -571,9 +530,13 @@ void ext4_fname_crypto_free_buffer(struct ext4_str *crypto_str)
571 * ext4_fname_disk_to_usr() - converts a filename from disk space to user space 530 * ext4_fname_disk_to_usr() - converts a filename from disk space to user space
572 */ 531 */
573int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, 532int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx,
574 const struct ext4_str *iname, 533 struct dx_hash_info *hinfo,
575 struct ext4_str *oname) 534 const struct ext4_str *iname,
535 struct ext4_str *oname)
576{ 536{
537 char buf[24];
538 int ret;
539
577 if (ctx == NULL) 540 if (ctx == NULL)
578 return -EIO; 541 return -EIO;
579 if (iname->len < 3) { 542 if (iname->len < 3) {
@@ -587,18 +550,33 @@ int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx,
587 } 550 }
588 if (ctx->has_valid_key) 551 if (ctx->has_valid_key)
589 return ext4_fname_decrypt(ctx, iname, oname); 552 return ext4_fname_decrypt(ctx, iname, oname);
590 else 553
591 return ext4_fname_hash(ctx, iname, oname); 554 if (iname->len <= EXT4_FNAME_CRYPTO_DIGEST_SIZE) {
555 ret = digest_encode(iname->name, iname->len, oname->name);
556 oname->len = ret;
557 return ret;
558 }
559 if (hinfo) {
560 memcpy(buf, &hinfo->hash, 4);
561 memcpy(buf+4, &hinfo->minor_hash, 4);
562 } else
563 memset(buf, 0, 8);
564 memcpy(buf + 8, iname->name + iname->len - 16, 16);
565 oname->name[0] = '_';
566 ret = digest_encode(buf, 24, oname->name+1);
567 oname->len = ret + 1;
568 return ret + 1;
592} 569}
593 570
594int ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, 571int ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx,
572 struct dx_hash_info *hinfo,
595 const struct ext4_dir_entry_2 *de, 573 const struct ext4_dir_entry_2 *de,
596 struct ext4_str *oname) 574 struct ext4_str *oname)
597{ 575{
598 struct ext4_str iname = {.name = (unsigned char *) de->name, 576 struct ext4_str iname = {.name = (unsigned char *) de->name,
599 .len = de->name_len }; 577 .len = de->name_len };
600 578
601 return _ext4_fname_disk_to_usr(ctx, &iname, oname); 579 return _ext4_fname_disk_to_usr(ctx, hinfo, &iname, oname);
602} 580}
603 581
604 582
@@ -640,10 +618,11 @@ int ext4_fname_usr_to_hash(struct ext4_fname_crypto_ctx *ctx,
640 const struct qstr *iname, 618 const struct qstr *iname,
641 struct dx_hash_info *hinfo) 619 struct dx_hash_info *hinfo)
642{ 620{
643 struct ext4_str tmp, tmp2; 621 struct ext4_str tmp;
644 int ret = 0; 622 int ret = 0;
623 char buf[EXT4_FNAME_CRYPTO_DIGEST_SIZE+1];
645 624
646 if (!ctx || !ctx->has_valid_key || 625 if (!ctx ||
647 ((iname->name[0] == '.') && 626 ((iname->name[0] == '.') &&
648 ((iname->len == 1) || 627 ((iname->len == 1) ||
649 ((iname->name[1] == '.') && (iname->len == 2))))) { 628 ((iname->name[1] == '.') && (iname->len == 2))))) {
@@ -651,59 +630,90 @@ int ext4_fname_usr_to_hash(struct ext4_fname_crypto_ctx *ctx,
651 return 0; 630 return 0;
652 } 631 }
653 632
633 if (!ctx->has_valid_key && iname->name[0] == '_') {
634 if (iname->len != 33)
635 return -ENOENT;
636 ret = digest_decode(iname->name+1, iname->len, buf);
637 if (ret != 24)
638 return -ENOENT;
639 memcpy(&hinfo->hash, buf, 4);
640 memcpy(&hinfo->minor_hash, buf + 4, 4);
641 return 0;
642 }
643
644 if (!ctx->has_valid_key && iname->name[0] != '_') {
645 if (iname->len > 43)
646 return -ENOENT;
647 ret = digest_decode(iname->name, iname->len, buf);
648 ext4fs_dirhash(buf, ret, hinfo);
649 return 0;
650 }
651
654 /* First encrypt the plaintext name */ 652 /* First encrypt the plaintext name */
655 ret = ext4_fname_crypto_alloc_buffer(ctx, iname->len, &tmp); 653 ret = ext4_fname_crypto_alloc_buffer(ctx, iname->len, &tmp);
656 if (ret < 0) 654 if (ret < 0)
657 return ret; 655 return ret;
658 656
659 ret = ext4_fname_encrypt(ctx, iname, &tmp); 657 ret = ext4_fname_encrypt(ctx, iname, &tmp);
660 if (ret < 0) 658 if (ret >= 0) {
661 goto out; 659 ext4fs_dirhash(tmp.name, tmp.len, hinfo);
662 660 ret = 0;
663 tmp2.len = (4 * ((EXT4_FNAME_CRYPTO_DIGEST_SIZE + 2) / 3)) + 1;
664 tmp2.name = kmalloc(tmp2.len + 1, GFP_KERNEL);
665 if (tmp2.name == NULL) {
666 ret = -ENOMEM;
667 goto out;
668 } 661 }
669 662
670 ret = ext4_fname_hash(ctx, &tmp, &tmp2);
671 if (ret > 0)
672 ext4fs_dirhash(tmp2.name, tmp2.len, hinfo);
673 ext4_fname_crypto_free_buffer(&tmp2);
674out:
675 ext4_fname_crypto_free_buffer(&tmp); 663 ext4_fname_crypto_free_buffer(&tmp);
676 return ret; 664 return ret;
677} 665}
678 666
679/** 667int ext4_fname_match(struct ext4_fname_crypto_ctx *ctx, struct ext4_str *cstr,
680 * ext4_fname_disk_to_htree() - converts a filename from disk space to htree-access string 668 int len, const char * const name,
681 */ 669 struct ext4_dir_entry_2 *de)
682int ext4_fname_disk_to_hash(struct ext4_fname_crypto_ctx *ctx,
683 const struct ext4_dir_entry_2 *de,
684 struct dx_hash_info *hinfo)
685{ 670{
686 struct ext4_str iname = {.name = (unsigned char *) de->name, 671 int ret = -ENOENT;
687 .len = de->name_len}; 672 int bigname = (*name == '_');
688 struct ext4_str tmp;
689 int ret;
690 673
691 if (!ctx || 674 if (ctx->has_valid_key) {
692 ((iname.name[0] == '.') && 675 if (cstr->name == NULL) {
693 ((iname.len == 1) || 676 struct qstr istr;
694 ((iname.name[1] == '.') && (iname.len == 2))))) { 677
695 ext4fs_dirhash(iname.name, iname.len, hinfo); 678 ret = ext4_fname_crypto_alloc_buffer(ctx, len, cstr);
696 return 0; 679 if (ret < 0)
680 goto errout;
681 istr.name = name;
682 istr.len = len;
683 ret = ext4_fname_encrypt(ctx, &istr, cstr);
684 if (ret < 0)
685 goto errout;
686 }
687 } else {
688 if (cstr->name == NULL) {
689 cstr->name = kmalloc(32, GFP_KERNEL);
690 if (cstr->name == NULL)
691 return -ENOMEM;
692 if ((bigname && (len != 33)) ||
693 (!bigname && (len > 43)))
694 goto errout;
695 ret = digest_decode(name+bigname, len-bigname,
696 cstr->name);
697 if (ret < 0) {
698 ret = -ENOENT;
699 goto errout;
700 }
701 cstr->len = ret;
702 }
703 if (bigname) {
704 if (de->name_len < 16)
705 return 0;
706 ret = memcmp(de->name + de->name_len - 16,
707 cstr->name + 8, 16);
708 return (ret == 0) ? 1 : 0;
709 }
697 } 710 }
698 711 if (de->name_len != cstr->len)
699 tmp.len = (4 * ((EXT4_FNAME_CRYPTO_DIGEST_SIZE + 2) / 3)) + 1; 712 return 0;
700 tmp.name = kmalloc(tmp.len + 1, GFP_KERNEL); 713 ret = memcmp(de->name, cstr->name, cstr->len);
701 if (tmp.name == NULL) 714 return (ret == 0) ? 1 : 0;
702 return -ENOMEM; 715errout:
703 716 kfree(cstr->name);
704 ret = ext4_fname_hash(ctx, &iname, &tmp); 717 cstr->name = NULL;
705 if (ret > 0)
706 ext4fs_dirhash(tmp.name, tmp.len, hinfo);
707 ext4_fname_crypto_free_buffer(&tmp);
708 return ret; 718 return ret;
709} 719}
diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
index c8392af8abbb..52170d0b7c40 100644
--- a/fs/ext4/crypto_key.c
+++ b/fs/ext4/crypto_key.c
@@ -110,6 +110,7 @@ int ext4_generate_encryption_key(struct inode *inode)
110 } 110 }
111 res = 0; 111 res = 0;
112 112
113 ei->i_crypt_policy_flags = ctx.flags;
113 if (S_ISREG(inode->i_mode)) 114 if (S_ISREG(inode->i_mode))
114 crypt_key->mode = ctx.contents_encryption_mode; 115 crypt_key->mode = ctx.contents_encryption_mode;
115 else if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) 116 else if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
diff --git a/fs/ext4/crypto_policy.c b/fs/ext4/crypto_policy.c
index 30eaf9e9864a..a6d6291aea16 100644
--- a/fs/ext4/crypto_policy.c
+++ b/fs/ext4/crypto_policy.c
@@ -37,6 +37,8 @@ static int ext4_is_encryption_context_consistent_with_policy(
37 return 0; 37 return 0;
38 return (memcmp(ctx.master_key_descriptor, policy->master_key_descriptor, 38 return (memcmp(ctx.master_key_descriptor, policy->master_key_descriptor,
39 EXT4_KEY_DESCRIPTOR_SIZE) == 0 && 39 EXT4_KEY_DESCRIPTOR_SIZE) == 0 &&
40 (ctx.flags ==
41 policy->flags) &&
40 (ctx.contents_encryption_mode == 42 (ctx.contents_encryption_mode ==
41 policy->contents_encryption_mode) && 43 policy->contents_encryption_mode) &&
42 (ctx.filenames_encryption_mode == 44 (ctx.filenames_encryption_mode ==
@@ -56,25 +58,25 @@ static int ext4_create_encryption_context_from_policy(
56 printk(KERN_WARNING 58 printk(KERN_WARNING
57 "%s: Invalid contents encryption mode %d\n", __func__, 59 "%s: Invalid contents encryption mode %d\n", __func__,
58 policy->contents_encryption_mode); 60 policy->contents_encryption_mode);
59 res = -EINVAL; 61 return -EINVAL;
60 goto out;
61 } 62 }
62 if (!ext4_valid_filenames_enc_mode(policy->filenames_encryption_mode)) { 63 if (!ext4_valid_filenames_enc_mode(policy->filenames_encryption_mode)) {
63 printk(KERN_WARNING 64 printk(KERN_WARNING
64 "%s: Invalid filenames encryption mode %d\n", __func__, 65 "%s: Invalid filenames encryption mode %d\n", __func__,
65 policy->filenames_encryption_mode); 66 policy->filenames_encryption_mode);
66 res = -EINVAL; 67 return -EINVAL;
67 goto out;
68 } 68 }
69 if (policy->flags & ~EXT4_POLICY_FLAGS_VALID)
70 return -EINVAL;
69 ctx.contents_encryption_mode = policy->contents_encryption_mode; 71 ctx.contents_encryption_mode = policy->contents_encryption_mode;
70 ctx.filenames_encryption_mode = policy->filenames_encryption_mode; 72 ctx.filenames_encryption_mode = policy->filenames_encryption_mode;
73 ctx.flags = policy->flags;
71 BUILD_BUG_ON(sizeof(ctx.nonce) != EXT4_KEY_DERIVATION_NONCE_SIZE); 74 BUILD_BUG_ON(sizeof(ctx.nonce) != EXT4_KEY_DERIVATION_NONCE_SIZE);
72 get_random_bytes(ctx.nonce, EXT4_KEY_DERIVATION_NONCE_SIZE); 75 get_random_bytes(ctx.nonce, EXT4_KEY_DERIVATION_NONCE_SIZE);
73 76
74 res = ext4_xattr_set(inode, EXT4_XATTR_INDEX_ENCRYPTION, 77 res = ext4_xattr_set(inode, EXT4_XATTR_INDEX_ENCRYPTION,
75 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, &ctx, 78 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, &ctx,
76 sizeof(ctx), 0); 79 sizeof(ctx), 0);
77out:
78 if (!res) 80 if (!res)
79 ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT); 81 ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
80 return res; 82 return res;
@@ -115,6 +117,7 @@ int ext4_get_policy(struct inode *inode, struct ext4_encryption_policy *policy)
115 policy->version = 0; 117 policy->version = 0;
116 policy->contents_encryption_mode = ctx.contents_encryption_mode; 118 policy->contents_encryption_mode = ctx.contents_encryption_mode;
117 policy->filenames_encryption_mode = ctx.filenames_encryption_mode; 119 policy->filenames_encryption_mode = ctx.filenames_encryption_mode;
120 policy->flags = ctx.flags;
118 memcpy(&policy->master_key_descriptor, ctx.master_key_descriptor, 121 memcpy(&policy->master_key_descriptor, ctx.master_key_descriptor,
119 EXT4_KEY_DESCRIPTOR_SIZE); 122 EXT4_KEY_DESCRIPTOR_SIZE);
120 return 0; 123 return 0;
@@ -176,6 +179,7 @@ int ext4_inherit_context(struct inode *parent, struct inode *child)
176 EXT4_ENCRYPTION_MODE_AES_256_XTS; 179 EXT4_ENCRYPTION_MODE_AES_256_XTS;
177 ctx.filenames_encryption_mode = 180 ctx.filenames_encryption_mode =
178 EXT4_ENCRYPTION_MODE_AES_256_CTS; 181 EXT4_ENCRYPTION_MODE_AES_256_CTS;
182 ctx.flags = 0;
179 memset(ctx.master_key_descriptor, 0x42, 183 memset(ctx.master_key_descriptor, 0x42,
180 EXT4_KEY_DESCRIPTOR_SIZE); 184 EXT4_KEY_DESCRIPTOR_SIZE);
181 res = 0; 185 res = 0;
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 61db51a5ce4c..5665d82d2332 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -249,7 +249,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
249 } else { 249 } else {
250 /* Directory is encrypted */ 250 /* Directory is encrypted */
251 err = ext4_fname_disk_to_usr(enc_ctx, 251 err = ext4_fname_disk_to_usr(enc_ctx,
252 de, &fname_crypto_str); 252 NULL, de, &fname_crypto_str);
253 if (err < 0) 253 if (err < 0)
254 goto errout; 254 goto errout;
255 if (!dir_emit(ctx, 255 if (!dir_emit(ctx,
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ef267adce19a..9a83f149ac85 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -911,6 +911,7 @@ struct ext4_inode_info {
911 911
912 /* on-disk additional length */ 912 /* on-disk additional length */
913 __u16 i_extra_isize; 913 __u16 i_extra_isize;
914 char i_crypt_policy_flags;
914 915
915 /* Indicate the inline data space. */ 916 /* Indicate the inline data space. */
916 u16 i_inline_off; 917 u16 i_inline_off;
@@ -1066,12 +1067,6 @@ extern void ext4_set_bits(void *bm, int cur, int len);
1066/* Metadata checksum algorithm codes */ 1067/* Metadata checksum algorithm codes */
1067#define EXT4_CRC32C_CHKSUM 1 1068#define EXT4_CRC32C_CHKSUM 1
1068 1069
1069/* Encryption algorithms */
1070#define EXT4_ENCRYPTION_MODE_INVALID 0
1071#define EXT4_ENCRYPTION_MODE_AES_256_XTS 1
1072#define EXT4_ENCRYPTION_MODE_AES_256_GCM 2
1073#define EXT4_ENCRYPTION_MODE_AES_256_CBC 3
1074
1075/* 1070/*
1076 * Structure of the super block 1071 * Structure of the super block
1077 */ 1072 */
@@ -2093,9 +2088,11 @@ u32 ext4_fname_crypto_round_up(u32 size, u32 blksize);
2093int ext4_fname_crypto_alloc_buffer(struct ext4_fname_crypto_ctx *ctx, 2088int ext4_fname_crypto_alloc_buffer(struct ext4_fname_crypto_ctx *ctx,
2094 u32 ilen, struct ext4_str *crypto_str); 2089 u32 ilen, struct ext4_str *crypto_str);
2095int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, 2090int _ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx,
2091 struct dx_hash_info *hinfo,
2096 const struct ext4_str *iname, 2092 const struct ext4_str *iname,
2097 struct ext4_str *oname); 2093 struct ext4_str *oname);
2098int ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx, 2094int ext4_fname_disk_to_usr(struct ext4_fname_crypto_ctx *ctx,
2095 struct dx_hash_info *hinfo,
2099 const struct ext4_dir_entry_2 *de, 2096 const struct ext4_dir_entry_2 *de,
2100 struct ext4_str *oname); 2097 struct ext4_str *oname);
2101int ext4_fname_usr_to_disk(struct ext4_fname_crypto_ctx *ctx, 2098int ext4_fname_usr_to_disk(struct ext4_fname_crypto_ctx *ctx,
@@ -2104,11 +2101,12 @@ int ext4_fname_usr_to_disk(struct ext4_fname_crypto_ctx *ctx,
2104int ext4_fname_usr_to_hash(struct ext4_fname_crypto_ctx *ctx, 2101int ext4_fname_usr_to_hash(struct ext4_fname_crypto_ctx *ctx,
2105 const struct qstr *iname, 2102 const struct qstr *iname,
2106 struct dx_hash_info *hinfo); 2103 struct dx_hash_info *hinfo);
2107int ext4_fname_disk_to_hash(struct ext4_fname_crypto_ctx *ctx,
2108 const struct ext4_dir_entry_2 *de,
2109 struct dx_hash_info *hinfo);
2110int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx, 2104int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx,
2111 u32 namelen); 2105 u32 namelen);
2106int ext4_fname_match(struct ext4_fname_crypto_ctx *ctx, struct ext4_str *cstr,
2107 int len, const char * const name,
2108 struct ext4_dir_entry_2 *de);
2109
2112 2110
2113#ifdef CONFIG_EXT4_FS_ENCRYPTION 2111#ifdef CONFIG_EXT4_FS_ENCRYPTION
2114void ext4_put_fname_crypto_ctx(struct ext4_fname_crypto_ctx **ctx); 2112void ext4_put_fname_crypto_ctx(struct ext4_fname_crypto_ctx **ctx);
@@ -2891,7 +2889,6 @@ extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
2891 struct ext4_map_blocks *map, int flags); 2889 struct ext4_map_blocks *map, int flags);
2892extern int ext4_ext_calc_metadata_amount(struct inode *inode, 2890extern int ext4_ext_calc_metadata_amount(struct inode *inode,
2893 ext4_lblk_t lblocks); 2891 ext4_lblk_t lblocks);
2894extern int ext4_extent_tree_init(handle_t *, struct inode *);
2895extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, 2892extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
2896 int num, 2893 int num,
2897 struct ext4_ext_path *path); 2894 struct ext4_ext_path *path);
diff --git a/fs/ext4/ext4_crypto.h b/fs/ext4/ext4_crypto.h
index c2ba35a914b6..d75159c101ce 100644
--- a/fs/ext4/ext4_crypto.h
+++ b/fs/ext4/ext4_crypto.h
@@ -20,12 +20,20 @@ struct ext4_encryption_policy {
20 char version; 20 char version;
21 char contents_encryption_mode; 21 char contents_encryption_mode;
22 char filenames_encryption_mode; 22 char filenames_encryption_mode;
23 char flags;
23 char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE]; 24 char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE];
24} __attribute__((__packed__)); 25} __attribute__((__packed__));
25 26
26#define EXT4_ENCRYPTION_CONTEXT_FORMAT_V1 1 27#define EXT4_ENCRYPTION_CONTEXT_FORMAT_V1 1
27#define EXT4_KEY_DERIVATION_NONCE_SIZE 16 28#define EXT4_KEY_DERIVATION_NONCE_SIZE 16
28 29
30#define EXT4_POLICY_FLAGS_PAD_4 0x00
31#define EXT4_POLICY_FLAGS_PAD_8 0x01
32#define EXT4_POLICY_FLAGS_PAD_16 0x02
33#define EXT4_POLICY_FLAGS_PAD_32 0x03
34#define EXT4_POLICY_FLAGS_PAD_MASK 0x03
35#define EXT4_POLICY_FLAGS_VALID 0x03
36
29/** 37/**
30 * Encryption context for inode 38 * Encryption context for inode
31 * 39 *
@@ -41,7 +49,7 @@ struct ext4_encryption_context {
41 char format; 49 char format;
42 char contents_encryption_mode; 50 char contents_encryption_mode;
43 char filenames_encryption_mode; 51 char filenames_encryption_mode;
44 char reserved; 52 char flags;
45 char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE]; 53 char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE];
46 char nonce[EXT4_KEY_DERIVATION_NONCE_SIZE]; 54 char nonce[EXT4_KEY_DERIVATION_NONCE_SIZE];
47} __attribute__((__packed__)); 55} __attribute__((__packed__));
@@ -120,6 +128,7 @@ struct ext4_fname_crypto_ctx {
120 struct crypto_hash *htfm; 128 struct crypto_hash *htfm;
121 struct page *workpage; 129 struct page *workpage;
122 struct ext4_encryption_key key; 130 struct ext4_encryption_key key;
131 unsigned flags : 8;
123 unsigned has_valid_key : 1; 132 unsigned has_valid_key : 1;
124 unsigned ctfm_key_is_ready : 1; 133 unsigned ctfm_key_is_ready : 1;
125}; 134};
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index 3445035c7e01..d41843181818 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -87,6 +87,12 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
87 ext4_put_nojournal(handle); 87 ext4_put_nojournal(handle);
88 return 0; 88 return 0;
89 } 89 }
90
91 if (!handle->h_transaction) {
92 err = jbd2_journal_stop(handle);
93 return handle->h_err ? handle->h_err : err;
94 }
95
90 sb = handle->h_transaction->t_journal->j_private; 96 sb = handle->h_transaction->t_journal->j_private;
91 err = handle->h_err; 97 err = handle->h_err;
92 rc = jbd2_journal_stop(handle); 98 rc = jbd2_journal_stop(handle);
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 973816bfe4a9..e003a1e81dc3 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -377,7 +377,7 @@ static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
377 ext4_lblk_t lblock = le32_to_cpu(ext->ee_block); 377 ext4_lblk_t lblock = le32_to_cpu(ext->ee_block);
378 ext4_lblk_t last = lblock + len - 1; 378 ext4_lblk_t last = lblock + len - 1;
379 379
380 if (lblock > last) 380 if (len == 0 || lblock > last)
381 return 0; 381 return 0;
382 return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len); 382 return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len);
383} 383}
@@ -4927,13 +4927,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
4927 if (ret) 4927 if (ret)
4928 return ret; 4928 return ret;
4929 4929
4930 /*
4931 * currently supporting (pre)allocate mode for extent-based
4932 * files _only_
4933 */
4934 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
4935 return -EOPNOTSUPP;
4936
4937 if (mode & FALLOC_FL_COLLAPSE_RANGE) 4930 if (mode & FALLOC_FL_COLLAPSE_RANGE)
4938 return ext4_collapse_range(inode, offset, len); 4931 return ext4_collapse_range(inode, offset, len);
4939 4932
@@ -4955,6 +4948,14 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
4955 4948
4956 mutex_lock(&inode->i_mutex); 4949 mutex_lock(&inode->i_mutex);
4957 4950
4951 /*
4952 * We only support preallocation for extent-based files only
4953 */
4954 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
4955 ret = -EOPNOTSUPP;
4956 goto out;
4957 }
4958
4958 if (!(mode & FALLOC_FL_KEEP_SIZE) && 4959 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
4959 offset + len > i_size_read(inode)) { 4960 offset + len > i_size_read(inode)) {
4960 new_size = offset + len; 4961 new_size = offset + len;
@@ -5395,6 +5396,14 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
5395 loff_t new_size, ioffset; 5396 loff_t new_size, ioffset;
5396 int ret; 5397 int ret;
5397 5398
5399 /*
5400 * We need to test this early because xfstests assumes that a
5401 * collapse range of (0, 1) will return EOPNOTSUPP if the file
5402 * system does not support collapse range.
5403 */
5404 if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
5405 return -EOPNOTSUPP;
5406
5398 /* Collapse range works only on fs block size aligned offsets. */ 5407 /* Collapse range works only on fs block size aligned offsets. */
5399 if (offset & (EXT4_CLUSTER_SIZE(sb) - 1) || 5408 if (offset & (EXT4_CLUSTER_SIZE(sb) - 1) ||
5400 len & (EXT4_CLUSTER_SIZE(sb) - 1)) 5409 len & (EXT4_CLUSTER_SIZE(sb) - 1))
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index d33d5a6852b9..26724aeece73 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -703,6 +703,14 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
703 703
704 BUG_ON(end < lblk); 704 BUG_ON(end < lblk);
705 705
706 if ((status & EXTENT_STATUS_DELAYED) &&
707 (status & EXTENT_STATUS_WRITTEN)) {
708 ext4_warning(inode->i_sb, "Inserting extent [%u/%u] as "
709 " delayed and written which can potentially "
710 " cause data loss.\n", lblk, len);
711 WARN_ON(1);
712 }
713
706 newes.es_lblk = lblk; 714 newes.es_lblk = lblk;
707 newes.es_len = len; 715 newes.es_len = len;
708 ext4_es_store_pblock_status(&newes, pblk, status); 716 ext4_es_store_pblock_status(&newes, pblk, status);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index cbd0654a2675..0554b0b5957b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -531,6 +531,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
531 status = map->m_flags & EXT4_MAP_UNWRITTEN ? 531 status = map->m_flags & EXT4_MAP_UNWRITTEN ?
532 EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; 532 EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
533 if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) && 533 if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) &&
534 !(status & EXTENT_STATUS_WRITTEN) &&
534 ext4_find_delalloc_range(inode, map->m_lblk, 535 ext4_find_delalloc_range(inode, map->m_lblk,
535 map->m_lblk + map->m_len - 1)) 536 map->m_lblk + map->m_len - 1))
536 status |= EXTENT_STATUS_DELAYED; 537 status |= EXTENT_STATUS_DELAYED;
@@ -635,6 +636,7 @@ found:
635 status = map->m_flags & EXT4_MAP_UNWRITTEN ? 636 status = map->m_flags & EXT4_MAP_UNWRITTEN ?
636 EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; 637 EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
637 if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) && 638 if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) &&
639 !(status & EXTENT_STATUS_WRITTEN) &&
638 ext4_find_delalloc_range(inode, map->m_lblk, 640 ext4_find_delalloc_range(inode, map->m_lblk,
639 map->m_lblk + map->m_len - 1)) 641 map->m_lblk + map->m_len - 1))
640 status |= EXTENT_STATUS_DELAYED; 642 status |= EXTENT_STATUS_DELAYED;
@@ -4343,7 +4345,7 @@ static void ext4_update_other_inodes_time(struct super_block *sb,
4343 int inode_size = EXT4_INODE_SIZE(sb); 4345 int inode_size = EXT4_INODE_SIZE(sb);
4344 4346
4345 oi.orig_ino = orig_ino; 4347 oi.orig_ino = orig_ino;
4346 ino = orig_ino & ~(inodes_per_block - 1); 4348 ino = (orig_ino & ~(inodes_per_block - 1)) + 1;
4347 for (i = 0; i < inodes_per_block; i++, ino++, buf += inode_size) { 4349 for (i = 0; i < inodes_per_block; i++, ino++, buf += inode_size) {
4348 if (ino == orig_ino) 4350 if (ino == orig_ino)
4349 continue; 4351 continue;
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 7223b0b4bc38..814f3beb4369 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -640,7 +640,7 @@ static struct stats dx_show_leaf(struct inode *dir,
640 ext4_put_fname_crypto_ctx(&ctx); 640 ext4_put_fname_crypto_ctx(&ctx);
641 ctx = NULL; 641 ctx = NULL;
642 } 642 }
643 res = ext4_fname_disk_to_usr(ctx, de, 643 res = ext4_fname_disk_to_usr(ctx, NULL, de,
644 &fname_crypto_str); 644 &fname_crypto_str);
645 if (res < 0) { 645 if (res < 0) {
646 printk(KERN_WARNING "Error " 646 printk(KERN_WARNING "Error "
@@ -653,15 +653,8 @@ static struct stats dx_show_leaf(struct inode *dir,
653 name = fname_crypto_str.name; 653 name = fname_crypto_str.name;
654 len = fname_crypto_str.len; 654 len = fname_crypto_str.len;
655 } 655 }
656 res = ext4_fname_disk_to_hash(ctx, de, 656 ext4fs_dirhash(de->name, de->name_len,
657 &h); 657 &h);
658 if (res < 0) {
659 printk(KERN_WARNING "Error "
660 "converting filename "
661 "from disk to htree"
662 "\n");
663 h.hash = 0xDEADBEEF;
664 }
665 printk("%*.s:(E)%x.%u ", len, name, 658 printk("%*.s:(E)%x.%u ", len, name,
666 h.hash, (unsigned) ((char *) de 659 h.hash, (unsigned) ((char *) de
667 - base)); 660 - base));
@@ -1008,15 +1001,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
1008 /* silently ignore the rest of the block */ 1001 /* silently ignore the rest of the block */
1009 break; 1002 break;
1010 } 1003 }
1011#ifdef CONFIG_EXT4_FS_ENCRYPTION
1012 err = ext4_fname_disk_to_hash(ctx, de, hinfo);
1013 if (err < 0) {
1014 count = err;
1015 goto errout;
1016 }
1017#else
1018 ext4fs_dirhash(de->name, de->name_len, hinfo); 1004 ext4fs_dirhash(de->name, de->name_len, hinfo);
1019#endif
1020 if ((hinfo->hash < start_hash) || 1005 if ((hinfo->hash < start_hash) ||
1021 ((hinfo->hash == start_hash) && 1006 ((hinfo->hash == start_hash) &&
1022 (hinfo->minor_hash < start_minor_hash))) 1007 (hinfo->minor_hash < start_minor_hash)))
@@ -1032,7 +1017,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
1032 &tmp_str); 1017 &tmp_str);
1033 } else { 1018 } else {
1034 /* Directory is encrypted */ 1019 /* Directory is encrypted */
1035 err = ext4_fname_disk_to_usr(ctx, de, 1020 err = ext4_fname_disk_to_usr(ctx, hinfo, de,
1036 &fname_crypto_str); 1021 &fname_crypto_str);
1037 if (err < 0) { 1022 if (err < 0) {
1038 count = err; 1023 count = err;
@@ -1193,26 +1178,10 @@ static int dx_make_map(struct inode *dir, struct ext4_dir_entry_2 *de,
1193 int count = 0; 1178 int count = 0;
1194 char *base = (char *) de; 1179 char *base = (char *) de;
1195 struct dx_hash_info h = *hinfo; 1180 struct dx_hash_info h = *hinfo;
1196#ifdef CONFIG_EXT4_FS_ENCRYPTION
1197 struct ext4_fname_crypto_ctx *ctx = NULL;
1198 int err;
1199
1200 ctx = ext4_get_fname_crypto_ctx(dir, EXT4_NAME_LEN);
1201 if (IS_ERR(ctx))
1202 return PTR_ERR(ctx);
1203#endif
1204 1181
1205 while ((char *) de < base + blocksize) { 1182 while ((char *) de < base + blocksize) {
1206 if (de->name_len && de->inode) { 1183 if (de->name_len && de->inode) {
1207#ifdef CONFIG_EXT4_FS_ENCRYPTION
1208 err = ext4_fname_disk_to_hash(ctx, de, &h);
1209 if (err < 0) {
1210 ext4_put_fname_crypto_ctx(&ctx);
1211 return err;
1212 }
1213#else
1214 ext4fs_dirhash(de->name, de->name_len, &h); 1184 ext4fs_dirhash(de->name, de->name_len, &h);
1215#endif
1216 map_tail--; 1185 map_tail--;
1217 map_tail->hash = h.hash; 1186 map_tail->hash = h.hash;
1218 map_tail->offs = ((char *) de - base)>>2; 1187 map_tail->offs = ((char *) de - base)>>2;
@@ -1223,9 +1192,6 @@ static int dx_make_map(struct inode *dir, struct ext4_dir_entry_2 *de,
1223 /* XXX: do we need to check rec_len == 0 case? -Chris */ 1192 /* XXX: do we need to check rec_len == 0 case? -Chris */
1224 de = ext4_next_entry(de, blocksize); 1193 de = ext4_next_entry(de, blocksize);
1225 } 1194 }
1226#ifdef CONFIG_EXT4_FS_ENCRYPTION
1227 ext4_put_fname_crypto_ctx(&ctx);
1228#endif
1229 return count; 1195 return count;
1230} 1196}
1231 1197
@@ -1287,16 +1253,8 @@ static inline int ext4_match(struct ext4_fname_crypto_ctx *ctx,
1287 return 0; 1253 return 0;
1288 1254
1289#ifdef CONFIG_EXT4_FS_ENCRYPTION 1255#ifdef CONFIG_EXT4_FS_ENCRYPTION
1290 if (ctx) { 1256 if (ctx)
1291 /* Directory is encrypted */ 1257 return ext4_fname_match(ctx, fname_crypto_str, len, name, de);
1292 res = ext4_fname_disk_to_usr(ctx, de, fname_crypto_str);
1293 if (res < 0)
1294 return res;
1295 if (len != res)
1296 return 0;
1297 res = memcmp(name, fname_crypto_str->name, len);
1298 return (res == 0) ? 1 : 0;
1299 }
1300#endif 1258#endif
1301 if (len != de->name_len) 1259 if (len != de->name_len)
1302 return 0; 1260 return 0;
@@ -1324,16 +1282,6 @@ int search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
1324 if (IS_ERR(ctx)) 1282 if (IS_ERR(ctx))
1325 return -1; 1283 return -1;
1326 1284
1327 if (ctx != NULL) {
1328 /* Allocate buffer to hold maximum name length */
1329 res = ext4_fname_crypto_alloc_buffer(ctx, EXT4_NAME_LEN,
1330 &fname_crypto_str);
1331 if (res < 0) {
1332 ext4_put_fname_crypto_ctx(&ctx);
1333 return -1;
1334 }
1335 }
1336
1337 de = (struct ext4_dir_entry_2 *)search_buf; 1285 de = (struct ext4_dir_entry_2 *)search_buf;
1338 dlimit = search_buf + buf_size; 1286 dlimit = search_buf + buf_size;
1339 while ((char *) de < dlimit) { 1287 while ((char *) de < dlimit) {
@@ -1872,14 +1820,6 @@ int ext4_find_dest_de(struct inode *dir, struct inode *inode,
1872 return res; 1820 return res;
1873 } 1821 }
1874 reclen = EXT4_DIR_REC_LEN(res); 1822 reclen = EXT4_DIR_REC_LEN(res);
1875
1876 /* Allocate buffer to hold maximum name length */
1877 res = ext4_fname_crypto_alloc_buffer(ctx, EXT4_NAME_LEN,
1878 &fname_crypto_str);
1879 if (res < 0) {
1880 ext4_put_fname_crypto_ctx(&ctx);
1881 return -1;
1882 }
1883 } 1823 }
1884 1824
1885 de = (struct ext4_dir_entry_2 *)buf; 1825 de = (struct ext4_dir_entry_2 *)buf;
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 8a8ec6293b19..cf0c472047e3 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1432,12 +1432,15 @@ static int ext4_flex_group_add(struct super_block *sb,
1432 goto exit; 1432 goto exit;
1433 /* 1433 /*
1434 * We will always be modifying at least the superblock and GDT 1434 * We will always be modifying at least the superblock and GDT
1435 * block. If we are adding a group past the last current GDT block, 1435 * blocks. If we are adding a group past the last current GDT block,
1436 * we will also modify the inode and the dindirect block. If we 1436 * we will also modify the inode and the dindirect block. If we
1437 * are adding a group with superblock/GDT backups we will also 1437 * are adding a group with superblock/GDT backups we will also
1438 * modify each of the reserved GDT dindirect blocks. 1438 * modify each of the reserved GDT dindirect blocks.
1439 */ 1439 */
1440 credit = flex_gd->count * 4 + reserved_gdb; 1440 credit = 3; /* sb, resize inode, resize inode dindirect */
1441 /* GDT blocks */
1442 credit += 1 + DIV_ROUND_UP(flex_gd->count, EXT4_DESC_PER_BLOCK(sb));
1443 credit += reserved_gdb; /* Reserved GDT dindirect blocks */
1441 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, credit); 1444 handle = ext4_journal_start_sb(sb, EXT4_HT_RESIZE, credit);
1442 if (IS_ERR(handle)) { 1445 if (IS_ERR(handle)) {
1443 err = PTR_ERR(handle); 1446 err = PTR_ERR(handle);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f06d0589ddba..ca9d4a2fed41 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -294,6 +294,8 @@ static void __save_error_info(struct super_block *sb, const char *func,
294 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 294 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
295 295
296 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 296 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
297 if (bdev_read_only(sb->s_bdev))
298 return;
297 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 299 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
298 es->s_last_error_time = cpu_to_le32(get_seconds()); 300 es->s_last_error_time = cpu_to_le32(get_seconds());
299 strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func)); 301 strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 19f78f20975e..187b78920314 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -74,7 +74,7 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)
74 goto errout; 74 goto errout;
75 } 75 }
76 pstr.name = paddr; 76 pstr.name = paddr;
77 res = _ext4_fname_disk_to_usr(ctx, &cstr, &pstr); 77 res = _ext4_fname_disk_to_usr(ctx, NULL, &cstr, &pstr);
78 if (res < 0) 78 if (res < 0)
79 goto errout; 79 goto errout;
80 /* Null-terminate the name */ 80 /* Null-terminate the name */
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b91b0e10678e..1e1aae669fa8 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1513,6 +1513,7 @@ static int f2fs_write_data_pages(struct address_space *mapping,
1513{ 1513{
1514 struct inode *inode = mapping->host; 1514 struct inode *inode = mapping->host;
1515 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1515 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1516 bool locked = false;
1516 int ret; 1517 int ret;
1517 long diff; 1518 long diff;
1518 1519
@@ -1533,7 +1534,13 @@ static int f2fs_write_data_pages(struct address_space *mapping,
1533 1534
1534 diff = nr_pages_to_write(sbi, DATA, wbc); 1535 diff = nr_pages_to_write(sbi, DATA, wbc);
1535 1536
1537 if (!S_ISDIR(inode->i_mode)) {
1538 mutex_lock(&sbi->writepages);
1539 locked = true;
1540 }
1536 ret = write_cache_pages(mapping, wbc, __f2fs_writepage, mapping); 1541 ret = write_cache_pages(mapping, wbc, __f2fs_writepage, mapping);
1542 if (locked)
1543 mutex_unlock(&sbi->writepages);
1537 1544
1538 f2fs_submit_merged_bio(sbi, DATA, WRITE); 1545 f2fs_submit_merged_bio(sbi, DATA, WRITE);
1539 1546
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index d8921cf2ba9a..8de34ab6d5b1 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -625,6 +625,7 @@ struct f2fs_sb_info {
625 struct mutex cp_mutex; /* checkpoint procedure lock */ 625 struct mutex cp_mutex; /* checkpoint procedure lock */
626 struct rw_semaphore cp_rwsem; /* blocking FS operations */ 626 struct rw_semaphore cp_rwsem; /* blocking FS operations */
627 struct rw_semaphore node_write; /* locking node writes */ 627 struct rw_semaphore node_write; /* locking node writes */
628 struct mutex writepages; /* mutex for writepages() */
628 wait_queue_head_t cp_wait; 629 wait_queue_head_t cp_wait;
629 630
630 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 631 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 7e3794edae42..658e8079aaf9 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -298,16 +298,14 @@ fail:
298 298
299static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd) 299static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd)
300{ 300{
301 struct page *page; 301 struct page *page = page_follow_link_light(dentry, nd);
302 302
303 page = page_follow_link_light(dentry, nd); 303 if (IS_ERR_OR_NULL(page))
304 if (IS_ERR(page))
305 return page; 304 return page;
306 305
307 /* this is broken symlink case */ 306 /* this is broken symlink case */
308 if (*nd_get_link(nd) == 0) { 307 if (*nd_get_link(nd) == 0) {
309 kunmap(page); 308 page_put_link(dentry, nd, page);
310 page_cache_release(page);
311 return ERR_PTR(-ENOENT); 309 return ERR_PTR(-ENOENT);
312 } 310 }
313 return page; 311 return page;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 160b88346b24..b2dd1b01f076 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1035,6 +1035,7 @@ try_onemore:
1035 sbi->raw_super = raw_super; 1035 sbi->raw_super = raw_super;
1036 sbi->raw_super_buf = raw_super_buf; 1036 sbi->raw_super_buf = raw_super_buf;
1037 mutex_init(&sbi->gc_mutex); 1037 mutex_init(&sbi->gc_mutex);
1038 mutex_init(&sbi->writepages);
1038 mutex_init(&sbi->cp_mutex); 1039 mutex_init(&sbi->cp_mutex);
1039 init_rwsem(&sbi->node_write); 1040 init_rwsem(&sbi->node_write);
1040 clear_sbi_flag(sbi, SBI_POR_DOING); 1041 clear_sbi_flag(sbi, SBI_POR_DOING);
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index ef263174acd2..07d8d8f52faf 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -581,7 +581,7 @@ static int hostfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
581 if (name == NULL) 581 if (name == NULL)
582 goto out_put; 582 goto out_put;
583 583
584 fd = file_create(name, mode & S_IFMT); 584 fd = file_create(name, mode & 0777);
585 if (fd < 0) 585 if (fd < 0)
586 error = fd; 586 error = fd;
587 else 587 else
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index b5128c6e63ad..a9079d035ae5 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -842,15 +842,23 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
842{ 842{
843 jbd2_journal_revoke_header_t *header; 843 jbd2_journal_revoke_header_t *header;
844 int offset, max; 844 int offset, max;
845 int csum_size = 0;
846 __u32 rcount;
845 int record_len = 4; 847 int record_len = 4;
846 848
847 header = (jbd2_journal_revoke_header_t *) bh->b_data; 849 header = (jbd2_journal_revoke_header_t *) bh->b_data;
848 offset = sizeof(jbd2_journal_revoke_header_t); 850 offset = sizeof(jbd2_journal_revoke_header_t);
849 max = be32_to_cpu(header->r_count); 851 rcount = be32_to_cpu(header->r_count);
850 852
851 if (!jbd2_revoke_block_csum_verify(journal, header)) 853 if (!jbd2_revoke_block_csum_verify(journal, header))
852 return -EINVAL; 854 return -EINVAL;
853 855
856 if (jbd2_journal_has_csum_v2or3(journal))
857 csum_size = sizeof(struct jbd2_journal_revoke_tail);
858 if (rcount > journal->j_blocksize - csum_size)
859 return -EINVAL;
860 max = rcount;
861
854 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) 862 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
855 record_len = 8; 863 record_len = 8;
856 864
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index c6cbaef2bda1..14214da80eb8 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -577,7 +577,7 @@ static void write_one_revoke_record(journal_t *journal,
577{ 577{
578 int csum_size = 0; 578 int csum_size = 0;
579 struct buffer_head *descriptor; 579 struct buffer_head *descriptor;
580 int offset; 580 int sz, offset;
581 journal_header_t *header; 581 journal_header_t *header;
582 582
583 /* If we are already aborting, this all becomes a noop. We 583 /* If we are already aborting, this all becomes a noop. We
@@ -594,9 +594,14 @@ static void write_one_revoke_record(journal_t *journal,
594 if (jbd2_journal_has_csum_v2or3(journal)) 594 if (jbd2_journal_has_csum_v2or3(journal))
595 csum_size = sizeof(struct jbd2_journal_revoke_tail); 595 csum_size = sizeof(struct jbd2_journal_revoke_tail);
596 596
597 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
598 sz = 8;
599 else
600 sz = 4;
601
597 /* Make sure we have a descriptor with space left for the record */ 602 /* Make sure we have a descriptor with space left for the record */
598 if (descriptor) { 603 if (descriptor) {
599 if (offset >= journal->j_blocksize - csum_size) { 604 if (offset + sz > journal->j_blocksize - csum_size) {
600 flush_descriptor(journal, descriptor, offset, write_op); 605 flush_descriptor(journal, descriptor, offset, write_op);
601 descriptor = NULL; 606 descriptor = NULL;
602 } 607 }
@@ -619,16 +624,13 @@ static void write_one_revoke_record(journal_t *journal,
619 *descriptorp = descriptor; 624 *descriptorp = descriptor;
620 } 625 }
621 626
622 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) { 627 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
623 * ((__be64 *)(&descriptor->b_data[offset])) = 628 * ((__be64 *)(&descriptor->b_data[offset])) =
624 cpu_to_be64(record->blocknr); 629 cpu_to_be64(record->blocknr);
625 offset += 8; 630 else
626
627 } else {
628 * ((__be32 *)(&descriptor->b_data[offset])) = 631 * ((__be32 *)(&descriptor->b_data[offset])) =
629 cpu_to_be32(record->blocknr); 632 cpu_to_be32(record->blocknr);
630 offset += 4; 633 offset += sz;
631 }
632 634
633 *offsetp = offset; 635 *offsetp = offset;
634} 636}
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 5f09370c90a8..ff2f2e6ad311 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -551,7 +551,6 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
551 int result; 551 int result;
552 int wanted; 552 int wanted;
553 553
554 WARN_ON(!transaction);
555 if (is_handle_aborted(handle)) 554 if (is_handle_aborted(handle))
556 return -EROFS; 555 return -EROFS;
557 journal = transaction->t_journal; 556 journal = transaction->t_journal;
@@ -627,7 +626,6 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, gfp_t gfp_mask)
627 tid_t tid; 626 tid_t tid;
628 int need_to_start, ret; 627 int need_to_start, ret;
629 628
630 WARN_ON(!transaction);
631 /* If we've had an abort of any type, don't even think about 629 /* If we've had an abort of any type, don't even think about
632 * actually doing the restart! */ 630 * actually doing the restart! */
633 if (is_handle_aborted(handle)) 631 if (is_handle_aborted(handle))
@@ -785,7 +783,6 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
785 int need_copy = 0; 783 int need_copy = 0;
786 unsigned long start_lock, time_lock; 784 unsigned long start_lock, time_lock;
787 785
788 WARN_ON(!transaction);
789 if (is_handle_aborted(handle)) 786 if (is_handle_aborted(handle))
790 return -EROFS; 787 return -EROFS;
791 journal = transaction->t_journal; 788 journal = transaction->t_journal;
@@ -1051,7 +1048,6 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)
1051 int err; 1048 int err;
1052 1049
1053 jbd_debug(5, "journal_head %p\n", jh); 1050 jbd_debug(5, "journal_head %p\n", jh);
1054 WARN_ON(!transaction);
1055 err = -EROFS; 1051 err = -EROFS;
1056 if (is_handle_aborted(handle)) 1052 if (is_handle_aborted(handle))
1057 goto out; 1053 goto out;
@@ -1266,7 +1262,6 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh)
1266 struct journal_head *jh; 1262 struct journal_head *jh;
1267 int ret = 0; 1263 int ret = 0;
1268 1264
1269 WARN_ON(!transaction);
1270 if (is_handle_aborted(handle)) 1265 if (is_handle_aborted(handle))
1271 return -EROFS; 1266 return -EROFS;
1272 journal = transaction->t_journal; 1267 journal = transaction->t_journal;
@@ -1397,7 +1392,6 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
1397 int err = 0; 1392 int err = 0;
1398 int was_modified = 0; 1393 int was_modified = 0;
1399 1394
1400 WARN_ON(!transaction);
1401 if (is_handle_aborted(handle)) 1395 if (is_handle_aborted(handle))
1402 return -EROFS; 1396 return -EROFS;
1403 journal = transaction->t_journal; 1397 journal = transaction->t_journal;
@@ -1530,8 +1524,22 @@ int jbd2_journal_stop(handle_t *handle)
1530 tid_t tid; 1524 tid_t tid;
1531 pid_t pid; 1525 pid_t pid;
1532 1526
1533 if (!transaction) 1527 if (!transaction) {
1534 goto free_and_exit; 1528 /*
1529 * Handle is already detached from the transaction so
1530 * there is nothing to do other than decrease a refcount,
1531 * or free the handle if refcount drops to zero
1532 */
1533 if (--handle->h_ref > 0) {
1534 jbd_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1,
1535 handle->h_ref);
1536 return err;
1537 } else {
1538 if (handle->h_rsv_handle)
1539 jbd2_free_handle(handle->h_rsv_handle);
1540 goto free_and_exit;
1541 }
1542 }
1535 journal = transaction->t_journal; 1543 journal = transaction->t_journal;
1536 1544
1537 J_ASSERT(journal_current_handle() == handle); 1545 J_ASSERT(journal_current_handle() == handle);
@@ -2373,7 +2381,6 @@ int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode)
2373 transaction_t *transaction = handle->h_transaction; 2381 transaction_t *transaction = handle->h_transaction;
2374 journal_t *journal; 2382 journal_t *journal;
2375 2383
2376 WARN_ON(!transaction);
2377 if (is_handle_aborted(handle)) 2384 if (is_handle_aborted(handle))
2378 return -EROFS; 2385 return -EROFS;
2379 journal = transaction->t_journal; 2386 journal = transaction->t_journal;
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index f131fc23ffc4..fffca9517321 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -518,7 +518,14 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
518 if (!kn) 518 if (!kn)
519 goto err_out1; 519 goto err_out1;
520 520
521 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); 521 /*
522 * If the ino of the sysfs entry created for a kmem cache gets
523 * allocated from an ida layer, which is accounted to the memcg that
524 * owns the cache, the memcg will get pinned forever. So do not account
525 * ino ida allocations.
526 */
527 ret = ida_simple_get(&root->ino_ida, 1, 0,
528 GFP_KERNEL | __GFP_NOACCOUNT);
522 if (ret < 0) 529 if (ret < 0)
523 goto err_out2; 530 goto err_out2;
524 kn->ino = ret; 531 kn->ino = ret;
diff --git a/fs/namei.c b/fs/namei.c
index 4a8d998b7274..fe30d3be43a8 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1415,6 +1415,7 @@ static int lookup_fast(struct nameidata *nd,
1415 */ 1415 */
1416 if (nd->flags & LOOKUP_RCU) { 1416 if (nd->flags & LOOKUP_RCU) {
1417 unsigned seq; 1417 unsigned seq;
1418 bool negative;
1418 dentry = __d_lookup_rcu(parent, &nd->last, &seq); 1419 dentry = __d_lookup_rcu(parent, &nd->last, &seq);
1419 if (!dentry) 1420 if (!dentry)
1420 goto unlazy; 1421 goto unlazy;
@@ -1424,8 +1425,11 @@ static int lookup_fast(struct nameidata *nd,
1424 * the dentry name information from lookup. 1425 * the dentry name information from lookup.
1425 */ 1426 */
1426 *inode = dentry->d_inode; 1427 *inode = dentry->d_inode;
1428 negative = d_is_negative(dentry);
1427 if (read_seqcount_retry(&dentry->d_seq, seq)) 1429 if (read_seqcount_retry(&dentry->d_seq, seq))
1428 return -ECHILD; 1430 return -ECHILD;
1431 if (negative)
1432 return -ENOENT;
1429 1433
1430 /* 1434 /*
1431 * This sequence count validates that the parent had no 1435 * This sequence count validates that the parent had no
@@ -1472,6 +1476,10 @@ unlazy:
1472 goto need_lookup; 1476 goto need_lookup;
1473 } 1477 }
1474 1478
1479 if (unlikely(d_is_negative(dentry))) {
1480 dput(dentry);
1481 return -ENOENT;
1482 }
1475 path->mnt = mnt; 1483 path->mnt = mnt;
1476 path->dentry = dentry; 1484 path->dentry = dentry;
1477 err = follow_managed(path, nd->flags); 1485 err = follow_managed(path, nd->flags);
@@ -1583,10 +1591,10 @@ static inline int walk_component(struct nameidata *nd, struct path *path,
1583 goto out_err; 1591 goto out_err;
1584 1592
1585 inode = path->dentry->d_inode; 1593 inode = path->dentry->d_inode;
1594 err = -ENOENT;
1595 if (d_is_negative(path->dentry))
1596 goto out_path_put;
1586 } 1597 }
1587 err = -ENOENT;
1588 if (d_is_negative(path->dentry))
1589 goto out_path_put;
1590 1598
1591 if (should_follow_link(path->dentry, follow)) { 1599 if (should_follow_link(path->dentry, follow)) {
1592 if (nd->flags & LOOKUP_RCU) { 1600 if (nd->flags & LOOKUP_RCU) {
@@ -3036,14 +3044,13 @@ retry_lookup:
3036 3044
3037 BUG_ON(nd->flags & LOOKUP_RCU); 3045 BUG_ON(nd->flags & LOOKUP_RCU);
3038 inode = path->dentry->d_inode; 3046 inode = path->dentry->d_inode;
3039finish_lookup:
3040 /* we _can_ be in RCU mode here */
3041 error = -ENOENT; 3047 error = -ENOENT;
3042 if (d_is_negative(path->dentry)) { 3048 if (d_is_negative(path->dentry)) {
3043 path_to_nameidata(path, nd); 3049 path_to_nameidata(path, nd);
3044 goto out; 3050 goto out;
3045 } 3051 }
3046 3052finish_lookup:
3053 /* we _can_ be in RCU mode here */
3047 if (should_follow_link(path->dentry, !symlink_ok)) { 3054 if (should_follow_link(path->dentry, !symlink_ok)) {
3048 if (nd->flags & LOOKUP_RCU) { 3055 if (nd->flags & LOOKUP_RCU) {
3049 if (unlikely(nd->path.mnt != path->mnt || 3056 if (unlikely(nd->path.mnt != path->mnt ||
@@ -3226,7 +3233,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
3226 3233
3227 if (unlikely(file->f_flags & __O_TMPFILE)) { 3234 if (unlikely(file->f_flags & __O_TMPFILE)) {
3228 error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened); 3235 error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened);
3229 goto out; 3236 goto out2;
3230 } 3237 }
3231 3238
3232 error = path_init(dfd, pathname, flags, nd); 3239 error = path_init(dfd, pathname, flags, nd);
@@ -3256,6 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
3256 } 3263 }
3257out: 3264out:
3258 path_cleanup(nd); 3265 path_cleanup(nd);
3266out2:
3259 if (!(opened & FILE_OPENED)) { 3267 if (!(opened & FILE_OPENED)) {
3260 BUG_ON(!error); 3268 BUG_ON(!error);
3261 put_filp(file); 3269 put_filp(file);
diff --git a/fs/namespace.c b/fs/namespace.c
index 1f4f9dac6e5a..1b9e11167bae 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3179,6 +3179,12 @@ bool fs_fully_visible(struct file_system_type *type)
3179 if (mnt->mnt.mnt_sb->s_type != type) 3179 if (mnt->mnt.mnt_sb->s_type != type)
3180 continue; 3180 continue;
3181 3181
3182 /* This mount is not fully visible if it's root directory
3183 * is not the root directory of the filesystem.
3184 */
3185 if (mnt->mnt.mnt_root != mnt->mnt.mnt_sb->s_root)
3186 continue;
3187
3182 /* This mount is not fully visible if there are any child mounts 3188 /* This mount is not fully visible if there are any child mounts
3183 * that cover anything except for empty directories. 3189 * that cover anything except for empty directories.
3184 */ 3190 */
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 45b35b9b1e36..55e1e3af23a3 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -38,6 +38,7 @@
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/errno.h> 40#include <linux/errno.h>
41#include <linux/file.h>
41#include <linux/string.h> 42#include <linux/string.h>
42#include <linux/ratelimit.h> 43#include <linux/ratelimit.h>
43#include <linux/printk.h> 44#include <linux/printk.h>
@@ -5604,6 +5605,7 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
5604 p->server = server; 5605 p->server = server;
5605 atomic_inc(&lsp->ls_count); 5606 atomic_inc(&lsp->ls_count);
5606 p->ctx = get_nfs_open_context(ctx); 5607 p->ctx = get_nfs_open_context(ctx);
5608 get_file(fl->fl_file);
5607 memcpy(&p->fl, fl, sizeof(p->fl)); 5609 memcpy(&p->fl, fl, sizeof(p->fl));
5608 return p; 5610 return p;
5609out_free_seqid: 5611out_free_seqid:
@@ -5716,6 +5718,7 @@ static void nfs4_lock_release(void *calldata)
5716 nfs_free_seqid(data->arg.lock_seqid); 5718 nfs_free_seqid(data->arg.lock_seqid);
5717 nfs4_put_lock_state(data->lsp); 5719 nfs4_put_lock_state(data->lsp);
5718 put_nfs_open_context(data->ctx); 5720 put_nfs_open_context(data->ctx);
5721 fput(data->fl.fl_file);
5719 kfree(data); 5722 kfree(data);
5720 dprintk("%s: done!\n", __func__); 5723 dprintk("%s: done!\n", __func__);
5721} 5724}
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index d12a4be613a5..dfc19f1575a1 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1845,12 +1845,15 @@ int nfs_wb_all(struct inode *inode)
1845 trace_nfs_writeback_inode_enter(inode); 1845 trace_nfs_writeback_inode_enter(inode);
1846 1846
1847 ret = filemap_write_and_wait(inode->i_mapping); 1847 ret = filemap_write_and_wait(inode->i_mapping);
1848 if (!ret) { 1848 if (ret)
1849 ret = nfs_commit_inode(inode, FLUSH_SYNC); 1849 goto out;
1850 if (!ret) 1850 ret = nfs_commit_inode(inode, FLUSH_SYNC);
1851 pnfs_sync_inode(inode, true); 1851 if (ret < 0)
1852 } 1852 goto out;
1853 pnfs_sync_inode(inode, true);
1854 ret = 0;
1853 1855
1856out:
1854 trace_nfs_writeback_inode_exit(inode, ret); 1857 trace_nfs_writeback_inode_exit(inode, ret);
1855 return ret; 1858 return ret;
1856} 1859}
diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
index 03d647bf195d..cdefaa331a07 100644
--- a/fs/nfsd/blocklayout.c
+++ b/fs/nfsd/blocklayout.c
@@ -181,6 +181,17 @@ nfsd4_block_proc_layoutcommit(struct inode *inode,
181} 181}
182 182
183const struct nfsd4_layout_ops bl_layout_ops = { 183const struct nfsd4_layout_ops bl_layout_ops = {
184 /*
185 * Pretend that we send notification to the client. This is a blatant
186 * lie to force recent Linux clients to cache our device IDs.
187 * We rarely ever change the device ID, so the harm of leaking deviceids
188 * for a while isn't too bad. Unfortunately RFC5661 is a complete mess
189 * in this regard, but I filed errata 4119 for this a while ago, and
190 * hopefully the Linux client will eventually start caching deviceids
191 * without this again.
192 */
193 .notify_types =
194 NOTIFY_DEVICEID4_DELETE | NOTIFY_DEVICEID4_CHANGE,
184 .proc_getdeviceinfo = nfsd4_block_proc_getdeviceinfo, 195 .proc_getdeviceinfo = nfsd4_block_proc_getdeviceinfo,
185 .encode_getdeviceinfo = nfsd4_block_encode_getdeviceinfo, 196 .encode_getdeviceinfo = nfsd4_block_encode_getdeviceinfo,
186 .proc_layoutget = nfsd4_block_proc_layoutget, 197 .proc_layoutget = nfsd4_block_proc_layoutget,
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 58277859a467..5694cfb7a47b 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -224,7 +224,7 @@ static int nfs_cb_stat_to_errno(int status)
224} 224}
225 225
226static int decode_cb_op_status(struct xdr_stream *xdr, enum nfs_opnum4 expected, 226static int decode_cb_op_status(struct xdr_stream *xdr, enum nfs_opnum4 expected,
227 enum nfsstat4 *status) 227 int *status)
228{ 228{
229 __be32 *p; 229 __be32 *p;
230 u32 op; 230 u32 op;
@@ -235,7 +235,7 @@ static int decode_cb_op_status(struct xdr_stream *xdr, enum nfs_opnum4 expected,
235 op = be32_to_cpup(p++); 235 op = be32_to_cpup(p++);
236 if (unlikely(op != expected)) 236 if (unlikely(op != expected))
237 goto out_unexpected; 237 goto out_unexpected;
238 *status = be32_to_cpup(p); 238 *status = nfs_cb_stat_to_errno(be32_to_cpup(p));
239 return 0; 239 return 0;
240out_overflow: 240out_overflow:
241 print_overflow_msg(__func__, xdr); 241 print_overflow_msg(__func__, xdr);
@@ -446,22 +446,16 @@ out_overflow:
446static int decode_cb_sequence4res(struct xdr_stream *xdr, 446static int decode_cb_sequence4res(struct xdr_stream *xdr,
447 struct nfsd4_callback *cb) 447 struct nfsd4_callback *cb)
448{ 448{
449 enum nfsstat4 nfserr;
450 int status; 449 int status;
451 450
452 if (cb->cb_minorversion == 0) 451 if (cb->cb_minorversion == 0)
453 return 0; 452 return 0;
454 453
455 status = decode_cb_op_status(xdr, OP_CB_SEQUENCE, &nfserr); 454 status = decode_cb_op_status(xdr, OP_CB_SEQUENCE, &cb->cb_status);
456 if (unlikely(status)) 455 if (unlikely(status || cb->cb_status))
457 goto out; 456 return status;
458 if (unlikely(nfserr != NFS4_OK)) 457
459 goto out_default; 458 return decode_cb_sequence4resok(xdr, cb);
460 status = decode_cb_sequence4resok(xdr, cb);
461out:
462 return status;
463out_default:
464 return nfs_cb_stat_to_errno(nfserr);
465} 459}
466 460
467/* 461/*
@@ -524,26 +518,19 @@ static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp,
524 struct nfsd4_callback *cb) 518 struct nfsd4_callback *cb)
525{ 519{
526 struct nfs4_cb_compound_hdr hdr; 520 struct nfs4_cb_compound_hdr hdr;
527 enum nfsstat4 nfserr;
528 int status; 521 int status;
529 522
530 status = decode_cb_compound4res(xdr, &hdr); 523 status = decode_cb_compound4res(xdr, &hdr);
531 if (unlikely(status)) 524 if (unlikely(status))
532 goto out; 525 return status;
533 526
534 if (cb != NULL) { 527 if (cb != NULL) {
535 status = decode_cb_sequence4res(xdr, cb); 528 status = decode_cb_sequence4res(xdr, cb);
536 if (unlikely(status)) 529 if (unlikely(status || cb->cb_status))
537 goto out; 530 return status;
538 } 531 }
539 532
540 status = decode_cb_op_status(xdr, OP_CB_RECALL, &nfserr); 533 return decode_cb_op_status(xdr, OP_CB_RECALL, &cb->cb_status);
541 if (unlikely(status))
542 goto out;
543 if (unlikely(nfserr != NFS4_OK))
544 status = nfs_cb_stat_to_errno(nfserr);
545out:
546 return status;
547} 534}
548 535
549#ifdef CONFIG_NFSD_PNFS 536#ifdef CONFIG_NFSD_PNFS
@@ -621,24 +608,18 @@ static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp,
621 struct nfsd4_callback *cb) 608 struct nfsd4_callback *cb)
622{ 609{
623 struct nfs4_cb_compound_hdr hdr; 610 struct nfs4_cb_compound_hdr hdr;
624 enum nfsstat4 nfserr;
625 int status; 611 int status;
626 612
627 status = decode_cb_compound4res(xdr, &hdr); 613 status = decode_cb_compound4res(xdr, &hdr);
628 if (unlikely(status)) 614 if (unlikely(status))
629 goto out; 615 return status;
616
630 if (cb) { 617 if (cb) {
631 status = decode_cb_sequence4res(xdr, cb); 618 status = decode_cb_sequence4res(xdr, cb);
632 if (unlikely(status)) 619 if (unlikely(status || cb->cb_status))
633 goto out; 620 return status;
634 } 621 }
635 status = decode_cb_op_status(xdr, OP_CB_LAYOUTRECALL, &nfserr); 622 return decode_cb_op_status(xdr, OP_CB_LAYOUTRECALL, &cb->cb_status);
636 if (unlikely(status))
637 goto out;
638 if (unlikely(nfserr != NFS4_OK))
639 status = nfs_cb_stat_to_errno(nfserr);
640out:
641 return status;
642} 623}
643#endif /* CONFIG_NFSD_PNFS */ 624#endif /* CONFIG_NFSD_PNFS */
644 625
@@ -898,13 +879,6 @@ static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata)
898 if (!nfsd41_cb_get_slot(clp, task)) 879 if (!nfsd41_cb_get_slot(clp, task))
899 return; 880 return;
900 } 881 }
901 spin_lock(&clp->cl_lock);
902 if (list_empty(&cb->cb_per_client)) {
903 /* This is the first call, not a restart */
904 cb->cb_done = false;
905 list_add(&cb->cb_per_client, &clp->cl_callbacks);
906 }
907 spin_unlock(&clp->cl_lock);
908 rpc_call_start(task); 882 rpc_call_start(task);
909} 883}
910 884
@@ -918,22 +892,33 @@ static void nfsd4_cb_done(struct rpc_task *task, void *calldata)
918 892
919 if (clp->cl_minorversion) { 893 if (clp->cl_minorversion) {
920 /* No need for lock, access serialized in nfsd4_cb_prepare */ 894 /* No need for lock, access serialized in nfsd4_cb_prepare */
921 ++clp->cl_cb_session->se_cb_seq_nr; 895 if (!task->tk_status)
896 ++clp->cl_cb_session->se_cb_seq_nr;
922 clear_bit(0, &clp->cl_cb_slot_busy); 897 clear_bit(0, &clp->cl_cb_slot_busy);
923 rpc_wake_up_next(&clp->cl_cb_waitq); 898 rpc_wake_up_next(&clp->cl_cb_waitq);
924 dprintk("%s: freed slot, new seqid=%d\n", __func__, 899 dprintk("%s: freed slot, new seqid=%d\n", __func__,
925 clp->cl_cb_session->se_cb_seq_nr); 900 clp->cl_cb_session->se_cb_seq_nr);
926 } 901 }
927 902
928 if (clp->cl_cb_client != task->tk_client) { 903 /*
929 /* We're shutting down or changing cl_cb_client; leave 904 * If the backchannel connection was shut down while this
930 * it to nfsd4_process_cb_update to restart the call if 905 * task was queued, we need to resubmit it after setting up
931 * necessary. */ 906 * a new backchannel connection.
907 *
908 * Note that if we lost our callback connection permanently
909 * the submission code will error out, so we don't need to
910 * handle that case here.
911 */
912 if (task->tk_flags & RPC_TASK_KILLED) {
913 task->tk_status = 0;
914 cb->cb_need_restart = true;
932 return; 915 return;
933 } 916 }
934 917
935 if (cb->cb_done) 918 if (cb->cb_status) {
936 return; 919 WARN_ON_ONCE(task->tk_status);
920 task->tk_status = cb->cb_status;
921 }
937 922
938 switch (cb->cb_ops->done(cb, task)) { 923 switch (cb->cb_ops->done(cb, task)) {
939 case 0: 924 case 0:
@@ -949,21 +934,17 @@ static void nfsd4_cb_done(struct rpc_task *task, void *calldata)
949 default: 934 default:
950 BUG(); 935 BUG();
951 } 936 }
952 cb->cb_done = true;
953} 937}
954 938
955static void nfsd4_cb_release(void *calldata) 939static void nfsd4_cb_release(void *calldata)
956{ 940{
957 struct nfsd4_callback *cb = calldata; 941 struct nfsd4_callback *cb = calldata;
958 struct nfs4_client *clp = cb->cb_clp;
959
960 if (cb->cb_done) {
961 spin_lock(&clp->cl_lock);
962 list_del(&cb->cb_per_client);
963 spin_unlock(&clp->cl_lock);
964 942
943 if (cb->cb_need_restart)
944 nfsd4_run_cb(cb);
945 else
965 cb->cb_ops->release(cb); 946 cb->cb_ops->release(cb);
966 } 947
967} 948}
968 949
969static const struct rpc_call_ops nfsd4_cb_ops = { 950static const struct rpc_call_ops nfsd4_cb_ops = {
@@ -1058,9 +1039,6 @@ static void nfsd4_process_cb_update(struct nfsd4_callback *cb)
1058 nfsd4_mark_cb_down(clp, err); 1039 nfsd4_mark_cb_down(clp, err);
1059 return; 1040 return;
1060 } 1041 }
1061 /* Yay, the callback channel's back! Restart any callbacks: */
1062 list_for_each_entry(cb, &clp->cl_callbacks, cb_per_client)
1063 queue_work(callback_wq, &cb->cb_work);
1064} 1042}
1065 1043
1066static void 1044static void
@@ -1071,8 +1049,12 @@ nfsd4_run_cb_work(struct work_struct *work)
1071 struct nfs4_client *clp = cb->cb_clp; 1049 struct nfs4_client *clp = cb->cb_clp;
1072 struct rpc_clnt *clnt; 1050 struct rpc_clnt *clnt;
1073 1051
1074 if (cb->cb_ops && cb->cb_ops->prepare) 1052 if (cb->cb_need_restart) {
1075 cb->cb_ops->prepare(cb); 1053 cb->cb_need_restart = false;
1054 } else {
1055 if (cb->cb_ops && cb->cb_ops->prepare)
1056 cb->cb_ops->prepare(cb);
1057 }
1076 1058
1077 if (clp->cl_flags & NFSD4_CLIENT_CB_FLAG_MASK) 1059 if (clp->cl_flags & NFSD4_CLIENT_CB_FLAG_MASK)
1078 nfsd4_process_cb_update(cb); 1060 nfsd4_process_cb_update(cb);
@@ -1084,6 +1066,15 @@ nfsd4_run_cb_work(struct work_struct *work)
1084 cb->cb_ops->release(cb); 1066 cb->cb_ops->release(cb);
1085 return; 1067 return;
1086 } 1068 }
1069
1070 /*
1071 * Don't send probe messages for 4.1 or later.
1072 */
1073 if (!cb->cb_ops && clp->cl_minorversion) {
1074 clp->cl_cb_state = NFSD4_CB_UP;
1075 return;
1076 }
1077
1087 cb->cb_msg.rpc_cred = clp->cl_cb_cred; 1078 cb->cb_msg.rpc_cred = clp->cl_cb_cred;
1088 rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN, 1079 rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
1089 cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb); 1080 cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb);
@@ -1098,8 +1089,8 @@ void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
1098 cb->cb_msg.rpc_resp = cb; 1089 cb->cb_msg.rpc_resp = cb;
1099 cb->cb_ops = ops; 1090 cb->cb_ops = ops;
1100 INIT_WORK(&cb->cb_work, nfsd4_run_cb_work); 1091 INIT_WORK(&cb->cb_work, nfsd4_run_cb_work);
1101 INIT_LIST_HEAD(&cb->cb_per_client); 1092 cb->cb_status = 0;
1102 cb->cb_done = true; 1093 cb->cb_need_restart = false;
1103} 1094}
1104 1095
1105void nfsd4_run_cb(struct nfsd4_callback *cb) 1096void nfsd4_run_cb(struct nfsd4_callback *cb)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 38f2d7abe3a7..039f9c8a95e8 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -94,6 +94,7 @@ static struct kmem_cache *lockowner_slab;
94static struct kmem_cache *file_slab; 94static struct kmem_cache *file_slab;
95static struct kmem_cache *stateid_slab; 95static struct kmem_cache *stateid_slab;
96static struct kmem_cache *deleg_slab; 96static struct kmem_cache *deleg_slab;
97static struct kmem_cache *odstate_slab;
97 98
98static void free_session(struct nfsd4_session *); 99static void free_session(struct nfsd4_session *);
99 100
@@ -281,6 +282,7 @@ put_nfs4_file(struct nfs4_file *fi)
281 if (atomic_dec_and_lock(&fi->fi_ref, &state_lock)) { 282 if (atomic_dec_and_lock(&fi->fi_ref, &state_lock)) {
282 hlist_del_rcu(&fi->fi_hash); 283 hlist_del_rcu(&fi->fi_hash);
283 spin_unlock(&state_lock); 284 spin_unlock(&state_lock);
285 WARN_ON_ONCE(!list_empty(&fi->fi_clnt_odstate));
284 WARN_ON_ONCE(!list_empty(&fi->fi_delegations)); 286 WARN_ON_ONCE(!list_empty(&fi->fi_delegations));
285 call_rcu(&fi->fi_rcu, nfsd4_free_file_rcu); 287 call_rcu(&fi->fi_rcu, nfsd4_free_file_rcu);
286 } 288 }
@@ -471,6 +473,86 @@ static void nfs4_file_put_access(struct nfs4_file *fp, u32 access)
471 __nfs4_file_put_access(fp, O_RDONLY); 473 __nfs4_file_put_access(fp, O_RDONLY);
472} 474}
473 475
476/*
477 * Allocate a new open/delegation state counter. This is needed for
478 * pNFS for proper return on close semantics.
479 *
480 * Note that we only allocate it for pNFS-enabled exports, otherwise
481 * all pointers to struct nfs4_clnt_odstate are always NULL.
482 */
483static struct nfs4_clnt_odstate *
484alloc_clnt_odstate(struct nfs4_client *clp)
485{
486 struct nfs4_clnt_odstate *co;
487
488 co = kmem_cache_zalloc(odstate_slab, GFP_KERNEL);
489 if (co) {
490 co->co_client = clp;
491 atomic_set(&co->co_odcount, 1);
492 }
493 return co;
494}
495
496static void
497hash_clnt_odstate_locked(struct nfs4_clnt_odstate *co)
498{
499 struct nfs4_file *fp = co->co_file;
500
501 lockdep_assert_held(&fp->fi_lock);
502 list_add(&co->co_perfile, &fp->fi_clnt_odstate);
503}
504
505static inline void
506get_clnt_odstate(struct nfs4_clnt_odstate *co)
507{
508 if (co)
509 atomic_inc(&co->co_odcount);
510}
511
512static void
513put_clnt_odstate(struct nfs4_clnt_odstate *co)
514{
515 struct nfs4_file *fp;
516
517 if (!co)
518 return;
519
520 fp = co->co_file;
521 if (atomic_dec_and_lock(&co->co_odcount, &fp->fi_lock)) {
522 list_del(&co->co_perfile);
523 spin_unlock(&fp->fi_lock);
524
525 nfsd4_return_all_file_layouts(co->co_client, fp);
526 kmem_cache_free(odstate_slab, co);
527 }
528}
529
530static struct nfs4_clnt_odstate *
531find_or_hash_clnt_odstate(struct nfs4_file *fp, struct nfs4_clnt_odstate *new)
532{
533 struct nfs4_clnt_odstate *co;
534 struct nfs4_client *cl;
535
536 if (!new)
537 return NULL;
538
539 cl = new->co_client;
540
541 spin_lock(&fp->fi_lock);
542 list_for_each_entry(co, &fp->fi_clnt_odstate, co_perfile) {
543 if (co->co_client == cl) {
544 get_clnt_odstate(co);
545 goto out;
546 }
547 }
548 co = new;
549 co->co_file = fp;
550 hash_clnt_odstate_locked(new);
551out:
552 spin_unlock(&fp->fi_lock);
553 return co;
554}
555
474struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, 556struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl,
475 struct kmem_cache *slab) 557 struct kmem_cache *slab)
476{ 558{
@@ -606,7 +688,8 @@ static void block_delegations(struct knfsd_fh *fh)
606} 688}
607 689
608static struct nfs4_delegation * 690static struct nfs4_delegation *
609alloc_init_deleg(struct nfs4_client *clp, struct svc_fh *current_fh) 691alloc_init_deleg(struct nfs4_client *clp, struct svc_fh *current_fh,
692 struct nfs4_clnt_odstate *odstate)
610{ 693{
611 struct nfs4_delegation *dp; 694 struct nfs4_delegation *dp;
612 long n; 695 long n;
@@ -631,6 +714,8 @@ alloc_init_deleg(struct nfs4_client *clp, struct svc_fh *current_fh)
631 INIT_LIST_HEAD(&dp->dl_perfile); 714 INIT_LIST_HEAD(&dp->dl_perfile);
632 INIT_LIST_HEAD(&dp->dl_perclnt); 715 INIT_LIST_HEAD(&dp->dl_perclnt);
633 INIT_LIST_HEAD(&dp->dl_recall_lru); 716 INIT_LIST_HEAD(&dp->dl_recall_lru);
717 dp->dl_clnt_odstate = odstate;
718 get_clnt_odstate(odstate);
634 dp->dl_type = NFS4_OPEN_DELEGATE_READ; 719 dp->dl_type = NFS4_OPEN_DELEGATE_READ;
635 dp->dl_retries = 1; 720 dp->dl_retries = 1;
636 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, 721 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client,
@@ -714,6 +799,7 @@ static void destroy_delegation(struct nfs4_delegation *dp)
714 spin_lock(&state_lock); 799 spin_lock(&state_lock);
715 unhash_delegation_locked(dp); 800 unhash_delegation_locked(dp);
716 spin_unlock(&state_lock); 801 spin_unlock(&state_lock);
802 put_clnt_odstate(dp->dl_clnt_odstate);
717 nfs4_put_deleg_lease(dp->dl_stid.sc_file); 803 nfs4_put_deleg_lease(dp->dl_stid.sc_file);
718 nfs4_put_stid(&dp->dl_stid); 804 nfs4_put_stid(&dp->dl_stid);
719} 805}
@@ -724,6 +810,7 @@ static void revoke_delegation(struct nfs4_delegation *dp)
724 810
725 WARN_ON(!list_empty(&dp->dl_recall_lru)); 811 WARN_ON(!list_empty(&dp->dl_recall_lru));
726 812
813 put_clnt_odstate(dp->dl_clnt_odstate);
727 nfs4_put_deleg_lease(dp->dl_stid.sc_file); 814 nfs4_put_deleg_lease(dp->dl_stid.sc_file);
728 815
729 if (clp->cl_minorversion == 0) 816 if (clp->cl_minorversion == 0)
@@ -933,6 +1020,7 @@ static void nfs4_free_ol_stateid(struct nfs4_stid *stid)
933{ 1020{
934 struct nfs4_ol_stateid *stp = openlockstateid(stid); 1021 struct nfs4_ol_stateid *stp = openlockstateid(stid);
935 1022
1023 put_clnt_odstate(stp->st_clnt_odstate);
936 release_all_access(stp); 1024 release_all_access(stp);
937 if (stp->st_stateowner) 1025 if (stp->st_stateowner)
938 nfs4_put_stateowner(stp->st_stateowner); 1026 nfs4_put_stateowner(stp->st_stateowner);
@@ -1538,7 +1626,6 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
1538 INIT_LIST_HEAD(&clp->cl_openowners); 1626 INIT_LIST_HEAD(&clp->cl_openowners);
1539 INIT_LIST_HEAD(&clp->cl_delegations); 1627 INIT_LIST_HEAD(&clp->cl_delegations);
1540 INIT_LIST_HEAD(&clp->cl_lru); 1628 INIT_LIST_HEAD(&clp->cl_lru);
1541 INIT_LIST_HEAD(&clp->cl_callbacks);
1542 INIT_LIST_HEAD(&clp->cl_revoked); 1629 INIT_LIST_HEAD(&clp->cl_revoked);
1543#ifdef CONFIG_NFSD_PNFS 1630#ifdef CONFIG_NFSD_PNFS
1544 INIT_LIST_HEAD(&clp->cl_lo_states); 1631 INIT_LIST_HEAD(&clp->cl_lo_states);
@@ -1634,6 +1721,7 @@ __destroy_client(struct nfs4_client *clp)
1634 while (!list_empty(&reaplist)) { 1721 while (!list_empty(&reaplist)) {
1635 dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru); 1722 dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru);
1636 list_del_init(&dp->dl_recall_lru); 1723 list_del_init(&dp->dl_recall_lru);
1724 put_clnt_odstate(dp->dl_clnt_odstate);
1637 nfs4_put_deleg_lease(dp->dl_stid.sc_file); 1725 nfs4_put_deleg_lease(dp->dl_stid.sc_file);
1638 nfs4_put_stid(&dp->dl_stid); 1726 nfs4_put_stid(&dp->dl_stid);
1639 } 1727 }
@@ -3057,6 +3145,7 @@ static void nfsd4_init_file(struct knfsd_fh *fh, unsigned int hashval,
3057 spin_lock_init(&fp->fi_lock); 3145 spin_lock_init(&fp->fi_lock);
3058 INIT_LIST_HEAD(&fp->fi_stateids); 3146 INIT_LIST_HEAD(&fp->fi_stateids);
3059 INIT_LIST_HEAD(&fp->fi_delegations); 3147 INIT_LIST_HEAD(&fp->fi_delegations);
3148 INIT_LIST_HEAD(&fp->fi_clnt_odstate);
3060 fh_copy_shallow(&fp->fi_fhandle, fh); 3149 fh_copy_shallow(&fp->fi_fhandle, fh);
3061 fp->fi_deleg_file = NULL; 3150 fp->fi_deleg_file = NULL;
3062 fp->fi_had_conflict = false; 3151 fp->fi_had_conflict = false;
@@ -3073,6 +3162,7 @@ static void nfsd4_init_file(struct knfsd_fh *fh, unsigned int hashval,
3073void 3162void
3074nfsd4_free_slabs(void) 3163nfsd4_free_slabs(void)
3075{ 3164{
3165 kmem_cache_destroy(odstate_slab);
3076 kmem_cache_destroy(openowner_slab); 3166 kmem_cache_destroy(openowner_slab);
3077 kmem_cache_destroy(lockowner_slab); 3167 kmem_cache_destroy(lockowner_slab);
3078 kmem_cache_destroy(file_slab); 3168 kmem_cache_destroy(file_slab);
@@ -3103,8 +3193,14 @@ nfsd4_init_slabs(void)
3103 sizeof(struct nfs4_delegation), 0, 0, NULL); 3193 sizeof(struct nfs4_delegation), 0, 0, NULL);
3104 if (deleg_slab == NULL) 3194 if (deleg_slab == NULL)
3105 goto out_free_stateid_slab; 3195 goto out_free_stateid_slab;
3196 odstate_slab = kmem_cache_create("nfsd4_odstate",
3197 sizeof(struct nfs4_clnt_odstate), 0, 0, NULL);
3198 if (odstate_slab == NULL)
3199 goto out_free_deleg_slab;
3106 return 0; 3200 return 0;
3107 3201
3202out_free_deleg_slab:
3203 kmem_cache_destroy(deleg_slab);
3108out_free_stateid_slab: 3204out_free_stateid_slab:
3109 kmem_cache_destroy(stateid_slab); 3205 kmem_cache_destroy(stateid_slab);
3110out_free_file_slab: 3206out_free_file_slab:
@@ -3581,6 +3677,14 @@ alloc_stateid:
3581 open->op_stp = nfs4_alloc_open_stateid(clp); 3677 open->op_stp = nfs4_alloc_open_stateid(clp);
3582 if (!open->op_stp) 3678 if (!open->op_stp)
3583 return nfserr_jukebox; 3679 return nfserr_jukebox;
3680
3681 if (nfsd4_has_session(cstate) &&
3682 (cstate->current_fh.fh_export->ex_flags & NFSEXP_PNFS)) {
3683 open->op_odstate = alloc_clnt_odstate(clp);
3684 if (!open->op_odstate)
3685 return nfserr_jukebox;
3686 }
3687
3584 return nfs_ok; 3688 return nfs_ok;
3585} 3689}
3586 3690
@@ -3869,7 +3973,7 @@ out_fput:
3869 3973
3870static struct nfs4_delegation * 3974static struct nfs4_delegation *
3871nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, 3975nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh,
3872 struct nfs4_file *fp) 3976 struct nfs4_file *fp, struct nfs4_clnt_odstate *odstate)
3873{ 3977{
3874 int status; 3978 int status;
3875 struct nfs4_delegation *dp; 3979 struct nfs4_delegation *dp;
@@ -3877,7 +3981,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh,
3877 if (fp->fi_had_conflict) 3981 if (fp->fi_had_conflict)
3878 return ERR_PTR(-EAGAIN); 3982 return ERR_PTR(-EAGAIN);
3879 3983
3880 dp = alloc_init_deleg(clp, fh); 3984 dp = alloc_init_deleg(clp, fh, odstate);
3881 if (!dp) 3985 if (!dp)
3882 return ERR_PTR(-ENOMEM); 3986 return ERR_PTR(-ENOMEM);
3883 3987
@@ -3903,6 +4007,7 @@ out_unlock:
3903 spin_unlock(&state_lock); 4007 spin_unlock(&state_lock);
3904out: 4008out:
3905 if (status) { 4009 if (status) {
4010 put_clnt_odstate(dp->dl_clnt_odstate);
3906 nfs4_put_stid(&dp->dl_stid); 4011 nfs4_put_stid(&dp->dl_stid);
3907 return ERR_PTR(status); 4012 return ERR_PTR(status);
3908 } 4013 }
@@ -3980,7 +4085,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open,
3980 default: 4085 default:
3981 goto out_no_deleg; 4086 goto out_no_deleg;
3982 } 4087 }
3983 dp = nfs4_set_delegation(clp, fh, stp->st_stid.sc_file); 4088 dp = nfs4_set_delegation(clp, fh, stp->st_stid.sc_file, stp->st_clnt_odstate);
3984 if (IS_ERR(dp)) 4089 if (IS_ERR(dp))
3985 goto out_no_deleg; 4090 goto out_no_deleg;
3986 4091
@@ -4069,6 +4174,11 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
4069 release_open_stateid(stp); 4174 release_open_stateid(stp);
4070 goto out; 4175 goto out;
4071 } 4176 }
4177
4178 stp->st_clnt_odstate = find_or_hash_clnt_odstate(fp,
4179 open->op_odstate);
4180 if (stp->st_clnt_odstate == open->op_odstate)
4181 open->op_odstate = NULL;
4072 } 4182 }
4073 update_stateid(&stp->st_stid.sc_stateid); 4183 update_stateid(&stp->st_stid.sc_stateid);
4074 memcpy(&open->op_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t)); 4184 memcpy(&open->op_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
@@ -4129,6 +4239,8 @@ void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
4129 kmem_cache_free(file_slab, open->op_file); 4239 kmem_cache_free(file_slab, open->op_file);
4130 if (open->op_stp) 4240 if (open->op_stp)
4131 nfs4_put_stid(&open->op_stp->st_stid); 4241 nfs4_put_stid(&open->op_stp->st_stid);
4242 if (open->op_odstate)
4243 kmem_cache_free(odstate_slab, open->op_odstate);
4132} 4244}
4133 4245
4134__be32 4246__be32
@@ -4385,10 +4497,17 @@ static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_s
4385 return nfserr_old_stateid; 4497 return nfserr_old_stateid;
4386} 4498}
4387 4499
4500static __be32 nfsd4_check_openowner_confirmed(struct nfs4_ol_stateid *ols)
4501{
4502 if (ols->st_stateowner->so_is_open_owner &&
4503 !(openowner(ols->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED))
4504 return nfserr_bad_stateid;
4505 return nfs_ok;
4506}
4507
4388static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) 4508static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
4389{ 4509{
4390 struct nfs4_stid *s; 4510 struct nfs4_stid *s;
4391 struct nfs4_ol_stateid *ols;
4392 __be32 status = nfserr_bad_stateid; 4511 __be32 status = nfserr_bad_stateid;
4393 4512
4394 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) 4513 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
@@ -4418,13 +4537,7 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
4418 break; 4537 break;
4419 case NFS4_OPEN_STID: 4538 case NFS4_OPEN_STID:
4420 case NFS4_LOCK_STID: 4539 case NFS4_LOCK_STID:
4421 ols = openlockstateid(s); 4540 status = nfsd4_check_openowner_confirmed(openlockstateid(s));
4422 if (ols->st_stateowner->so_is_open_owner
4423 && !(openowner(ols->st_stateowner)->oo_flags
4424 & NFS4_OO_CONFIRMED))
4425 status = nfserr_bad_stateid;
4426 else
4427 status = nfs_ok;
4428 break; 4541 break;
4429 default: 4542 default:
4430 printk("unknown stateid type %x\n", s->sc_type); 4543 printk("unknown stateid type %x\n", s->sc_type);
@@ -4516,8 +4629,8 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
4516 status = nfs4_check_fh(current_fh, stp); 4629 status = nfs4_check_fh(current_fh, stp);
4517 if (status) 4630 if (status)
4518 goto out; 4631 goto out;
4519 if (stp->st_stateowner->so_is_open_owner 4632 status = nfsd4_check_openowner_confirmed(stp);
4520 && !(openowner(stp->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED)) 4633 if (status)
4521 goto out; 4634 goto out;
4522 status = nfs4_check_openmode(stp, flags); 4635 status = nfs4_check_openmode(stp, flags);
4523 if (status) 4636 if (status)
@@ -4852,9 +4965,6 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4852 update_stateid(&stp->st_stid.sc_stateid); 4965 update_stateid(&stp->st_stid.sc_stateid);
4853 memcpy(&close->cl_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t)); 4966 memcpy(&close->cl_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
4854 4967
4855 nfsd4_return_all_file_layouts(stp->st_stateowner->so_client,
4856 stp->st_stid.sc_file);
4857
4858 nfsd4_close_open_stateid(stp); 4968 nfsd4_close_open_stateid(stp);
4859 4969
4860 /* put reference from nfs4_preprocess_seqid_op */ 4970 /* put reference from nfs4_preprocess_seqid_op */
@@ -6488,6 +6598,7 @@ nfs4_state_shutdown_net(struct net *net)
6488 list_for_each_safe(pos, next, &reaplist) { 6598 list_for_each_safe(pos, next, &reaplist) {
6489 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); 6599 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
6490 list_del_init(&dp->dl_recall_lru); 6600 list_del_init(&dp->dl_recall_lru);
6601 put_clnt_odstate(dp->dl_clnt_odstate);
6491 nfs4_put_deleg_lease(dp->dl_stid.sc_file); 6602 nfs4_put_deleg_lease(dp->dl_stid.sc_file);
6492 nfs4_put_stid(&dp->dl_stid); 6603 nfs4_put_stid(&dp->dl_stid);
6493 } 6604 }
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 4f3bfeb11766..dbc4f85a5008 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -63,12 +63,12 @@ typedef struct {
63 63
64struct nfsd4_callback { 64struct nfsd4_callback {
65 struct nfs4_client *cb_clp; 65 struct nfs4_client *cb_clp;
66 struct list_head cb_per_client;
67 u32 cb_minorversion; 66 u32 cb_minorversion;
68 struct rpc_message cb_msg; 67 struct rpc_message cb_msg;
69 struct nfsd4_callback_ops *cb_ops; 68 struct nfsd4_callback_ops *cb_ops;
70 struct work_struct cb_work; 69 struct work_struct cb_work;
71 bool cb_done; 70 int cb_status;
71 bool cb_need_restart;
72}; 72};
73 73
74struct nfsd4_callback_ops { 74struct nfsd4_callback_ops {
@@ -126,6 +126,7 @@ struct nfs4_delegation {
126 struct list_head dl_perfile; 126 struct list_head dl_perfile;
127 struct list_head dl_perclnt; 127 struct list_head dl_perclnt;
128 struct list_head dl_recall_lru; /* delegation recalled */ 128 struct list_head dl_recall_lru; /* delegation recalled */
129 struct nfs4_clnt_odstate *dl_clnt_odstate;
129 u32 dl_type; 130 u32 dl_type;
130 time_t dl_time; 131 time_t dl_time;
131/* For recall: */ 132/* For recall: */
@@ -332,7 +333,6 @@ struct nfs4_client {
332 int cl_cb_state; 333 int cl_cb_state;
333 struct nfsd4_callback cl_cb_null; 334 struct nfsd4_callback cl_cb_null;
334 struct nfsd4_session *cl_cb_session; 335 struct nfsd4_session *cl_cb_session;
335 struct list_head cl_callbacks; /* list of in-progress callbacks */
336 336
337 /* for all client information that callback code might need: */ 337 /* for all client information that callback code might need: */
338 spinlock_t cl_lock; 338 spinlock_t cl_lock;
@@ -465,6 +465,17 @@ static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
465} 465}
466 466
467/* 467/*
468 * Per-client state indicating no. of opens and outstanding delegations
469 * on a file from a particular client.'od' stands for 'open & delegation'
470 */
471struct nfs4_clnt_odstate {
472 struct nfs4_client *co_client;
473 struct nfs4_file *co_file;
474 struct list_head co_perfile;
475 atomic_t co_odcount;
476};
477
478/*
468 * nfs4_file: a file opened by some number of (open) nfs4_stateowners. 479 * nfs4_file: a file opened by some number of (open) nfs4_stateowners.
469 * 480 *
470 * These objects are global. nfsd keeps one instance of a nfs4_file per 481 * These objects are global. nfsd keeps one instance of a nfs4_file per
@@ -485,6 +496,7 @@ struct nfs4_file {
485 struct list_head fi_delegations; 496 struct list_head fi_delegations;
486 struct rcu_head fi_rcu; 497 struct rcu_head fi_rcu;
487 }; 498 };
499 struct list_head fi_clnt_odstate;
488 /* One each for O_RDONLY, O_WRONLY, O_RDWR: */ 500 /* One each for O_RDONLY, O_WRONLY, O_RDWR: */
489 struct file * fi_fds[3]; 501 struct file * fi_fds[3];
490 /* 502 /*
@@ -526,6 +538,7 @@ struct nfs4_ol_stateid {
526 struct list_head st_perstateowner; 538 struct list_head st_perstateowner;
527 struct list_head st_locks; 539 struct list_head st_locks;
528 struct nfs4_stateowner * st_stateowner; 540 struct nfs4_stateowner * st_stateowner;
541 struct nfs4_clnt_odstate * st_clnt_odstate;
529 unsigned char st_access_bmap; 542 unsigned char st_access_bmap;
530 unsigned char st_deny_bmap; 543 unsigned char st_deny_bmap;
531 struct nfs4_ol_stateid * st_openstp; 544 struct nfs4_ol_stateid * st_openstp;
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index f982ae84f0cd..2f8c092be2b3 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -247,6 +247,7 @@ struct nfsd4_open {
247 struct nfs4_openowner *op_openowner; /* used during processing */ 247 struct nfs4_openowner *op_openowner; /* used during processing */
248 struct nfs4_file *op_file; /* used during processing */ 248 struct nfs4_file *op_file; /* used during processing */
249 struct nfs4_ol_stateid *op_stp; /* used during processing */ 249 struct nfs4_ol_stateid *op_stp; /* used during processing */
250 struct nfs4_clnt_odstate *op_odstate; /* used during processing */
250 struct nfs4_acl *op_acl; 251 struct nfs4_acl *op_acl;
251 struct xdr_netobj op_label; 252 struct xdr_netobj op_label;
252}; 253};
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index 059f37137f9a..919fd5bb14a8 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -388,7 +388,7 @@ static int nilfs_btree_root_broken(const struct nilfs_btree_node *node,
388 nchildren = nilfs_btree_node_get_nchildren(node); 388 nchildren = nilfs_btree_node_get_nchildren(node);
389 389
390 if (unlikely(level < NILFS_BTREE_LEVEL_NODE_MIN || 390 if (unlikely(level < NILFS_BTREE_LEVEL_NODE_MIN ||
391 level > NILFS_BTREE_LEVEL_MAX || 391 level >= NILFS_BTREE_LEVEL_MAX ||
392 nchildren < 0 || 392 nchildren < 0 ||
393 nchildren > NILFS_BTREE_ROOT_NCHILDREN_MAX)) { 393 nchildren > NILFS_BTREE_ROOT_NCHILDREN_MAX)) {
394 pr_crit("NILFS: bad btree root (inode number=%lu): level = %d, flags = 0x%x, nchildren = %d\n", 394 pr_crit("NILFS: bad btree root (inode number=%lu): level = %d, flags = 0x%x, nchildren = %d\n",
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c
index a6944b25fd5b..fdf4b41d0609 100644
--- a/fs/ocfs2/dlm/dlmmaster.c
+++ b/fs/ocfs2/dlm/dlmmaster.c
@@ -757,6 +757,19 @@ lookup:
757 if (tmpres) { 757 if (tmpres) {
758 spin_unlock(&dlm->spinlock); 758 spin_unlock(&dlm->spinlock);
759 spin_lock(&tmpres->spinlock); 759 spin_lock(&tmpres->spinlock);
760
761 /*
762 * Right after dlm spinlock was released, dlm_thread could have
763 * purged the lockres. Check if lockres got unhashed. If so
764 * start over.
765 */
766 if (hlist_unhashed(&tmpres->hash_node)) {
767 spin_unlock(&tmpres->spinlock);
768 dlm_lockres_put(tmpres);
769 tmpres = NULL;
770 goto lookup;
771 }
772
760 /* Wait on the thread that is mastering the resource */ 773 /* Wait on the thread that is mastering the resource */
761 if (tmpres->owner == DLM_LOCK_RES_OWNER_UNKNOWN) { 774 if (tmpres->owner == DLM_LOCK_RES_OWNER_UNKNOWN) {
762 __dlm_wait_on_lockres(tmpres); 775 __dlm_wait_on_lockres(tmpres);
diff --git a/fs/omfs/bitmap.c b/fs/omfs/bitmap.c
index 082234581d05..83f4e76511c2 100644
--- a/fs/omfs/bitmap.c
+++ b/fs/omfs/bitmap.c
@@ -159,7 +159,7 @@ int omfs_allocate_range(struct super_block *sb,
159 goto out; 159 goto out;
160 160
161found: 161found:
162 *return_block = i * bits_per_entry + bit; 162 *return_block = (u64) i * bits_per_entry + bit;
163 *return_size = run; 163 *return_size = run;
164 ret = set_run(sb, i, bits_per_entry, bit, run, 1); 164 ret = set_run(sb, i, bits_per_entry, bit, run, 1);
165 165
diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c
index 138321b0c6c2..3d935c81789a 100644
--- a/fs/omfs/inode.c
+++ b/fs/omfs/inode.c
@@ -306,7 +306,8 @@ static const struct super_operations omfs_sops = {
306 */ 306 */
307static int omfs_get_imap(struct super_block *sb) 307static int omfs_get_imap(struct super_block *sb)
308{ 308{
309 unsigned int bitmap_size, count, array_size; 309 unsigned int bitmap_size, array_size;
310 int count;
310 struct omfs_sb_info *sbi = OMFS_SB(sb); 311 struct omfs_sb_info *sbi = OMFS_SB(sb);
311 struct buffer_head *bh; 312 struct buffer_head *bh;
312 unsigned long **ptr; 313 unsigned long **ptr;
@@ -359,7 +360,7 @@ nomem:
359} 360}
360 361
361enum { 362enum {
362 Opt_uid, Opt_gid, Opt_umask, Opt_dmask, Opt_fmask 363 Opt_uid, Opt_gid, Opt_umask, Opt_dmask, Opt_fmask, Opt_err
363}; 364};
364 365
365static const match_table_t tokens = { 366static const match_table_t tokens = {
@@ -368,6 +369,7 @@ static const match_table_t tokens = {
368 {Opt_umask, "umask=%o"}, 369 {Opt_umask, "umask=%o"},
369 {Opt_dmask, "dmask=%o"}, 370 {Opt_dmask, "dmask=%o"},
370 {Opt_fmask, "fmask=%o"}, 371 {Opt_fmask, "fmask=%o"},
372 {Opt_err, NULL},
371}; 373};
372 374
373static int parse_options(char *options, struct omfs_sb_info *sbi) 375static int parse_options(char *options, struct omfs_sb_info *sbi)
@@ -548,8 +550,10 @@ static int omfs_fill_super(struct super_block *sb, void *data, int silent)
548 } 550 }
549 551
550 sb->s_root = d_make_root(root); 552 sb->s_root = d_make_root(root);
551 if (!sb->s_root) 553 if (!sb->s_root) {
554 ret = -ENOMEM;
552 goto out_brelse_bh2; 555 goto out_brelse_bh2;
556 }
553 printk(KERN_DEBUG "omfs: Mounted volume %s\n", omfs_rb->r_name); 557 printk(KERN_DEBUG "omfs: Mounted volume %s\n", omfs_rb->r_name);
554 558
555 ret = 0; 559 ret = 0;
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 24f640441bd9..84d693d37428 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -299,6 +299,9 @@ int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
299 struct cred *override_cred; 299 struct cred *override_cred;
300 char *link = NULL; 300 char *link = NULL;
301 301
302 if (WARN_ON(!workdir))
303 return -EROFS;
304
302 ovl_path_upper(parent, &parentpath); 305 ovl_path_upper(parent, &parentpath);
303 upperdir = parentpath.dentry; 306 upperdir = parentpath.dentry;
304 307
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index d139405d2bfa..692ceda3bc21 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -222,6 +222,9 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry,
222 struct kstat stat; 222 struct kstat stat;
223 int err; 223 int err;
224 224
225 if (WARN_ON(!workdir))
226 return ERR_PTR(-EROFS);
227
225 err = ovl_lock_rename_workdir(workdir, upperdir); 228 err = ovl_lock_rename_workdir(workdir, upperdir);
226 if (err) 229 if (err)
227 goto out; 230 goto out;
@@ -322,6 +325,9 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
322 struct dentry *newdentry; 325 struct dentry *newdentry;
323 int err; 326 int err;
324 327
328 if (WARN_ON(!workdir))
329 return -EROFS;
330
325 err = ovl_lock_rename_workdir(workdir, upperdir); 331 err = ovl_lock_rename_workdir(workdir, upperdir);
326 if (err) 332 if (err)
327 goto out; 333 goto out;
@@ -506,11 +512,28 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir)
506 struct dentry *opaquedir = NULL; 512 struct dentry *opaquedir = NULL;
507 int err; 513 int err;
508 514
509 if (is_dir && OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) { 515 if (WARN_ON(!workdir))
510 opaquedir = ovl_check_empty_and_clear(dentry); 516 return -EROFS;
511 err = PTR_ERR(opaquedir); 517
512 if (IS_ERR(opaquedir)) 518 if (is_dir) {
513 goto out; 519 if (OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) {
520 opaquedir = ovl_check_empty_and_clear(dentry);
521 err = PTR_ERR(opaquedir);
522 if (IS_ERR(opaquedir))
523 goto out;
524 } else {
525 LIST_HEAD(list);
526
527 /*
528 * When removing an empty opaque directory, then it
529 * makes no sense to replace it with an exact replica of
530 * itself. But emptiness still needs to be checked.
531 */
532 err = ovl_check_empty_dir(dentry, &list);
533 ovl_cache_free(&list);
534 if (err)
535 goto out;
536 }
514 } 537 }
515 538
516 err = ovl_lock_rename_workdir(workdir, upperdir); 539 err = ovl_lock_rename_workdir(workdir, upperdir);
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 5f0d1993e6e3..bf8537c7f455 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -529,7 +529,7 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
529{ 529{
530 struct ovl_fs *ufs = sb->s_fs_info; 530 struct ovl_fs *ufs = sb->s_fs_info;
531 531
532 if (!(*flags & MS_RDONLY) && !ufs->upper_mnt) 532 if (!(*flags & MS_RDONLY) && (!ufs->upper_mnt || !ufs->workdir))
533 return -EROFS; 533 return -EROFS;
534 534
535 return 0; 535 return 0;
@@ -925,9 +925,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
925 ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry); 925 ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry);
926 err = PTR_ERR(ufs->workdir); 926 err = PTR_ERR(ufs->workdir);
927 if (IS_ERR(ufs->workdir)) { 927 if (IS_ERR(ufs->workdir)) {
928 pr_err("overlayfs: failed to create directory %s/%s\n", 928 pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n",
929 ufs->config.workdir, OVL_WORKDIR_NAME); 929 ufs->config.workdir, OVL_WORKDIR_NAME, -err);
930 goto out_put_upper_mnt; 930 sb->s_flags |= MS_RDONLY;
931 ufs->workdir = NULL;
931 } 932 }
932 } 933 }
933 934
@@ -997,7 +998,6 @@ out_put_lower_mnt:
997 kfree(ufs->lower_mnt); 998 kfree(ufs->lower_mnt);
998out_put_workdir: 999out_put_workdir:
999 dput(ufs->workdir); 1000 dput(ufs->workdir);
1000out_put_upper_mnt:
1001 mntput(ufs->upper_mnt); 1001 mntput(ufs->upper_mnt);
1002out_put_lowerpath: 1002out_put_lowerpath:
1003 for (i = 0; i < numlower; i++) 1003 for (i = 0; i < numlower; i++)
diff --git a/fs/splice.c b/fs/splice.c
index 476024bb6546..bfe62ae40f40 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1161,7 +1161,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
1161 long ret, bytes; 1161 long ret, bytes;
1162 umode_t i_mode; 1162 umode_t i_mode;
1163 size_t len; 1163 size_t len;
1164 int i, flags; 1164 int i, flags, more;
1165 1165
1166 /* 1166 /*
1167 * We require the input being a regular file, as we don't want to 1167 * We require the input being a regular file, as we don't want to
@@ -1204,6 +1204,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
1204 * Don't block on output, we have to drain the direct pipe. 1204 * Don't block on output, we have to drain the direct pipe.
1205 */ 1205 */
1206 sd->flags &= ~SPLICE_F_NONBLOCK; 1206 sd->flags &= ~SPLICE_F_NONBLOCK;
1207 more = sd->flags & SPLICE_F_MORE;
1207 1208
1208 while (len) { 1209 while (len) {
1209 size_t read_len; 1210 size_t read_len;
@@ -1217,6 +1218,15 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
1217 sd->total_len = read_len; 1218 sd->total_len = read_len;
1218 1219
1219 /* 1220 /*
1221 * If more data is pending, set SPLICE_F_MORE
1222 * If this is the last data and SPLICE_F_MORE was not set
1223 * initially, clears it.
1224 */
1225 if (read_len < len)
1226 sd->flags |= SPLICE_F_MORE;
1227 else if (!more)
1228 sd->flags &= ~SPLICE_F_MORE;
1229 /*
1220 * NOTE: nonblocking mode only applies to the input. We 1230 * NOTE: nonblocking mode only applies to the input. We
1221 * must not do the output in nonblocking mode as then we 1231 * must not do the output in nonblocking mode as then we
1222 * could get stuck data in the internal pipe: 1232 * could get stuck data in the internal pipe:
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index 04e79d57bca6..e9d401ce93bb 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -574,8 +574,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
574 * After the last attribute is removed revert to original inode format, 574 * After the last attribute is removed revert to original inode format,
575 * making all literal area available to the data fork once more. 575 * making all literal area available to the data fork once more.
576 */ 576 */
577STATIC void 577void
578xfs_attr_fork_reset( 578xfs_attr_fork_remove(
579 struct xfs_inode *ip, 579 struct xfs_inode *ip,
580 struct xfs_trans *tp) 580 struct xfs_trans *tp)
581{ 581{
@@ -641,7 +641,7 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
641 (mp->m_flags & XFS_MOUNT_ATTR2) && 641 (mp->m_flags & XFS_MOUNT_ATTR2) &&
642 (dp->i_d.di_format != XFS_DINODE_FMT_BTREE) && 642 (dp->i_d.di_format != XFS_DINODE_FMT_BTREE) &&
643 !(args->op_flags & XFS_DA_OP_ADDNAME)) { 643 !(args->op_flags & XFS_DA_OP_ADDNAME)) {
644 xfs_attr_fork_reset(dp, args->trans); 644 xfs_attr_fork_remove(dp, args->trans);
645 } else { 645 } else {
646 xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); 646 xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
647 dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize); 647 dp->i_d.di_forkoff = xfs_attr_shortform_bytesfit(dp, totsize);
@@ -905,7 +905,7 @@ xfs_attr3_leaf_to_shortform(
905 if (forkoff == -1) { 905 if (forkoff == -1) {
906 ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2); 906 ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2);
907 ASSERT(dp->i_d.di_format != XFS_DINODE_FMT_BTREE); 907 ASSERT(dp->i_d.di_format != XFS_DINODE_FMT_BTREE);
908 xfs_attr_fork_reset(dp, args->trans); 908 xfs_attr_fork_remove(dp, args->trans);
909 goto out; 909 goto out;
910 } 910 }
911 911
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.h b/fs/xfs/libxfs/xfs_attr_leaf.h
index 025c4b820c03..882c8d338891 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.h
+++ b/fs/xfs/libxfs/xfs_attr_leaf.h
@@ -53,7 +53,7 @@ int xfs_attr_shortform_remove(struct xfs_da_args *args);
53int xfs_attr_shortform_list(struct xfs_attr_list_context *context); 53int xfs_attr_shortform_list(struct xfs_attr_list_context *context);
54int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp); 54int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
55int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes); 55int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes);
56 56void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
57 57
58/* 58/*
59 * Internal routines when attribute fork size == XFS_LBSIZE(mp). 59 * Internal routines when attribute fork size == XFS_LBSIZE(mp).
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index aeffeaaac0ec..f1026e86dabc 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3224,12 +3224,24 @@ xfs_bmap_extsize_align(
3224 align_alen += temp; 3224 align_alen += temp;
3225 align_off -= temp; 3225 align_off -= temp;
3226 } 3226 }
3227
3228 /* Same adjustment for the end of the requested area. */
3229 temp = (align_alen % extsz);
3230 if (temp)
3231 align_alen += extsz - temp;
3232
3227 /* 3233 /*
3228 * Same adjustment for the end of the requested area. 3234 * For large extent hint sizes, the aligned extent might be larger than
3235 * MAXEXTLEN. In that case, reduce the size by an extsz so that it pulls
3236 * the length back under MAXEXTLEN. The outer allocation loops handle
3237 * short allocation just fine, so it is safe to do this. We only want to
3238 * do it when we are forced to, though, because it means more allocation
3239 * operations are required.
3229 */ 3240 */
3230 if ((temp = (align_alen % extsz))) { 3241 while (align_alen > MAXEXTLEN)
3231 align_alen += extsz - temp; 3242 align_alen -= extsz;
3232 } 3243 ASSERT(align_alen <= MAXEXTLEN);
3244
3233 /* 3245 /*
3234 * If the previous block overlaps with this proposed allocation 3246 * If the previous block overlaps with this proposed allocation
3235 * then move the start forward without adjusting the length. 3247 * then move the start forward without adjusting the length.
@@ -3318,7 +3330,9 @@ xfs_bmap_extsize_align(
3318 return -EINVAL; 3330 return -EINVAL;
3319 } else { 3331 } else {
3320 ASSERT(orig_off >= align_off); 3332 ASSERT(orig_off >= align_off);
3321 ASSERT(orig_end <= align_off + align_alen); 3333 /* see MAXEXTLEN handling above */
3334 ASSERT(orig_end <= align_off + align_alen ||
3335 align_alen + extsz > MAXEXTLEN);
3322 } 3336 }
3323 3337
3324#ifdef DEBUG 3338#ifdef DEBUG
@@ -4099,13 +4113,6 @@ xfs_bmapi_reserve_delalloc(
4099 /* Figure out the extent size, adjust alen */ 4113 /* Figure out the extent size, adjust alen */
4100 extsz = xfs_get_extsz_hint(ip); 4114 extsz = xfs_get_extsz_hint(ip);
4101 if (extsz) { 4115 if (extsz) {
4102 /*
4103 * Make sure we don't exceed a single extent length when we
4104 * align the extent by reducing length we are going to
4105 * allocate by the maximum amount extent size aligment may
4106 * require.
4107 */
4108 alen = XFS_FILBLKS_MIN(len, MAXEXTLEN - (2 * extsz - 1));
4109 error = xfs_bmap_extsize_align(mp, got, prev, extsz, rt, eof, 4116 error = xfs_bmap_extsize_align(mp, got, prev, extsz, rt, eof,
4110 1, 0, &aoff, &alen); 4117 1, 0, &aoff, &alen);
4111 ASSERT(!error); 4118 ASSERT(!error);
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 07349a183a11..1c9e75521250 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -376,7 +376,7 @@ xfs_ialloc_ag_alloc(
376 */ 376 */
377 newlen = args.mp->m_ialloc_inos; 377 newlen = args.mp->m_ialloc_inos;
378 if (args.mp->m_maxicount && 378 if (args.mp->m_maxicount &&
379 percpu_counter_read(&args.mp->m_icount) + newlen > 379 percpu_counter_read_positive(&args.mp->m_icount) + newlen >
380 args.mp->m_maxicount) 380 args.mp->m_maxicount)
381 return -ENOSPC; 381 return -ENOSPC;
382 args.minlen = args.maxlen = args.mp->m_ialloc_blks; 382 args.minlen = args.maxlen = args.mp->m_ialloc_blks;
@@ -1339,10 +1339,13 @@ xfs_dialloc(
1339 * If we have already hit the ceiling of inode blocks then clear 1339 * If we have already hit the ceiling of inode blocks then clear
1340 * okalloc so we scan all available agi structures for a free 1340 * okalloc so we scan all available agi structures for a free
1341 * inode. 1341 * inode.
1342 *
1343 * Read rough value of mp->m_icount by percpu_counter_read_positive,
1344 * which will sacrifice the preciseness but improve the performance.
1342 */ 1345 */
1343 if (mp->m_maxicount && 1346 if (mp->m_maxicount &&
1344 percpu_counter_read(&mp->m_icount) + mp->m_ialloc_inos > 1347 percpu_counter_read_positive(&mp->m_icount) + mp->m_ialloc_inos
1345 mp->m_maxicount) { 1348 > mp->m_maxicount) {
1346 noroom = 1; 1349 noroom = 1;
1347 okalloc = 0; 1350 okalloc = 0;
1348 } 1351 }
diff --git a/fs/xfs/xfs_attr_inactive.c b/fs/xfs/xfs_attr_inactive.c
index f9c1c64782d3..3fbf167cfb4c 100644
--- a/fs/xfs/xfs_attr_inactive.c
+++ b/fs/xfs/xfs_attr_inactive.c
@@ -380,23 +380,31 @@ xfs_attr3_root_inactive(
380 return error; 380 return error;
381} 381}
382 382
383/*
384 * xfs_attr_inactive kills all traces of an attribute fork on an inode. It
385 * removes both the on-disk and in-memory inode fork. Note that this also has to
386 * handle the condition of inodes without attributes but with an attribute fork
387 * configured, so we can't use xfs_inode_hasattr() here.
388 *
389 * The in-memory attribute fork is removed even on error.
390 */
383int 391int
384xfs_attr_inactive(xfs_inode_t *dp) 392xfs_attr_inactive(
393 struct xfs_inode *dp)
385{ 394{
386 xfs_trans_t *trans; 395 struct xfs_trans *trans;
387 xfs_mount_t *mp; 396 struct xfs_mount *mp;
388 int error; 397 int cancel_flags = 0;
398 int lock_mode = XFS_ILOCK_SHARED;
399 int error = 0;
389 400
390 mp = dp->i_mount; 401 mp = dp->i_mount;
391 ASSERT(! XFS_NOT_DQATTACHED(mp, dp)); 402 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
392 403
393 xfs_ilock(dp, XFS_ILOCK_SHARED); 404 xfs_ilock(dp, lock_mode);
394 if (!xfs_inode_hasattr(dp) || 405 if (!XFS_IFORK_Q(dp))
395 dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) { 406 goto out_destroy_fork;
396 xfs_iunlock(dp, XFS_ILOCK_SHARED); 407 xfs_iunlock(dp, lock_mode);
397 return 0;
398 }
399 xfs_iunlock(dp, XFS_ILOCK_SHARED);
400 408
401 /* 409 /*
402 * Start our first transaction of the day. 410 * Start our first transaction of the day.
@@ -408,13 +416,18 @@ xfs_attr_inactive(xfs_inode_t *dp)
408 * the inode in every transaction to let it float upward through 416 * the inode in every transaction to let it float upward through
409 * the log. 417 * the log.
410 */ 418 */
419 lock_mode = 0;
411 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL); 420 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
412 error = xfs_trans_reserve(trans, &M_RES(mp)->tr_attrinval, 0, 0); 421 error = xfs_trans_reserve(trans, &M_RES(mp)->tr_attrinval, 0, 0);
413 if (error) { 422 if (error)
414 xfs_trans_cancel(trans, 0); 423 goto out_cancel;
415 return error; 424
416 } 425 lock_mode = XFS_ILOCK_EXCL;
417 xfs_ilock(dp, XFS_ILOCK_EXCL); 426 cancel_flags = XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT;
427 xfs_ilock(dp, lock_mode);
428
429 if (!XFS_IFORK_Q(dp))
430 goto out_cancel;
418 431
419 /* 432 /*
420 * No need to make quota reservations here. We expect to release some 433 * No need to make quota reservations here. We expect to release some
@@ -422,29 +435,31 @@ xfs_attr_inactive(xfs_inode_t *dp)
422 */ 435 */
423 xfs_trans_ijoin(trans, dp, 0); 436 xfs_trans_ijoin(trans, dp, 0);
424 437
425 /* 438 /* invalidate and truncate the attribute fork extents */
426 * Decide on what work routines to call based on the inode size. 439 if (dp->i_d.di_aformat != XFS_DINODE_FMT_LOCAL) {
427 */ 440 error = xfs_attr3_root_inactive(&trans, dp);
428 if (!xfs_inode_hasattr(dp) || 441 if (error)
429 dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) { 442 goto out_cancel;
430 error = 0; 443
431 goto out; 444 error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0);
445 if (error)
446 goto out_cancel;
432 } 447 }
433 error = xfs_attr3_root_inactive(&trans, dp);
434 if (error)
435 goto out;
436 448
437 error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0); 449 /* Reset the attribute fork - this also destroys the in-core fork */
438 if (error) 450 xfs_attr_fork_remove(dp, trans);
439 goto out;
440 451
441 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES); 452 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES);
442 xfs_iunlock(dp, XFS_ILOCK_EXCL); 453 xfs_iunlock(dp, lock_mode);
443
444 return error; 454 return error;
445 455
446out: 456out_cancel:
447 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT); 457 xfs_trans_cancel(trans, cancel_flags);
448 xfs_iunlock(dp, XFS_ILOCK_EXCL); 458out_destroy_fork:
459 /* kill the in-core attr fork before we drop the inode lock */
460 if (dp->i_afp)
461 xfs_idestroy_fork(dp, XFS_ATTR_FORK);
462 if (lock_mode)
463 xfs_iunlock(dp, lock_mode);
449 return error; 464 return error;
450} 465}
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 8121e75352ee..3b7591224f4a 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -124,7 +124,7 @@ xfs_iozero(
124 status = 0; 124 status = 0;
125 } while (count); 125 } while (count);
126 126
127 return (-status); 127 return status;
128} 128}
129 129
130int 130int
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index d6ebc85192b7..539a85fddbc2 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1946,21 +1946,17 @@ xfs_inactive(
1946 /* 1946 /*
1947 * If there are attributes associated with the file then blow them away 1947 * If there are attributes associated with the file then blow them away
1948 * now. The code calls a routine that recursively deconstructs the 1948 * now. The code calls a routine that recursively deconstructs the
1949 * attribute fork. We need to just commit the current transaction 1949 * attribute fork. If also blows away the in-core attribute fork.
1950 * because we can't use it for xfs_attr_inactive().
1951 */ 1950 */
1952 if (ip->i_d.di_anextents > 0) { 1951 if (XFS_IFORK_Q(ip)) {
1953 ASSERT(ip->i_d.di_forkoff != 0);
1954
1955 error = xfs_attr_inactive(ip); 1952 error = xfs_attr_inactive(ip);
1956 if (error) 1953 if (error)
1957 return; 1954 return;
1958 } 1955 }
1959 1956
1960 if (ip->i_afp) 1957 ASSERT(!ip->i_afp);
1961 xfs_idestroy_fork(ip, XFS_ATTR_FORK);
1962
1963 ASSERT(ip->i_d.di_anextents == 0); 1958 ASSERT(ip->i_d.di_anextents == 0);
1959 ASSERT(ip->i_d.di_forkoff == 0);
1964 1960
1965 /* 1961 /*
1966 * Free the inode. 1962 * Free the inode.
@@ -2883,7 +2879,13 @@ xfs_rename_alloc_whiteout(
2883 if (error) 2879 if (error)
2884 return error; 2880 return error;
2885 2881
2886 /* Satisfy xfs_bumplink that this is a real tmpfile */ 2882 /*
2883 * Prepare the tmpfile inode as if it were created through the VFS.
2884 * Otherwise, the link increment paths will complain about nlink 0->1.
2885 * Drop the link count as done by d_tmpfile(), complete the inode setup
2886 * and flag it as linkable.
2887 */
2888 drop_nlink(VFS_I(tmpfile));
2887 xfs_finish_inode_setup(tmpfile); 2889 xfs_finish_inode_setup(tmpfile);
2888 VFS_I(tmpfile)->i_state |= I_LINKABLE; 2890 VFS_I(tmpfile)->i_state |= I_LINKABLE;
2889 2891
@@ -3151,7 +3153,7 @@ xfs_rename(
3151 * intermediate state on disk. 3153 * intermediate state on disk.
3152 */ 3154 */
3153 if (wip) { 3155 if (wip) {
3154 ASSERT(wip->i_d.di_nlink == 0); 3156 ASSERT(VFS_I(wip)->i_nlink == 0 && wip->i_d.di_nlink == 0);
3155 error = xfs_bumplink(tp, wip); 3157 error = xfs_bumplink(tp, wip);
3156 if (error) 3158 if (error)
3157 goto out_trans_abort; 3159 goto out_trans_abort;
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 2ce7ee3b4ec1..6f23fbdfb365 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -1084,14 +1084,18 @@ xfs_log_sbcount(xfs_mount_t *mp)
1084 return xfs_sync_sb(mp, true); 1084 return xfs_sync_sb(mp, true);
1085} 1085}
1086 1086
1087/*
1088 * Deltas for the inode count are +/-64, hence we use a large batch size
1089 * of 128 so we don't need to take the counter lock on every update.
1090 */
1091#define XFS_ICOUNT_BATCH 128
1087int 1092int
1088xfs_mod_icount( 1093xfs_mod_icount(
1089 struct xfs_mount *mp, 1094 struct xfs_mount *mp,
1090 int64_t delta) 1095 int64_t delta)
1091{ 1096{
1092 /* deltas are +/-64, hence the large batch size of 128. */ 1097 __percpu_counter_add(&mp->m_icount, delta, XFS_ICOUNT_BATCH);
1093 __percpu_counter_add(&mp->m_icount, delta, 128); 1098 if (__percpu_counter_compare(&mp->m_icount, 0, XFS_ICOUNT_BATCH) < 0) {
1094 if (percpu_counter_compare(&mp->m_icount, 0) < 0) {
1095 ASSERT(0); 1099 ASSERT(0);
1096 percpu_counter_add(&mp->m_icount, -delta); 1100 percpu_counter_add(&mp->m_icount, -delta);
1097 return -EINVAL; 1101 return -EINVAL;
@@ -1113,6 +1117,14 @@ xfs_mod_ifree(
1113 return 0; 1117 return 0;
1114} 1118}
1115 1119
1120/*
1121 * Deltas for the block count can vary from 1 to very large, but lock contention
1122 * only occurs on frequent small block count updates such as in the delayed
1123 * allocation path for buffered writes (page a time updates). Hence we set
1124 * a large batch count (1024) to minimise global counter updates except when
1125 * we get near to ENOSPC and we have to be very accurate with our updates.
1126 */
1127#define XFS_FDBLOCKS_BATCH 1024
1116int 1128int
1117xfs_mod_fdblocks( 1129xfs_mod_fdblocks(
1118 struct xfs_mount *mp, 1130 struct xfs_mount *mp,
@@ -1151,25 +1163,19 @@ xfs_mod_fdblocks(
1151 * Taking blocks away, need to be more accurate the closer we 1163 * Taking blocks away, need to be more accurate the closer we
1152 * are to zero. 1164 * are to zero.
1153 * 1165 *
1154 * batch size is set to a maximum of 1024 blocks - if we are
1155 * allocating of freeing extents larger than this then we aren't
1156 * going to be hammering the counter lock so a lock per update
1157 * is not a problem.
1158 *
1159 * If the counter has a value of less than 2 * max batch size, 1166 * If the counter has a value of less than 2 * max batch size,
1160 * then make everything serialise as we are real close to 1167 * then make everything serialise as we are real close to
1161 * ENOSPC. 1168 * ENOSPC.
1162 */ 1169 */
1163#define __BATCH 1024 1170 if (__percpu_counter_compare(&mp->m_fdblocks, 2 * XFS_FDBLOCKS_BATCH,
1164 if (percpu_counter_compare(&mp->m_fdblocks, 2 * __BATCH) < 0) 1171 XFS_FDBLOCKS_BATCH) < 0)
1165 batch = 1; 1172 batch = 1;
1166 else 1173 else
1167 batch = __BATCH; 1174 batch = XFS_FDBLOCKS_BATCH;
1168#undef __BATCH
1169 1175
1170 __percpu_counter_add(&mp->m_fdblocks, delta, batch); 1176 __percpu_counter_add(&mp->m_fdblocks, delta, batch);
1171 if (percpu_counter_compare(&mp->m_fdblocks, 1177 if (__percpu_counter_compare(&mp->m_fdblocks, XFS_ALLOC_SET_ASIDE(mp),
1172 XFS_ALLOC_SET_ASIDE(mp)) >= 0) { 1178 XFS_FDBLOCKS_BATCH) >= 0) {
1173 /* we had space! */ 1179 /* we had space! */
1174 return 0; 1180 return 0;
1175 } 1181 }
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index f5ca0e989bba..1c3002e1db20 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -124,7 +124,6 @@
124#ifndef ACPI_USE_SYSTEM_INTTYPES 124#ifndef ACPI_USE_SYSTEM_INTTYPES
125 125
126typedef unsigned char u8; 126typedef unsigned char u8;
127typedef unsigned char u8;
128typedef unsigned short u16; 127typedef unsigned short u16;
129typedef short s16; 128typedef short s16;
130typedef COMPILER_DEPENDENT_UINT64 u64; 129typedef COMPILER_DEPENDENT_UINT64 u64;
diff --git a/include/drm/drm_pciids.h b/include/drm/drm_pciids.h
index 2dd405c9be78..45c39a37f924 100644
--- a/include/drm/drm_pciids.h
+++ b/include/drm/drm_pciids.h
@@ -186,6 +186,7 @@
186 {0x1002, 0x6658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \ 186 {0x1002, 0x6658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \
187 {0x1002, 0x665c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \ 187 {0x1002, 0x665c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \
188 {0x1002, 0x665d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \ 188 {0x1002, 0x665d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \
189 {0x1002, 0x665f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|RADEON_NEW_MEMMAP}, \
189 {0x1002, 0x6660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ 190 {0x1002, 0x6660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
190 {0x1002, 0x6663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ 191 {0x1002, 0x6663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
191 {0x1002, 0x6664, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ 192 {0x1002, 0x6664, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
diff --git a/include/dt-bindings/sound/audio-jack-events.h b/include/dt-bindings/sound/audio-jack-events.h
new file mode 100644
index 000000000000..378349f28069
--- /dev/null
+++ b/include/dt-bindings/sound/audio-jack-events.h
@@ -0,0 +1,9 @@
1#ifndef __AUDIO_JACK_EVENTS_H
2#define __AUDIO_JACK_EVENTS_H
3
4#define JACK_HEADPHONE 1
5#define JACK_MICROPHONE 2
6#define JACK_LINEOUT 3
7#define JACK_LINEIN 4
8
9#endif /* __AUDIO_JACK_EVENTS_H */
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index a1b25e35ea5f..b7299febc4b4 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -220,7 +220,7 @@ enum rq_flag_bits {
220 220
221/* This mask is used for both bio and request merge checking */ 221/* This mask is used for both bio and request merge checking */
222#define REQ_NOMERGE_FLAGS \ 222#define REQ_NOMERGE_FLAGS \
223 (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA) 223 (REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA | REQ_FLUSH_SEQ)
224 224
225#define REQ_RAHEAD (1ULL << __REQ_RAHEAD) 225#define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
226#define REQ_THROTTLED (1ULL << __REQ_THROTTLED) 226#define REQ_THROTTLED (1ULL << __REQ_THROTTLED)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 7f9a516f24de..5d93a6645e88 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -821,8 +821,6 @@ extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
821extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t, 821extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
822 struct scsi_ioctl_command __user *); 822 struct scsi_ioctl_command __user *);
823 823
824extern void blk_queue_bio(struct request_queue *q, struct bio *bio);
825
826/* 824/*
827 * A queue has just exitted congestion. Note this in the global counter of 825 * A queue has just exitted congestion. Note this in the global counter of
828 * congested queues, and wake up anyone who was waiting for requests to be 826 * congested queues, and wake up anyone who was waiting for requests to be
diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h
index ae2982c0f7a6..656da2a12ffe 100644
--- a/include/linux/brcmphy.h
+++ b/include/linux/brcmphy.h
@@ -17,7 +17,7 @@
17#define PHY_ID_BCM7250 0xae025280 17#define PHY_ID_BCM7250 0xae025280
18#define PHY_ID_BCM7364 0xae025260 18#define PHY_ID_BCM7364 0xae025260
19#define PHY_ID_BCM7366 0x600d8490 19#define PHY_ID_BCM7366 0x600d8490
20#define PHY_ID_BCM7425 0x03625e60 20#define PHY_ID_BCM7425 0x600d86b0
21#define PHY_ID_BCM7429 0x600d8730 21#define PHY_ID_BCM7429 0x600d8730
22#define PHY_ID_BCM7439 0x600d8480 22#define PHY_ID_BCM7439 0x600d8480
23#define PHY_ID_BCM7439_2 0xae025080 23#define PHY_ID_BCM7439_2 0xae025080
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index cdf13ca7cac3..371e560d13cf 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -9,10 +9,24 @@
9 + __GNUC_MINOR__ * 100 \ 9 + __GNUC_MINOR__ * 100 \
10 + __GNUC_PATCHLEVEL__) 10 + __GNUC_PATCHLEVEL__)
11 11
12
13/* Optimization barrier */ 12/* Optimization barrier */
13
14/* The "volatile" is due to gcc bugs */ 14/* The "volatile" is due to gcc bugs */
15#define barrier() __asm__ __volatile__("": : :"memory") 15#define barrier() __asm__ __volatile__("": : :"memory")
16/*
17 * This version is i.e. to prevent dead stores elimination on @ptr
18 * where gcc and llvm may behave differently when otherwise using
19 * normal barrier(): while gcc behavior gets along with a normal
20 * barrier(), llvm needs an explicit input variable to be assumed
21 * clobbered. The issue is as follows: while the inline asm might
22 * access any memory it wants, the compiler could have fit all of
23 * @ptr into memory registers instead, and since @ptr never escaped
24 * from that, it proofed that the inline asm wasn't touching any of
25 * it. This version works well with both compilers, i.e. we're telling
26 * the compiler that the inline asm absolutely may see the contents
27 * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
28 */
29#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
16 30
17/* 31/*
18 * This macro obfuscates arithmetic on a variable address so that gcc 32 * This macro obfuscates arithmetic on a variable address so that gcc
diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h
index ba147a1727e6..0c9a2f2c2802 100644
--- a/include/linux/compiler-intel.h
+++ b/include/linux/compiler-intel.h
@@ -13,9 +13,12 @@
13/* Intel ECC compiler doesn't support gcc specific asm stmts. 13/* Intel ECC compiler doesn't support gcc specific asm stmts.
14 * It uses intrinsics to do the equivalent things. 14 * It uses intrinsics to do the equivalent things.
15 */ 15 */
16#undef barrier_data
16#undef RELOC_HIDE 17#undef RELOC_HIDE
17#undef OPTIMIZER_HIDE_VAR 18#undef OPTIMIZER_HIDE_VAR
18 19
20#define barrier_data(ptr) barrier()
21
19#define RELOC_HIDE(ptr, off) \ 22#define RELOC_HIDE(ptr, off) \
20 ({ unsigned long __ptr; \ 23 ({ unsigned long __ptr; \
21 __ptr = (unsigned long) (ptr); \ 24 __ptr = (unsigned long) (ptr); \
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 0e41ca0e5927..867722591be2 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -169,6 +169,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
169# define barrier() __memory_barrier() 169# define barrier() __memory_barrier()
170#endif 170#endif
171 171
172#ifndef barrier_data
173# define barrier_data(ptr) barrier()
174#endif
175
172/* Unreachable code */ 176/* Unreachable code */
173#ifndef unreachable 177#ifndef unreachable
174# define unreachable() do { } while (1) 178# define unreachable() do { } while (1)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 27e285b92b5f..59915ea5373c 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -151,10 +151,8 @@ static inline unsigned int cpumask_any_but(const struct cpumask *mask,
151 return 1; 151 return 1;
152} 152}
153 153
154static inline int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp) 154static inline unsigned int cpumask_local_spread(unsigned int i, int node)
155{ 155{
156 set_bit(0, cpumask_bits(dstp));
157
158 return 0; 156 return 0;
159} 157}
160 158
@@ -208,7 +206,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
208 206
209int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *); 207int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
210int cpumask_any_but(const struct cpumask *mask, unsigned int cpu); 208int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
211int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp); 209unsigned int cpumask_local_spread(unsigned int i, int node);
212 210
213/** 211/**
214 * for_each_cpu - iterate over every cpu in a mask 212 * for_each_cpu - iterate over every cpu in a mask
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 46e83c2156c6..f9ecf63d47f1 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -46,7 +46,7 @@ const char *ftrace_print_hex_seq(struct trace_seq *p,
46 const unsigned char *buf, int len); 46 const unsigned char *buf, int len);
47 47
48const char *ftrace_print_array_seq(struct trace_seq *p, 48const char *ftrace_print_array_seq(struct trace_seq *p,
49 const void *buf, int buf_len, 49 const void *buf, int count,
50 size_t el_size); 50 size_t el_size);
51 51
52struct trace_iterator; 52struct trace_iterator;
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 97a9373e61e8..15928f0647e4 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -30,6 +30,7 @@ struct vm_area_struct;
30#define ___GFP_HARDWALL 0x20000u 30#define ___GFP_HARDWALL 0x20000u
31#define ___GFP_THISNODE 0x40000u 31#define ___GFP_THISNODE 0x40000u
32#define ___GFP_RECLAIMABLE 0x80000u 32#define ___GFP_RECLAIMABLE 0x80000u
33#define ___GFP_NOACCOUNT 0x100000u
33#define ___GFP_NOTRACK 0x200000u 34#define ___GFP_NOTRACK 0x200000u
34#define ___GFP_NO_KSWAPD 0x400000u 35#define ___GFP_NO_KSWAPD 0x400000u
35#define ___GFP_OTHER_NODE 0x800000u 36#define ___GFP_OTHER_NODE 0x800000u
@@ -87,6 +88,7 @@ struct vm_area_struct;
87#define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) /* Enforce hardwall cpuset memory allocs */ 88#define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) /* Enforce hardwall cpuset memory allocs */
88#define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE)/* No fallback, no policies */ 89#define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE)/* No fallback, no policies */
89#define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) /* Page is reclaimable */ 90#define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) /* Page is reclaimable */
91#define __GFP_NOACCOUNT ((__force gfp_t)___GFP_NOACCOUNT) /* Don't account to kmemcg */
90#define __GFP_NOTRACK ((__force gfp_t)___GFP_NOTRACK) /* Don't track with kmemcheck */ 92#define __GFP_NOTRACK ((__force gfp_t)___GFP_NOTRACK) /* Don't track with kmemcheck */
91 93
92#define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD) 94#define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 0408421d885f..0042bf330b99 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -74,7 +74,7 @@ struct sensor_hub_pending {
74 * @usage: Usage id for this hub device instance. 74 * @usage: Usage id for this hub device instance.
75 * @start_collection_index: Starting index for a phy type collection 75 * @start_collection_index: Starting index for a phy type collection
76 * @end_collection_index: Last index for a phy type collection 76 * @end_collection_index: Last index for a phy type collection
77 * @mutex: synchronizing mutex. 77 * @mutex_ptr: synchronizing mutex pointer.
78 * @pending: Holds information of pending sync read request. 78 * @pending: Holds information of pending sync read request.
79 */ 79 */
80struct hid_sensor_hub_device { 80struct hid_sensor_hub_device {
@@ -84,7 +84,7 @@ struct hid_sensor_hub_device {
84 u32 usage; 84 u32 usage;
85 int start_collection_index; 85 int start_collection_index;
86 int end_collection_index; 86 int end_collection_index;
87 struct mutex mutex; 87 struct mutex *mutex_ptr;
88 struct sensor_hub_pending pending; 88 struct sensor_hub_pending pending;
89}; 89};
90 90
diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
index 36ec4ae74634..9de976b4f9a7 100644
--- a/include/linux/irqchip/arm-gic.h
+++ b/include/linux/irqchip/arm-gic.h
@@ -95,8 +95,6 @@
95 95
96struct device_node; 96struct device_node;
97 97
98extern struct irq_chip gic_arch_extn;
99
100void gic_set_irqchip_flags(unsigned long flags); 98void gic_set_irqchip_flags(unsigned long flags);
101void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *, 99void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
102 u32 offset, struct device_node *); 100 u32 offset, struct device_node *);
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index e60a745ac198..e804306ef5e8 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -40,6 +40,10 @@
40#error KEXEC_CONTROL_MEMORY_LIMIT not defined 40#error KEXEC_CONTROL_MEMORY_LIMIT not defined
41#endif 41#endif
42 42
43#ifndef KEXEC_CONTROL_MEMORY_GFP
44#define KEXEC_CONTROL_MEMORY_GFP GFP_KERNEL
45#endif
46
43#ifndef KEXEC_CONTROL_PAGE_SIZE 47#ifndef KEXEC_CONTROL_PAGE_SIZE
44#error KEXEC_CONTROL_PAGE_SIZE not defined 48#error KEXEC_CONTROL_PAGE_SIZE not defined
45#endif 49#endif
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index 5fc3d1083071..2b6a204bd8d4 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -166,19 +166,34 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2)
166} 166}
167 167
168#if BITS_PER_LONG < 64 168#if BITS_PER_LONG < 64
169extern u64 __ktime_divns(const ktime_t kt, s64 div); 169extern s64 __ktime_divns(const ktime_t kt, s64 div);
170static inline u64 ktime_divns(const ktime_t kt, s64 div) 170static inline s64 ktime_divns(const ktime_t kt, s64 div)
171{ 171{
172 /*
173 * Negative divisors could cause an inf loop,
174 * so bug out here.
175 */
176 BUG_ON(div < 0);
172 if (__builtin_constant_p(div) && !(div >> 32)) { 177 if (__builtin_constant_p(div) && !(div >> 32)) {
173 u64 ns = kt.tv64; 178 s64 ns = kt.tv64;
174 do_div(ns, div); 179 u64 tmp = ns < 0 ? -ns : ns;
175 return ns; 180
181 do_div(tmp, div);
182 return ns < 0 ? -tmp : tmp;
176 } else { 183 } else {
177 return __ktime_divns(kt, div); 184 return __ktime_divns(kt, div);
178 } 185 }
179} 186}
180#else /* BITS_PER_LONG < 64 */ 187#else /* BITS_PER_LONG < 64 */
181# define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) 188static inline s64 ktime_divns(const ktime_t kt, s64 div)
189{
190 /*
191 * 32-bit implementation cannot handle negative divisors,
192 * so catch them on 64bit as well.
193 */
194 WARN_ON(div < 0);
195 return kt.tv64 / div;
196}
182#endif 197#endif
183 198
184static inline s64 ktime_to_us(const ktime_t kt) 199static inline s64 ktime_to_us(const ktime_t kt)
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 8dad4a307bb8..28aeae46f355 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -205,6 +205,7 @@ enum {
205 ATA_LFLAG_SW_ACTIVITY = (1 << 7), /* keep activity stats */ 205 ATA_LFLAG_SW_ACTIVITY = (1 << 7), /* keep activity stats */
206 ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */ 206 ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */
207 ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */ 207 ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */
208 ATA_LFLAG_CHANGED = (1 << 10), /* LPM state changed on this link */
208 209
209 /* struct ata_port flags */ 210 /* struct ata_port flags */
210 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */ 211 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
@@ -309,6 +310,12 @@ enum {
309 */ 310 */
310 ATA_TMOUT_PMP_SRST_WAIT = 5000, 311 ATA_TMOUT_PMP_SRST_WAIT = 5000,
311 312
313 /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might
314 * be a spurious PHY event, so ignore the first PHY event that
315 * occurs within 10s after the policy change.
316 */
317 ATA_TMOUT_SPURIOUS_PHY = 10000,
318
312 /* ATA bus states */ 319 /* ATA bus states */
313 BUS_UNKNOWN = 0, 320 BUS_UNKNOWN = 0,
314 BUS_DMA = 1, 321 BUS_DMA = 1,
@@ -788,6 +795,8 @@ struct ata_link {
788 struct ata_eh_context eh_context; 795 struct ata_eh_context eh_context;
789 796
790 struct ata_device device[ATA_MAX_DEVICES]; 797 struct ata_device device[ATA_MAX_DEVICES];
798
799 unsigned long last_lpm_change; /* when last LPM change happened */
791}; 800};
792#define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag) 801#define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
793#define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0]) 802#define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
@@ -1201,6 +1210,7 @@ extern struct ata_device *ata_dev_pair(struct ata_device *adev);
1201extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev); 1210extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
1202extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap); 1211extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
1203extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q); 1212extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
1213extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
1204 1214
1205extern int ata_cable_40wire(struct ata_port *ap); 1215extern int ata_cable_40wire(struct ata_port *ap);
1206extern int ata_cable_80wire(struct ata_port *ap); 1216extern int ata_cable_80wire(struct ata_port *ap);
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 72dff5fb0d0c..6c8918114804 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -463,6 +463,8 @@ memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **memcg, int order)
463 if (!memcg_kmem_enabled()) 463 if (!memcg_kmem_enabled())
464 return true; 464 return true;
465 465
466 if (gfp & __GFP_NOACCOUNT)
467 return true;
466 /* 468 /*
467 * __GFP_NOFAIL allocations will move on even if charging is not 469 * __GFP_NOFAIL allocations will move on even if charging is not
468 * possible. Therefore we don't even try, and have this allocation 470 * possible. Therefore we don't even try, and have this allocation
@@ -522,6 +524,8 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)
522{ 524{
523 if (!memcg_kmem_enabled()) 525 if (!memcg_kmem_enabled())
524 return cachep; 526 return cachep;
527 if (gfp & __GFP_NOACCOUNT)
528 return cachep;
525 if (gfp & __GFP_NOFAIL) 529 if (gfp & __GFP_NOFAIL)
526 return cachep; 530 return cachep;
527 if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD)) 531 if (in_interrupt() || (!current->mm) || (current->flags & PF_KTHREAD))
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index bcbde799ec69..05b9a694e213 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -25,7 +25,6 @@
25#ifndef _LINUX_NETDEVICE_H 25#ifndef _LINUX_NETDEVICE_H
26#define _LINUX_NETDEVICE_H 26#define _LINUX_NETDEVICE_H
27 27
28#include <linux/pm_qos.h>
29#include <linux/timer.h> 28#include <linux/timer.h>
30#include <linux/bug.h> 29#include <linux/bug.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
@@ -60,6 +59,7 @@ struct phy_device;
60struct wireless_dev; 59struct wireless_dev;
61/* 802.15.4 specific */ 60/* 802.15.4 specific */
62struct wpan_dev; 61struct wpan_dev;
62struct mpls_dev;
63 63
64void netdev_set_default_ethtool_ops(struct net_device *dev, 64void netdev_set_default_ethtool_ops(struct net_device *dev,
65 const struct ethtool_ops *ops); 65 const struct ethtool_ops *ops);
@@ -976,7 +976,8 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
976 * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh, 976 * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
977 * u16 flags) 977 * u16 flags)
978 * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq, 978 * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
979 * struct net_device *dev, u32 filter_mask) 979 * struct net_device *dev, u32 filter_mask,
980 * int nlflags)
980 * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh, 981 * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
981 * u16 flags); 982 * u16 flags);
982 * 983 *
@@ -1172,7 +1173,8 @@ struct net_device_ops {
1172 int (*ndo_bridge_getlink)(struct sk_buff *skb, 1173 int (*ndo_bridge_getlink)(struct sk_buff *skb,
1173 u32 pid, u32 seq, 1174 u32 pid, u32 seq,
1174 struct net_device *dev, 1175 struct net_device *dev,
1175 u32 filter_mask); 1176 u32 filter_mask,
1177 int nlflags);
1176 int (*ndo_bridge_dellink)(struct net_device *dev, 1178 int (*ndo_bridge_dellink)(struct net_device *dev,
1177 struct nlmsghdr *nlh, 1179 struct nlmsghdr *nlh,
1178 u16 flags); 1180 u16 flags);
@@ -1496,8 +1498,6 @@ enum netdev_priv_flags {
1496 * 1498 *
1497 * @qdisc_tx_busylock: XXX: need comments on this one 1499 * @qdisc_tx_busylock: XXX: need comments on this one
1498 * 1500 *
1499 * @pm_qos_req: Power Management QoS object
1500 *
1501 * FIXME: cleanup struct net_device such that network protocol info 1501 * FIXME: cleanup struct net_device such that network protocol info
1502 * moves out. 1502 * moves out.
1503 */ 1503 */
@@ -1627,6 +1627,9 @@ struct net_device {
1627 void *ax25_ptr; 1627 void *ax25_ptr;
1628 struct wireless_dev *ieee80211_ptr; 1628 struct wireless_dev *ieee80211_ptr;
1629 struct wpan_dev *ieee802154_ptr; 1629 struct wpan_dev *ieee802154_ptr;
1630#if IS_ENABLED(CONFIG_MPLS_ROUTING)
1631 struct mpls_dev __rcu *mpls_ptr;
1632#endif
1630 1633
1631/* 1634/*
1632 * Cache lines mostly used on receive path (including eth_type_trans()) 1635 * Cache lines mostly used on receive path (including eth_type_trans())
@@ -2021,10 +2024,10 @@ struct pcpu_sw_netstats {
2021({ \ 2024({ \
2022 typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \ 2025 typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
2023 if (pcpu_stats) { \ 2026 if (pcpu_stats) { \
2024 int i; \ 2027 int __cpu; \
2025 for_each_possible_cpu(i) { \ 2028 for_each_possible_cpu(__cpu) { \
2026 typeof(type) *stat; \ 2029 typeof(type) *stat; \
2027 stat = per_cpu_ptr(pcpu_stats, i); \ 2030 stat = per_cpu_ptr(pcpu_stats, __cpu); \
2028 u64_stats_init(&stat->syncp); \ 2031 u64_stats_init(&stat->syncp); \
2029 } \ 2032 } \
2030 } \ 2033 } \
diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
index ab8f76dba668..f2fdb5a52070 100644
--- a/include/linux/netfilter_bridge.h
+++ b/include/linux/netfilter_bridge.h
@@ -39,12 +39,24 @@ static inline void br_drop_fake_rtable(struct sk_buff *skb)
39 39
40static inline int nf_bridge_get_physinif(const struct sk_buff *skb) 40static inline int nf_bridge_get_physinif(const struct sk_buff *skb)
41{ 41{
42 return skb->nf_bridge ? skb->nf_bridge->physindev->ifindex : 0; 42 struct nf_bridge_info *nf_bridge;
43
44 if (skb->nf_bridge == NULL)
45 return 0;
46
47 nf_bridge = skb->nf_bridge;
48 return nf_bridge->physindev ? nf_bridge->physindev->ifindex : 0;
43} 49}
44 50
45static inline int nf_bridge_get_physoutif(const struct sk_buff *skb) 51static inline int nf_bridge_get_physoutif(const struct sk_buff *skb)
46{ 52{
47 return skb->nf_bridge ? skb->nf_bridge->physoutdev->ifindex : 0; 53 struct nf_bridge_info *nf_bridge;
54
55 if (skb->nf_bridge == NULL)
56 return 0;
57
58 nf_bridge = skb->nf_bridge;
59 return nf_bridge->physoutdev ? nf_bridge->physoutdev->ifindex : 0;
48} 60}
49 61
50static inline struct net_device * 62static inline struct net_device *
diff --git a/include/linux/nilfs2_fs.h b/include/linux/nilfs2_fs.h
index ff3fea3194c6..9abb763e4b86 100644
--- a/include/linux/nilfs2_fs.h
+++ b/include/linux/nilfs2_fs.h
@@ -460,7 +460,7 @@ struct nilfs_btree_node {
460/* level */ 460/* level */
461#define NILFS_BTREE_LEVEL_DATA 0 461#define NILFS_BTREE_LEVEL_DATA 0
462#define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1) 462#define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
463#define NILFS_BTREE_LEVEL_MAX 14 463#define NILFS_BTREE_LEVEL_MAX 14 /* Max level (exclusive) */
464 464
465/** 465/**
466 * struct nilfs_palloc_group_desc - block group descriptor 466 * struct nilfs_palloc_group_desc - block group descriptor
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 38cff8f6716d..2f7b9a40f627 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2541,10 +2541,6 @@
2541 2541
2542#define PCI_VENDOR_ID_INTEL 0x8086 2542#define PCI_VENDOR_ID_INTEL 0x8086
2543#define PCI_DEVICE_ID_INTEL_EESSC 0x0008 2543#define PCI_DEVICE_ID_INTEL_EESSC 0x0008
2544#define PCI_DEVICE_ID_INTEL_SNB_IMC 0x0100
2545#define PCI_DEVICE_ID_INTEL_IVB_IMC 0x0154
2546#define PCI_DEVICE_ID_INTEL_IVB_E3_IMC 0x0150
2547#define PCI_DEVICE_ID_INTEL_HSW_IMC 0x0c00
2548#define PCI_DEVICE_ID_INTEL_PXHD_0 0x0320 2544#define PCI_DEVICE_ID_INTEL_PXHD_0 0x0320
2549#define PCI_DEVICE_ID_INTEL_PXHD_1 0x0321 2545#define PCI_DEVICE_ID_INTEL_PXHD_1 0x0321
2550#define PCI_DEVICE_ID_INTEL_PXH_0 0x0329 2546#define PCI_DEVICE_ID_INTEL_PXH_0 0x0329
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h
index 50e50095c8d1..84a109449610 100644
--- a/include/linux/percpu_counter.h
+++ b/include/linux/percpu_counter.h
@@ -41,7 +41,12 @@ void percpu_counter_destroy(struct percpu_counter *fbc);
41void percpu_counter_set(struct percpu_counter *fbc, s64 amount); 41void percpu_counter_set(struct percpu_counter *fbc, s64 amount);
42void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch); 42void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch);
43s64 __percpu_counter_sum(struct percpu_counter *fbc); 43s64 __percpu_counter_sum(struct percpu_counter *fbc);
44int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs); 44int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch);
45
46static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
47{
48 return __percpu_counter_compare(fbc, rhs, percpu_counter_batch);
49}
45 50
46static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount) 51static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)
47{ 52{
@@ -116,6 +121,12 @@ static inline int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
116 return 0; 121 return 0;
117} 122}
118 123
124static inline int
125__percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch)
126{
127 return percpu_counter_compare(fbc, rhs);
128}
129
119static inline void 130static inline void
120percpu_counter_add(struct percpu_counter *fbc, s64 amount) 131percpu_counter_add(struct percpu_counter *fbc, s64 amount)
121{ 132{
diff --git a/include/linux/platform_data/si5351.h b/include/linux/platform_data/si5351.h
index a947ab8b441a..533d9807e543 100644
--- a/include/linux/platform_data/si5351.h
+++ b/include/linux/platform_data/si5351.h
@@ -5,8 +5,6 @@
5#ifndef __LINUX_PLATFORM_DATA_SI5351_H__ 5#ifndef __LINUX_PLATFORM_DATA_SI5351_H__
6#define __LINUX_PLATFORM_DATA_SI5351_H__ 6#define __LINUX_PLATFORM_DATA_SI5351_H__
7 7
8struct clk;
9
10/** 8/**
11 * enum si5351_pll_src - Si5351 pll clock source 9 * enum si5351_pll_src - Si5351 pll clock source
12 * @SI5351_PLL_SRC_DEFAULT: default, do not change eeprom config 10 * @SI5351_PLL_SRC_DEFAULT: default, do not change eeprom config
@@ -107,8 +105,6 @@ struct si5351_clkout_config {
107 * @clkout: array of clkout configuration 105 * @clkout: array of clkout configuration
108 */ 106 */
109struct si5351_platform_data { 107struct si5351_platform_data {
110 struct clk *clk_xtal;
111 struct clk *clk_clkin;
112 enum si5351_pll_src pll_src[2]; 108 enum si5351_pll_src pll_src[2];
113 struct si5351_clkout_config clkout[8]; 109 struct si5351_clkout_config clkout[8];
114}; 110};
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index e23d242d1230..843ceca9a21e 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -17,6 +17,7 @@
17#ifndef _LINUX_RHASHTABLE_H 17#ifndef _LINUX_RHASHTABLE_H
18#define _LINUX_RHASHTABLE_H 18#define _LINUX_RHASHTABLE_H
19 19
20#include <linux/atomic.h>
20#include <linux/compiler.h> 21#include <linux/compiler.h>
21#include <linux/errno.h> 22#include <linux/errno.h>
22#include <linux/jhash.h> 23#include <linux/jhash.h>
@@ -100,6 +101,7 @@ struct rhashtable;
100 * @key_len: Length of key 101 * @key_len: Length of key
101 * @key_offset: Offset of key in struct to be hashed 102 * @key_offset: Offset of key in struct to be hashed
102 * @head_offset: Offset of rhash_head in struct to be hashed 103 * @head_offset: Offset of rhash_head in struct to be hashed
104 * @insecure_max_entries: Maximum number of entries (may be exceeded)
103 * @max_size: Maximum size while expanding 105 * @max_size: Maximum size while expanding
104 * @min_size: Minimum size while shrinking 106 * @min_size: Minimum size while shrinking
105 * @nulls_base: Base value to generate nulls marker 107 * @nulls_base: Base value to generate nulls marker
@@ -115,6 +117,7 @@ struct rhashtable_params {
115 size_t key_len; 117 size_t key_len;
116 size_t key_offset; 118 size_t key_offset;
117 size_t head_offset; 119 size_t head_offset;
120 unsigned int insecure_max_entries;
118 unsigned int max_size; 121 unsigned int max_size;
119 unsigned int min_size; 122 unsigned int min_size;
120 u32 nulls_base; 123 u32 nulls_base;
@@ -282,7 +285,20 @@ static inline bool rht_shrink_below_30(const struct rhashtable *ht,
282static inline bool rht_grow_above_100(const struct rhashtable *ht, 285static inline bool rht_grow_above_100(const struct rhashtable *ht,
283 const struct bucket_table *tbl) 286 const struct bucket_table *tbl)
284{ 287{
285 return atomic_read(&ht->nelems) > tbl->size; 288 return atomic_read(&ht->nelems) > tbl->size &&
289 (!ht->p.max_size || tbl->size < ht->p.max_size);
290}
291
292/**
293 * rht_grow_above_max - returns true if table is above maximum
294 * @ht: hash table
295 * @tbl: current table
296 */
297static inline bool rht_grow_above_max(const struct rhashtable *ht,
298 const struct bucket_table *tbl)
299{
300 return ht->p.insecure_max_entries &&
301 atomic_read(&ht->nelems) >= ht->p.insecure_max_entries;
286} 302}
287 303
288/* The bucket lock is selected based on the hash and protects mutations 304/* The bucket lock is selected based on the hash and protects mutations
@@ -588,6 +604,10 @@ restart:
588 goto out; 604 goto out;
589 } 605 }
590 606
607 err = -E2BIG;
608 if (unlikely(rht_grow_above_max(ht, tbl)))
609 goto out;
610
591 if (unlikely(rht_grow_above_100(ht, tbl))) { 611 if (unlikely(rht_grow_above_100(ht, tbl))) {
592slow_path: 612slow_path:
593 spin_unlock_bh(lock); 613 spin_unlock_bh(lock);
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 2da5d1081ad9..7b8e260c4a27 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -122,5 +122,5 @@ extern int ndo_dflt_fdb_del(struct ndmsg *ndm,
122 122
123extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 123extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
124 struct net_device *dev, u16 mode, 124 struct net_device *dev, u16 mode,
125 u32 flags, u32 mask); 125 u32 flags, u32 mask, int nlflags);
126#endif /* __LINUX_RTNETLINK_H */ 126#endif /* __LINUX_RTNETLINK_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8222ae40ecb0..26a2e6122734 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -175,14 +175,6 @@ extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load);
175extern void calc_global_load(unsigned long ticks); 175extern void calc_global_load(unsigned long ticks);
176extern void update_cpu_load_nohz(void); 176extern void update_cpu_load_nohz(void);
177 177
178/* Notifier for when a task gets migrated to a new CPU */
179struct task_migration_notifier {
180 struct task_struct *task;
181 int from_cpu;
182 int to_cpu;
183};
184extern void register_task_migration_notifier(struct notifier_block *n);
185
186extern unsigned long get_parent_ip(unsigned long addr); 178extern unsigned long get_parent_ip(unsigned long addr);
187 179
188extern void dump_cpu_task(int cpu); 180extern void dump_cpu_task(int cpu);
diff --git a/include/linux/sched/rt.h b/include/linux/sched/rt.h
index 6341f5be6e24..a30b172df6e1 100644
--- a/include/linux/sched/rt.h
+++ b/include/linux/sched/rt.h
@@ -18,7 +18,7 @@ static inline int rt_task(struct task_struct *p)
18#ifdef CONFIG_RT_MUTEXES 18#ifdef CONFIG_RT_MUTEXES
19extern int rt_mutex_getprio(struct task_struct *p); 19extern int rt_mutex_getprio(struct task_struct *p);
20extern void rt_mutex_setprio(struct task_struct *p, int prio); 20extern void rt_mutex_setprio(struct task_struct *p, int prio);
21extern int rt_mutex_check_prio(struct task_struct *task, int newprio); 21extern int rt_mutex_get_effective_prio(struct task_struct *task, int newprio);
22extern struct task_struct *rt_mutex_get_top_task(struct task_struct *task); 22extern struct task_struct *rt_mutex_get_top_task(struct task_struct *task);
23extern void rt_mutex_adjust_pi(struct task_struct *p); 23extern void rt_mutex_adjust_pi(struct task_struct *p);
24static inline bool tsk_is_pi_blocked(struct task_struct *tsk) 24static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
@@ -31,9 +31,10 @@ static inline int rt_mutex_getprio(struct task_struct *p)
31 return p->normal_prio; 31 return p->normal_prio;
32} 32}
33 33
34static inline int rt_mutex_check_prio(struct task_struct *task, int newprio) 34static inline int rt_mutex_get_effective_prio(struct task_struct *task,
35 int newprio)
35{ 36{
36 return 0; 37 return newprio;
37} 38}
38 39
39static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *task) 40static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 06793b598f44..f15154a879c7 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -176,6 +176,7 @@ struct nf_bridge_info {
176 struct net_device *physindev; 176 struct net_device *physindev;
177 struct net_device *physoutdev; 177 struct net_device *physoutdev;
178 char neigh_header[8]; 178 char neigh_header[8];
179 __be32 ipv4_daddr;
179}; 180};
180#endif 181#endif
181 182
@@ -773,6 +774,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
773 774
774struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags, 775struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
775 int node); 776 int node);
777struct sk_buff *__build_skb(void *data, unsigned int frag_size);
776struct sk_buff *build_skb(void *data, unsigned int frag_size); 778struct sk_buff *build_skb(void *data, unsigned int frag_size);
777static inline struct sk_buff *alloc_skb(unsigned int size, 779static inline struct sk_buff *alloc_skb(unsigned int size,
778 gfp_t priority) 780 gfp_t priority)
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 0caa3a2d4106..e8bbf403618f 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -145,11 +145,21 @@ struct tcp_sock {
145 * read the code and the spec side by side (and laugh ...) 145 * read the code and the spec side by side (and laugh ...)
146 * See RFC793 and RFC1122. The RFC writes these in capitals. 146 * See RFC793 and RFC1122. The RFC writes these in capitals.
147 */ 147 */
148 u64 bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived
149 * sum(delta(rcv_nxt)), or how many bytes
150 * were acked.
151 */
148 u32 rcv_nxt; /* What we want to receive next */ 152 u32 rcv_nxt; /* What we want to receive next */
149 u32 copied_seq; /* Head of yet unread data */ 153 u32 copied_seq; /* Head of yet unread data */
150 u32 rcv_wup; /* rcv_nxt on last window update sent */ 154 u32 rcv_wup; /* rcv_nxt on last window update sent */
151 u32 snd_nxt; /* Next sequence we send */ 155 u32 snd_nxt; /* Next sequence we send */
152 156
157 u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked
158 * sum(delta(snd_una)), or how many bytes
159 * were acked.
160 */
161 struct u64_stats_sync syncp; /* protects 64bit vars (cf tcp_get_info()) */
162
153 u32 snd_una; /* First byte we want an ack for */ 163 u32 snd_una; /* First byte we want an ack for */
154 u32 snd_sml; /* Last byte of the most recently transmitted small packet */ 164 u32 snd_sml; /* Last byte of the most recently transmitted small packet */
155 u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */ 165 u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 358a337af598..d76631f615c2 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -339,6 +339,7 @@ struct tty_file_private {
339#define TTY_EXCLUSIVE 3 /* Exclusive open mode */ 339#define TTY_EXCLUSIVE 3 /* Exclusive open mode */
340#define TTY_DEBUG 4 /* Debugging */ 340#define TTY_DEBUG 4 /* Debugging */
341#define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */ 341#define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */
342#define TTY_OTHER_DONE 6 /* Closed pty has completed input processing */
342#define TTY_LDISC_OPEN 11 /* Line discipline is open */ 343#define TTY_LDISC_OPEN 11 /* Line discipline is open */
343#define TTY_PTY_LOCK 16 /* pty private */ 344#define TTY_PTY_LOCK 16 /* pty private */
344#define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ 345#define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */
@@ -462,7 +463,6 @@ extern int tty_hung_up_p(struct file *filp);
462extern void do_SAK(struct tty_struct *tty); 463extern void do_SAK(struct tty_struct *tty);
463extern void __do_SAK(struct tty_struct *tty); 464extern void __do_SAK(struct tty_struct *tty);
464extern void no_tty(void); 465extern void no_tty(void);
465extern void tty_flush_to_ldisc(struct tty_struct *tty);
466extern void tty_buffer_free_all(struct tty_port *port); 466extern void tty_buffer_free_all(struct tty_port *port);
467extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld); 467extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld);
468extern void tty_buffer_init(struct tty_port *port); 468extern void tty_buffer_init(struct tty_port *port);
@@ -491,6 +491,7 @@ static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
491 491
492extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old); 492extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
493extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); 493extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b);
494extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
494 495
495extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); 496extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
496extern void tty_ldisc_deref(struct tty_ldisc *); 497extern void tty_ldisc_deref(struct tty_ldisc *);
diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
index 0ee05da38899..03835522dfcb 100644
--- a/include/linux/uidgid.h
+++ b/include/linux/uidgid.h
@@ -109,12 +109,12 @@ static inline bool gid_lte(kgid_t left, kgid_t right)
109 109
110static inline bool uid_valid(kuid_t uid) 110static inline bool uid_valid(kuid_t uid)
111{ 111{
112 return !uid_eq(uid, INVALID_UID); 112 return __kuid_val(uid) != (uid_t) -1;
113} 113}
114 114
115static inline bool gid_valid(kgid_t gid) 115static inline bool gid_valid(kgid_t gid)
116{ 116{
117 return !gid_eq(gid, INVALID_GID); 117 return __kgid_val(gid) != (gid_t) -1;
118} 118}
119 119
120#ifdef CONFIG_USER_NS 120#ifdef CONFIG_USER_NS
diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h
index a7f2604c5f25..7f5f78bd15ad 100644
--- a/include/linux/usb_usual.h
+++ b/include/linux/usb_usual.h
@@ -77,6 +77,8 @@
77 /* Cannot handle ATA_12 or ATA_16 CDBs */ \ 77 /* Cannot handle ATA_12 or ATA_16 CDBs */ \
78 US_FLAG(NO_REPORT_OPCODES, 0x04000000) \ 78 US_FLAG(NO_REPORT_OPCODES, 0x04000000) \
79 /* Cannot handle MI_REPORT_SUPPORTED_OPERATION_CODES */ \ 79 /* Cannot handle MI_REPORT_SUPPORTED_OPERATION_CODES */ \
80 US_FLAG(MAX_SECTORS_240, 0x08000000) \
81 /* Sets max_sectors to 240 */ \
80 82
81#define US_FLAG(name, value) US_FL_##name = value , 83#define US_FLAG(name, value) US_FL_##name = value ,
82enum { US_DO_ALL_FLAGS }; 84enum { US_DO_ALL_FLAGS };
diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h
index d5f4fb69dba3..f9b2ce58039b 100644
--- a/include/linux/util_macros.h
+++ b/include/linux/util_macros.h
@@ -5,7 +5,7 @@
5({ \ 5({ \
6 typeof(as) __fc_i, __fc_as = (as) - 1; \ 6 typeof(as) __fc_i, __fc_as = (as) - 1; \
7 typeof(x) __fc_x = (x); \ 7 typeof(x) __fc_x = (x); \
8 typeof(*a) *__fc_a = (a); \ 8 typeof(*a) const *__fc_a = (a); \
9 for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \ 9 for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \
10 if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] + \ 10 if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] + \
11 __fc_a[__fc_i + 1], 2)) \ 11 __fc_a[__fc_i + 1], 2)) \
diff --git a/include/net/bonding.h b/include/net/bonding.h
index fda6feeb6c1f..78ed135e9dea 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -30,13 +30,6 @@
30#include <net/bond_alb.h> 30#include <net/bond_alb.h>
31#include <net/bond_options.h> 31#include <net/bond_options.h>
32 32
33#define DRV_VERSION "3.7.1"
34#define DRV_RELDATE "April 27, 2011"
35#define DRV_NAME "bonding"
36#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
37
38#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
39
40#define BOND_MAX_ARP_TARGETS 16 33#define BOND_MAX_ARP_TARGETS 16
41 34
42#define BOND_DEFAULT_MIIMON 100 35#define BOND_DEFAULT_MIIMON 100
diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index eeda67652766..6ea16c84293b 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -30,11 +30,13 @@ struct wpan_phy_cca;
30struct cfg802154_ops { 30struct cfg802154_ops {
31 struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy, 31 struct net_device * (*add_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
32 const char *name, 32 const char *name,
33 unsigned char name_assign_type,
33 int type); 34 int type);
34 void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy, 35 void (*del_virtual_intf_deprecated)(struct wpan_phy *wpan_phy,
35 struct net_device *dev); 36 struct net_device *dev);
36 int (*add_virtual_intf)(struct wpan_phy *wpan_phy, 37 int (*add_virtual_intf)(struct wpan_phy *wpan_phy,
37 const char *name, 38 const char *name,
39 unsigned char name_assign_type,
38 enum nl802154_iftype type, 40 enum nl802154_iftype type,
39 __le64 extended_addr); 41 __le64 extended_addr);
40 int (*del_virtual_intf)(struct wpan_phy *wpan_phy, 42 int (*del_virtual_intf)(struct wpan_phy *wpan_phy,
diff --git a/include/net/codel.h b/include/net/codel.h
index aeee28081245..1e18005f7f65 100644
--- a/include/net/codel.h
+++ b/include/net/codel.h
@@ -120,11 +120,13 @@ static inline u32 codel_time_to_us(codel_time_t val)
120 * struct codel_params - contains codel parameters 120 * struct codel_params - contains codel parameters
121 * @target: target queue size (in time units) 121 * @target: target queue size (in time units)
122 * @interval: width of moving time window 122 * @interval: width of moving time window
123 * @mtu: device mtu, or minimal queue backlog in bytes.
123 * @ecn: is Explicit Congestion Notification enabled 124 * @ecn: is Explicit Congestion Notification enabled
124 */ 125 */
125struct codel_params { 126struct codel_params {
126 codel_time_t target; 127 codel_time_t target;
127 codel_time_t interval; 128 codel_time_t interval;
129 u32 mtu;
128 bool ecn; 130 bool ecn;
129}; 131};
130 132
@@ -166,10 +168,12 @@ struct codel_stats {
166 u32 ecn_mark; 168 u32 ecn_mark;
167}; 169};
168 170
169static void codel_params_init(struct codel_params *params) 171static void codel_params_init(struct codel_params *params,
172 const struct Qdisc *sch)
170{ 173{
171 params->interval = MS2TIME(100); 174 params->interval = MS2TIME(100);
172 params->target = MS2TIME(5); 175 params->target = MS2TIME(5);
176 params->mtu = psched_mtu(qdisc_dev(sch));
173 params->ecn = false; 177 params->ecn = false;
174} 178}
175 179
@@ -180,7 +184,7 @@ static void codel_vars_init(struct codel_vars *vars)
180 184
181static void codel_stats_init(struct codel_stats *stats) 185static void codel_stats_init(struct codel_stats *stats)
182{ 186{
183 stats->maxpacket = 256; 187 stats->maxpacket = 0;
184} 188}
185 189
186/* 190/*
@@ -234,7 +238,7 @@ static bool codel_should_drop(const struct sk_buff *skb,
234 stats->maxpacket = qdisc_pkt_len(skb); 238 stats->maxpacket = qdisc_pkt_len(skb);
235 239
236 if (codel_time_before(vars->ldelay, params->target) || 240 if (codel_time_before(vars->ldelay, params->target) ||
237 sch->qstats.backlog <= stats->maxpacket) { 241 sch->qstats.backlog <= params->mtu) {
238 /* went below - stay below for at least interval */ 242 /* went below - stay below for at least interval */
239 vars->first_above_time = 0; 243 vars->first_above_time = 0;
240 return false; 244 return false;
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 7b5887cd1172..497bc14cdb85 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -129,9 +129,10 @@ struct inet_connection_sock {
129 129
130 u32 probe_timestamp; 130 u32 probe_timestamp;
131 } icsk_mtup; 131 } icsk_mtup;
132 u32 icsk_ca_priv[16];
133 u32 icsk_user_timeout; 132 u32 icsk_user_timeout;
134#define ICSK_CA_PRIV_SIZE (16 * sizeof(u32)) 133
134 u64 icsk_ca_priv[64 / sizeof(u64)];
135#define ICSK_CA_PRIV_SIZE (8 * sizeof(u64))
135}; 136};
136 137
137#define ICSK_TIME_RETRANS 1 /* Retransmit timer */ 138#define ICSK_TIME_RETRANS 1 /* Retransmit timer */
@@ -279,12 +280,6 @@ static inline void inet_csk_reqsk_queue_add(struct sock *sk,
279void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, 280void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
280 unsigned long timeout); 281 unsigned long timeout);
281 282
282static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
283 struct request_sock *req)
284{
285 reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
286}
287
288static inline void inet_csk_reqsk_queue_added(struct sock *sk, 283static inline void inet_csk_reqsk_queue_added(struct sock *sk,
289 const unsigned long timeout) 284 const unsigned long timeout)
290{ 285{
@@ -306,19 +301,7 @@ static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
306 return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue); 301 return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
307} 302}
308 303
309static inline void inet_csk_reqsk_queue_unlink(struct sock *sk, 304void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
310 struct request_sock *req)
311{
312 reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req);
313}
314
315static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
316 struct request_sock *req)
317{
318 inet_csk_reqsk_queue_unlink(sk, req);
319 inet_csk_reqsk_queue_removed(sk, req);
320 reqsk_put(req);
321}
322 305
323void inet_csk_destroy_sock(struct sock *sk); 306void inet_csk_destroy_sock(struct sock *sk);
324void inet_csk_prepare_forced_close(struct sock *sk); 307void inet_csk_prepare_forced_close(struct sock *sk);
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index b4bef1152c05..8e3668b44c29 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1666,6 +1666,8 @@ struct ieee80211_tx_control {
1666 * @sta: station table entry, %NULL for per-vif queue 1666 * @sta: station table entry, %NULL for per-vif queue
1667 * @tid: the TID for this queue (unused for per-vif queue) 1667 * @tid: the TID for this queue (unused for per-vif queue)
1668 * @ac: the AC for this queue 1668 * @ac: the AC for this queue
1669 * @drv_priv: data area for driver use, will always be aligned to
1670 * sizeof(void *).
1669 * 1671 *
1670 * The driver can obtain packets from this queue by calling 1672 * The driver can obtain packets from this queue by calling
1671 * ieee80211_tx_dequeue(). 1673 * ieee80211_tx_dequeue().
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index e18e7fd43f47..7df28a4c23f9 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -247,19 +247,109 @@ static inline void ieee802154_le64_to_be64(void *be64_dst, const void *le64_src)
247 __put_unaligned_memmove64(swab64p(le64_src), be64_dst); 247 __put_unaligned_memmove64(swab64p(le64_src), be64_dst);
248} 248}
249 249
250/* Basic interface to register ieee802154 device */ 250/**
251 * ieee802154_alloc_hw - Allocate a new hardware device
252 *
253 * This must be called once for each hardware device. The returned pointer
254 * must be used to refer to this device when calling other functions.
255 * mac802154 allocates a private data area for the driver pointed to by
256 * @priv in &struct ieee802154_hw, the size of this area is given as
257 * @priv_data_len.
258 *
259 * @priv_data_len: length of private data
260 * @ops: callbacks for this device
261 *
262 * Return: A pointer to the new hardware device, or %NULL on error.
263 */
251struct ieee802154_hw * 264struct ieee802154_hw *
252ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops); 265ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops);
266
267/**
268 * ieee802154_free_hw - free hardware descriptor
269 *
270 * This function frees everything that was allocated, including the
271 * private data for the driver. You must call ieee802154_unregister_hw()
272 * before calling this function.
273 *
274 * @hw: the hardware to free
275 */
253void ieee802154_free_hw(struct ieee802154_hw *hw); 276void ieee802154_free_hw(struct ieee802154_hw *hw);
277
278/**
279 * ieee802154_register_hw - Register hardware device
280 *
281 * You must call this function before any other functions in
282 * mac802154. Note that before a hardware can be registered, you
283 * need to fill the contained wpan_phy's information.
284 *
285 * @hw: the device to register as returned by ieee802154_alloc_hw()
286 *
287 * Return: 0 on success. An error code otherwise.
288 */
254int ieee802154_register_hw(struct ieee802154_hw *hw); 289int ieee802154_register_hw(struct ieee802154_hw *hw);
290
291/**
292 * ieee802154_unregister_hw - Unregister a hardware device
293 *
294 * This function instructs mac802154 to free allocated resources
295 * and unregister netdevices from the networking subsystem.
296 *
297 * @hw: the hardware to unregister
298 */
255void ieee802154_unregister_hw(struct ieee802154_hw *hw); 299void ieee802154_unregister_hw(struct ieee802154_hw *hw);
256 300
301/**
302 * ieee802154_rx - receive frame
303 *
304 * Use this function to hand received frames to mac802154. The receive
305 * buffer in @skb must start with an IEEE 802.15.4 header. In case of a
306 * paged @skb is used, the driver is recommended to put the ieee802154
307 * header of the frame on the linear part of the @skb to avoid memory
308 * allocation and/or memcpy by the stack.
309 *
310 * This function may not be called in IRQ context. Calls to this function
311 * for a single hardware must be synchronized against each other.
312 *
313 * @hw: the hardware this frame came in on
314 * @skb: the buffer to receive, owned by mac802154 after this call
315 */
257void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb); 316void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb);
317
318/**
319 * ieee802154_rx_irqsafe - receive frame
320 *
321 * Like ieee802154_rx() but can be called in IRQ context
322 * (internally defers to a tasklet.)
323 *
324 * @hw: the hardware this frame came in on
325 * @skb: the buffer to receive, owned by mac802154 after this call
326 * @lqi: link quality indicator
327 */
258void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, 328void ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb,
259 u8 lqi); 329 u8 lqi);
260 330/**
331 * ieee802154_wake_queue - wake ieee802154 queue
332 * @hw: pointer as obtained from ieee802154_alloc_hw().
333 *
334 * Drivers should use this function instead of netif_wake_queue.
335 */
261void ieee802154_wake_queue(struct ieee802154_hw *hw); 336void ieee802154_wake_queue(struct ieee802154_hw *hw);
337
338/**
339 * ieee802154_stop_queue - stop ieee802154 queue
340 * @hw: pointer as obtained from ieee802154_alloc_hw().
341 *
342 * Drivers should use this function instead of netif_stop_queue.
343 */
262void ieee802154_stop_queue(struct ieee802154_hw *hw); 344void ieee802154_stop_queue(struct ieee802154_hw *hw);
345
346/**
347 * ieee802154_xmit_complete - frame transmission complete
348 *
349 * @hw: pointer as obtained from ieee802154_alloc_hw().
350 * @skb: buffer for transmission
351 * @ifs_handling: indicate interframe space handling
352 */
263void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb, 353void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
264 bool ifs_handling); 354 bool ifs_handling);
265 355
diff --git a/include/net/request_sock.h b/include/net/request_sock.h
index fe41f3ceb008..9f4265ce8892 100644
--- a/include/net/request_sock.h
+++ b/include/net/request_sock.h
@@ -212,24 +212,6 @@ static inline int reqsk_queue_empty(struct request_sock_queue *queue)
212 return queue->rskq_accept_head == NULL; 212 return queue->rskq_accept_head == NULL;
213} 213}
214 214
215static inline void reqsk_queue_unlink(struct request_sock_queue *queue,
216 struct request_sock *req)
217{
218 struct listen_sock *lopt = queue->listen_opt;
219 struct request_sock **prev;
220
221 spin_lock(&queue->syn_wait_lock);
222
223 prev = &lopt->syn_table[req->rsk_hash];
224 while (*prev != req)
225 prev = &(*prev)->dl_next;
226 *prev = req->dl_next;
227
228 spin_unlock(&queue->syn_wait_lock);
229 if (del_timer(&req->rsk_timer))
230 reqsk_put(req);
231}
232
233static inline void reqsk_queue_add(struct request_sock_queue *queue, 215static inline void reqsk_queue_add(struct request_sock_queue *queue,
234 struct request_sock *req, 216 struct request_sock *req,
235 struct sock *parent, 217 struct sock *parent,
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index c56a438c3a1e..ce13cf20f625 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -574,11 +574,14 @@ static inline void sctp_v6_map_v4(union sctp_addr *addr)
574/* Map v4 address to v4-mapped v6 address */ 574/* Map v4 address to v4-mapped v6 address */
575static inline void sctp_v4_map_v6(union sctp_addr *addr) 575static inline void sctp_v4_map_v6(union sctp_addr *addr)
576{ 576{
577 __be16 port;
578
579 port = addr->v4.sin_port;
580 addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
581 addr->v6.sin6_port = port;
577 addr->v6.sin6_family = AF_INET6; 582 addr->v6.sin6_family = AF_INET6;
578 addr->v6.sin6_flowinfo = 0; 583 addr->v6.sin6_flowinfo = 0;
579 addr->v6.sin6_scope_id = 0; 584 addr->v6.sin6_scope_id = 0;
580 addr->v6.sin6_port = addr->v4.sin_port;
581 addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
582 addr->v6.sin6_addr.s6_addr32[0] = 0; 585 addr->v6.sin6_addr.s6_addr32[0] = 0;
583 addr->v6.sin6_addr.s6_addr32[1] = 0; 586 addr->v6.sin6_addr.s6_addr32[1] = 0;
584 addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff); 587 addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 051dc5c2802d..6d204f3f9df8 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -576,7 +576,7 @@ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize)
576} 576}
577 577
578/* tcp.c */ 578/* tcp.c */
579void tcp_get_info(const struct sock *, struct tcp_info *); 579void tcp_get_info(struct sock *, struct tcp_info *);
580 580
581/* Read 'sendfile()'-style from a TCP socket */ 581/* Read 'sendfile()'-style from a TCP socket */
582typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *, 582typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *,
@@ -804,6 +804,8 @@ enum tcp_ca_ack_event_flags {
804/* Requires ECN/ECT set on all packets */ 804/* Requires ECN/ECT set on all packets */
805#define TCP_CONG_NEEDS_ECN 0x2 805#define TCP_CONG_NEEDS_ECN 0x2
806 806
807union tcp_cc_info;
808
807struct tcp_congestion_ops { 809struct tcp_congestion_ops {
808 struct list_head list; 810 struct list_head list;
809 u32 key; 811 u32 key;
@@ -829,7 +831,8 @@ struct tcp_congestion_ops {
829 /* hook for packet ack accounting (optional) */ 831 /* hook for packet ack accounting (optional) */
830 void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us); 832 void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us);
831 /* get info for inet_diag (optional) */ 833 /* get info for inet_diag (optional) */
832 int (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb); 834 size_t (*get_info)(struct sock *sk, u32 ext, int *attr,
835 union tcp_cc_info *info);
833 836
834 char name[TCP_CA_NAME_MAX]; 837 char name[TCP_CA_NAME_MAX];
835 struct module *owner; 838 struct module *owner;
diff --git a/include/rdma/ib_addr.h b/include/rdma/ib_addr.h
index ce55906b54a0..ac54c27a2bfd 100644
--- a/include/rdma/ib_addr.h
+++ b/include/rdma/ib_addr.h
@@ -160,7 +160,7 @@ static inline int rdma_ip2gid(struct sockaddr *addr, union ib_gid *gid)
160} 160}
161 161
162/* Important - sockaddr should be a union of sockaddr_in and sockaddr_in6 */ 162/* Important - sockaddr should be a union of sockaddr_in and sockaddr_in6 */
163static inline int rdma_gid2ip(struct sockaddr *out, union ib_gid *gid) 163static inline void rdma_gid2ip(struct sockaddr *out, union ib_gid *gid)
164{ 164{
165 if (ipv6_addr_v4mapped((struct in6_addr *)gid)) { 165 if (ipv6_addr_v4mapped((struct in6_addr *)gid)) {
166 struct sockaddr_in *out_in = (struct sockaddr_in *)out; 166 struct sockaddr_in *out_in = (struct sockaddr_in *)out;
@@ -173,7 +173,6 @@ static inline int rdma_gid2ip(struct sockaddr *out, union ib_gid *gid)
173 out_in->sin6_family = AF_INET6; 173 out_in->sin6_family = AF_INET6;
174 memcpy(&out_in->sin6_addr.s6_addr, gid->raw, 16); 174 memcpy(&out_in->sin6_addr.s6_addr, gid->raw, 16);
175 } 175 }
176 return 0;
177} 176}
178 177
179static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr, 178static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr,
diff --git a/include/rdma/ib_cm.h b/include/rdma/ib_cm.h
index 0e3ff30647d5..39ed2d2fbd51 100644
--- a/include/rdma/ib_cm.h
+++ b/include/rdma/ib_cm.h
@@ -105,7 +105,8 @@ enum ib_cm_data_size {
105 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216, 105 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
106 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136, 106 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
107 IB_CM_SIDR_REP_INFO_LENGTH = 72, 107 IB_CM_SIDR_REP_INFO_LENGTH = 72,
108 IB_CM_COMPARE_SIZE = 64 108 /* compare done u32 at a time */
109 IB_CM_COMPARE_SIZE = (64 / sizeof(u32))
109}; 110};
110 111
111struct ib_cm_id; 112struct ib_cm_id;
@@ -337,8 +338,8 @@ void ib_destroy_cm_id(struct ib_cm_id *cm_id);
337#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL) 338#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)
338 339
339struct ib_cm_compare_data { 340struct ib_cm_compare_data {
340 u8 data[IB_CM_COMPARE_SIZE]; 341 u32 data[IB_CM_COMPARE_SIZE];
341 u8 mask[IB_CM_COMPARE_SIZE]; 342 u32 mask[IB_CM_COMPARE_SIZE];
342}; 343};
343 344
344/** 345/**
diff --git a/include/rdma/iw_portmap.h b/include/rdma/iw_portmap.h
index 928b2775e992..fda31673a562 100644
--- a/include/rdma/iw_portmap.h
+++ b/include/rdma/iw_portmap.h
@@ -148,6 +148,16 @@ int iwpm_add_mapping_cb(struct sk_buff *, struct netlink_callback *);
148int iwpm_add_and_query_mapping_cb(struct sk_buff *, struct netlink_callback *); 148int iwpm_add_and_query_mapping_cb(struct sk_buff *, struct netlink_callback *);
149 149
150/** 150/**
151 * iwpm_remote_info_cb - Process remote connecting peer address info, which
152 * the port mapper has received from the connecting peer
153 *
154 * @cb: Contains the received message (payload and netlink header)
155 *
156 * Stores the IPv4/IPv6 address info in a hash table
157 */
158int iwpm_remote_info_cb(struct sk_buff *, struct netlink_callback *);
159
160/**
151 * iwpm_mapping_error_cb - Process port mapper notification for error 161 * iwpm_mapping_error_cb - Process port mapper notification for error
152 * 162 *
153 * @skb: 163 * @skb:
@@ -175,6 +185,21 @@ int iwpm_mapping_info_cb(struct sk_buff *, struct netlink_callback *);
175int iwpm_ack_mapping_info_cb(struct sk_buff *, struct netlink_callback *); 185int iwpm_ack_mapping_info_cb(struct sk_buff *, struct netlink_callback *);
176 186
177/** 187/**
188 * iwpm_get_remote_info - Get the remote connecting peer address info
189 *
190 * @mapped_loc_addr: Mapped local address of the listening peer
191 * @mapped_rem_addr: Mapped remote address of the connecting peer
192 * @remote_addr: To store the remote address of the connecting peer
193 * @nl_client: The index of the netlink client
194 *
195 * The remote address info is retrieved and provided to the client in
196 * the remote_addr. After that it is removed from the hash table
197 */
198int iwpm_get_remote_info(struct sockaddr_storage *mapped_loc_addr,
199 struct sockaddr_storage *mapped_rem_addr,
200 struct sockaddr_storage *remote_addr, u8 nl_client);
201
202/**
178 * iwpm_create_mapinfo - Store local and mapped IPv4/IPv6 address 203 * iwpm_create_mapinfo - Store local and mapped IPv4/IPv6 address
179 * info in a hash table 204 * info in a hash table
180 * @local_addr: Local ip/tcp address 205 * @local_addr: Local ip/tcp address
diff --git a/include/scsi/scsi_devinfo.h b/include/scsi/scsi_devinfo.h
index 183eaab7c380..96e3f56519e7 100644
--- a/include/scsi/scsi_devinfo.h
+++ b/include/scsi/scsi_devinfo.h
@@ -36,5 +36,6 @@
36 for sequential scan */ 36 for sequential scan */
37#define BLIST_TRY_VPD_PAGES 0x10000000 /* Attempt to read VPD pages */ 37#define BLIST_TRY_VPD_PAGES 0x10000000 /* Attempt to read VPD pages */
38#define BLIST_NO_RSOC 0x20000000 /* don't try to issue RSOC */ 38#define BLIST_NO_RSOC 0x20000000 /* don't try to issue RSOC */
39#define BLIST_MAX_1024 0x40000000 /* maximum 1024 sector cdb length */
39 40
40#endif 41#endif
diff --git a/include/sound/designware_i2s.h b/include/sound/designware_i2s.h
index 26f406e0f673..3a8fca9409a7 100644
--- a/include/sound/designware_i2s.h
+++ b/include/sound/designware_i2s.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (ST) 2012 Rajeev Kumar (rajeev-dlh.kumar@st.com) 2 * Copyright (ST) 2012 Rajeev Kumar (rajeevkumar.linux@gmail.com)
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h
index eb73a3a39ec2..f86ef5ea9b01 100644
--- a/include/sound/dmaengine_pcm.h
+++ b/include/sound/dmaengine_pcm.h
@@ -91,11 +91,6 @@ void snd_dmaengine_pcm_set_config_from_dai_data(
91 */ 91 */
92#define SND_DMAENGINE_PCM_FLAG_NO_DT BIT(1) 92#define SND_DMAENGINE_PCM_FLAG_NO_DT BIT(1)
93/* 93/*
94 * The platforms dmaengine driver does not support reporting the amount of
95 * bytes that are still left to transfer.
96 */
97#define SND_DMAENGINE_PCM_FLAG_NO_RESIDUE BIT(2)
98/*
99 * The PCM is half duplex and the DMA channel is shared between capture and 94 * The PCM is half duplex and the DMA channel is shared between capture and
100 * playback. 95 * playback.
101 */ 96 */
diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h
index 0de95ccb92cf..5bd134651f5e 100644
--- a/include/sound/emu10k1.h
+++ b/include/sound/emu10k1.h
@@ -41,7 +41,8 @@
41 41
42#define EMUPAGESIZE 4096 42#define EMUPAGESIZE 4096
43#define MAXREQVOICES 8 43#define MAXREQVOICES 8
44#define MAXPAGES 8192 44#define MAXPAGES0 4096 /* 32 bit mode */
45#define MAXPAGES1 8192 /* 31 bit mode */
45#define RESERVED 0 46#define RESERVED 0
46#define NUM_MIDI 16 47#define NUM_MIDI 16
47#define NUM_G 64 /* use all channels */ 48#define NUM_G 64 /* use all channels */
@@ -50,8 +51,7 @@
50 51
51/* FIXME? - according to the OSS driver the EMU10K1 needs a 29 bit DMA mask */ 52/* FIXME? - according to the OSS driver the EMU10K1 needs a 29 bit DMA mask */
52#define EMU10K1_DMA_MASK 0x7fffffffUL /* 31bit */ 53#define EMU10K1_DMA_MASK 0x7fffffffUL /* 31bit */
53#define AUDIGY_DMA_MASK 0x7fffffffUL /* 31bit FIXME - 32 should work? */ 54#define AUDIGY_DMA_MASK 0xffffffffUL /* 32bit mode */
54 /* See ALSA bug #1276 - rlrevell */
55 55
56#define TMEMSIZE 256*1024 56#define TMEMSIZE 256*1024
57#define TMEMSIZEREG 4 57#define TMEMSIZEREG 4
@@ -466,8 +466,11 @@
466 466
467#define MAPB 0x0d /* Cache map B */ 467#define MAPB 0x0d /* Cache map B */
468 468
469#define MAP_PTE_MASK 0xffffe000 /* The 19 MSBs of the PTE indexed by the PTI */ 469#define MAP_PTE_MASK0 0xfffff000 /* The 20 MSBs of the PTE indexed by the PTI */
470#define MAP_PTI_MASK 0x00001fff /* The 13 bit index to one of the 8192 PTE dwords */ 470#define MAP_PTI_MASK0 0x00000fff /* The 12 bit index to one of the 4096 PTE dwords */
471
472#define MAP_PTE_MASK1 0xffffe000 /* The 19 MSBs of the PTE indexed by the PTI */
473#define MAP_PTI_MASK1 0x00001fff /* The 13 bit index to one of the 8192 PTE dwords */
471 474
472/* 0x0e, 0x0f: Not used */ 475/* 0x0e, 0x0f: Not used */
473 476
@@ -1704,6 +1707,7 @@ struct snd_emu10k1 {
1704 unsigned short model; /* subsystem id */ 1707 unsigned short model; /* subsystem id */
1705 unsigned int card_type; /* EMU10K1_CARD_* */ 1708 unsigned int card_type; /* EMU10K1_CARD_* */
1706 unsigned int ecard_ctrl; /* ecard control bits */ 1709 unsigned int ecard_ctrl; /* ecard control bits */
1710 unsigned int address_mode; /* address mode */
1707 unsigned long dma_mask; /* PCI DMA mask */ 1711 unsigned long dma_mask; /* PCI DMA mask */
1708 unsigned int delay_pcm_irq; /* in samples */ 1712 unsigned int delay_pcm_irq; /* in samples */
1709 int max_cache_pages; /* max memory size / PAGE_SIZE */ 1713 int max_cache_pages; /* max memory size / PAGE_SIZE */
diff --git a/include/sound/rt5645.h b/include/sound/rt5645.h
index 120d9610054e..652cb9e4afe5 100644
--- a/include/sound/rt5645.h
+++ b/include/sound/rt5645.h
@@ -15,7 +15,6 @@ struct rt5645_platform_data {
15 /* IN2 can optionally be differential */ 15 /* IN2 can optionally be differential */
16 bool in2_diff; 16 bool in2_diff;
17 17
18 bool dmic_en;
19 unsigned int dmic1_data_pin; 18 unsigned int dmic1_data_pin;
20 /* 0 = IN2N; 1 = GPIO5; 2 = GPIO11 */ 19 /* 0 = IN2N; 1 = GPIO5; 2 = GPIO11 */
21 unsigned int dmic2_data_pin; 20 unsigned int dmic2_data_pin;
@@ -24,8 +23,6 @@ struct rt5645_platform_data {
24 unsigned int hp_det_gpio; 23 unsigned int hp_det_gpio;
25 bool gpio_hp_det_active_high; 24 bool gpio_hp_det_active_high;
26 25
27 /* true if codec's jd function is used */
28 bool en_jd_func;
29 unsigned int jd_mode; 26 unsigned int jd_mode;
30}; 27};
31 28
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 0bc83647d3fa..2f66e1c27f50 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -107,6 +107,10 @@ struct device;
107{ .id = snd_soc_dapm_mux, .name = wname, \ 107{ .id = snd_soc_dapm_mux, .name = wname, \
108 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ 108 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
109 .kcontrol_news = wcontrols, .num_kcontrols = 1} 109 .kcontrol_news = wcontrols, .num_kcontrols = 1}
110#define SND_SOC_DAPM_DEMUX(wname, wreg, wshift, winvert, wcontrols) \
111{ .id = snd_soc_dapm_demux, .name = wname, \
112 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
113 .kcontrol_news = wcontrols, .num_kcontrols = 1}
110 114
111/* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */ 115/* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
112#define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\ 116#define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\
@@ -287,7 +291,7 @@ struct device;
287 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 291 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,\
288 .tlv.p = (tlv_array), \ 292 .tlv.p = (tlv_array), \
289 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \ 293 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw, \
290 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) } 294 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 1) }
291#define SOC_DAPM_SINGLE_TLV_VIRT(xname, max, tlv_array) \ 295#define SOC_DAPM_SINGLE_TLV_VIRT(xname, max, tlv_array) \
292 SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0, tlv_array) 296 SOC_DAPM_SINGLE(xname, SND_SOC_NOPM, 0, max, 0, tlv_array)
293#define SOC_DAPM_ENUM(xname, xenum) \ 297#define SOC_DAPM_ENUM(xname, xenum) \
@@ -444,11 +448,15 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
444struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( 448struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm(
445 struct snd_kcontrol *kcontrol); 449 struct snd_kcontrol *kcontrol);
446 450
451int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm,
452 enum snd_soc_bias_level level);
453
447/* dapm widget types */ 454/* dapm widget types */
448enum snd_soc_dapm_type { 455enum snd_soc_dapm_type {
449 snd_soc_dapm_input = 0, /* input pin */ 456 snd_soc_dapm_input = 0, /* input pin */
450 snd_soc_dapm_output, /* output pin */ 457 snd_soc_dapm_output, /* output pin */
451 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */ 458 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
459 snd_soc_dapm_demux, /* connects the input to one of multiple outputs */
452 snd_soc_dapm_mixer, /* mixes several analog signals together */ 460 snd_soc_dapm_mixer, /* mixes several analog signals together */
453 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */ 461 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
454 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */ 462 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
@@ -585,6 +593,10 @@ struct snd_soc_dapm_update {
585 int val; 593 int val;
586}; 594};
587 595
596struct snd_soc_dapm_wcache {
597 struct snd_soc_dapm_widget *widget;
598};
599
588/* DAPM context */ 600/* DAPM context */
589struct snd_soc_dapm_context { 601struct snd_soc_dapm_context {
590 enum snd_soc_bias_level bias_level; 602 enum snd_soc_bias_level bias_level;
@@ -606,6 +618,9 @@ struct snd_soc_dapm_context {
606 int (*set_bias_level)(struct snd_soc_dapm_context *dapm, 618 int (*set_bias_level)(struct snd_soc_dapm_context *dapm,
607 enum snd_soc_bias_level level); 619 enum snd_soc_bias_level level);
608 620
621 struct snd_soc_dapm_wcache path_sink_cache;
622 struct snd_soc_dapm_wcache path_source_cache;
623
609#ifdef CONFIG_DEBUG_FS 624#ifdef CONFIG_DEBUG_FS
610 struct dentry *debugfs_dapm; 625 struct dentry *debugfs_dapm;
611#endif 626#endif
@@ -623,4 +638,35 @@ struct snd_soc_dapm_stats {
623 int neighbour_checks; 638 int neighbour_checks;
624}; 639};
625 640
641/**
642 * snd_soc_dapm_init_bias_level() - Initialize DAPM bias level
643 * @dapm: The DAPM context to initialize
644 * @level: The DAPM level to initialize to
645 *
646 * This function only sets the driver internal state of the DAPM level and will
647 * not modify the state of the device. Hence it should not be used during normal
648 * operation, but only to synchronize the internal state to the device state.
649 * E.g. during driver probe to set the DAPM level to the one corresponding with
650 * the power-on reset state of the device.
651 *
652 * To change the DAPM state of the device use snd_soc_dapm_set_bias_level().
653 */
654static inline void snd_soc_dapm_init_bias_level(
655 struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
656{
657 dapm->bias_level = level;
658}
659
660/**
661 * snd_soc_dapm_get_bias_level() - Get current DAPM bias level
662 * @dapm: The context for which to get the bias level
663 *
664 * Returns: The current bias level of the passed DAPM context.
665 */
666static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(
667 struct snd_soc_dapm_context *dapm)
668{
669 return dapm->bias_level;
670}
671
626#endif 672#endif
diff --git a/include/sound/soc.h b/include/sound/soc.h
index fcb312b3f258..f10f48fad5d5 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -190,8 +190,12 @@
190#define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \ 190#define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
191{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 191{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
192 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues} 192 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
193#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xnitmes, xtexts, xvalues) \ 193#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
194 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xnitmes, xtexts, xvalues) 194 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
195#define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
196{ .reg = xreg, .shift_l = xshift, .shift_r = xshift, \
197 .mask = xmask, .items = xitems, .texts = xtexts, \
198 .values = xvalues, .autodisable = 1}
195#define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \ 199#define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
196 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts) 200 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
197#define SOC_ENUM(xname, xenum) \ 201#define SOC_ENUM(xname, xenum) \
@@ -312,6 +316,11 @@
312 ARRAY_SIZE(xtexts), xtexts, xvalues) 316 ARRAY_SIZE(xtexts), xtexts, xvalues)
313#define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \ 317#define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
314 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues) 318 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
319
320#define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
321 const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
322 xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
323
315#define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \ 324#define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
316 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts) 325 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
317 326
@@ -387,8 +396,20 @@ int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
387int snd_soc_register_card(struct snd_soc_card *card); 396int snd_soc_register_card(struct snd_soc_card *card);
388int snd_soc_unregister_card(struct snd_soc_card *card); 397int snd_soc_unregister_card(struct snd_soc_card *card);
389int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card); 398int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
399#ifdef CONFIG_PM_SLEEP
390int snd_soc_suspend(struct device *dev); 400int snd_soc_suspend(struct device *dev);
391int snd_soc_resume(struct device *dev); 401int snd_soc_resume(struct device *dev);
402#else
403static inline int snd_soc_suspend(struct device *dev)
404{
405 return 0;
406}
407
408static inline int snd_soc_resume(struct device *dev)
409{
410 return 0;
411}
412#endif
392int snd_soc_poweroff(struct device *dev); 413int snd_soc_poweroff(struct device *dev);
393int snd_soc_register_platform(struct device *dev, 414int snd_soc_register_platform(struct device *dev,
394 const struct snd_soc_platform_driver *platform_drv); 415 const struct snd_soc_platform_driver *platform_drv);
@@ -807,7 +828,7 @@ struct snd_soc_codec {
807 /* component */ 828 /* component */
808 struct snd_soc_component component; 829 struct snd_soc_component component;
809 830
810 /* dapm */ 831 /* Don't access this directly, use snd_soc_codec_get_dapm() */
811 struct snd_soc_dapm_context dapm; 832 struct snd_soc_dapm_context dapm;
812 833
813#ifdef CONFIG_DEBUG_FS 834#ifdef CONFIG_DEBUG_FS
@@ -949,6 +970,24 @@ struct snd_soc_dai_link {
949 970
950 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */ 971 enum snd_soc_dpcm_trigger trigger[2]; /* trigger type for DPCM */
951 972
973 /* codec/machine specific init - e.g. add machine controls */
974 int (*init)(struct snd_soc_pcm_runtime *rtd);
975
976 /* optional hw_params re-writing for BE and FE sync */
977 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
978 struct snd_pcm_hw_params *params);
979
980 /* machine stream operations */
981 const struct snd_soc_ops *ops;
982 const struct snd_soc_compr_ops *compr_ops;
983
984 /* For unidirectional dai links */
985 bool playback_only;
986 bool capture_only;
987
988 /* Mark this pcm with non atomic ops */
989 bool nonatomic;
990
952 /* Keep DAI active over suspend */ 991 /* Keep DAI active over suspend */
953 unsigned int ignore_suspend:1; 992 unsigned int ignore_suspend:1;
954 993
@@ -957,9 +996,6 @@ struct snd_soc_dai_link {
957 unsigned int symmetric_channels:1; 996 unsigned int symmetric_channels:1;
958 unsigned int symmetric_samplebits:1; 997 unsigned int symmetric_samplebits:1;
959 998
960 /* Mark this pcm with non atomic ops */
961 bool nonatomic;
962
963 /* Do not create a PCM for this DAI link (Backend link) */ 999 /* Do not create a PCM for this DAI link (Backend link) */
964 unsigned int no_pcm:1; 1000 unsigned int no_pcm:1;
965 1001
@@ -970,23 +1006,11 @@ struct snd_soc_dai_link {
970 unsigned int dpcm_capture:1; 1006 unsigned int dpcm_capture:1;
971 unsigned int dpcm_playback:1; 1007 unsigned int dpcm_playback:1;
972 1008
1009 /* DPCM used FE & BE merged format */
1010 unsigned int dpcm_merged_format:1;
1011
973 /* pmdown_time is ignored at stop */ 1012 /* pmdown_time is ignored at stop */
974 unsigned int ignore_pmdown_time:1; 1013 unsigned int ignore_pmdown_time:1;
975
976 /* codec/machine specific init - e.g. add machine controls */
977 int (*init)(struct snd_soc_pcm_runtime *rtd);
978
979 /* optional hw_params re-writing for BE and FE sync */
980 int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
981 struct snd_pcm_hw_params *params);
982
983 /* machine stream operations */
984 const struct snd_soc_ops *ops;
985 const struct snd_soc_compr_ops *compr_ops;
986
987 /* For unidirectional dai links */
988 bool playback_only;
989 bool capture_only;
990}; 1014};
991 1015
992struct snd_soc_codec_conf { 1016struct snd_soc_codec_conf {
@@ -1188,6 +1212,7 @@ struct soc_enum {
1188 unsigned int mask; 1212 unsigned int mask;
1189 const char * const *texts; 1213 const char * const *texts;
1190 const unsigned int *values; 1214 const unsigned int *values;
1215 unsigned int autodisable:1;
1191}; 1216};
1192 1217
1193/** 1218/**
@@ -1270,6 +1295,58 @@ static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
1270} 1295}
1271 1296
1272/** 1297/**
1298 * snd_soc_codec_get_dapm() - Returns the DAPM context for the CODEC
1299 * @codec: The CODEC for which to get the DAPM context
1300 *
1301 * Note: Use this function instead of directly accessing the CODEC's dapm field
1302 */
1303static inline struct snd_soc_dapm_context *snd_soc_codec_get_dapm(
1304 struct snd_soc_codec *codec)
1305{
1306 return &codec->dapm;
1307}
1308
1309/**
1310 * snd_soc_dapm_init_bias_level() - Initialize CODEC DAPM bias level
1311 * @dapm: The CODEC for which to initialize the DAPM bias level
1312 * @level: The DAPM level to initialize to
1313 *
1314 * Initializes the CODEC DAPM bias level. See snd_soc_dapm_init_bias_level().
1315 */
1316static inline void snd_soc_codec_init_bias_level(struct snd_soc_codec *codec,
1317 enum snd_soc_bias_level level)
1318{
1319 snd_soc_dapm_init_bias_level(snd_soc_codec_get_dapm(codec), level);
1320}
1321
1322/**
1323 * snd_soc_dapm_get_bias_level() - Get current CODEC DAPM bias level
1324 * @codec: The CODEC for which to get the DAPM bias level
1325 *
1326 * Returns: The current DAPM bias level of the CODEC.
1327 */
1328static inline enum snd_soc_bias_level snd_soc_codec_get_bias_level(
1329 struct snd_soc_codec *codec)
1330{
1331 return snd_soc_dapm_get_bias_level(snd_soc_codec_get_dapm(codec));
1332}
1333
1334/**
1335 * snd_soc_codec_force_bias_level() - Set the CODEC DAPM bias level
1336 * @codec: The CODEC for which to set the level
1337 * @level: The level to set to
1338 *
1339 * Forces the CODEC bias level to a specific state. See
1340 * snd_soc_dapm_force_bias_level().
1341 */
1342static inline int snd_soc_codec_force_bias_level(struct snd_soc_codec *codec,
1343 enum snd_soc_bias_level level)
1344{
1345 return snd_soc_dapm_force_bias_level(snd_soc_codec_get_dapm(codec),
1346 level);
1347}
1348
1349/**
1273 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol 1350 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
1274 * @kcontrol: The kcontrol 1351 * @kcontrol: The kcontrol
1275 * 1352 *
diff --git a/include/sound/spear_dma.h b/include/sound/spear_dma.h
index 65aca51fe255..e290de4e7e82 100644
--- a/include/sound/spear_dma.h
+++ b/include/sound/spear_dma.h
@@ -1,7 +1,7 @@
1/* 1/*
2* linux/spear_dma.h 2* linux/spear_dma.h
3* 3*
4* Copyright (ST) 2012 Rajeev Kumar (rajeev-dlh.kumar@st.com) 4* Copyright (ST) 2012 Rajeev Kumar (rajeevkumar.linux@gmail.com)
5* 5*
6* This program is free software; you can redistribute it and/or modify 6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by 7* it under the terms of the GNU General Public License as published by
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index d61be7297b2c..5f1225706993 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -1,9 +1,7 @@
1#ifndef TARGET_CORE_BACKEND_H 1#ifndef TARGET_CORE_BACKEND_H
2#define TARGET_CORE_BACKEND_H 2#define TARGET_CORE_BACKEND_H
3 3
4#define TRANSPORT_PLUGIN_PHBA_PDEV 1 4#define TRANSPORT_FLAG_PASSTHROUGH 1
5#define TRANSPORT_PLUGIN_VHBA_PDEV 2
6#define TRANSPORT_PLUGIN_VHBA_VDEV 3
7 5
8struct target_backend_cits { 6struct target_backend_cits {
9 struct config_item_type tb_dev_cit; 7 struct config_item_type tb_dev_cit;
@@ -22,7 +20,7 @@ struct se_subsystem_api {
22 char inquiry_rev[4]; 20 char inquiry_rev[4];
23 struct module *owner; 21 struct module *owner;
24 22
25 u8 transport_type; 23 u8 transport_flags;
26 24
27 int (*attach_hba)(struct se_hba *, u32); 25 int (*attach_hba)(struct se_hba *, u32);
28 void (*detach_hba)(struct se_hba *); 26 void (*detach_hba)(struct se_hba *);
@@ -138,5 +136,7 @@ int se_dev_set_queue_depth(struct se_device *, u32);
138int se_dev_set_max_sectors(struct se_device *, u32); 136int se_dev_set_max_sectors(struct se_device *, u32);
139int se_dev_set_optimal_sectors(struct se_device *, u32); 137int se_dev_set_optimal_sectors(struct se_device *, u32);
140int se_dev_set_block_size(struct se_device *, u32); 138int se_dev_set_block_size(struct se_device *, u32);
139sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd,
140 sense_reason_t (*exec_cmd)(struct se_cmd *cmd));
141 141
142#endif /* TARGET_CORE_BACKEND_H */ 142#endif /* TARGET_CORE_BACKEND_H */
diff --git a/include/target/target_core_configfs.h b/include/target/target_core_configfs.h
index 25bb04c4209e..b99c01170392 100644
--- a/include/target/target_core_configfs.h
+++ b/include/target/target_core_configfs.h
@@ -40,8 +40,6 @@ struct target_fabric_configfs {
40 struct config_item *tf_fabric; 40 struct config_item *tf_fabric;
41 /* Passed from fabric modules */ 41 /* Passed from fabric modules */
42 struct config_item_type *tf_fabric_cit; 42 struct config_item_type *tf_fabric_cit;
43 /* Pointer to target core subsystem */
44 struct configfs_subsystem *tf_subsys;
45 /* Pointer to fabric's struct module */ 43 /* Pointer to fabric's struct module */
46 struct module *tf_module; 44 struct module *tf_module;
47 struct target_core_fabric_ops tf_ops; 45 struct target_core_fabric_ops tf_ops;
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h
index 17c7f5ac7ea0..0f4dc3768587 100644
--- a/include/target/target_core_fabric.h
+++ b/include/target/target_core_fabric.h
@@ -4,7 +4,6 @@
4struct target_core_fabric_ops { 4struct target_core_fabric_ops {
5 struct module *module; 5 struct module *module;
6 const char *name; 6 const char *name;
7 struct configfs_subsystem *tf_subsys;
8 char *(*get_fabric_name)(void); 7 char *(*get_fabric_name)(void);
9 u8 (*get_fabric_proto_ident)(struct se_portal_group *); 8 u8 (*get_fabric_proto_ident)(struct se_portal_group *);
10 char *(*tpg_get_wwn)(struct se_portal_group *); 9 char *(*tpg_get_wwn)(struct se_portal_group *);
@@ -109,6 +108,9 @@ struct target_core_fabric_ops {
109int target_register_template(const struct target_core_fabric_ops *fo); 108int target_register_template(const struct target_core_fabric_ops *fo);
110void target_unregister_template(const struct target_core_fabric_ops *fo); 109void target_unregister_template(const struct target_core_fabric_ops *fo);
111 110
111int target_depend_item(struct config_item *item);
112void target_undepend_item(struct config_item *item);
113
112struct se_session *transport_init_session(enum target_prot_op); 114struct se_session *transport_init_session(enum target_prot_op);
113int transport_alloc_session_tags(struct se_session *, unsigned int, 115int transport_alloc_session_tags(struct se_session *, unsigned int,
114 unsigned int); 116 unsigned int);
diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h
index 81ea59812117..f7554fd7fc62 100644
--- a/include/trace/events/kmem.h
+++ b/include/trace/events/kmem.h
@@ -140,19 +140,42 @@ DEFINE_EVENT(kmem_free, kfree,
140 TP_ARGS(call_site, ptr) 140 TP_ARGS(call_site, ptr)
141); 141);
142 142
143DEFINE_EVENT(kmem_free, kmem_cache_free, 143DEFINE_EVENT_CONDITION(kmem_free, kmem_cache_free,
144 144
145 TP_PROTO(unsigned long call_site, const void *ptr), 145 TP_PROTO(unsigned long call_site, const void *ptr),
146 146
147 TP_ARGS(call_site, ptr) 147 TP_ARGS(call_site, ptr),
148
149 /*
150 * This trace can be potentially called from an offlined cpu.
151 * Since trace points use RCU and RCU should not be used from
152 * offline cpus, filter such calls out.
153 * While this trace can be called from a preemptable section,
154 * it has no impact on the condition since tasks can migrate
155 * only from online cpus to other online cpus. Thus its safe
156 * to use raw_smp_processor_id.
157 */
158 TP_CONDITION(cpu_online(raw_smp_processor_id()))
148); 159);
149 160
150TRACE_EVENT(mm_page_free, 161TRACE_EVENT_CONDITION(mm_page_free,
151 162
152 TP_PROTO(struct page *page, unsigned int order), 163 TP_PROTO(struct page *page, unsigned int order),
153 164
154 TP_ARGS(page, order), 165 TP_ARGS(page, order),
155 166
167
168 /*
169 * This trace can be potentially called from an offlined cpu.
170 * Since trace points use RCU and RCU should not be used from
171 * offline cpus, filter such calls out.
172 * While this trace can be called from a preemptable section,
173 * it has no impact on the condition since tasks can migrate
174 * only from online cpus to other online cpus. Thus its safe
175 * to use raw_smp_processor_id.
176 */
177 TP_CONDITION(cpu_online(raw_smp_processor_id())),
178
156 TP_STRUCT__entry( 179 TP_STRUCT__entry(
157 __field( unsigned long, pfn ) 180 __field( unsigned long, pfn )
158 __field( unsigned int, order ) 181 __field( unsigned int, order )
@@ -253,12 +276,35 @@ DEFINE_EVENT(mm_page, mm_page_alloc_zone_locked,
253 TP_ARGS(page, order, migratetype) 276 TP_ARGS(page, order, migratetype)
254); 277);
255 278
256DEFINE_EVENT_PRINT(mm_page, mm_page_pcpu_drain, 279TRACE_EVENT_CONDITION(mm_page_pcpu_drain,
257 280
258 TP_PROTO(struct page *page, unsigned int order, int migratetype), 281 TP_PROTO(struct page *page, unsigned int order, int migratetype),
259 282
260 TP_ARGS(page, order, migratetype), 283 TP_ARGS(page, order, migratetype),
261 284
285 /*
286 * This trace can be potentially called from an offlined cpu.
287 * Since trace points use RCU and RCU should not be used from
288 * offline cpus, filter such calls out.
289 * While this trace can be called from a preemptable section,
290 * it has no impact on the condition since tasks can migrate
291 * only from online cpus to other online cpus. Thus its safe
292 * to use raw_smp_processor_id.
293 */
294 TP_CONDITION(cpu_online(raw_smp_processor_id())),
295
296 TP_STRUCT__entry(
297 __field( unsigned long, pfn )
298 __field( unsigned int, order )
299 __field( int, migratetype )
300 ),
301
302 TP_fast_assign(
303 __entry->pfn = page ? page_to_pfn(page) : -1UL;
304 __entry->order = order;
305 __entry->migratetype = migratetype;
306 ),
307
262 TP_printk("page=%p pfn=%lu order=%d migratetype=%d", 308 TP_printk("page=%p pfn=%lu order=%d migratetype=%d",
263 pfn_to_page(__entry->pfn), __entry->pfn, 309 pfn_to_page(__entry->pfn), __entry->pfn,
264 __entry->order, __entry->migratetype) 310 __entry->order, __entry->migratetype)
diff --git a/include/uapi/linux/inet_diag.h b/include/uapi/linux/inet_diag.h
index d65c0a09efd3..c7093c75bdd6 100644
--- a/include/uapi/linux/inet_diag.h
+++ b/include/uapi/linux/inet_diag.h
@@ -143,4 +143,8 @@ struct tcp_dctcp_info {
143 __u32 dctcp_ab_tot; 143 __u32 dctcp_ab_tot;
144}; 144};
145 145
146union tcp_cc_info {
147 struct tcpvegas_info vegas;
148 struct tcp_dctcp_info dctcp;
149};
146#endif /* _UAPI_INET_DIAG_H_ */ 150#endif /* _UAPI_INET_DIAG_H_ */
diff --git a/include/uapi/linux/mpls.h b/include/uapi/linux/mpls.h
index bc9abfe88c9a..139d4dd1cab8 100644
--- a/include/uapi/linux/mpls.h
+++ b/include/uapi/linux/mpls.h
@@ -31,4 +31,14 @@ struct mpls_label {
31#define MPLS_LS_TTL_MASK 0x000000FF 31#define MPLS_LS_TTL_MASK 0x000000FF
32#define MPLS_LS_TTL_SHIFT 0 32#define MPLS_LS_TTL_SHIFT 0
33 33
34/* Reserved labels */
35#define MPLS_LABEL_IPV4NULL 0 /* RFC3032 */
36#define MPLS_LABEL_RTALERT 1 /* RFC3032 */
37#define MPLS_LABEL_IPV6NULL 2 /* RFC3032 */
38#define MPLS_LABEL_IMPLNULL 3 /* RFC3032 */
39#define MPLS_LABEL_ENTROPY 7 /* RFC6790 */
40#define MPLS_LABEL_GAL 13 /* RFC5586 */
41#define MPLS_LABEL_OAMALERT 14 /* RFC3429 */
42#define MPLS_LABEL_EXTENSION 15 /* RFC7274 */
43
34#endif /* _UAPI_MPLS_H */ 44#endif /* _UAPI_MPLS_H */
diff --git a/include/uapi/linux/netfilter/nf_conntrack_tcp.h b/include/uapi/linux/netfilter/nf_conntrack_tcp.h
index 9993a421201c..ef9f80f0f529 100644
--- a/include/uapi/linux/netfilter/nf_conntrack_tcp.h
+++ b/include/uapi/linux/netfilter/nf_conntrack_tcp.h
@@ -42,6 +42,9 @@ enum tcp_conntrack {
42/* The field td_maxack has been set */ 42/* The field td_maxack has been set */
43#define IP_CT_TCP_FLAG_MAXACK_SET 0x20 43#define IP_CT_TCP_FLAG_MAXACK_SET 0x20
44 44
45/* Marks possibility for expected RFC5961 challenge ACK */
46#define IP_CT_EXP_CHALLENGE_ACK 0x40
47
45struct nf_ct_tcp_flags { 48struct nf_ct_tcp_flags {
46 __u8 flags; 49 __u8 flags;
47 __u8 mask; 50 __u8 mask;
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 974db03f7b1a..17fb02f488da 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -337,7 +337,7 @@ struct rtnexthop {
337#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */ 337#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
338#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */ 338#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
339#define RTNH_F_ONLINK 4 /* Gateway is forced on link */ 339#define RTNH_F_ONLINK 4 /* Gateway is forced on link */
340#define RTNH_F_EXTERNAL 8 /* Route installed externally */ 340#define RTNH_F_OFFLOAD 8 /* offloaded route */
341 341
342/* Macros to handle hexthops */ 342/* Macros to handle hexthops */
343 343
diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h
index 3b9718328d8b..faa72f4fa547 100644
--- a/include/uapi/linux/tcp.h
+++ b/include/uapi/linux/tcp.h
@@ -112,6 +112,7 @@ enum {
112#define TCP_FASTOPEN 23 /* Enable FastOpen on listeners */ 112#define TCP_FASTOPEN 23 /* Enable FastOpen on listeners */
113#define TCP_TIMESTAMP 24 113#define TCP_TIMESTAMP 24
114#define TCP_NOTSENT_LOWAT 25 /* limit number of unsent bytes in write queue */ 114#define TCP_NOTSENT_LOWAT 25 /* limit number of unsent bytes in write queue */
115#define TCP_CC_INFO 26 /* Get Congestion Control (optional) info */
115 116
116struct tcp_repair_opt { 117struct tcp_repair_opt {
117 __u32 opt_code; 118 __u32 opt_code;
@@ -189,6 +190,8 @@ struct tcp_info {
189 190
190 __u64 tcpi_pacing_rate; 191 __u64 tcpi_pacing_rate;
191 __u64 tcpi_max_pacing_rate; 192 __u64 tcpi_max_pacing_rate;
193 __u64 tcpi_bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked */
194 __u64 tcpi_bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived */
192}; 195};
193 196
194/* for TCP_MD5SIG socket option */ 197/* for TCP_MD5SIG socket option */
diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h
index a3318f31e8e7..915980ac68df 100644
--- a/include/uapi/linux/virtio_ring.h
+++ b/include/uapi/linux/virtio_ring.h
@@ -155,7 +155,7 @@ static inline unsigned vring_size(unsigned int num, unsigned long align)
155} 155}
156 156
157/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */ 157/* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */
158/* Assuming a given event_idx value from the other size, if 158/* Assuming a given event_idx value from the other side, if
159 * we have just incremented index from old to new_idx, 159 * we have just incremented index from old to new_idx,
160 * should we trigger an event? */ 160 * should we trigger an event? */
161static inline int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old) 161static inline int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
diff --git a/include/uapi/rdma/rdma_netlink.h b/include/uapi/rdma/rdma_netlink.h
index de69170a30ce..6e4bb4270ca2 100644
--- a/include/uapi/rdma/rdma_netlink.h
+++ b/include/uapi/rdma/rdma_netlink.h
@@ -37,6 +37,7 @@ enum {
37 RDMA_NL_IWPM_ADD_MAPPING, 37 RDMA_NL_IWPM_ADD_MAPPING,
38 RDMA_NL_IWPM_QUERY_MAPPING, 38 RDMA_NL_IWPM_QUERY_MAPPING,
39 RDMA_NL_IWPM_REMOVE_MAPPING, 39 RDMA_NL_IWPM_REMOVE_MAPPING,
40 RDMA_NL_IWPM_REMOTE_INFO,
40 RDMA_NL_IWPM_HANDLE_ERR, 41 RDMA_NL_IWPM_HANDLE_ERR,
41 RDMA_NL_IWPM_MAPINFO, 42 RDMA_NL_IWPM_MAPINFO,
42 RDMA_NL_IWPM_MAPINFO_NUM, 43 RDMA_NL_IWPM_MAPINFO_NUM,
diff --git a/include/xen/events.h b/include/xen/events.h
index 5321cd9636e6..7d95fdf9cf3e 100644
--- a/include/xen/events.h
+++ b/include/xen/events.h
@@ -17,7 +17,7 @@ int bind_evtchn_to_irqhandler(unsigned int evtchn,
17 irq_handler_t handler, 17 irq_handler_t handler,
18 unsigned long irqflags, const char *devname, 18 unsigned long irqflags, const char *devname,
19 void *dev_id); 19 void *dev_id);
20int bind_virq_to_irq(unsigned int virq, unsigned int cpu); 20int bind_virq_to_irq(unsigned int virq, unsigned int cpu, bool percpu);
21int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, 21int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
22 irq_handler_t handler, 22 irq_handler_t handler,
23 unsigned long irqflags, const char *devname, 23 unsigned long irqflags, const char *devname,
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 143ca5ffab7a..4478f4b4aae2 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -191,6 +191,7 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
191 struct gnttab_unmap_grant_ref *kunmap_ops, 191 struct gnttab_unmap_grant_ref *kunmap_ops,
192 struct page **pages, unsigned int count); 192 struct page **pages, unsigned int count);
193void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item); 193void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item);
194int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item);
194 195
195 196
196/* Perform a batch of grant map/copy operations. Retry every batch slot 197/* Perform a batch of grant map/copy operations. Retry every batch slot
diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
index c643e6a94c9a..0ce4f32017ea 100644
--- a/include/xen/xen-ops.h
+++ b/include/xen/xen-ops.h
@@ -13,6 +13,7 @@ void xen_arch_post_suspend(int suspend_cancelled);
13 13
14void xen_timer_resume(void); 14void xen_timer_resume(void);
15void xen_arch_resume(void); 15void xen_arch_resume(void);
16void xen_arch_suspend(void);
16 17
17void xen_resume_notifier_register(struct notifier_block *nb); 18void xen_resume_notifier_register(struct notifier_block *nb);
18void xen_resume_notifier_unregister(struct notifier_block *nb); 19void xen_resume_notifier_unregister(struct notifier_block *nb);
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 8369ffa5f33d..a95bbdb2a502 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -225,10 +225,11 @@ dev_t name_to_dev_t(const char *name)
225#endif 225#endif
226 226
227 if (strncmp(name, "/dev/", 5) != 0) { 227 if (strncmp(name, "/dev/", 5) != 0) {
228 unsigned maj, min; 228 unsigned maj, min, offset;
229 char dummy; 229 char dummy;
230 230
231 if (sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2) { 231 if ((sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2) ||
232 (sscanf(name, "%u:%u:%u:%c", &maj, &min, &offset, &dummy) == 3)) {
232 res = MKDEV(maj, min); 233 res = MKDEV(maj, min);
233 if (maj != MAJOR(res) || min != MINOR(res)) 234 if (maj != MAJOR(res) || min != MINOR(res))
234 goto fail; 235 goto fail;
diff --git a/kernel/Makefile b/kernel/Makefile
index 0f8f8b0bc1bf..60c302cfb4d3 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -197,9 +197,9 @@ x509.genkey:
197 @echo >>x509.genkey "x509_extensions = myexts" 197 @echo >>x509.genkey "x509_extensions = myexts"
198 @echo >>x509.genkey 198 @echo >>x509.genkey
199 @echo >>x509.genkey "[ req_distinguished_name ]" 199 @echo >>x509.genkey "[ req_distinguished_name ]"
200 @echo >>x509.genkey "O = Magrathea" 200 @echo >>x509.genkey "#O = Unspecified company"
201 @echo >>x509.genkey "CN = Glacier signing key" 201 @echo >>x509.genkey "CN = Build time autogenerated kernel key"
202 @echo >>x509.genkey "emailAddress = slartibartfast@magrathea.h2g2" 202 @echo >>x509.genkey "#emailAddress = unspecified.user@unspecified.company"
203 @echo >>x509.genkey 203 @echo >>x509.genkey
204 @echo >>x509.genkey "[ myexts ]" 204 @echo >>x509.genkey "[ myexts ]"
205 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE" 205 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE"
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 4139a0f8b558..54f0e7fcd0e2 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -357,8 +357,8 @@ select_insn:
357 ALU64_MOD_X: 357 ALU64_MOD_X:
358 if (unlikely(SRC == 0)) 358 if (unlikely(SRC == 0))
359 return 0; 359 return 0;
360 tmp = DST; 360 div64_u64_rem(DST, SRC, &tmp);
361 DST = do_div(tmp, SRC); 361 DST = tmp;
362 CONT; 362 CONT;
363 ALU_MOD_X: 363 ALU_MOD_X:
364 if (unlikely(SRC == 0)) 364 if (unlikely(SRC == 0))
@@ -367,8 +367,8 @@ select_insn:
367 DST = do_div(tmp, (u32) SRC); 367 DST = do_div(tmp, (u32) SRC);
368 CONT; 368 CONT;
369 ALU64_MOD_K: 369 ALU64_MOD_K:
370 tmp = DST; 370 div64_u64_rem(DST, IMM, &tmp);
371 DST = do_div(tmp, IMM); 371 DST = tmp;
372 CONT; 372 CONT;
373 ALU_MOD_K: 373 ALU_MOD_K:
374 tmp = (u32) DST; 374 tmp = (u32) DST;
@@ -377,7 +377,7 @@ select_insn:
377 ALU64_DIV_X: 377 ALU64_DIV_X:
378 if (unlikely(SRC == 0)) 378 if (unlikely(SRC == 0))
379 return 0; 379 return 0;
380 do_div(DST, SRC); 380 DST = div64_u64(DST, SRC);
381 CONT; 381 CONT;
382 ALU_DIV_X: 382 ALU_DIV_X:
383 if (unlikely(SRC == 0)) 383 if (unlikely(SRC == 0))
@@ -387,7 +387,7 @@ select_insn:
387 DST = (u32) tmp; 387 DST = (u32) tmp;
388 CONT; 388 CONT;
389 ALU64_DIV_K: 389 ALU64_DIV_K:
390 do_div(DST, IMM); 390 DST = div64_u64(DST, IMM);
391 CONT; 391 CONT;
392 ALU_DIV_K: 392 ALU_DIV_K:
393 tmp = (u32) DST; 393 tmp = (u32) DST;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 81aa3a4ece9f..1a3bf48743ce 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -913,10 +913,30 @@ static void put_ctx(struct perf_event_context *ctx)
913 * Those places that change perf_event::ctx will hold both 913 * Those places that change perf_event::ctx will hold both
914 * perf_event_ctx::mutex of the 'old' and 'new' ctx value. 914 * perf_event_ctx::mutex of the 'old' and 'new' ctx value.
915 * 915 *
916 * Lock ordering is by mutex address. There is one other site where 916 * Lock ordering is by mutex address. There are two other sites where
917 * perf_event_context::mutex nests and that is put_event(). But remember that 917 * perf_event_context::mutex nests and those are:
918 * that is a parent<->child context relation, and migration does not affect 918 *
919 * children, therefore these two orderings should not interact. 919 * - perf_event_exit_task_context() [ child , 0 ]
920 * __perf_event_exit_task()
921 * sync_child_event()
922 * put_event() [ parent, 1 ]
923 *
924 * - perf_event_init_context() [ parent, 0 ]
925 * inherit_task_group()
926 * inherit_group()
927 * inherit_event()
928 * perf_event_alloc()
929 * perf_init_event()
930 * perf_try_init_event() [ child , 1 ]
931 *
932 * While it appears there is an obvious deadlock here -- the parent and child
933 * nesting levels are inverted between the two. This is in fact safe because
934 * life-time rules separate them. That is an exiting task cannot fork, and a
935 * spawning task cannot (yet) exit.
936 *
937 * But remember that that these are parent<->child context relations, and
938 * migration does not affect children, therefore these two orderings should not
939 * interact.
920 * 940 *
921 * The change in perf_event::ctx does not affect children (as claimed above) 941 * The change in perf_event::ctx does not affect children (as claimed above)
922 * because the sys_perf_event_open() case will install a new event and break 942 * because the sys_perf_event_open() case will install a new event and break
@@ -3657,9 +3677,6 @@ static void perf_remove_from_owner(struct perf_event *event)
3657 } 3677 }
3658} 3678}
3659 3679
3660/*
3661 * Called when the last reference to the file is gone.
3662 */
3663static void put_event(struct perf_event *event) 3680static void put_event(struct perf_event *event)
3664{ 3681{
3665 struct perf_event_context *ctx; 3682 struct perf_event_context *ctx;
@@ -3697,6 +3714,9 @@ int perf_event_release_kernel(struct perf_event *event)
3697} 3714}
3698EXPORT_SYMBOL_GPL(perf_event_release_kernel); 3715EXPORT_SYMBOL_GPL(perf_event_release_kernel);
3699 3716
3717/*
3718 * Called when the last reference to the file is gone.
3719 */
3700static int perf_release(struct inode *inode, struct file *file) 3720static int perf_release(struct inode *inode, struct file *file)
3701{ 3721{
3702 put_event(file->private_data); 3722 put_event(file->private_data);
@@ -7364,7 +7384,12 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
7364 return -ENODEV; 7384 return -ENODEV;
7365 7385
7366 if (event->group_leader != event) { 7386 if (event->group_leader != event) {
7367 ctx = perf_event_ctx_lock(event->group_leader); 7387 /*
7388 * This ctx->mutex can nest when we're called through
7389 * inheritance. See the perf_event_ctx_lock_nested() comment.
7390 */
7391 ctx = perf_event_ctx_lock_nested(event->group_leader,
7392 SINGLE_DEPTH_NESTING);
7368 BUG_ON(!ctx); 7393 BUG_ON(!ctx);
7369 } 7394 }
7370 7395
diff --git a/kernel/irq/dummychip.c b/kernel/irq/dummychip.c
index 988dc58e8847..2feb6feca0cc 100644
--- a/kernel/irq/dummychip.c
+++ b/kernel/irq/dummychip.c
@@ -57,5 +57,6 @@ struct irq_chip dummy_irq_chip = {
57 .irq_ack = noop, 57 .irq_ack = noop,
58 .irq_mask = noop, 58 .irq_mask = noop,
59 .irq_unmask = noop, 59 .irq_unmask = noop,
60 .flags = IRQCHIP_SKIP_SET_WAKE,
60}; 61};
61EXPORT_SYMBOL_GPL(dummy_irq_chip); 62EXPORT_SYMBOL_GPL(dummy_irq_chip);
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 38c25b1f2fd5..7a36fdcca5bf 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -707,7 +707,7 @@ static struct page *kimage_alloc_normal_control_pages(struct kimage *image,
707 do { 707 do {
708 unsigned long pfn, epfn, addr, eaddr; 708 unsigned long pfn, epfn, addr, eaddr;
709 709
710 pages = kimage_alloc_pages(GFP_KERNEL, order); 710 pages = kimage_alloc_pages(KEXEC_CONTROL_MEMORY_GFP, order);
711 if (!pages) 711 if (!pages)
712 break; 712 break;
713 pfn = page_to_pfn(pages); 713 pfn = page_to_pfn(pages);
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index b73279367087..b025295f4966 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -265,15 +265,17 @@ struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
265} 265}
266 266
267/* 267/*
268 * Called by sched_setscheduler() to check whether the priority change 268 * Called by sched_setscheduler() to get the priority which will be
269 * is overruled by a possible priority boosting. 269 * effective after the change.
270 */ 270 */
271int rt_mutex_check_prio(struct task_struct *task, int newprio) 271int rt_mutex_get_effective_prio(struct task_struct *task, int newprio)
272{ 272{
273 if (!task_has_pi_waiters(task)) 273 if (!task_has_pi_waiters(task))
274 return 0; 274 return newprio;
275 275
276 return task_top_pi_waiter(task)->task->prio <= newprio; 276 if (task_top_pi_waiter(task)->task->prio <= newprio)
277 return task_top_pi_waiter(task)->task->prio;
278 return newprio;
277} 279}
278 280
279/* 281/*
diff --git a/kernel/module.c b/kernel/module.c
index 42a1d2afb217..cfc9e843a924 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3370,6 +3370,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
3370 module_bug_cleanup(mod); 3370 module_bug_cleanup(mod);
3371 mutex_unlock(&module_mutex); 3371 mutex_unlock(&module_mutex);
3372 3372
3373 blocking_notifier_call_chain(&module_notify_list,
3374 MODULE_STATE_GOING, mod);
3375
3373 /* we can't deallocate the module until we clear memory protection */ 3376 /* we can't deallocate the module until we clear memory protection */
3374 unset_module_init_ro_nx(mod); 3377 unset_module_init_ro_nx(mod);
3375 unset_module_core_ro_nx(mod); 3378 unset_module_core_ro_nx(mod);
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 233165da782f..8cf7304b2867 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -162,11 +162,14 @@ static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
162static int kthread_prio = CONFIG_RCU_KTHREAD_PRIO; 162static int kthread_prio = CONFIG_RCU_KTHREAD_PRIO;
163module_param(kthread_prio, int, 0644); 163module_param(kthread_prio, int, 0644);
164 164
165/* Delay in jiffies for grace-period initialization delays. */ 165/* Delay in jiffies for grace-period initialization delays, debug only. */
166static int gp_init_delay = IS_ENABLED(CONFIG_RCU_TORTURE_TEST_SLOW_INIT) 166#ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT
167 ? CONFIG_RCU_TORTURE_TEST_SLOW_INIT_DELAY 167static int gp_init_delay = CONFIG_RCU_TORTURE_TEST_SLOW_INIT_DELAY;
168 : 0;
169module_param(gp_init_delay, int, 0644); 168module_param(gp_init_delay, int, 0644);
169#else /* #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */
170static const int gp_init_delay;
171#endif /* #else #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */
172#define PER_RCU_NODE_PERIOD 10 /* Number of grace periods between delays. */
170 173
171/* 174/*
172 * Track the rcutorture test sequence number and the update version 175 * Track the rcutorture test sequence number and the update version
@@ -1843,9 +1846,8 @@ static int rcu_gp_init(struct rcu_state *rsp)
1843 raw_spin_unlock_irq(&rnp->lock); 1846 raw_spin_unlock_irq(&rnp->lock);
1844 cond_resched_rcu_qs(); 1847 cond_resched_rcu_qs();
1845 ACCESS_ONCE(rsp->gp_activity) = jiffies; 1848 ACCESS_ONCE(rsp->gp_activity) = jiffies;
1846 if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_SLOW_INIT) && 1849 if (gp_init_delay > 0 &&
1847 gp_init_delay > 0 && 1850 !(rsp->gpnum % (rcu_num_nodes * PER_RCU_NODE_PERIOD)))
1848 !(rsp->gpnum % (rcu_num_nodes * 10)))
1849 schedule_timeout_uninterruptible(gp_init_delay); 1851 schedule_timeout_uninterruptible(gp_init_delay);
1850 } 1852 }
1851 1853
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f9123a82cbb6..123673291ffb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1016,13 +1016,6 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
1016 rq_clock_skip_update(rq, true); 1016 rq_clock_skip_update(rq, true);
1017} 1017}
1018 1018
1019static ATOMIC_NOTIFIER_HEAD(task_migration_notifier);
1020
1021void register_task_migration_notifier(struct notifier_block *n)
1022{
1023 atomic_notifier_chain_register(&task_migration_notifier, n);
1024}
1025
1026#ifdef CONFIG_SMP 1019#ifdef CONFIG_SMP
1027void set_task_cpu(struct task_struct *p, unsigned int new_cpu) 1020void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
1028{ 1021{
@@ -1053,18 +1046,10 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
1053 trace_sched_migrate_task(p, new_cpu); 1046 trace_sched_migrate_task(p, new_cpu);
1054 1047
1055 if (task_cpu(p) != new_cpu) { 1048 if (task_cpu(p) != new_cpu) {
1056 struct task_migration_notifier tmn;
1057
1058 if (p->sched_class->migrate_task_rq) 1049 if (p->sched_class->migrate_task_rq)
1059 p->sched_class->migrate_task_rq(p, new_cpu); 1050 p->sched_class->migrate_task_rq(p, new_cpu);
1060 p->se.nr_migrations++; 1051 p->se.nr_migrations++;
1061 perf_sw_event_sched(PERF_COUNT_SW_CPU_MIGRATIONS, 1, 0); 1052 perf_sw_event_sched(PERF_COUNT_SW_CPU_MIGRATIONS, 1, 0);
1062
1063 tmn.task = p;
1064 tmn.from_cpu = task_cpu(p);
1065 tmn.to_cpu = new_cpu;
1066
1067 atomic_notifier_call_chain(&task_migration_notifier, 0, &tmn);
1068 } 1053 }
1069 1054
1070 __set_task_cpu(p, new_cpu); 1055 __set_task_cpu(p, new_cpu);
@@ -3315,15 +3300,18 @@ static void __setscheduler_params(struct task_struct *p,
3315 3300
3316/* Actually do priority change: must hold pi & rq lock. */ 3301/* Actually do priority change: must hold pi & rq lock. */
3317static void __setscheduler(struct rq *rq, struct task_struct *p, 3302static void __setscheduler(struct rq *rq, struct task_struct *p,
3318 const struct sched_attr *attr) 3303 const struct sched_attr *attr, bool keep_boost)
3319{ 3304{
3320 __setscheduler_params(p, attr); 3305 __setscheduler_params(p, attr);
3321 3306
3322 /* 3307 /*
3323 * If we get here, there was no pi waiters boosting the 3308 * Keep a potential priority boosting if called from
3324 * task. It is safe to use the normal prio. 3309 * sched_setscheduler().
3325 */ 3310 */
3326 p->prio = normal_prio(p); 3311 if (keep_boost)
3312 p->prio = rt_mutex_get_effective_prio(p, normal_prio(p));
3313 else
3314 p->prio = normal_prio(p);
3327 3315
3328 if (dl_prio(p->prio)) 3316 if (dl_prio(p->prio))
3329 p->sched_class = &dl_sched_class; 3317 p->sched_class = &dl_sched_class;
@@ -3423,7 +3411,7 @@ static int __sched_setscheduler(struct task_struct *p,
3423 int newprio = dl_policy(attr->sched_policy) ? MAX_DL_PRIO - 1 : 3411 int newprio = dl_policy(attr->sched_policy) ? MAX_DL_PRIO - 1 :
3424 MAX_RT_PRIO - 1 - attr->sched_priority; 3412 MAX_RT_PRIO - 1 - attr->sched_priority;
3425 int retval, oldprio, oldpolicy = -1, queued, running; 3413 int retval, oldprio, oldpolicy = -1, queued, running;
3426 int policy = attr->sched_policy; 3414 int new_effective_prio, policy = attr->sched_policy;
3427 unsigned long flags; 3415 unsigned long flags;
3428 const struct sched_class *prev_class; 3416 const struct sched_class *prev_class;
3429 struct rq *rq; 3417 struct rq *rq;
@@ -3605,15 +3593,14 @@ change:
3605 oldprio = p->prio; 3593 oldprio = p->prio;
3606 3594
3607 /* 3595 /*
3608 * Special case for priority boosted tasks. 3596 * Take priority boosted tasks into account. If the new
3609 * 3597 * effective priority is unchanged, we just store the new
3610 * If the new priority is lower or equal (user space view)
3611 * than the current (boosted) priority, we just store the new
3612 * normal parameters and do not touch the scheduler class and 3598 * normal parameters and do not touch the scheduler class and
3613 * the runqueue. This will be done when the task deboost 3599 * the runqueue. This will be done when the task deboost
3614 * itself. 3600 * itself.
3615 */ 3601 */
3616 if (rt_mutex_check_prio(p, newprio)) { 3602 new_effective_prio = rt_mutex_get_effective_prio(p, newprio);
3603 if (new_effective_prio == oldprio) {
3617 __setscheduler_params(p, attr); 3604 __setscheduler_params(p, attr);
3618 task_rq_unlock(rq, p, &flags); 3605 task_rq_unlock(rq, p, &flags);
3619 return 0; 3606 return 0;
@@ -3627,7 +3614,7 @@ change:
3627 put_prev_task(rq, p); 3614 put_prev_task(rq, p);
3628 3615
3629 prev_class = p->sched_class; 3616 prev_class = p->sched_class;
3630 __setscheduler(rq, p, attr); 3617 __setscheduler(rq, p, attr, true);
3631 3618
3632 if (running) 3619 if (running)
3633 p->sched_class->set_curr_task(rq); 3620 p->sched_class->set_curr_task(rq);
@@ -4402,10 +4389,7 @@ long __sched io_schedule_timeout(long timeout)
4402 long ret; 4389 long ret;
4403 4390
4404 current->in_iowait = 1; 4391 current->in_iowait = 1;
4405 if (old_iowait) 4392 blk_schedule_flush_plug(current);
4406 blk_schedule_flush_plug(current);
4407 else
4408 blk_flush_plug(current);
4409 4393
4410 delayacct_blkio_start(); 4394 delayacct_blkio_start();
4411 rq = raw_rq(); 4395 rq = raw_rq();
@@ -7012,27 +6996,23 @@ static int cpuset_cpu_inactive(struct notifier_block *nfb, unsigned long action,
7012 unsigned long flags; 6996 unsigned long flags;
7013 long cpu = (long)hcpu; 6997 long cpu = (long)hcpu;
7014 struct dl_bw *dl_b; 6998 struct dl_bw *dl_b;
6999 bool overflow;
7000 int cpus;
7015 7001
7016 switch (action & ~CPU_TASKS_FROZEN) { 7002 switch (action) {
7017 case CPU_DOWN_PREPARE: 7003 case CPU_DOWN_PREPARE:
7018 /* explicitly allow suspend */ 7004 rcu_read_lock_sched();
7019 if (!(action & CPU_TASKS_FROZEN)) { 7005 dl_b = dl_bw_of(cpu);
7020 bool overflow;
7021 int cpus;
7022
7023 rcu_read_lock_sched();
7024 dl_b = dl_bw_of(cpu);
7025 7006
7026 raw_spin_lock_irqsave(&dl_b->lock, flags); 7007 raw_spin_lock_irqsave(&dl_b->lock, flags);
7027 cpus = dl_bw_cpus(cpu); 7008 cpus = dl_bw_cpus(cpu);
7028 overflow = __dl_overflow(dl_b, cpus, 0, 0); 7009 overflow = __dl_overflow(dl_b, cpus, 0, 0);
7029 raw_spin_unlock_irqrestore(&dl_b->lock, flags); 7010 raw_spin_unlock_irqrestore(&dl_b->lock, flags);
7030 7011
7031 rcu_read_unlock_sched(); 7012 rcu_read_unlock_sched();
7032 7013
7033 if (overflow) 7014 if (overflow)
7034 return notifier_from_errno(-EBUSY); 7015 return notifier_from_errno(-EBUSY);
7035 }
7036 cpuset_update_active_cpus(false); 7016 cpuset_update_active_cpus(false);
7037 break; 7017 break;
7038 case CPU_DOWN_PREPARE_FROZEN: 7018 case CPU_DOWN_PREPARE_FROZEN:
@@ -7361,7 +7341,7 @@ static void normalize_task(struct rq *rq, struct task_struct *p)
7361 queued = task_on_rq_queued(p); 7341 queued = task_on_rq_queued(p);
7362 if (queued) 7342 if (queued)
7363 dequeue_task(rq, p, 0); 7343 dequeue_task(rq, p, 0);
7364 __setscheduler(rq, p, &attr); 7344 __setscheduler(rq, p, &attr, false);
7365 if (queued) { 7345 if (queued) {
7366 enqueue_task(rq, p, 0); 7346 enqueue_task(rq, p, 0);
7367 resched_curr(rq); 7347 resched_curr(rq);
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index deef1caa94c6..fefcb1fa5160 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
81 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); 81 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
82 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); 82 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
83 int next_state, entered_state; 83 int next_state, entered_state;
84 unsigned int broadcast;
85 bool reflect; 84 bool reflect;
86 85
87 /* 86 /*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
150 goto exit_idle; 149 goto exit_idle;
151 } 150 }
152 151
153 broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
154
155 /*
156 * Tell the time framework to switch to a broadcast timer
157 * because our local timer will be shutdown. If a local timer
158 * is used from another cpu as a broadcast timer, this call may
159 * fail if it is not available
160 */
161 if (broadcast && tick_broadcast_enter())
162 goto use_default;
163
164 /* Take note of the planned idle state. */ 152 /* Take note of the planned idle state. */
165 idle_set_state(this_rq(), &drv->states[next_state]); 153 idle_set_state(this_rq(), &drv->states[next_state]);
166 154
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
174 /* The cpu is no longer idle or about to enter idle. */ 162 /* The cpu is no longer idle or about to enter idle. */
175 idle_set_state(this_rq(), NULL); 163 idle_set_state(this_rq(), NULL);
176 164
177 if (broadcast) 165 if (entered_state == -EBUSY)
178 tick_broadcast_exit(); 166 goto use_default;
179 167
180 /* 168 /*
181 * Give the governor an opportunity to reflect on the outcome 169 * Give the governor an opportunity to reflect on the outcome
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index 11dc22a6983b..637a09461c1d 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -117,11 +117,7 @@ static int __clockevents_set_state(struct clock_event_device *dev,
117 /* Transition with new state-specific callbacks */ 117 /* Transition with new state-specific callbacks */
118 switch (state) { 118 switch (state) {
119 case CLOCK_EVT_STATE_DETACHED: 119 case CLOCK_EVT_STATE_DETACHED:
120 /* 120 /* The clockevent device is getting replaced. Shut it down. */
121 * This is an internal state, which is guaranteed to go from
122 * SHUTDOWN to DETACHED. No driver interaction required.
123 */
124 return 0;
125 121
126 case CLOCK_EVT_STATE_SHUTDOWN: 122 case CLOCK_EVT_STATE_SHUTDOWN:
127 return dev->set_state_shutdown(dev); 123 return dev->set_state_shutdown(dev);
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 76d4bd962b19..93ef7190bdea 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -266,21 +266,23 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
266/* 266/*
267 * Divide a ktime value by a nanosecond value 267 * Divide a ktime value by a nanosecond value
268 */ 268 */
269u64 __ktime_divns(const ktime_t kt, s64 div) 269s64 __ktime_divns(const ktime_t kt, s64 div)
270{ 270{
271 u64 dclc;
272 int sft = 0; 271 int sft = 0;
272 s64 dclc;
273 u64 tmp;
273 274
274 dclc = ktime_to_ns(kt); 275 dclc = ktime_to_ns(kt);
276 tmp = dclc < 0 ? -dclc : dclc;
277
275 /* Make sure the divisor is less than 2^32: */ 278 /* Make sure the divisor is less than 2^32: */
276 while (div >> 32) { 279 while (div >> 32) {
277 sft++; 280 sft++;
278 div >>= 1; 281 div >>= 1;
279 } 282 }
280 dclc >>= sft; 283 tmp >>= sft;
281 do_div(dclc, (unsigned long) div); 284 do_div(tmp, (unsigned long) div);
282 285 return dclc < 0 ? -tmp : tmp;
283 return dclc;
284} 286}
285EXPORT_SYMBOL_GPL(__ktime_divns); 287EXPORT_SYMBOL_GPL(__ktime_divns);
286#endif /* BITS_PER_LONG >= 64 */ 288#endif /* BITS_PER_LONG >= 64 */
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 692bf7184c8c..25a086bcb700 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -178,12 +178,13 @@ ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
178EXPORT_SYMBOL(ftrace_print_hex_seq); 178EXPORT_SYMBOL(ftrace_print_hex_seq);
179 179
180const char * 180const char *
181ftrace_print_array_seq(struct trace_seq *p, const void *buf, int buf_len, 181ftrace_print_array_seq(struct trace_seq *p, const void *buf, int count,
182 size_t el_size) 182 size_t el_size)
183{ 183{
184 const char *ret = trace_seq_buffer_ptr(p); 184 const char *ret = trace_seq_buffer_ptr(p);
185 const char *prefix = ""; 185 const char *prefix = "";
186 void *ptr = (void *)buf; 186 void *ptr = (void *)buf;
187 size_t buf_len = count * el_size;
187 188
188 trace_seq_putc(p, '{'); 189 trace_seq_putc(p, '{');
189 190
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 2316f50b07a4..581a68a04c64 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -41,6 +41,8 @@
41#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT) 41#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
42#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT) 42#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
43 43
44static DEFINE_MUTEX(watchdog_proc_mutex);
45
44#ifdef CONFIG_HARDLOCKUP_DETECTOR 46#ifdef CONFIG_HARDLOCKUP_DETECTOR
45static unsigned long __read_mostly watchdog_enabled = SOFT_WATCHDOG_ENABLED|NMI_WATCHDOG_ENABLED; 47static unsigned long __read_mostly watchdog_enabled = SOFT_WATCHDOG_ENABLED|NMI_WATCHDOG_ENABLED;
46#else 48#else
@@ -608,26 +610,36 @@ void watchdog_nmi_enable_all(void)
608{ 610{
609 int cpu; 611 int cpu;
610 612
611 if (!watchdog_user_enabled) 613 mutex_lock(&watchdog_proc_mutex);
612 return; 614
615 if (!(watchdog_enabled & NMI_WATCHDOG_ENABLED))
616 goto unlock;
613 617
614 get_online_cpus(); 618 get_online_cpus();
615 for_each_online_cpu(cpu) 619 for_each_online_cpu(cpu)
616 watchdog_nmi_enable(cpu); 620 watchdog_nmi_enable(cpu);
617 put_online_cpus(); 621 put_online_cpus();
622
623unlock:
624 mutex_unlock(&watchdog_proc_mutex);
618} 625}
619 626
620void watchdog_nmi_disable_all(void) 627void watchdog_nmi_disable_all(void)
621{ 628{
622 int cpu; 629 int cpu;
623 630
631 mutex_lock(&watchdog_proc_mutex);
632
624 if (!watchdog_running) 633 if (!watchdog_running)
625 return; 634 goto unlock;
626 635
627 get_online_cpus(); 636 get_online_cpus();
628 for_each_online_cpu(cpu) 637 for_each_online_cpu(cpu)
629 watchdog_nmi_disable(cpu); 638 watchdog_nmi_disable(cpu);
630 put_online_cpus(); 639 put_online_cpus();
640
641unlock:
642 mutex_unlock(&watchdog_proc_mutex);
631} 643}
632#else 644#else
633static int watchdog_nmi_enable(unsigned int cpu) { return 0; } 645static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
@@ -744,8 +756,6 @@ static int proc_watchdog_update(void)
744 756
745} 757}
746 758
747static DEFINE_MUTEX(watchdog_proc_mutex);
748
749/* 759/*
750 * common function for watchdog, nmi_watchdog and soft_watchdog parameter 760 * common function for watchdog, nmi_watchdog and soft_watchdog parameter
751 * 761 *
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 17670573dda8..ba2b0c87e65b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1281,6 +1281,7 @@ config RCU_TORTURE_TEST_SLOW_INIT_DELAY
1281 int "How much to slow down RCU grace-period initialization" 1281 int "How much to slow down RCU grace-period initialization"
1282 range 0 5 1282 range 0 5
1283 default 3 1283 default 3
1284 depends on RCU_TORTURE_TEST_SLOW_INIT
1284 help 1285 help
1285 This option specifies the number of jiffies to wait between 1286 This option specifies the number of jiffies to wait between
1286 each rcu_node structure initialization. 1287 each rcu_node structure initialization.
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index 4fecaedc80a2..777eda7d1ab4 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -10,8 +10,11 @@ config KASAN
10 help 10 help
11 Enables kernel address sanitizer - runtime memory debugger, 11 Enables kernel address sanitizer - runtime memory debugger,
12 designed to find out-of-bounds accesses and use-after-free bugs. 12 designed to find out-of-bounds accesses and use-after-free bugs.
13 This is strictly debugging feature. It consumes about 1/8 13 This is strictly a debugging feature and it requires a gcc version
14 of available memory and brings about ~x3 performance slowdown. 14 of 4.9.2 or later. Detection of out of bounds accesses to stack or
15 global variables requires gcc 5.0 or later.
16 This feature consumes about 1/8 of available memory and brings about
17 ~x3 performance slowdown.
15 For better error detection enable CONFIG_STACKTRACE, 18 For better error detection enable CONFIG_STACKTRACE,
16 and add slub_debug=U to boot cmdline. 19 and add slub_debug=U to boot cmdline.
17 20
@@ -40,6 +43,7 @@ config KASAN_INLINE
40 memory accesses. This is faster than outline (in some workloads 43 memory accesses. This is faster than outline (in some workloads
41 it gives about x2 boost over outline instrumentation), but 44 it gives about x2 boost over outline instrumentation), but
42 make kernel's .text size much bigger. 45 make kernel's .text size much bigger.
46 This requires a gcc version of 5.0 or later.
43 47
44endchoice 48endchoice
45 49
diff --git a/lib/cpumask.c b/lib/cpumask.c
index 830dd5dec40f..5f627084f2e9 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -139,64 +139,42 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask)
139#endif 139#endif
140 140
141/** 141/**
142 * cpumask_set_cpu_local_first - set i'th cpu with local numa cpu's first 142 * cpumask_local_spread - select the i'th cpu with local numa cpu's first
143 *
144 * @i: index number 143 * @i: index number
145 * @numa_node: local numa_node 144 * @node: local numa_node
146 * @dstp: cpumask with the relevant cpu bit set according to the policy
147 * 145 *
148 * This function sets the cpumask according to a numa aware policy. 146 * This function selects an online CPU according to a numa aware policy;
149 * cpumask could be used as an affinity hint for the IRQ related to a 147 * local cpus are returned first, followed by non-local ones, then it
150 * queue. When the policy is to spread queues across cores - local cores 148 * wraps around.
151 * first.
152 * 149 *
153 * Returns 0 on success, -ENOMEM for no memory, and -EAGAIN when failed to set 150 * It's not very efficient, but useful for setup.
154 * the cpu bit and need to re-call the function.
155 */ 151 */
156int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp) 152unsigned int cpumask_local_spread(unsigned int i, int node)
157{ 153{
158 cpumask_var_t mask;
159 int cpu; 154 int cpu;
160 int ret = 0;
161
162 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
163 return -ENOMEM;
164 155
156 /* Wrap: we always want a cpu. */
165 i %= num_online_cpus(); 157 i %= num_online_cpus();
166 158
167 if (numa_node == -1 || !cpumask_of_node(numa_node)) { 159 if (node == -1) {
168 /* Use all online cpu's for non numa aware system */ 160 for_each_cpu(cpu, cpu_online_mask)
169 cpumask_copy(mask, cpu_online_mask); 161 if (i-- == 0)
162 return cpu;
170 } else { 163 } else {
171 int n; 164 /* NUMA first. */
172 165 for_each_cpu_and(cpu, cpumask_of_node(node), cpu_online_mask)
173 cpumask_and(mask, 166 if (i-- == 0)
174 cpumask_of_node(numa_node), cpu_online_mask); 167 return cpu;
175 168
176 n = cpumask_weight(mask); 169 for_each_cpu(cpu, cpu_online_mask) {
177 if (i >= n) { 170 /* Skip NUMA nodes, done above. */
178 i -= n; 171 if (cpumask_test_cpu(cpu, cpumask_of_node(node)))
179 172 continue;
180 /* If index > number of local cpu's, mask out local 173
181 * cpu's 174 if (i-- == 0)
182 */ 175 return cpu;
183 cpumask_andnot(mask, cpu_online_mask, mask);
184 } 176 }
185 } 177 }
186 178 BUG();
187 for_each_cpu(cpu, mask) {
188 if (--i < 0)
189 goto out;
190 }
191
192 ret = -EAGAIN;
193
194out:
195 free_cpumask_var(mask);
196
197 if (!ret)
198 cpumask_set_cpu(cpu, dstp);
199
200 return ret;
201} 179}
202EXPORT_SYMBOL(cpumask_set_cpu_local_first); 180EXPORT_SYMBOL(cpumask_local_spread);
diff --git a/lib/find_last_bit.c b/lib/find_last_bit.c
deleted file mode 100644
index 3e3be40c6a6e..000000000000
--- a/lib/find_last_bit.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/* find_last_bit.c: fallback find next bit implementation
2 *
3 * Copyright (C) 2008 IBM Corporation
4 * Written by Rusty Russell <rusty@rustcorp.com.au>
5 * (Inspired by David Howell's find_next_bit implementation)
6 *
7 * Rewritten by Yury Norov <yury.norov@gmail.com> to decrease
8 * size and improve performance, 2015.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#include <linux/bitops.h>
17#include <linux/bitmap.h>
18#include <linux/export.h>
19#include <linux/kernel.h>
20
21#ifndef find_last_bit
22
23unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
24{
25 if (size) {
26 unsigned long val = BITMAP_LAST_WORD_MASK(size);
27 unsigned long idx = (size-1) / BITS_PER_LONG;
28
29 do {
30 val &= addr[idx];
31 if (val)
32 return idx * BITS_PER_LONG + __fls(val);
33
34 val = ~0ul;
35 } while (idx--);
36 }
37 return size;
38}
39EXPORT_SYMBOL(find_last_bit);
40
41#endif
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 48144cdae819..f051d69f0910 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -197,13 +197,13 @@ static int percpu_counter_hotcpu_callback(struct notifier_block *nb,
197 * Compare counter against given value. 197 * Compare counter against given value.
198 * Return 1 if greater, 0 if equal and -1 if less 198 * Return 1 if greater, 0 if equal and -1 if less
199 */ 199 */
200int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs) 200int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch)
201{ 201{
202 s64 count; 202 s64 count;
203 203
204 count = percpu_counter_read(fbc); 204 count = percpu_counter_read(fbc);
205 /* Check to see if rough count will be sufficient for comparison */ 205 /* Check to see if rough count will be sufficient for comparison */
206 if (abs(count - rhs) > (percpu_counter_batch*num_online_cpus())) { 206 if (abs(count - rhs) > (batch * num_online_cpus())) {
207 if (count > rhs) 207 if (count > rhs)
208 return 1; 208 return 1;
209 else 209 else
@@ -218,7 +218,7 @@ int percpu_counter_compare(struct percpu_counter *fbc, s64 rhs)
218 else 218 else
219 return 0; 219 return 0;
220} 220}
221EXPORT_SYMBOL(percpu_counter_compare); 221EXPORT_SYMBOL(__percpu_counter_compare);
222 222
223static int __init percpu_counter_startup(void) 223static int __init percpu_counter_startup(void)
224{ 224{
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 4898442b837f..4396434e4715 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -14,6 +14,7 @@
14 * published by the Free Software Foundation. 14 * published by the Free Software Foundation.
15 */ 15 */
16 16
17#include <linux/atomic.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/log2.h> 20#include <linux/log2.h>
@@ -405,13 +406,18 @@ int rhashtable_insert_rehash(struct rhashtable *ht)
405 406
406 if (rht_grow_above_75(ht, tbl)) 407 if (rht_grow_above_75(ht, tbl))
407 size *= 2; 408 size *= 2;
408 /* More than two rehashes (not resizes) detected. */ 409 /* Do not schedule more than one rehash */
409 else if (WARN_ON(old_tbl != tbl && old_tbl->size == size)) 410 else if (old_tbl != tbl)
410 return -EBUSY; 411 return -EBUSY;
411 412
412 new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC); 413 new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC);
413 if (new_tbl == NULL) 414 if (new_tbl == NULL) {
415 /* Schedule async resize/rehash to try allocation
416 * non-atomic context.
417 */
418 schedule_work(&ht->run_work);
414 return -ENOMEM; 419 return -ENOMEM;
420 }
415 421
416 err = rhashtable_rehash_attach(ht, tbl, new_tbl); 422 err = rhashtable_rehash_attach(ht, tbl, new_tbl);
417 if (err) { 423 if (err) {
@@ -441,6 +447,10 @@ int rhashtable_insert_slow(struct rhashtable *ht, const void *key,
441 if (key && rhashtable_lookup_fast(ht, key, ht->p)) 447 if (key && rhashtable_lookup_fast(ht, key, ht->p))
442 goto exit; 448 goto exit;
443 449
450 err = -E2BIG;
451 if (unlikely(rht_grow_above_max(ht, tbl)))
452 goto exit;
453
444 err = -EAGAIN; 454 err = -EAGAIN;
445 if (rhashtable_check_elasticity(ht, tbl, hash) || 455 if (rhashtable_check_elasticity(ht, tbl, hash) ||
446 rht_grow_above_100(ht, tbl)) 456 rht_grow_above_100(ht, tbl))
@@ -733,6 +743,12 @@ int rhashtable_init(struct rhashtable *ht,
733 if (params->max_size) 743 if (params->max_size)
734 ht->p.max_size = rounddown_pow_of_two(params->max_size); 744 ht->p.max_size = rounddown_pow_of_two(params->max_size);
735 745
746 if (params->insecure_max_entries)
747 ht->p.insecure_max_entries =
748 rounddown_pow_of_two(params->insecure_max_entries);
749 else
750 ht->p.insecure_max_entries = ht->p.max_size * 2;
751
736 ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE); 752 ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE);
737 753
738 /* The maximum (not average) chain length grows with the 754 /* The maximum (not average) chain length grows with the
diff --git a/lib/string.c b/lib/string.c
index a5792019193c..bb3d4b6993c4 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -607,7 +607,7 @@ EXPORT_SYMBOL(memset);
607void memzero_explicit(void *s, size_t count) 607void memzero_explicit(void *s, size_t count)
608{ 608{
609 memset(s, 0, count); 609 memset(s, 0, count);
610 barrier(); 610 barrier_data(s);
611} 611}
612EXPORT_SYMBOL(memzero_explicit); 612EXPORT_SYMBOL(memzero_explicit);
613 613
diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c
index 329caf56df22..4ca5fe0042e1 100644
--- a/mm/hwpoison-inject.c
+++ b/mm/hwpoison-inject.c
@@ -34,13 +34,13 @@ static int hwpoison_inject(void *data, u64 val)
34 if (!hwpoison_filter_enable) 34 if (!hwpoison_filter_enable)
35 goto inject; 35 goto inject;
36 36
37 if (!PageLRU(p) && !PageHuge(p)) 37 if (!PageLRU(hpage) && !PageHuge(p))
38 shake_page(p, 0); 38 shake_page(hpage, 0);
39 /* 39 /*
40 * This implies unable to support non-LRU pages. 40 * This implies unable to support non-LRU pages.
41 */ 41 */
42 if (!PageLRU(p) && !PageHuge(p)) 42 if (!PageLRU(hpage) && !PageHuge(p))
43 return 0; 43 goto put_out;
44 44
45 /* 45 /*
46 * do a racy check with elevated page count, to make sure PG_hwpoison 46 * do a racy check with elevated page count, to make sure PG_hwpoison
@@ -52,11 +52,14 @@ static int hwpoison_inject(void *data, u64 val)
52 err = hwpoison_filter(hpage); 52 err = hwpoison_filter(hpage);
53 unlock_page(hpage); 53 unlock_page(hpage);
54 if (err) 54 if (err)
55 return 0; 55 goto put_out;
56 56
57inject: 57inject:
58 pr_info("Injecting memory failure at pfn %#lx\n", pfn); 58 pr_info("Injecting memory failure at pfn %#lx\n", pfn);
59 return memory_failure(pfn, 18, MF_COUNT_INCREASED); 59 return memory_failure(pfn, 18, MF_COUNT_INCREASED);
60put_out:
61 put_page(hpage);
62 return 0;
60} 63}
61 64
62static int hwpoison_unpoison(void *data, u64 val) 65static int hwpoison_unpoison(void *data, u64 val)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 5405aff5a590..f0fe4f2c1fa7 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -115,7 +115,8 @@
115#define BYTES_PER_POINTER sizeof(void *) 115#define BYTES_PER_POINTER sizeof(void *)
116 116
117/* GFP bitmask for kmemleak internal allocations */ 117/* GFP bitmask for kmemleak internal allocations */
118#define gfp_kmemleak_mask(gfp) (((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \ 118#define gfp_kmemleak_mask(gfp) (((gfp) & (GFP_KERNEL | GFP_ATOMIC | \
119 __GFP_NOACCOUNT)) | \
119 __GFP_NORETRY | __GFP_NOMEMALLOC | \ 120 __GFP_NORETRY | __GFP_NOMEMALLOC | \
120 __GFP_NOWARN) 121 __GFP_NOWARN)
121 122
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index d9359b770cd9..501820c815b3 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1187,10 +1187,10 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
1187 * The check (unnecessarily) ignores LRU pages being isolated and 1187 * The check (unnecessarily) ignores LRU pages being isolated and
1188 * walked by the page reclaim code, however that's not a big loss. 1188 * walked by the page reclaim code, however that's not a big loss.
1189 */ 1189 */
1190 if (!PageHuge(p) && !PageTransTail(p)) { 1190 if (!PageHuge(p)) {
1191 if (!PageLRU(p)) 1191 if (!PageLRU(hpage))
1192 shake_page(p, 0); 1192 shake_page(hpage, 0);
1193 if (!PageLRU(p)) { 1193 if (!PageLRU(hpage)) {
1194 /* 1194 /*
1195 * shake_page could have turned it free. 1195 * shake_page could have turned it free.
1196 */ 1196 */
@@ -1777,12 +1777,12 @@ int soft_offline_page(struct page *page, int flags)
1777 } else if (ret == 0) { /* for free pages */ 1777 } else if (ret == 0) { /* for free pages */
1778 if (PageHuge(page)) { 1778 if (PageHuge(page)) {
1779 set_page_hwpoison_huge_page(hpage); 1779 set_page_hwpoison_huge_page(hpage);
1780 dequeue_hwpoisoned_huge_page(hpage); 1780 if (!dequeue_hwpoisoned_huge_page(hpage))
1781 atomic_long_add(1 << compound_order(hpage), 1781 atomic_long_add(1 << compound_order(hpage),
1782 &num_poisoned_pages); 1782 &num_poisoned_pages);
1783 } else { 1783 } else {
1784 SetPageHWPoison(page); 1784 if (!TestSetPageHWPoison(page))
1785 atomic_long_inc(&num_poisoned_pages); 1785 atomic_long_inc(&num_poisoned_pages);
1786 } 1786 }
1787 } 1787 }
1788 unset_migratetype_isolate(page, MIGRATE_MOVABLE); 1788 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index ede26291d4aa..747743237d9f 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2518,7 +2518,7 @@ static void __init check_numabalancing_enable(void)
2518 if (numabalancing_override) 2518 if (numabalancing_override)
2519 set_numabalancing_state(numabalancing_override == 1); 2519 set_numabalancing_state(numabalancing_override == 1);
2520 2520
2521 if (nr_node_ids > 1 && !numabalancing_override) { 2521 if (num_online_nodes() > 1 && !numabalancing_override) {
2522 pr_info("%s automatic NUMA balancing. " 2522 pr_info("%s automatic NUMA balancing. "
2523 "Configure with numa_balancing= or the " 2523 "Configure with numa_balancing= or the "
2524 "kernel.numa_balancing sysctl", 2524 "kernel.numa_balancing sysctl",
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 5daf5568b9e1..eb59f7eea508 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -580,7 +580,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
580 long x; 580 long x;
581 581
582 x = div64_s64(((s64)setpoint - (s64)dirty) << RATELIMIT_CALC_SHIFT, 582 x = div64_s64(((s64)setpoint - (s64)dirty) << RATELIMIT_CALC_SHIFT,
583 limit - setpoint + 1); 583 (limit - setpoint) | 1);
584 pos_ratio = x; 584 pos_ratio = x;
585 pos_ratio = pos_ratio * x >> RATELIMIT_CALC_SHIFT; 585 pos_ratio = pos_ratio * x >> RATELIMIT_CALC_SHIFT;
586 pos_ratio = pos_ratio * x >> RATELIMIT_CALC_SHIFT; 586 pos_ratio = pos_ratio * x >> RATELIMIT_CALC_SHIFT;
@@ -807,7 +807,7 @@ static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
807 * scale global setpoint to bdi's: 807 * scale global setpoint to bdi's:
808 * bdi_setpoint = setpoint * bdi_thresh / thresh 808 * bdi_setpoint = setpoint * bdi_thresh / thresh
809 */ 809 */
810 x = div_u64((u64)bdi_thresh << 16, thresh + 1); 810 x = div_u64((u64)bdi_thresh << 16, thresh | 1);
811 bdi_setpoint = setpoint * (u64)x >> 16; 811 bdi_setpoint = setpoint * (u64)x >> 16;
812 /* 812 /*
813 * Use span=(8*write_bw) in single bdi case as indicated by 813 * Use span=(8*write_bw) in single bdi case as indicated by
@@ -822,7 +822,7 @@ static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
822 822
823 if (bdi_dirty < x_intercept - span / 4) { 823 if (bdi_dirty < x_intercept - span / 4) {
824 pos_ratio = div64_u64(pos_ratio * (x_intercept - bdi_dirty), 824 pos_ratio = div64_u64(pos_ratio * (x_intercept - bdi_dirty),
825 x_intercept - bdi_setpoint + 1); 825 (x_intercept - bdi_setpoint) | 1);
826 } else 826 } else
827 pos_ratio /= 4; 827 pos_ratio /= 4;
828 828
diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index 755a42c76eb4..303c908790ef 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -101,7 +101,8 @@ void unset_migratetype_isolate(struct page *page, unsigned migratetype)
101 buddy_idx = __find_buddy_index(page_idx, order); 101 buddy_idx = __find_buddy_index(page_idx, order);
102 buddy = page + (buddy_idx - page_idx); 102 buddy = page + (buddy_idx - page_idx);
103 103
104 if (!is_migrate_isolate_page(buddy)) { 104 if (pfn_valid_within(page_to_pfn(buddy)) &&
105 !is_migrate_isolate_page(buddy)) {
105 __isolate_free_page(page, order); 106 __isolate_free_page(page, order);
106 kernel_map_pages(page, (1 << order), 1); 107 kernel_map_pages(page, (1 << order), 1);
107 set_page_refcounted(page); 108 set_page_refcounted(page);
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 98a30a5b8664..59555f0f8fc8 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -443,7 +443,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
443 case NETDEV_UP: 443 case NETDEV_UP:
444 /* Put all VLANs for this dev in the up state too. */ 444 /* Put all VLANs for this dev in the up state too. */
445 vlan_group_for_each_dev(grp, i, vlandev) { 445 vlan_group_for_each_dev(grp, i, vlandev) {
446 flgs = vlandev->flags; 446 flgs = dev_get_flags(vlandev);
447 if (flgs & IFF_UP) 447 if (flgs & IFF_UP)
448 continue; 448 continue;
449 449
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 476709bd068a..c4802f3bd4c5 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1557,7 +1557,8 @@ static int hci_dev_do_close(struct hci_dev *hdev)
1557{ 1557{
1558 BT_DBG("%s %p", hdev->name, hdev); 1558 BT_DBG("%s %p", hdev->name, hdev);
1559 1559
1560 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER)) { 1560 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
1561 test_bit(HCI_UP, &hdev->flags)) {
1561 /* Execute vendor specific shutdown routine */ 1562 /* Execute vendor specific shutdown routine */
1562 if (hdev->shutdown) 1563 if (hdev->shutdown)
1563 hdev->shutdown(hdev); 1564 hdev->shutdown(hdev);
@@ -2853,9 +2854,11 @@ static void le_scan_disable_work_complete(struct hci_dev *hdev, u8 status,
2853 * state. If we were running both LE and BR/EDR inquiry 2854 * state. If we were running both LE and BR/EDR inquiry
2854 * simultaneously, and BR/EDR inquiry is already 2855 * simultaneously, and BR/EDR inquiry is already
2855 * finished, stop discovery, otherwise BR/EDR inquiry 2856 * finished, stop discovery, otherwise BR/EDR inquiry
2856 * will stop discovery when finished. 2857 * will stop discovery when finished. If we will resolve
2858 * remote device name, do not change discovery state.
2857 */ 2859 */
2858 if (!test_bit(HCI_INQUIRY, &hdev->flags)) 2860 if (!test_bit(HCI_INQUIRY, &hdev->flags) &&
2861 hdev->discovery.state != DISCOVERY_RESOLVING)
2859 hci_discovery_set_state(hdev, 2862 hci_discovery_set_state(hdev,
2860 DISCOVERY_STOPPED); 2863 DISCOVERY_STOPPED);
2861 } else { 2864 } else {
diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index 409608960899..e29ad70b3000 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -170,7 +170,7 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
170 struct br_port_msg *bpm; 170 struct br_port_msg *bpm;
171 struct nlattr *nest, *nest2; 171 struct nlattr *nest, *nest2;
172 172
173 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), NLM_F_MULTI); 173 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0);
174 if (!nlh) 174 if (!nlh)
175 return -EMSGSIZE; 175 return -EMSGSIZE;
176 176
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 4b6722f8f179..a3abe6ed111e 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1072,7 +1072,7 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
1072 1072
1073 err = br_ip6_multicast_add_group(br, port, &grec->grec_mca, 1073 err = br_ip6_multicast_add_group(br, port, &grec->grec_mca,
1074 vid); 1074 vid);
1075 if (!err) 1075 if (err)
1076 break; 1076 break;
1077 } 1077 }
1078 1078
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index ab55e2472beb..60ddfbeb47f5 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -37,10 +37,6 @@
37#include <net/route.h> 37#include <net/route.h>
38#include <net/netfilter/br_netfilter.h> 38#include <net/netfilter/br_netfilter.h>
39 39
40#if IS_ENABLED(CONFIG_NF_CONNTRACK)
41#include <net/netfilter/nf_conntrack.h>
42#endif
43
44#include <asm/uaccess.h> 40#include <asm/uaccess.h>
45#include "br_private.h" 41#include "br_private.h"
46#ifdef CONFIG_SYSCTL 42#ifdef CONFIG_SYSCTL
@@ -350,24 +346,15 @@ free_skb:
350 return 0; 346 return 0;
351} 347}
352 348
353static bool dnat_took_place(const struct sk_buff *skb) 349static bool daddr_was_changed(const struct sk_buff *skb,
350 const struct nf_bridge_info *nf_bridge)
354{ 351{
355#if IS_ENABLED(CONFIG_NF_CONNTRACK) 352 return ip_hdr(skb)->daddr != nf_bridge->ipv4_daddr;
356 enum ip_conntrack_info ctinfo;
357 struct nf_conn *ct;
358
359 ct = nf_ct_get(skb, &ctinfo);
360 if (!ct || nf_ct_is_untracked(ct))
361 return false;
362
363 return test_bit(IPS_DST_NAT_BIT, &ct->status);
364#else
365 return false;
366#endif
367} 353}
368 354
369/* This requires some explaining. If DNAT has taken place, 355/* This requires some explaining. If DNAT has taken place,
370 * we will need to fix up the destination Ethernet address. 356 * we will need to fix up the destination Ethernet address.
357 * This is also true when SNAT takes place (for the reply direction).
371 * 358 *
372 * There are two cases to consider: 359 * There are two cases to consider:
373 * 1. The packet was DNAT'ed to a device in the same bridge 360 * 1. The packet was DNAT'ed to a device in the same bridge
@@ -421,7 +408,7 @@ static int br_nf_pre_routing_finish(struct sock *sk, struct sk_buff *skb)
421 nf_bridge->pkt_otherhost = false; 408 nf_bridge->pkt_otherhost = false;
422 } 409 }
423 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING; 410 nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
424 if (dnat_took_place(skb)) { 411 if (daddr_was_changed(skb, nf_bridge)) {
425 if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) { 412 if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) {
426 struct in_device *in_dev = __in_dev_get_rcu(dev); 413 struct in_device *in_dev = __in_dev_get_rcu(dev);
427 414
@@ -632,6 +619,7 @@ static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
632 struct sk_buff *skb, 619 struct sk_buff *skb,
633 const struct nf_hook_state *state) 620 const struct nf_hook_state *state)
634{ 621{
622 struct nf_bridge_info *nf_bridge;
635 struct net_bridge_port *p; 623 struct net_bridge_port *p;
636 struct net_bridge *br; 624 struct net_bridge *br;
637 __u32 len = nf_bridge_encap_header_len(skb); 625 __u32 len = nf_bridge_encap_header_len(skb);
@@ -669,6 +657,9 @@ static unsigned int br_nf_pre_routing(const struct nf_hook_ops *ops,
669 if (!setup_pre_routing(skb)) 657 if (!setup_pre_routing(skb))
670 return NF_DROP; 658 return NF_DROP;
671 659
660 nf_bridge = nf_bridge_info_get(skb);
661 nf_bridge->ipv4_daddr = ip_hdr(skb)->daddr;
662
672 skb->protocol = htons(ETH_P_IP); 663 skb->protocol = htons(ETH_P_IP);
673 664
674 NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->sk, skb, 665 NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->sk, skb,
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 0e4ddb81610d..4b5c236998ff 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -394,7 +394,7 @@ errout:
394 * Dump information about all ports, in response to GETLINK 394 * Dump information about all ports, in response to GETLINK
395 */ 395 */
396int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, 396int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
397 struct net_device *dev, u32 filter_mask) 397 struct net_device *dev, u32 filter_mask, int nlflags)
398{ 398{
399 struct net_bridge_port *port = br_port_get_rtnl(dev); 399 struct net_bridge_port *port = br_port_get_rtnl(dev);
400 400
@@ -402,7 +402,7 @@ int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
402 !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) 402 !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
403 return 0; 403 return 0;
404 404
405 return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, NLM_F_MULTI, 405 return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
406 filter_mask, dev); 406 filter_mask, dev);
407} 407}
408 408
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 6ca0251cb478..3362c29400f1 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -828,7 +828,7 @@ void br_ifinfo_notify(int event, struct net_bridge_port *port);
828int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); 828int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
829int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); 829int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
830int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, 830int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
831 u32 filter_mask); 831 u32 filter_mask, int nlflags);
832 832
833#ifdef CONFIG_SYSFS 833#ifdef CONFIG_SYSFS
834/* br_sysfs_if.c */ 834/* br_sysfs_if.c */
diff --git a/net/bridge/br_stp_timer.c b/net/bridge/br_stp_timer.c
index 4fcaa67750fd..7caf7fae2d5b 100644
--- a/net/bridge/br_stp_timer.c
+++ b/net/bridge/br_stp_timer.c
@@ -97,7 +97,9 @@ static void br_forward_delay_timer_expired(unsigned long arg)
97 netif_carrier_on(br->dev); 97 netif_carrier_on(br->dev);
98 } 98 }
99 br_log_state(p); 99 br_log_state(p);
100 rcu_read_lock();
100 br_ifinfo_notify(RTM_NEWLINK, p); 101 br_ifinfo_notify(RTM_NEWLINK, p);
102 rcu_read_unlock();
101 spin_unlock(&br->lock); 103 spin_unlock(&br->lock);
102} 104}
103 105
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index 91180a7fc943..24c7c96bf5f8 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1117,6 +1117,8 @@ static int do_replace(struct net *net, const void __user *user,
1117 return -ENOMEM; 1117 return -ENOMEM;
1118 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter)) 1118 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
1119 return -ENOMEM; 1119 return -ENOMEM;
1120 if (tmp.num_counters == 0)
1121 return -EINVAL;
1120 1122
1121 tmp.name[sizeof(tmp.name) - 1] = 0; 1123 tmp.name[sizeof(tmp.name) - 1] = 0;
1122 1124
@@ -2159,6 +2161,8 @@ static int compat_copy_ebt_replace_from_user(struct ebt_replace *repl,
2159 return -ENOMEM; 2161 return -ENOMEM;
2160 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter)) 2162 if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter))
2161 return -ENOMEM; 2163 return -ENOMEM;
2164 if (tmp.num_counters == 0)
2165 return -EINVAL;
2162 2166
2163 memcpy(repl, &tmp, offsetof(struct ebt_replace, hook_entry)); 2167 memcpy(repl, &tmp, offsetof(struct ebt_replace, hook_entry));
2164 2168
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
index 4ec0c803aef1..112ad784838a 100644
--- a/net/caif/caif_socket.c
+++ b/net/caif/caif_socket.c
@@ -330,6 +330,10 @@ static long caif_stream_data_wait(struct sock *sk, long timeo)
330 release_sock(sk); 330 release_sock(sk);
331 timeo = schedule_timeout(timeo); 331 timeo = schedule_timeout(timeo);
332 lock_sock(sk); 332 lock_sock(sk);
333
334 if (sock_flag(sk, SOCK_DEAD))
335 break;
336
333 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags); 337 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
334 } 338 }
335 339
@@ -373,6 +377,10 @@ static int caif_stream_recvmsg(struct socket *sock, struct msghdr *msg,
373 struct sk_buff *skb; 377 struct sk_buff *skb;
374 378
375 lock_sock(sk); 379 lock_sock(sk);
380 if (sock_flag(sk, SOCK_DEAD)) {
381 err = -ECONNRESET;
382 goto unlock;
383 }
376 skb = skb_dequeue(&sk->sk_receive_queue); 384 skb = skb_dequeue(&sk->sk_receive_queue);
377 caif_check_flow_release(sk); 385 caif_check_flow_release(sk);
378 386
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 41a4abc7e98e..c4ec9239249a 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1306,8 +1306,6 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc,
1306 if (list_empty(&req->r_osd_item)) 1306 if (list_empty(&req->r_osd_item))
1307 req->r_osd = NULL; 1307 req->r_osd = NULL;
1308 } 1308 }
1309
1310 list_del_init(&req->r_req_lru_item); /* can be on notarget */
1311 ceph_osdc_put_request(req); 1309 ceph_osdc_put_request(req);
1312} 1310}
1313 1311
@@ -2017,20 +2015,29 @@ static void kick_requests(struct ceph_osd_client *osdc, bool force_resend,
2017 err = __map_request(osdc, req, 2015 err = __map_request(osdc, req,
2018 force_resend || force_resend_writes); 2016 force_resend || force_resend_writes);
2019 dout("__map_request returned %d\n", err); 2017 dout("__map_request returned %d\n", err);
2020 if (err == 0)
2021 continue; /* no change and no osd was specified */
2022 if (err < 0) 2018 if (err < 0)
2023 continue; /* hrm! */ 2019 continue; /* hrm! */
2024 if (req->r_osd == NULL) { 2020 if (req->r_osd == NULL || err > 0) {
2025 dout("tid %llu maps to no valid osd\n", req->r_tid); 2021 if (req->r_osd == NULL) {
2026 needmap++; /* request a newer map */ 2022 dout("lingering %p tid %llu maps to no osd\n",
2027 continue; 2023 req, req->r_tid);
2028 } 2024 /*
2025 * A homeless lingering request makes
2026 * no sense, as it's job is to keep
2027 * a particular OSD connection open.
2028 * Request a newer map and kick the
2029 * request, knowing that it won't be
2030 * resent until we actually get a map
2031 * that can tell us where to send it.
2032 */
2033 needmap++;
2034 }
2029 2035
2030 dout("kicking lingering %p tid %llu osd%d\n", req, req->r_tid, 2036 dout("kicking lingering %p tid %llu osd%d\n", req,
2031 req->r_osd ? req->r_osd->o_osd : -1); 2037 req->r_tid, req->r_osd ? req->r_osd->o_osd : -1);
2032 __register_request(osdc, req); 2038 __register_request(osdc, req);
2033 __unregister_linger_request(osdc, req); 2039 __unregister_linger_request(osdc, req);
2040 }
2034 } 2041 }
2035 reset_changed_osds(osdc); 2042 reset_changed_osds(osdc);
2036 mutex_unlock(&osdc->request_mutex); 2043 mutex_unlock(&osdc->request_mutex);
diff --git a/net/core/dev.c b/net/core/dev.c
index 1796cef55ab5..2c1c67fad64d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3079,7 +3079,7 @@ static struct rps_dev_flow *
3079set_rps_cpu(struct net_device *dev, struct sk_buff *skb, 3079set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3080 struct rps_dev_flow *rflow, u16 next_cpu) 3080 struct rps_dev_flow *rflow, u16 next_cpu)
3081{ 3081{
3082 if (next_cpu != RPS_NO_CPU) { 3082 if (next_cpu < nr_cpu_ids) {
3083#ifdef CONFIG_RFS_ACCEL 3083#ifdef CONFIG_RFS_ACCEL
3084 struct netdev_rx_queue *rxqueue; 3084 struct netdev_rx_queue *rxqueue;
3085 struct rps_dev_flow_table *flow_table; 3085 struct rps_dev_flow_table *flow_table;
@@ -3184,7 +3184,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3184 * If the desired CPU (where last recvmsg was done) is 3184 * If the desired CPU (where last recvmsg was done) is
3185 * different from current CPU (one in the rx-queue flow 3185 * different from current CPU (one in the rx-queue flow
3186 * table entry), switch if one of the following holds: 3186 * table entry), switch if one of the following holds:
3187 * - Current CPU is unset (equal to RPS_NO_CPU). 3187 * - Current CPU is unset (>= nr_cpu_ids).
3188 * - Current CPU is offline. 3188 * - Current CPU is offline.
3189 * - The current CPU's queue tail has advanced beyond the 3189 * - The current CPU's queue tail has advanced beyond the
3190 * last packet that was enqueued using this table entry. 3190 * last packet that was enqueued using this table entry.
@@ -3192,14 +3192,14 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3192 * have been dequeued, thus preserving in order delivery. 3192 * have been dequeued, thus preserving in order delivery.
3193 */ 3193 */
3194 if (unlikely(tcpu != next_cpu) && 3194 if (unlikely(tcpu != next_cpu) &&
3195 (tcpu == RPS_NO_CPU || !cpu_online(tcpu) || 3195 (tcpu >= nr_cpu_ids || !cpu_online(tcpu) ||
3196 ((int)(per_cpu(softnet_data, tcpu).input_queue_head - 3196 ((int)(per_cpu(softnet_data, tcpu).input_queue_head -
3197 rflow->last_qtail)) >= 0)) { 3197 rflow->last_qtail)) >= 0)) {
3198 tcpu = next_cpu; 3198 tcpu = next_cpu;
3199 rflow = set_rps_cpu(dev, skb, rflow, next_cpu); 3199 rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
3200 } 3200 }
3201 3201
3202 if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) { 3202 if (tcpu < nr_cpu_ids && cpu_online(tcpu)) {
3203 *rflowp = rflow; 3203 *rflowp = rflow;
3204 cpu = tcpu; 3204 cpu = tcpu;
3205 goto done; 3205 goto done;
@@ -3240,14 +3240,14 @@ bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index,
3240 struct rps_dev_flow_table *flow_table; 3240 struct rps_dev_flow_table *flow_table;
3241 struct rps_dev_flow *rflow; 3241 struct rps_dev_flow *rflow;
3242 bool expire = true; 3242 bool expire = true;
3243 int cpu; 3243 unsigned int cpu;
3244 3244
3245 rcu_read_lock(); 3245 rcu_read_lock();
3246 flow_table = rcu_dereference(rxqueue->rps_flow_table); 3246 flow_table = rcu_dereference(rxqueue->rps_flow_table);
3247 if (flow_table && flow_id <= flow_table->mask) { 3247 if (flow_table && flow_id <= flow_table->mask) {
3248 rflow = &flow_table->flows[flow_id]; 3248 rflow = &flow_table->flows[flow_id];
3249 cpu = ACCESS_ONCE(rflow->cpu); 3249 cpu = ACCESS_ONCE(rflow->cpu);
3250 if (rflow->filter == filter_id && cpu != RPS_NO_CPU && 3250 if (rflow->filter == filter_id && cpu < nr_cpu_ids &&
3251 ((int)(per_cpu(softnet_data, cpu).input_queue_head - 3251 ((int)(per_cpu(softnet_data, cpu).input_queue_head -
3252 rflow->last_qtail) < 3252 rflow->last_qtail) <
3253 (int)(10 * flow_table->mask))) 3253 (int)(10 * flow_table->mask)))
@@ -5209,7 +5209,7 @@ static int __netdev_upper_dev_link(struct net_device *dev,
5209 if (__netdev_find_adj(upper_dev, dev, &upper_dev->all_adj_list.upper)) 5209 if (__netdev_find_adj(upper_dev, dev, &upper_dev->all_adj_list.upper))
5210 return -EBUSY; 5210 return -EBUSY;
5211 5211
5212 if (__netdev_find_adj(dev, upper_dev, &dev->all_adj_list.upper)) 5212 if (__netdev_find_adj(dev, upper_dev, &dev->adj_list.upper))
5213 return -EEXIST; 5213 return -EEXIST;
5214 5214
5215 if (master && netdev_master_upper_dev_get(dev)) 5215 if (master && netdev_master_upper_dev_get(dev))
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 1d00b8922902..1347e11f5cc9 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -359,7 +359,15 @@ static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
359 int err; 359 int err;
360 struct ethtool_cmd cmd; 360 struct ethtool_cmd cmd;
361 361
362 err = __ethtool_get_settings(dev, &cmd); 362 if (!dev->ethtool_ops->get_settings)
363 return -EOPNOTSUPP;
364
365 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
366 return -EFAULT;
367
368 cmd.cmd = ETHTOOL_GSET;
369
370 err = dev->ethtool_ops->get_settings(dev, &cmd);
363 if (err < 0) 371 if (err < 0)
364 return err; 372 return err;
365 373
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 78fc04ad36fc..572af0011997 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -601,7 +601,7 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh)
601 } 601 }
602 602
603 err = rtnl_net_fill(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, 603 err = rtnl_net_fill(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0,
604 RTM_GETNSID, net, peer, -1); 604 RTM_NEWNSID, net, peer, -1);
605 if (err < 0) 605 if (err < 0)
606 goto err_out; 606 goto err_out;
607 607
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 358d52a38533..8de36824018d 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2416,6 +2416,9 @@ void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
2416{ 2416{
2417 struct sk_buff *skb; 2417 struct sk_buff *skb;
2418 2418
2419 if (dev->reg_state != NETREG_REGISTERED)
2420 return;
2421
2419 skb = rtmsg_ifinfo_build_skb(type, dev, change, flags); 2422 skb = rtmsg_ifinfo_build_skb(type, dev, change, flags);
2420 if (skb) 2423 if (skb)
2421 rtmsg_ifinfo_send(skb, dev, flags); 2424 rtmsg_ifinfo_send(skb, dev, flags);
@@ -2854,7 +2857,7 @@ static int brport_nla_put_flag(struct sk_buff *skb, u32 flags, u32 mask,
2854 2857
2855int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 2858int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2856 struct net_device *dev, u16 mode, 2859 struct net_device *dev, u16 mode,
2857 u32 flags, u32 mask) 2860 u32 flags, u32 mask, int nlflags)
2858{ 2861{
2859 struct nlmsghdr *nlh; 2862 struct nlmsghdr *nlh;
2860 struct ifinfomsg *ifm; 2863 struct ifinfomsg *ifm;
@@ -2863,7 +2866,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2863 u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN; 2866 u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
2864 struct net_device *br_dev = netdev_master_upper_dev_get(dev); 2867 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
2865 2868
2866 nlh = nlmsg_put(skb, pid, seq, RTM_NEWLINK, sizeof(*ifm), NLM_F_MULTI); 2869 nlh = nlmsg_put(skb, pid, seq, RTM_NEWLINK, sizeof(*ifm), nlflags);
2867 if (nlh == NULL) 2870 if (nlh == NULL)
2868 return -EMSGSIZE; 2871 return -EMSGSIZE;
2869 2872
@@ -2969,7 +2972,8 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
2969 if (br_dev && br_dev->netdev_ops->ndo_bridge_getlink) { 2972 if (br_dev && br_dev->netdev_ops->ndo_bridge_getlink) {
2970 if (idx >= cb->args[0] && 2973 if (idx >= cb->args[0] &&
2971 br_dev->netdev_ops->ndo_bridge_getlink( 2974 br_dev->netdev_ops->ndo_bridge_getlink(
2972 skb, portid, seq, dev, filter_mask) < 0) 2975 skb, portid, seq, dev, filter_mask,
2976 NLM_F_MULTI) < 0)
2973 break; 2977 break;
2974 idx++; 2978 idx++;
2975 } 2979 }
@@ -2977,7 +2981,8 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
2977 if (ops->ndo_bridge_getlink) { 2981 if (ops->ndo_bridge_getlink) {
2978 if (idx >= cb->args[0] && 2982 if (idx >= cb->args[0] &&
2979 ops->ndo_bridge_getlink(skb, portid, seq, dev, 2983 ops->ndo_bridge_getlink(skb, portid, seq, dev,
2980 filter_mask) < 0) 2984 filter_mask,
2985 NLM_F_MULTI) < 0)
2981 break; 2986 break;
2982 idx++; 2987 idx++;
2983 } 2988 }
@@ -3018,7 +3023,7 @@ static int rtnl_bridge_notify(struct net_device *dev)
3018 goto errout; 3023 goto errout;
3019 } 3024 }
3020 3025
3021 err = dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev, 0); 3026 err = dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev, 0, 0);
3022 if (err < 0) 3027 if (err < 0)
3023 goto errout; 3028 goto errout;
3024 3029
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index d1967dab9cc6..3cfff2a3d651 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -280,13 +280,14 @@ nodata:
280EXPORT_SYMBOL(__alloc_skb); 280EXPORT_SYMBOL(__alloc_skb);
281 281
282/** 282/**
283 * build_skb - build a network buffer 283 * __build_skb - build a network buffer
284 * @data: data buffer provided by caller 284 * @data: data buffer provided by caller
285 * @frag_size: size of fragment, or 0 if head was kmalloced 285 * @frag_size: size of data, or 0 if head was kmalloced
286 * 286 *
287 * Allocate a new &sk_buff. Caller provides space holding head and 287 * Allocate a new &sk_buff. Caller provides space holding head and
288 * skb_shared_info. @data must have been allocated by kmalloc() only if 288 * skb_shared_info. @data must have been allocated by kmalloc() only if
289 * @frag_size is 0, otherwise data should come from the page allocator. 289 * @frag_size is 0, otherwise data should come from the page allocator
290 * or vmalloc()
290 * The return is the new skb buffer. 291 * The return is the new skb buffer.
291 * On a failure the return is %NULL, and @data is not freed. 292 * On a failure the return is %NULL, and @data is not freed.
292 * Notes : 293 * Notes :
@@ -297,7 +298,7 @@ EXPORT_SYMBOL(__alloc_skb);
297 * before giving packet to stack. 298 * before giving packet to stack.
298 * RX rings only contains data buffers, not full skbs. 299 * RX rings only contains data buffers, not full skbs.
299 */ 300 */
300struct sk_buff *build_skb(void *data, unsigned int frag_size) 301struct sk_buff *__build_skb(void *data, unsigned int frag_size)
301{ 302{
302 struct skb_shared_info *shinfo; 303 struct skb_shared_info *shinfo;
303 struct sk_buff *skb; 304 struct sk_buff *skb;
@@ -311,7 +312,6 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
311 312
312 memset(skb, 0, offsetof(struct sk_buff, tail)); 313 memset(skb, 0, offsetof(struct sk_buff, tail));
313 skb->truesize = SKB_TRUESIZE(size); 314 skb->truesize = SKB_TRUESIZE(size);
314 skb->head_frag = frag_size != 0;
315 atomic_set(&skb->users, 1); 315 atomic_set(&skb->users, 1);
316 skb->head = data; 316 skb->head = data;
317 skb->data = data; 317 skb->data = data;
@@ -328,6 +328,23 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
328 328
329 return skb; 329 return skb;
330} 330}
331
332/* build_skb() is wrapper over __build_skb(), that specifically
333 * takes care of skb->head and skb->pfmemalloc
334 * This means that if @frag_size is not zero, then @data must be backed
335 * by a page fragment, not kmalloc() or vmalloc()
336 */
337struct sk_buff *build_skb(void *data, unsigned int frag_size)
338{
339 struct sk_buff *skb = __build_skb(data, frag_size);
340
341 if (skb && frag_size) {
342 skb->head_frag = 1;
343 if (virt_to_head_page(data)->pfmemalloc)
344 skb->pfmemalloc = 1;
345 }
346 return skb;
347}
331EXPORT_SYMBOL(build_skb); 348EXPORT_SYMBOL(build_skb);
332 349
333struct netdev_alloc_cache { 350struct netdev_alloc_cache {
@@ -348,7 +365,8 @@ static struct page *__page_frag_refill(struct netdev_alloc_cache *nc,
348 gfp_t gfp = gfp_mask; 365 gfp_t gfp = gfp_mask;
349 366
350 if (order) { 367 if (order) {
351 gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY; 368 gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY |
369 __GFP_NOMEMALLOC;
352 page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order); 370 page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order);
353 nc->frag.size = PAGE_SIZE << (page ? order : 0); 371 nc->frag.size = PAGE_SIZE << (page ? order : 0);
354 } 372 }
diff --git a/net/core/sock.c b/net/core/sock.c
index e891bcf325ca..292f42228bfb 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1474,8 +1474,8 @@ void sk_release_kernel(struct sock *sk)
1474 return; 1474 return;
1475 1475
1476 sock_hold(sk); 1476 sock_hold(sk);
1477 sock_net_set(sk, get_net(&init_net));
1478 sock_release(sk->sk_socket); 1477 sock_release(sk->sk_socket);
1478 sock_net_set(sk, get_net(&init_net));
1479 sock_put(sk); 1479 sock_put(sk);
1480} 1480}
1481EXPORT_SYMBOL(sk_release_kernel); 1481EXPORT_SYMBOL(sk_release_kernel);
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 2b4f21d34df6..ccf4c5629b3c 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -453,7 +453,8 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
453 iph->saddr, iph->daddr); 453 iph->saddr, iph->daddr);
454 if (req) { 454 if (req) {
455 nsk = dccp_check_req(sk, skb, req); 455 nsk = dccp_check_req(sk, skb, req);
456 reqsk_put(req); 456 if (!nsk)
457 reqsk_put(req);
457 return nsk; 458 return nsk;
458 } 459 }
459 nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo, 460 nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo,
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 9d0551092c6c..5165571f397a 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -301,7 +301,8 @@ static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
301 &iph->daddr, inet6_iif(skb)); 301 &iph->daddr, inet6_iif(skb));
302 if (req) { 302 if (req) {
303 nsk = dccp_check_req(sk, skb, req); 303 nsk = dccp_check_req(sk, skb, req);
304 reqsk_put(req); 304 if (!nsk)
305 reqsk_put(req);
305 return nsk; 306 return nsk;
306 } 307 }
307 nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo, 308 nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo,
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 5f566663e47f..30addee2dd03 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -186,8 +186,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
186 if (child == NULL) 186 if (child == NULL)
187 goto listen_overflow; 187 goto listen_overflow;
188 188
189 inet_csk_reqsk_queue_unlink(sk, req); 189 inet_csk_reqsk_queue_drop(sk, req);
190 inet_csk_reqsk_queue_removed(sk, req);
191 inet_csk_reqsk_queue_add(sk, req, child); 190 inet_csk_reqsk_queue_add(sk, req, child);
192out: 191out:
193 return child; 192 return child;
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 079a224471e7..e6f6cc3a1bcf 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -633,7 +633,7 @@ static int dsa_of_probe(struct device *dev)
633 if (cd->sw_addr > PHY_MAX_ADDR) 633 if (cd->sw_addr > PHY_MAX_ADDR)
634 continue; 634 continue;
635 635
636 if (!of_property_read_u32(np, "eeprom-length", &eeprom_len)) 636 if (!of_property_read_u32(child, "eeprom-length", &eeprom_len))
637 cd->eeprom_len = eeprom_len; 637 cd->eeprom_len = eeprom_len;
638 638
639 for_each_available_child_of_node(child, port) { 639 for_each_available_child_of_node(child, port) {
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index 05dab2957cd4..4adfd4d5471b 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -3,7 +3,9 @@ obj-$(CONFIG_IEEE802154_SOCKET) += ieee802154_socket.o
3obj-y += 6lowpan/ 3obj-y += 6lowpan/
4 4
5ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \ 5ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \
6 header_ops.o sysfs.o nl802154.o 6 header_ops.o sysfs.o nl802154.o trace.o
7ieee802154_socket-y := socket.o 7ieee802154_socket-y := socket.o
8 8
9CFLAGS_trace.o := -I$(src)
10
9ccflags-y += -D__CHECK_ENDIAN__ 11ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index 1b9d25f6e898..346c6665d25e 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -175,6 +175,7 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
175 int rc = -ENOBUFS; 175 int rc = -ENOBUFS;
176 struct net_device *dev; 176 struct net_device *dev;
177 int type = __IEEE802154_DEV_INVALID; 177 int type = __IEEE802154_DEV_INVALID;
178 unsigned char name_assign_type;
178 179
179 pr_debug("%s\n", __func__); 180 pr_debug("%s\n", __func__);
180 181
@@ -190,8 +191,10 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
190 if (devname[nla_len(info->attrs[IEEE802154_ATTR_DEV_NAME]) - 1] 191 if (devname[nla_len(info->attrs[IEEE802154_ATTR_DEV_NAME]) - 1]
191 != '\0') 192 != '\0')
192 return -EINVAL; /* phy name should be null-terminated */ 193 return -EINVAL; /* phy name should be null-terminated */
194 name_assign_type = NET_NAME_USER;
193 } else { 195 } else {
194 devname = "wpan%d"; 196 devname = "wpan%d";
197 name_assign_type = NET_NAME_ENUM;
195 } 198 }
196 199
197 if (strlen(devname) >= IFNAMSIZ) 200 if (strlen(devname) >= IFNAMSIZ)
@@ -221,7 +224,7 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
221 } 224 }
222 225
223 dev = rdev_add_virtual_intf_deprecated(wpan_phy_to_rdev(phy), devname, 226 dev = rdev_add_virtual_intf_deprecated(wpan_phy_to_rdev(phy), devname,
224 type); 227 name_assign_type, type);
225 if (IS_ERR(dev)) { 228 if (IS_ERR(dev)) {
226 rc = PTR_ERR(dev); 229 rc = PTR_ERR(dev);
227 goto nla_put_failure; 230 goto nla_put_failure;
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index a4daf91b8d0a..f3c12f6a4a39 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -589,7 +589,7 @@ static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
589 589
590 return rdev_add_virtual_intf(rdev, 590 return rdev_add_virtual_intf(rdev,
591 nla_data(info->attrs[NL802154_ATTR_IFNAME]), 591 nla_data(info->attrs[NL802154_ATTR_IFNAME]),
592 type, extended_addr); 592 NET_NAME_USER, type, extended_addr);
593} 593}
594 594
595static int nl802154_del_interface(struct sk_buff *skb, struct genl_info *info) 595static int nl802154_del_interface(struct sk_buff *skb, struct genl_info *info)
diff --git a/net/ieee802154/rdev-ops.h b/net/ieee802154/rdev-ops.h
index 7c46732fad2b..7b5a9dd94fe5 100644
--- a/net/ieee802154/rdev-ops.h
+++ b/net/ieee802154/rdev-ops.h
@@ -4,13 +4,16 @@
4#include <net/cfg802154.h> 4#include <net/cfg802154.h>
5 5
6#include "core.h" 6#include "core.h"
7#include "trace.h"
7 8
8static inline struct net_device * 9static inline struct net_device *
9rdev_add_virtual_intf_deprecated(struct cfg802154_registered_device *rdev, 10rdev_add_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
10 const char *name, int type) 11 const char *name,
12 unsigned char name_assign_type,
13 int type)
11{ 14{
12 return rdev->ops->add_virtual_intf_deprecated(&rdev->wpan_phy, name, 15 return rdev->ops->add_virtual_intf_deprecated(&rdev->wpan_phy, name,
13 type); 16 name_assign_type, type);
14} 17}
15 18
16static inline void 19static inline void
@@ -22,75 +25,131 @@ rdev_del_virtual_intf_deprecated(struct cfg802154_registered_device *rdev,
22 25
23static inline int 26static inline int
24rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name, 27rdev_add_virtual_intf(struct cfg802154_registered_device *rdev, char *name,
28 unsigned char name_assign_type,
25 enum nl802154_iftype type, __le64 extended_addr) 29 enum nl802154_iftype type, __le64 extended_addr)
26{ 30{
27 return rdev->ops->add_virtual_intf(&rdev->wpan_phy, name, type, 31 int ret;
32
33 trace_802154_rdev_add_virtual_intf(&rdev->wpan_phy, name, type,
28 extended_addr); 34 extended_addr);
35 ret = rdev->ops->add_virtual_intf(&rdev->wpan_phy, name,
36 name_assign_type, type,
37 extended_addr);
38 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
39 return ret;
29} 40}
30 41
31static inline int 42static inline int
32rdev_del_virtual_intf(struct cfg802154_registered_device *rdev, 43rdev_del_virtual_intf(struct cfg802154_registered_device *rdev,
33 struct wpan_dev *wpan_dev) 44 struct wpan_dev *wpan_dev)
34{ 45{
35 return rdev->ops->del_virtual_intf(&rdev->wpan_phy, wpan_dev); 46 int ret;
47
48 trace_802154_rdev_del_virtual_intf(&rdev->wpan_phy, wpan_dev);
49 ret = rdev->ops->del_virtual_intf(&rdev->wpan_phy, wpan_dev);
50 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
51 return ret;
36} 52}
37 53
38static inline int 54static inline int
39rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel) 55rdev_set_channel(struct cfg802154_registered_device *rdev, u8 page, u8 channel)
40{ 56{
41 return rdev->ops->set_channel(&rdev->wpan_phy, page, channel); 57 int ret;
58
59 trace_802154_rdev_set_channel(&rdev->wpan_phy, page, channel);
60 ret = rdev->ops->set_channel(&rdev->wpan_phy, page, channel);
61 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
62 return ret;
42} 63}
43 64
44static inline int 65static inline int
45rdev_set_cca_mode(struct cfg802154_registered_device *rdev, 66rdev_set_cca_mode(struct cfg802154_registered_device *rdev,
46 const struct wpan_phy_cca *cca) 67 const struct wpan_phy_cca *cca)
47{ 68{
48 return rdev->ops->set_cca_mode(&rdev->wpan_phy, cca); 69 int ret;
70
71 trace_802154_rdev_set_cca_mode(&rdev->wpan_phy, cca);
72 ret = rdev->ops->set_cca_mode(&rdev->wpan_phy, cca);
73 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
74 return ret;
49} 75}
50 76
51static inline int 77static inline int
52rdev_set_pan_id(struct cfg802154_registered_device *rdev, 78rdev_set_pan_id(struct cfg802154_registered_device *rdev,
53 struct wpan_dev *wpan_dev, __le16 pan_id) 79 struct wpan_dev *wpan_dev, __le16 pan_id)
54{ 80{
55 return rdev->ops->set_pan_id(&rdev->wpan_phy, wpan_dev, pan_id); 81 int ret;
82
83 trace_802154_rdev_set_pan_id(&rdev->wpan_phy, wpan_dev, pan_id);
84 ret = rdev->ops->set_pan_id(&rdev->wpan_phy, wpan_dev, pan_id);
85 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
86 return ret;
56} 87}
57 88
58static inline int 89static inline int
59rdev_set_short_addr(struct cfg802154_registered_device *rdev, 90rdev_set_short_addr(struct cfg802154_registered_device *rdev,
60 struct wpan_dev *wpan_dev, __le16 short_addr) 91 struct wpan_dev *wpan_dev, __le16 short_addr)
61{ 92{
62 return rdev->ops->set_short_addr(&rdev->wpan_phy, wpan_dev, short_addr); 93 int ret;
94
95 trace_802154_rdev_set_short_addr(&rdev->wpan_phy, wpan_dev, short_addr);
96 ret = rdev->ops->set_short_addr(&rdev->wpan_phy, wpan_dev, short_addr);
97 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
98 return ret;
63} 99}
64 100
65static inline int 101static inline int
66rdev_set_backoff_exponent(struct cfg802154_registered_device *rdev, 102rdev_set_backoff_exponent(struct cfg802154_registered_device *rdev,
67 struct wpan_dev *wpan_dev, u8 min_be, u8 max_be) 103 struct wpan_dev *wpan_dev, u8 min_be, u8 max_be)
68{ 104{
69 return rdev->ops->set_backoff_exponent(&rdev->wpan_phy, wpan_dev, 105 int ret;
106
107 trace_802154_rdev_set_backoff_exponent(&rdev->wpan_phy, wpan_dev,
70 min_be, max_be); 108 min_be, max_be);
109 ret = rdev->ops->set_backoff_exponent(&rdev->wpan_phy, wpan_dev,
110 min_be, max_be);
111 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
112 return ret;
71} 113}
72 114
73static inline int 115static inline int
74rdev_set_max_csma_backoffs(struct cfg802154_registered_device *rdev, 116rdev_set_max_csma_backoffs(struct cfg802154_registered_device *rdev,
75 struct wpan_dev *wpan_dev, u8 max_csma_backoffs) 117 struct wpan_dev *wpan_dev, u8 max_csma_backoffs)
76{ 118{
77 return rdev->ops->set_max_csma_backoffs(&rdev->wpan_phy, wpan_dev, 119 int ret;
78 max_csma_backoffs); 120
121 trace_802154_rdev_set_csma_backoffs(&rdev->wpan_phy, wpan_dev,
122 max_csma_backoffs);
123 ret = rdev->ops->set_max_csma_backoffs(&rdev->wpan_phy, wpan_dev,
124 max_csma_backoffs);
125 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
126 return ret;
79} 127}
80 128
81static inline int 129static inline int
82rdev_set_max_frame_retries(struct cfg802154_registered_device *rdev, 130rdev_set_max_frame_retries(struct cfg802154_registered_device *rdev,
83 struct wpan_dev *wpan_dev, s8 max_frame_retries) 131 struct wpan_dev *wpan_dev, s8 max_frame_retries)
84{ 132{
85 return rdev->ops->set_max_frame_retries(&rdev->wpan_phy, wpan_dev, 133 int ret;
134
135 trace_802154_rdev_set_max_frame_retries(&rdev->wpan_phy, wpan_dev,
86 max_frame_retries); 136 max_frame_retries);
137 ret = rdev->ops->set_max_frame_retries(&rdev->wpan_phy, wpan_dev,
138 max_frame_retries);
139 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
140 return ret;
87} 141}
88 142
89static inline int 143static inline int
90rdev_set_lbt_mode(struct cfg802154_registered_device *rdev, 144rdev_set_lbt_mode(struct cfg802154_registered_device *rdev,
91 struct wpan_dev *wpan_dev, bool mode) 145 struct wpan_dev *wpan_dev, bool mode)
92{ 146{
93 return rdev->ops->set_lbt_mode(&rdev->wpan_phy, wpan_dev, mode); 147 int ret;
148
149 trace_802154_rdev_set_lbt_mode(&rdev->wpan_phy, wpan_dev, mode);
150 ret = rdev->ops->set_lbt_mode(&rdev->wpan_phy, wpan_dev, mode);
151 trace_802154_rdev_return_int(&rdev->wpan_phy, ret);
152 return ret;
94} 153}
95 154
96#endif /* __CFG802154_RDEV_OPS */ 155#endif /* __CFG802154_RDEV_OPS */
diff --git a/net/ieee802154/trace.c b/net/ieee802154/trace.c
new file mode 100644
index 000000000000..95f997fad755
--- /dev/null
+++ b/net/ieee802154/trace.c
@@ -0,0 +1,7 @@
1#include <linux/module.h>
2
3#ifndef __CHECKER__
4#define CREATE_TRACE_POINTS
5#include "trace.h"
6
7#endif
diff --git a/net/ieee802154/trace.h b/net/ieee802154/trace.h
new file mode 100644
index 000000000000..5ac25eb6ed17
--- /dev/null
+++ b/net/ieee802154/trace.h
@@ -0,0 +1,247 @@
1/* Based on net/wireless/tracing.h */
2
3#undef TRACE_SYSTEM
4#define TRACE_SYSTEM cfg802154
5
6#if !defined(__RDEV_CFG802154_OPS_TRACE) || defined(TRACE_HEADER_MULTI_READ)
7#define __RDEV_CFG802154_OPS_TRACE
8
9#include <linux/tracepoint.h>
10
11#include <net/cfg802154.h>
12
13#define MAXNAME 32
14#define WPAN_PHY_ENTRY __array(char, wpan_phy_name, MAXNAME)
15#define WPAN_PHY_ASSIGN strlcpy(__entry->wpan_phy_name, \
16 wpan_phy_name(wpan_phy), \
17 MAXNAME)
18#define WPAN_PHY_PR_FMT "%s"
19#define WPAN_PHY_PR_ARG __entry->wpan_phy_name
20
21#define WPAN_DEV_ENTRY __field(u32, identifier)
22#define WPAN_DEV_ASSIGN (__entry->identifier) = (!IS_ERR_OR_NULL(wpan_dev) \
23 ? wpan_dev->identifier : 0)
24#define WPAN_DEV_PR_FMT "wpan_dev(%u)"
25#define WPAN_DEV_PR_ARG (__entry->identifier)
26
27#define WPAN_CCA_ENTRY __field(enum nl802154_cca_modes, cca_mode) \
28 __field(enum nl802154_cca_opts, cca_opt)
29#define WPAN_CCA_ASSIGN \
30 do { \
31 (__entry->cca_mode) = cca->mode; \
32 (__entry->cca_opt) = cca->opt; \
33 } while (0)
34#define WPAN_CCA_PR_FMT "cca_mode: %d, cca_opt: %d"
35#define WPAN_CCA_PR_ARG __entry->cca_mode, __entry->cca_opt
36
37#define BOOL_TO_STR(bo) (bo) ? "true" : "false"
38
39/*************************************************************
40 * rdev->ops traces *
41 *************************************************************/
42
43TRACE_EVENT(802154_rdev_add_virtual_intf,
44 TP_PROTO(struct wpan_phy *wpan_phy, char *name,
45 enum nl802154_iftype type, __le64 extended_addr),
46 TP_ARGS(wpan_phy, name, type, extended_addr),
47 TP_STRUCT__entry(
48 WPAN_PHY_ENTRY
49 __string(vir_intf_name, name ? name : "<noname>")
50 __field(enum nl802154_iftype, type)
51 __field(__le64, extended_addr)
52 ),
53 TP_fast_assign(
54 WPAN_PHY_ASSIGN;
55 __assign_str(vir_intf_name, name ? name : "<noname>");
56 __entry->type = type;
57 __entry->extended_addr = extended_addr;
58 ),
59 TP_printk(WPAN_PHY_PR_FMT ", virtual intf name: %s, type: %d, ea %llx",
60 WPAN_PHY_PR_ARG, __get_str(vir_intf_name), __entry->type,
61 __le64_to_cpu(__entry->extended_addr))
62);
63
64TRACE_EVENT(802154_rdev_del_virtual_intf,
65 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev),
66 TP_ARGS(wpan_phy, wpan_dev),
67 TP_STRUCT__entry(
68 WPAN_PHY_ENTRY
69 WPAN_DEV_ENTRY
70 ),
71 TP_fast_assign(
72 WPAN_PHY_ASSIGN;
73 WPAN_DEV_ASSIGN;
74 ),
75 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT, WPAN_PHY_PR_ARG,
76 WPAN_DEV_PR_ARG)
77);
78
79TRACE_EVENT(802154_rdev_set_channel,
80 TP_PROTO(struct wpan_phy *wpan_phy, u8 page, u8 channel),
81 TP_ARGS(wpan_phy, page, channel),
82 TP_STRUCT__entry(
83 WPAN_PHY_ENTRY
84 __field(u8, page)
85 __field(u8, channel)
86 ),
87 TP_fast_assign(
88 WPAN_PHY_ASSIGN;
89 __entry->page = page;
90 __entry->channel = channel;
91 ),
92 TP_printk(WPAN_PHY_PR_FMT ", page: %d, channel: %d", WPAN_PHY_PR_ARG,
93 __entry->page, __entry->channel)
94);
95
96TRACE_EVENT(802154_rdev_set_cca_mode,
97 TP_PROTO(struct wpan_phy *wpan_phy, const struct wpan_phy_cca *cca),
98 TP_ARGS(wpan_phy, cca),
99 TP_STRUCT__entry(
100 WPAN_PHY_ENTRY
101 WPAN_CCA_ENTRY
102 ),
103 TP_fast_assign(
104 WPAN_PHY_ASSIGN;
105 WPAN_CCA_ASSIGN;
106 ),
107 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_CCA_PR_FMT, WPAN_PHY_PR_ARG,
108 WPAN_CCA_PR_ARG)
109);
110
111DECLARE_EVENT_CLASS(802154_le16_template,
112 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
113 __le16 le16arg),
114 TP_ARGS(wpan_phy, wpan_dev, le16arg),
115 TP_STRUCT__entry(
116 WPAN_PHY_ENTRY
117 WPAN_DEV_ENTRY
118 __field(__le16, le16arg)
119 ),
120 TP_fast_assign(
121 WPAN_PHY_ASSIGN;
122 WPAN_DEV_ASSIGN;
123 __entry->le16arg = le16arg;
124 ),
125 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT ", pan id: 0x%04x",
126 WPAN_PHY_PR_ARG, WPAN_DEV_PR_ARG,
127 __le16_to_cpu(__entry->le16arg))
128);
129
130DEFINE_EVENT(802154_le16_template, 802154_rdev_set_pan_id,
131 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
132 __le16 le16arg),
133 TP_ARGS(wpan_phy, wpan_dev, le16arg)
134);
135
136DEFINE_EVENT_PRINT(802154_le16_template, 802154_rdev_set_short_addr,
137 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
138 __le16 le16arg),
139 TP_ARGS(wpan_phy, wpan_dev, le16arg),
140 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT ", sa: 0x%04x",
141 WPAN_PHY_PR_ARG, WPAN_DEV_PR_ARG,
142 __le16_to_cpu(__entry->le16arg))
143);
144
145TRACE_EVENT(802154_rdev_set_backoff_exponent,
146 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
147 u8 min_be, u8 max_be),
148 TP_ARGS(wpan_phy, wpan_dev, min_be, max_be),
149 TP_STRUCT__entry(
150 WPAN_PHY_ENTRY
151 WPAN_DEV_ENTRY
152 __field(u8, min_be)
153 __field(u8, max_be)
154 ),
155 TP_fast_assign(
156 WPAN_PHY_ASSIGN;
157 WPAN_DEV_ASSIGN;
158 __entry->min_be = min_be;
159 __entry->max_be = max_be;
160 ),
161
162 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT
163 ", min be: %d, max_be: %d", WPAN_PHY_PR_ARG,
164 WPAN_DEV_PR_ARG, __entry->min_be, __entry->max_be)
165);
166
167TRACE_EVENT(802154_rdev_set_csma_backoffs,
168 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
169 u8 max_csma_backoffs),
170 TP_ARGS(wpan_phy, wpan_dev, max_csma_backoffs),
171 TP_STRUCT__entry(
172 WPAN_PHY_ENTRY
173 WPAN_DEV_ENTRY
174 __field(u8, max_csma_backoffs)
175 ),
176 TP_fast_assign(
177 WPAN_PHY_ASSIGN;
178 WPAN_DEV_ASSIGN;
179 __entry->max_csma_backoffs = max_csma_backoffs;
180 ),
181
182 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT
183 ", max csma backoffs: %d", WPAN_PHY_PR_ARG,
184 WPAN_DEV_PR_ARG, __entry->max_csma_backoffs)
185);
186
187TRACE_EVENT(802154_rdev_set_max_frame_retries,
188 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
189 s8 max_frame_retries),
190 TP_ARGS(wpan_phy, wpan_dev, max_frame_retries),
191 TP_STRUCT__entry(
192 WPAN_PHY_ENTRY
193 WPAN_DEV_ENTRY
194 __field(s8, max_frame_retries)
195 ),
196 TP_fast_assign(
197 WPAN_PHY_ASSIGN;
198 WPAN_DEV_ASSIGN;
199 __entry->max_frame_retries = max_frame_retries;
200 ),
201
202 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT
203 ", max frame retries: %d", WPAN_PHY_PR_ARG,
204 WPAN_DEV_PR_ARG, __entry->max_frame_retries)
205);
206
207TRACE_EVENT(802154_rdev_set_lbt_mode,
208 TP_PROTO(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
209 bool mode),
210 TP_ARGS(wpan_phy, wpan_dev, mode),
211 TP_STRUCT__entry(
212 WPAN_PHY_ENTRY
213 WPAN_DEV_ENTRY
214 __field(bool, mode)
215 ),
216 TP_fast_assign(
217 WPAN_PHY_ASSIGN;
218 WPAN_DEV_ASSIGN;
219 __entry->mode = mode;
220 ),
221 TP_printk(WPAN_PHY_PR_FMT ", " WPAN_DEV_PR_FMT
222 ", lbt mode: %s", WPAN_PHY_PR_ARG,
223 WPAN_DEV_PR_ARG, BOOL_TO_STR(__entry->mode))
224);
225
226TRACE_EVENT(802154_rdev_return_int,
227 TP_PROTO(struct wpan_phy *wpan_phy, int ret),
228 TP_ARGS(wpan_phy, ret),
229 TP_STRUCT__entry(
230 WPAN_PHY_ENTRY
231 __field(int, ret)
232 ),
233 TP_fast_assign(
234 WPAN_PHY_ASSIGN;
235 __entry->ret = ret;
236 ),
237 TP_printk(WPAN_PHY_PR_FMT ", returned: %d", WPAN_PHY_PR_ARG,
238 __entry->ret)
239);
240
241#endif /* !__RDEV_CFG802154_OPS_TRACE || TRACE_HEADER_MULTI_READ */
242
243#undef TRACE_INCLUDE_PATH
244#define TRACE_INCLUDE_PATH .
245#undef TRACE_INCLUDE_FILE
246#define TRACE_INCLUDE_FILE trace
247#include <trace/define_trace.h>
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index e13fcc602da2..09b62e17dd8c 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1164,6 +1164,7 @@ int fib_table_insert(struct fib_table *tb, struct fib_config *cfg)
1164 state = fa->fa_state; 1164 state = fa->fa_state;
1165 new_fa->fa_state = state & ~FA_S_ACCESSED; 1165 new_fa->fa_state = state & ~FA_S_ACCESSED;
1166 new_fa->fa_slen = fa->fa_slen; 1166 new_fa->fa_slen = fa->fa_slen;
1167 new_fa->tb_id = tb->tb_id;
1167 1168
1168 err = netdev_switch_fib_ipv4_add(key, plen, fi, 1169 err = netdev_switch_fib_ipv4_add(key, plen, fi,
1169 new_fa->fa_tos, 1170 new_fa->fa_tos,
@@ -1764,7 +1765,7 @@ void fib_table_flush_external(struct fib_table *tb)
1764 /* record local slen */ 1765 /* record local slen */
1765 slen = fa->fa_slen; 1766 slen = fa->fa_slen;
1766 1767
1767 if (!fi || !(fi->fib_flags & RTNH_F_EXTERNAL)) 1768 if (!fi || !(fi->fib_flags & RTNH_F_OFFLOAD))
1768 continue; 1769 continue;
1769 1770
1770 netdev_switch_fib_ipv4_del(n->key, 1771 netdev_switch_fib_ipv4_del(n->key,
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 5c3dd6267ed3..8976ca423a07 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -564,6 +564,40 @@ int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req)
564} 564}
565EXPORT_SYMBOL(inet_rtx_syn_ack); 565EXPORT_SYMBOL(inet_rtx_syn_ack);
566 566
567/* return true if req was found in the syn_table[] */
568static bool reqsk_queue_unlink(struct request_sock_queue *queue,
569 struct request_sock *req)
570{
571 struct listen_sock *lopt = queue->listen_opt;
572 struct request_sock **prev;
573 bool found = false;
574
575 spin_lock(&queue->syn_wait_lock);
576
577 for (prev = &lopt->syn_table[req->rsk_hash]; *prev != NULL;
578 prev = &(*prev)->dl_next) {
579 if (*prev == req) {
580 *prev = req->dl_next;
581 found = true;
582 break;
583 }
584 }
585
586 spin_unlock(&queue->syn_wait_lock);
587 if (del_timer(&req->rsk_timer))
588 reqsk_put(req);
589 return found;
590}
591
592void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req)
593{
594 if (reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req)) {
595 reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
596 reqsk_put(req);
597 }
598}
599EXPORT_SYMBOL(inet_csk_reqsk_queue_drop);
600
567static void reqsk_timer_handler(unsigned long data) 601static void reqsk_timer_handler(unsigned long data)
568{ 602{
569 struct request_sock *req = (struct request_sock *)data; 603 struct request_sock *req = (struct request_sock *)data;
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index bb77ebdae3b3..4d32262c7502 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -224,14 +224,16 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
224 handler->idiag_get_info(sk, r, info); 224 handler->idiag_get_info(sk, r, info);
225 225
226 if (sk->sk_state < TCP_TIME_WAIT) { 226 if (sk->sk_state < TCP_TIME_WAIT) {
227 int err = 0; 227 union tcp_cc_info info;
228 size_t sz = 0;
229 int attr;
228 230
229 rcu_read_lock(); 231 rcu_read_lock();
230 ca_ops = READ_ONCE(icsk->icsk_ca_ops); 232 ca_ops = READ_ONCE(icsk->icsk_ca_ops);
231 if (ca_ops && ca_ops->get_info) 233 if (ca_ops && ca_ops->get_info)
232 err = ca_ops->get_info(sk, ext, skb); 234 sz = ca_ops->get_info(sk, ext, &attr, &info);
233 rcu_read_unlock(); 235 rcu_read_unlock();
234 if (err < 0) 236 if (sz && nla_put(skb, attr, sz, &info) < 0)
235 goto errout; 237 goto errout;
236 } 238 }
237 239
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 13bfe84bf3ca..a61200754f4b 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -1075,6 +1075,9 @@ static int do_replace(struct net *net, const void __user *user,
1075 /* overflow check */ 1075 /* overflow check */
1076 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1076 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1077 return -ENOMEM; 1077 return -ENOMEM;
1078 if (tmp.num_counters == 0)
1079 return -EINVAL;
1080
1078 tmp.name[sizeof(tmp.name)-1] = 0; 1081 tmp.name[sizeof(tmp.name)-1] = 0;
1079 1082
1080 newinfo = xt_alloc_table_info(tmp.size); 1083 newinfo = xt_alloc_table_info(tmp.size);
@@ -1499,6 +1502,9 @@ static int compat_do_replace(struct net *net, void __user *user,
1499 return -ENOMEM; 1502 return -ENOMEM;
1500 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1503 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1501 return -ENOMEM; 1504 return -ENOMEM;
1505 if (tmp.num_counters == 0)
1506 return -EINVAL;
1507
1502 tmp.name[sizeof(tmp.name)-1] = 0; 1508 tmp.name[sizeof(tmp.name)-1] = 0;
1503 1509
1504 newinfo = xt_alloc_table_info(tmp.size); 1510 newinfo = xt_alloc_table_info(tmp.size);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index c69db7fa25ee..2d0e265fef6e 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1262,6 +1262,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
1262 /* overflow check */ 1262 /* overflow check */
1263 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1263 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1264 return -ENOMEM; 1264 return -ENOMEM;
1265 if (tmp.num_counters == 0)
1266 return -EINVAL;
1267
1265 tmp.name[sizeof(tmp.name)-1] = 0; 1268 tmp.name[sizeof(tmp.name)-1] = 0;
1266 1269
1267 newinfo = xt_alloc_table_info(tmp.size); 1270 newinfo = xt_alloc_table_info(tmp.size);
@@ -1809,6 +1812,9 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1809 return -ENOMEM; 1812 return -ENOMEM;
1810 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1813 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1811 return -ENOMEM; 1814 return -ENOMEM;
1815 if (tmp.num_counters == 0)
1816 return -EINVAL;
1817
1812 tmp.name[sizeof(tmp.name)-1] = 0; 1818 tmp.name[sizeof(tmp.name)-1] = 0;
1813 1819
1814 newinfo = xt_alloc_table_info(tmp.size); 1820 newinfo = xt_alloc_table_info(tmp.size);
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index a93f260cf24c..05ff44b758df 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -158,6 +158,7 @@ void ping_unhash(struct sock *sk)
158 if (sk_hashed(sk)) { 158 if (sk_hashed(sk)) {
159 write_lock_bh(&ping_table.lock); 159 write_lock_bh(&ping_table.lock);
160 hlist_nulls_del(&sk->sk_nulls_node); 160 hlist_nulls_del(&sk->sk_nulls_node);
161 sk_nulls_node_init(&sk->sk_nulls_node);
161 sock_put(sk); 162 sock_put(sk);
162 isk->inet_num = 0; 163 isk->inet_num = 0;
163 isk->inet_sport = 0; 164 isk->inet_sport = 0;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index a78540f28276..f45f2a12f37b 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -902,6 +902,10 @@ static int ip_error(struct sk_buff *skb)
902 bool send; 902 bool send;
903 int code; 903 int code;
904 904
905 /* IP on this device is disabled. */
906 if (!in_dev)
907 goto out;
908
905 net = dev_net(rt->dst.dev); 909 net = dev_net(rt->dst.dev);
906 if (!IN_DEV_FORWARD(in_dev)) { 910 if (!IN_DEV_FORWARD(in_dev)) {
907 switch (rt->dst.error) { 911 switch (rt->dst.error) {
@@ -962,10 +966,7 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
962 if (dst_metric_locked(dst, RTAX_MTU)) 966 if (dst_metric_locked(dst, RTAX_MTU))
963 return; 967 return;
964 968
965 if (dst->dev->mtu < mtu) 969 if (ipv4_mtu(dst) < mtu)
966 return;
967
968 if (rt->rt_pmtu && rt->rt_pmtu < mtu)
969 return; 970 return;
970 971
971 if (mtu < ip_rt_min_pmtu) 972 if (mtu < ip_rt_min_pmtu)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 8c5cd9efebbc..f1377f2a0472 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -252,6 +252,7 @@
252#include <linux/types.h> 252#include <linux/types.h>
253#include <linux/fcntl.h> 253#include <linux/fcntl.h>
254#include <linux/poll.h> 254#include <linux/poll.h>
255#include <linux/inet_diag.h>
255#include <linux/init.h> 256#include <linux/init.h>
256#include <linux/fs.h> 257#include <linux/fs.h>
257#include <linux/skbuff.h> 258#include <linux/skbuff.h>
@@ -401,6 +402,7 @@ void tcp_init_sock(struct sock *sk)
401 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; 402 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
402 tp->snd_cwnd_clamp = ~0; 403 tp->snd_cwnd_clamp = ~0;
403 tp->mss_cache = TCP_MSS_DEFAULT; 404 tp->mss_cache = TCP_MSS_DEFAULT;
405 u64_stats_init(&tp->syncp);
404 406
405 tp->reordering = sysctl_tcp_reordering; 407 tp->reordering = sysctl_tcp_reordering;
406 tcp_enable_early_retrans(tp); 408 tcp_enable_early_retrans(tp);
@@ -2592,11 +2594,12 @@ EXPORT_SYMBOL(compat_tcp_setsockopt);
2592#endif 2594#endif
2593 2595
2594/* Return information about state of tcp endpoint in API format. */ 2596/* Return information about state of tcp endpoint in API format. */
2595void tcp_get_info(const struct sock *sk, struct tcp_info *info) 2597void tcp_get_info(struct sock *sk, struct tcp_info *info)
2596{ 2598{
2597 const struct tcp_sock *tp = tcp_sk(sk); 2599 const struct tcp_sock *tp = tcp_sk(sk);
2598 const struct inet_connection_sock *icsk = inet_csk(sk); 2600 const struct inet_connection_sock *icsk = inet_csk(sk);
2599 u32 now = tcp_time_stamp; 2601 u32 now = tcp_time_stamp;
2602 unsigned int start;
2600 u32 rate; 2603 u32 rate;
2601 2604
2602 memset(info, 0, sizeof(*info)); 2605 memset(info, 0, sizeof(*info));
@@ -2663,6 +2666,12 @@ void tcp_get_info(const struct sock *sk, struct tcp_info *info)
2663 2666
2664 rate = READ_ONCE(sk->sk_max_pacing_rate); 2667 rate = READ_ONCE(sk->sk_max_pacing_rate);
2665 info->tcpi_max_pacing_rate = rate != ~0U ? rate : ~0ULL; 2668 info->tcpi_max_pacing_rate = rate != ~0U ? rate : ~0ULL;
2669
2670 do {
2671 start = u64_stats_fetch_begin_irq(&tp->syncp);
2672 info->tcpi_bytes_acked = tp->bytes_acked;
2673 info->tcpi_bytes_received = tp->bytes_received;
2674 } while (u64_stats_fetch_retry_irq(&tp->syncp, start));
2666} 2675}
2667EXPORT_SYMBOL_GPL(tcp_get_info); 2676EXPORT_SYMBOL_GPL(tcp_get_info);
2668 2677
@@ -2734,6 +2743,26 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
2734 return -EFAULT; 2743 return -EFAULT;
2735 return 0; 2744 return 0;
2736 } 2745 }
2746 case TCP_CC_INFO: {
2747 const struct tcp_congestion_ops *ca_ops;
2748 union tcp_cc_info info;
2749 size_t sz = 0;
2750 int attr;
2751
2752 if (get_user(len, optlen))
2753 return -EFAULT;
2754
2755 ca_ops = icsk->icsk_ca_ops;
2756 if (ca_ops && ca_ops->get_info)
2757 sz = ca_ops->get_info(sk, ~0U, &attr, &info);
2758
2759 len = min_t(unsigned int, len, sz);
2760 if (put_user(len, optlen))
2761 return -EFAULT;
2762 if (copy_to_user(optval, &info, len))
2763 return -EFAULT;
2764 return 0;
2765 }
2737 case TCP_QUICKACK: 2766 case TCP_QUICKACK:
2738 val = !icsk->icsk_ack.pingpong; 2767 val = !icsk->icsk_ack.pingpong;
2739 break; 2768 break;
diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
index 4376016f7fa5..4c41c1287197 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -277,7 +277,8 @@ static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
277 } 277 }
278} 278}
279 279
280static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb) 280static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
281 union tcp_cc_info *info)
281{ 282{
282 const struct dctcp *ca = inet_csk_ca(sk); 283 const struct dctcp *ca = inet_csk_ca(sk);
283 284
@@ -286,18 +287,17 @@ static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
286 */ 287 */
287 if (ext & (1 << (INET_DIAG_DCTCPINFO - 1)) || 288 if (ext & (1 << (INET_DIAG_DCTCPINFO - 1)) ||
288 ext & (1 << (INET_DIAG_VEGASINFO - 1))) { 289 ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
289 struct tcp_dctcp_info info; 290 memset(info, 0, sizeof(struct tcp_dctcp_info));
290
291 memset(&info, 0, sizeof(info));
292 if (inet_csk(sk)->icsk_ca_ops != &dctcp_reno) { 291 if (inet_csk(sk)->icsk_ca_ops != &dctcp_reno) {
293 info.dctcp_enabled = 1; 292 info->dctcp.dctcp_enabled = 1;
294 info.dctcp_ce_state = (u16) ca->ce_state; 293 info->dctcp.dctcp_ce_state = (u16) ca->ce_state;
295 info.dctcp_alpha = ca->dctcp_alpha; 294 info->dctcp.dctcp_alpha = ca->dctcp_alpha;
296 info.dctcp_ab_ecn = ca->acked_bytes_ecn; 295 info->dctcp.dctcp_ab_ecn = ca->acked_bytes_ecn;
297 info.dctcp_ab_tot = ca->acked_bytes_total; 296 info->dctcp.dctcp_ab_tot = ca->acked_bytes_total;
298 } 297 }
299 298
300 return nla_put(skb, INET_DIAG_DCTCPINFO, sizeof(info), &info); 299 *attr = INET_DIAG_DCTCPINFO;
300 return sizeof(*info);
301 } 301 }
302 return 0; 302 return 0;
303} 303}
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index e3d87aca6be8..46b087a27503 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -206,6 +206,11 @@ static bool tcp_fastopen_create_child(struct sock *sk,
206 skb_set_owner_r(skb2, child); 206 skb_set_owner_r(skb2, child);
207 __skb_queue_tail(&child->sk_receive_queue, skb2); 207 __skb_queue_tail(&child->sk_receive_queue, skb2);
208 tp->syn_data_acked = 1; 208 tp->syn_data_acked = 1;
209
210 /* u64_stats_update_begin(&tp->syncp) not needed here,
211 * as we certainly are not changing upper 32bit value (0)
212 */
213 tp->bytes_received = end_seq - TCP_SKB_CB(skb)->seq - 1;
209 } else { 214 } else {
210 end_seq = TCP_SKB_CB(skb)->seq + 1; 215 end_seq = TCP_SKB_CB(skb)->seq + 1;
211 } 216 }
diff --git a/net/ipv4/tcp_illinois.c b/net/ipv4/tcp_illinois.c
index 67476f085e48..f71002e4db0b 100644
--- a/net/ipv4/tcp_illinois.c
+++ b/net/ipv4/tcp_illinois.c
@@ -300,24 +300,25 @@ static u32 tcp_illinois_ssthresh(struct sock *sk)
300} 300}
301 301
302/* Extract info for Tcp socket info provided via netlink. */ 302/* Extract info for Tcp socket info provided via netlink. */
303static int tcp_illinois_info(struct sock *sk, u32 ext, struct sk_buff *skb) 303static size_t tcp_illinois_info(struct sock *sk, u32 ext, int *attr,
304 union tcp_cc_info *info)
304{ 305{
305 const struct illinois *ca = inet_csk_ca(sk); 306 const struct illinois *ca = inet_csk_ca(sk);
306 307
307 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) { 308 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
308 struct tcpvegas_info info = { 309 info->vegas.tcpv_enabled = 1;
309 .tcpv_enabled = 1, 310 info->vegas.tcpv_rttcnt = ca->cnt_rtt;
310 .tcpv_rttcnt = ca->cnt_rtt, 311 info->vegas.tcpv_minrtt = ca->base_rtt;
311 .tcpv_minrtt = ca->base_rtt, 312 info->vegas.tcpv_rtt = 0;
312 };
313 313
314 if (info.tcpv_rttcnt > 0) { 314 if (info->vegas.tcpv_rttcnt > 0) {
315 u64 t = ca->sum_rtt; 315 u64 t = ca->sum_rtt;
316 316
317 do_div(t, info.tcpv_rttcnt); 317 do_div(t, info->vegas.tcpv_rttcnt);
318 info.tcpv_rtt = t; 318 info->vegas.tcpv_rtt = t;
319 } 319 }
320 return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info); 320 *attr = INET_DIAG_VEGASINFO;
321 return sizeof(struct tcpvegas_info);
321 } 322 }
322 return 0; 323 return 0;
323} 324}
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 3a4d9b34bed4..c9ab964189a0 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1820,14 +1820,12 @@ advance_sp:
1820 for (j = 0; j < used_sacks; j++) 1820 for (j = 0; j < used_sacks; j++)
1821 tp->recv_sack_cache[i++] = sp[j]; 1821 tp->recv_sack_cache[i++] = sp[j];
1822 1822
1823 tcp_mark_lost_retrans(sk);
1824
1825 tcp_verify_left_out(tp);
1826
1827 if ((state.reord < tp->fackets_out) && 1823 if ((state.reord < tp->fackets_out) &&
1828 ((inet_csk(sk)->icsk_ca_state != TCP_CA_Loss) || tp->undo_marker)) 1824 ((inet_csk(sk)->icsk_ca_state != TCP_CA_Loss) || tp->undo_marker))
1829 tcp_update_reordering(sk, tp->fackets_out - state.reord, 0); 1825 tcp_update_reordering(sk, tp->fackets_out - state.reord, 0);
1830 1826
1827 tcp_mark_lost_retrans(sk);
1828 tcp_verify_left_out(tp);
1831out: 1829out:
1832 1830
1833#if FASTRETRANS_DEBUG > 0 1831#if FASTRETRANS_DEBUG > 0
@@ -2700,16 +2698,21 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack)
2700 struct tcp_sock *tp = tcp_sk(sk); 2698 struct tcp_sock *tp = tcp_sk(sk);
2701 bool recovered = !before(tp->snd_una, tp->high_seq); 2699 bool recovered = !before(tp->snd_una, tp->high_seq);
2702 2700
2701 if ((flag & FLAG_SND_UNA_ADVANCED) &&
2702 tcp_try_undo_loss(sk, false))
2703 return;
2704
2703 if (tp->frto) { /* F-RTO RFC5682 sec 3.1 (sack enhanced version). */ 2705 if (tp->frto) { /* F-RTO RFC5682 sec 3.1 (sack enhanced version). */
2704 /* Step 3.b. A timeout is spurious if not all data are 2706 /* Step 3.b. A timeout is spurious if not all data are
2705 * lost, i.e., never-retransmitted data are (s)acked. 2707 * lost, i.e., never-retransmitted data are (s)acked.
2706 */ 2708 */
2707 if (tcp_try_undo_loss(sk, flag & FLAG_ORIG_SACK_ACKED)) 2709 if ((flag & FLAG_ORIG_SACK_ACKED) &&
2710 tcp_try_undo_loss(sk, true))
2708 return; 2711 return;
2709 2712
2710 if (after(tp->snd_nxt, tp->high_seq) && 2713 if (after(tp->snd_nxt, tp->high_seq)) {
2711 (flag & FLAG_DATA_SACKED || is_dupack)) { 2714 if (flag & FLAG_DATA_SACKED || is_dupack)
2712 tp->frto = 0; /* Loss was real: 2nd part of step 3.a */ 2715 tp->frto = 0; /* Step 3.a. loss was real */
2713 } else if (flag & FLAG_SND_UNA_ADVANCED && !recovered) { 2716 } else if (flag & FLAG_SND_UNA_ADVANCED && !recovered) {
2714 tp->high_seq = tp->snd_nxt; 2717 tp->high_seq = tp->snd_nxt;
2715 __tcp_push_pending_frames(sk, tcp_current_mss(sk), 2718 __tcp_push_pending_frames(sk, tcp_current_mss(sk),
@@ -2734,8 +2737,6 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack)
2734 else if (flag & FLAG_SND_UNA_ADVANCED) 2737 else if (flag & FLAG_SND_UNA_ADVANCED)
2735 tcp_reset_reno_sack(tp); 2738 tcp_reset_reno_sack(tp);
2736 } 2739 }
2737 if (tcp_try_undo_loss(sk, false))
2738 return;
2739 tcp_xmit_retransmit_queue(sk); 2740 tcp_xmit_retransmit_queue(sk);
2740} 2741}
2741 2742
@@ -3280,6 +3281,28 @@ static inline bool tcp_may_update_window(const struct tcp_sock *tp,
3280 (ack_seq == tp->snd_wl1 && nwin > tp->snd_wnd); 3281 (ack_seq == tp->snd_wl1 && nwin > tp->snd_wnd);
3281} 3282}
3282 3283
3284/* If we update tp->snd_una, also update tp->bytes_acked */
3285static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack)
3286{
3287 u32 delta = ack - tp->snd_una;
3288
3289 u64_stats_update_begin(&tp->syncp);
3290 tp->bytes_acked += delta;
3291 u64_stats_update_end(&tp->syncp);
3292 tp->snd_una = ack;
3293}
3294
3295/* If we update tp->rcv_nxt, also update tp->bytes_received */
3296static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq)
3297{
3298 u32 delta = seq - tp->rcv_nxt;
3299
3300 u64_stats_update_begin(&tp->syncp);
3301 tp->bytes_received += delta;
3302 u64_stats_update_end(&tp->syncp);
3303 tp->rcv_nxt = seq;
3304}
3305
3283/* Update our send window. 3306/* Update our send window.
3284 * 3307 *
3285 * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2 3308 * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2
@@ -3315,7 +3338,7 @@ static int tcp_ack_update_window(struct sock *sk, const struct sk_buff *skb, u32
3315 } 3338 }
3316 } 3339 }
3317 3340
3318 tp->snd_una = ack; 3341 tcp_snd_una_update(tp, ack);
3319 3342
3320 return flag; 3343 return flag;
3321} 3344}
@@ -3497,7 +3520,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3497 * Note, we use the fact that SND.UNA>=SND.WL2. 3520 * Note, we use the fact that SND.UNA>=SND.WL2.
3498 */ 3521 */
3499 tcp_update_wl(tp, ack_seq); 3522 tcp_update_wl(tp, ack_seq);
3500 tp->snd_una = ack; 3523 tcp_snd_una_update(tp, ack);
3501 flag |= FLAG_WIN_UPDATE; 3524 flag |= FLAG_WIN_UPDATE;
3502 3525
3503 tcp_in_ack_event(sk, CA_ACK_WIN_UPDATE); 3526 tcp_in_ack_event(sk, CA_ACK_WIN_UPDATE);
@@ -4236,7 +4259,7 @@ static void tcp_ofo_queue(struct sock *sk)
4236 4259
4237 tail = skb_peek_tail(&sk->sk_receive_queue); 4260 tail = skb_peek_tail(&sk->sk_receive_queue);
4238 eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen); 4261 eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen);
4239 tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; 4262 tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
4240 if (!eaten) 4263 if (!eaten)
4241 __skb_queue_tail(&sk->sk_receive_queue, skb); 4264 __skb_queue_tail(&sk->sk_receive_queue, skb);
4242 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) 4265 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
@@ -4404,7 +4427,7 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, int
4404 __skb_pull(skb, hdrlen); 4427 __skb_pull(skb, hdrlen);
4405 eaten = (tail && 4428 eaten = (tail &&
4406 tcp_try_coalesce(sk, tail, skb, fragstolen)) ? 1 : 0; 4429 tcp_try_coalesce(sk, tail, skb, fragstolen)) ? 1 : 0;
4407 tcp_sk(sk)->rcv_nxt = TCP_SKB_CB(skb)->end_seq; 4430 tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq);
4408 if (!eaten) { 4431 if (!eaten) {
4409 __skb_queue_tail(&sk->sk_receive_queue, skb); 4432 __skb_queue_tail(&sk->sk_receive_queue, skb);
4410 skb_set_owner_r(skb, sk); 4433 skb_set_owner_r(skb, sk);
@@ -4497,7 +4520,7 @@ queue_and_out:
4497 4520
4498 eaten = tcp_queue_rcv(sk, skb, 0, &fragstolen); 4521 eaten = tcp_queue_rcv(sk, skb, 0, &fragstolen);
4499 } 4522 }
4500 tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; 4523 tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
4501 if (skb->len) 4524 if (skb->len)
4502 tcp_event_data_recv(sk, skb); 4525 tcp_event_data_recv(sk, skb);
4503 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) 4526 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
@@ -5245,7 +5268,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
5245 tcp_rcv_rtt_measure_ts(sk, skb); 5268 tcp_rcv_rtt_measure_ts(sk, skb);
5246 5269
5247 __skb_pull(skb, tcp_header_len); 5270 __skb_pull(skb, tcp_header_len);
5248 tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; 5271 tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
5249 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPHPHITSTOUSER); 5272 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPHPHITSTOUSER);
5250 eaten = 1; 5273 eaten = 1;
5251 } 5274 }
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 3571f2be4470..fc1c658ec6c1 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1348,7 +1348,8 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
1348 req = inet_csk_search_req(sk, th->source, iph->saddr, iph->daddr); 1348 req = inet_csk_search_req(sk, th->source, iph->saddr, iph->daddr);
1349 if (req) { 1349 if (req) {
1350 nsk = tcp_check_req(sk, skb, req, false); 1350 nsk = tcp_check_req(sk, skb, req, false);
1351 reqsk_put(req); 1351 if (!nsk)
1352 reqsk_put(req);
1352 return nsk; 1353 return nsk;
1353 } 1354 }
1354 1355
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 63d6311b5365..b5732a54f2ad 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -300,7 +300,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
300 tw->tw_v6_daddr = sk->sk_v6_daddr; 300 tw->tw_v6_daddr = sk->sk_v6_daddr;
301 tw->tw_v6_rcv_saddr = sk->sk_v6_rcv_saddr; 301 tw->tw_v6_rcv_saddr = sk->sk_v6_rcv_saddr;
302 tw->tw_tclass = np->tclass; 302 tw->tw_tclass = np->tclass;
303 tw->tw_flowlabel = np->flow_label >> 12; 303 tw->tw_flowlabel = be32_to_cpu(np->flow_label & IPV6_FLOWLABEL_MASK);
304 tw->tw_ipv6only = sk->sk_ipv6only; 304 tw->tw_ipv6only = sk->sk_ipv6only;
305 } 305 }
306#endif 306#endif
@@ -755,10 +755,11 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
755 if (!child) 755 if (!child)
756 goto listen_overflow; 756 goto listen_overflow;
757 757
758 inet_csk_reqsk_queue_unlink(sk, req); 758 inet_csk_reqsk_queue_drop(sk, req);
759 inet_csk_reqsk_queue_removed(sk, req);
760
761 inet_csk_reqsk_queue_add(sk, req, child); 759 inet_csk_reqsk_queue_add(sk, req, child);
760 /* Warning: caller must not call reqsk_put(req);
761 * child stole last reference on it.
762 */
762 return child; 763 return child;
763 764
764listen_overflow: 765listen_overflow:
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 8c8d7e06b72f..a369e8a70b2c 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2812,39 +2812,65 @@ begin_fwd:
2812 } 2812 }
2813} 2813}
2814 2814
2815/* Send a fin. The caller locks the socket for us. This cannot be 2815/* We allow to exceed memory limits for FIN packets to expedite
2816 * allowed to fail queueing a FIN frame under any circumstances. 2816 * connection tear down and (memory) recovery.
2817 * Otherwise tcp_send_fin() could be tempted to either delay FIN
2818 * or even be forced to close flow without any FIN.
2819 */
2820static void sk_forced_wmem_schedule(struct sock *sk, int size)
2821{
2822 int amt, status;
2823
2824 if (size <= sk->sk_forward_alloc)
2825 return;
2826 amt = sk_mem_pages(size);
2827 sk->sk_forward_alloc += amt * SK_MEM_QUANTUM;
2828 sk_memory_allocated_add(sk, amt, &status);
2829}
2830
2831/* Send a FIN. The caller locks the socket for us.
2832 * We should try to send a FIN packet really hard, but eventually give up.
2817 */ 2833 */
2818void tcp_send_fin(struct sock *sk) 2834void tcp_send_fin(struct sock *sk)
2819{ 2835{
2836 struct sk_buff *skb, *tskb = tcp_write_queue_tail(sk);
2820 struct tcp_sock *tp = tcp_sk(sk); 2837 struct tcp_sock *tp = tcp_sk(sk);
2821 struct sk_buff *skb = tcp_write_queue_tail(sk);
2822 int mss_now;
2823 2838
2824 /* Optimization, tack on the FIN if we have a queue of 2839 /* Optimization, tack on the FIN if we have one skb in write queue and
2825 * unsent frames. But be careful about outgoing SACKS 2840 * this skb was not yet sent, or we are under memory pressure.
2826 * and IP options. 2841 * Note: in the latter case, FIN packet will be sent after a timeout,
2842 * as TCP stack thinks it has already been transmitted.
2827 */ 2843 */
2828 mss_now = tcp_current_mss(sk); 2844 if (tskb && (tcp_send_head(sk) || sk_under_memory_pressure(sk))) {
2829 2845coalesce:
2830 if (tcp_send_head(sk)) { 2846 TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN;
2831 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_FIN; 2847 TCP_SKB_CB(tskb)->end_seq++;
2832 TCP_SKB_CB(skb)->end_seq++;
2833 tp->write_seq++; 2848 tp->write_seq++;
2849 if (!tcp_send_head(sk)) {
2850 /* This means tskb was already sent.
2851 * Pretend we included the FIN on previous transmit.
2852 * We need to set tp->snd_nxt to the value it would have
2853 * if FIN had been sent. This is because retransmit path
2854 * does not change tp->snd_nxt.
2855 */
2856 tp->snd_nxt++;
2857 return;
2858 }
2834 } else { 2859 } else {
2835 /* Socket is locked, keep trying until memory is available. */ 2860 skb = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation);
2836 for (;;) { 2861 if (unlikely(!skb)) {
2837 skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation); 2862 if (tskb)
2838 if (skb) 2863 goto coalesce;
2839 break; 2864 return;
2840 yield();
2841 } 2865 }
2866 skb_reserve(skb, MAX_TCP_HEADER);
2867 sk_forced_wmem_schedule(sk, skb->truesize);
2842 /* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */ 2868 /* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
2843 tcp_init_nondata_skb(skb, tp->write_seq, 2869 tcp_init_nondata_skb(skb, tp->write_seq,
2844 TCPHDR_ACK | TCPHDR_FIN); 2870 TCPHDR_ACK | TCPHDR_FIN);
2845 tcp_queue_skb(sk, skb); 2871 tcp_queue_skb(sk, skb);
2846 } 2872 }
2847 __tcp_push_pending_frames(sk, mss_now, TCP_NAGLE_OFF); 2873 __tcp_push_pending_frames(sk, tcp_current_mss(sk), TCP_NAGLE_OFF);
2848} 2874}
2849 2875
2850/* We get here when a process closes a file descriptor (either due to 2876/* We get here when a process closes a file descriptor (either due to
diff --git a/net/ipv4/tcp_vegas.c b/net/ipv4/tcp_vegas.c
index c71a1b8f7bde..a6cea1d5e20d 100644
--- a/net/ipv4/tcp_vegas.c
+++ b/net/ipv4/tcp_vegas.c
@@ -286,18 +286,19 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
286} 286}
287 287
288/* Extract info for Tcp socket info provided via netlink. */ 288/* Extract info for Tcp socket info provided via netlink. */
289int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb) 289size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
290 union tcp_cc_info *info)
290{ 291{
291 const struct vegas *ca = inet_csk_ca(sk); 292 const struct vegas *ca = inet_csk_ca(sk);
293
292 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) { 294 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
293 struct tcpvegas_info info = { 295 info->vegas.tcpv_enabled = ca->doing_vegas_now,
294 .tcpv_enabled = ca->doing_vegas_now, 296 info->vegas.tcpv_rttcnt = ca->cntRTT,
295 .tcpv_rttcnt = ca->cntRTT, 297 info->vegas.tcpv_rtt = ca->baseRTT,
296 .tcpv_rtt = ca->baseRTT, 298 info->vegas.tcpv_minrtt = ca->minRTT,
297 .tcpv_minrtt = ca->minRTT, 299
298 }; 300 *attr = INET_DIAG_VEGASINFO;
299 301 return sizeof(struct tcpvegas_info);
300 return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
301 } 302 }
302 return 0; 303 return 0;
303} 304}
diff --git a/net/ipv4/tcp_vegas.h b/net/ipv4/tcp_vegas.h
index e8a6b33cc61d..ef9da5306c68 100644
--- a/net/ipv4/tcp_vegas.h
+++ b/net/ipv4/tcp_vegas.h
@@ -19,6 +19,7 @@ void tcp_vegas_init(struct sock *sk);
19void tcp_vegas_state(struct sock *sk, u8 ca_state); 19void tcp_vegas_state(struct sock *sk, u8 ca_state);
20void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us); 20void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us);
21void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event); 21void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event);
22int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb); 22size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
23 union tcp_cc_info *info);
23 24
24#endif /* __TCP_VEGAS_H */ 25#endif /* __TCP_VEGAS_H */
diff --git a/net/ipv4/tcp_westwood.c b/net/ipv4/tcp_westwood.c
index b3c57cceb990..c10732e39837 100644
--- a/net/ipv4/tcp_westwood.c
+++ b/net/ipv4/tcp_westwood.c
@@ -256,18 +256,19 @@ static void tcp_westwood_event(struct sock *sk, enum tcp_ca_event event)
256} 256}
257 257
258/* Extract info for Tcp socket info provided via netlink. */ 258/* Extract info for Tcp socket info provided via netlink. */
259static int tcp_westwood_info(struct sock *sk, u32 ext, struct sk_buff *skb) 259static size_t tcp_westwood_info(struct sock *sk, u32 ext, int *attr,
260 union tcp_cc_info *info)
260{ 261{
261 const struct westwood *ca = inet_csk_ca(sk); 262 const struct westwood *ca = inet_csk_ca(sk);
262 263
263 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) { 264 if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
264 struct tcpvegas_info info = { 265 info->vegas.tcpv_enabled = 1;
265 .tcpv_enabled = 1, 266 info->vegas.tcpv_rttcnt = 0;
266 .tcpv_rtt = jiffies_to_usecs(ca->rtt), 267 info->vegas.tcpv_rtt = jiffies_to_usecs(ca->rtt),
267 .tcpv_minrtt = jiffies_to_usecs(ca->rtt_min), 268 info->vegas.tcpv_minrtt = jiffies_to_usecs(ca->rtt_min),
268 };
269 269
270 return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info); 270 *attr = INET_DIAG_VEGASINFO;
271 return sizeof(struct tcpvegas_info);
271 } 272 }
272 return 0; 273 return 0;
273} 274}
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 96dbffff5a24..bde57b113009 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -693,6 +693,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
693{ 693{
694 struct rt6_info *iter = NULL; 694 struct rt6_info *iter = NULL;
695 struct rt6_info **ins; 695 struct rt6_info **ins;
696 struct rt6_info **fallback_ins = NULL;
696 int replace = (info->nlh && 697 int replace = (info->nlh &&
697 (info->nlh->nlmsg_flags & NLM_F_REPLACE)); 698 (info->nlh->nlmsg_flags & NLM_F_REPLACE));
698 int add = (!info->nlh || 699 int add = (!info->nlh ||
@@ -716,8 +717,13 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
716 (info->nlh->nlmsg_flags & NLM_F_EXCL)) 717 (info->nlh->nlmsg_flags & NLM_F_EXCL))
717 return -EEXIST; 718 return -EEXIST;
718 if (replace) { 719 if (replace) {
719 found++; 720 if (rt_can_ecmp == rt6_qualify_for_ecmp(iter)) {
720 break; 721 found++;
722 break;
723 }
724 if (rt_can_ecmp)
725 fallback_ins = fallback_ins ?: ins;
726 goto next_iter;
721 } 727 }
722 728
723 if (iter->dst.dev == rt->dst.dev && 729 if (iter->dst.dev == rt->dst.dev &&
@@ -753,9 +759,17 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
753 if (iter->rt6i_metric > rt->rt6i_metric) 759 if (iter->rt6i_metric > rt->rt6i_metric)
754 break; 760 break;
755 761
762next_iter:
756 ins = &iter->dst.rt6_next; 763 ins = &iter->dst.rt6_next;
757 } 764 }
758 765
766 if (fallback_ins && !found) {
767 /* No ECMP-able route found, replace first non-ECMP one */
768 ins = fallback_ins;
769 iter = *ins;
770 found++;
771 }
772
759 /* Reset round-robin state, if necessary */ 773 /* Reset round-robin state, if necessary */
760 if (ins == &fn->leaf) 774 if (ins == &fn->leaf)
761 fn->rr_ptr = NULL; 775 fn->rr_ptr = NULL;
@@ -815,6 +829,8 @@ add:
815 } 829 }
816 830
817 } else { 831 } else {
832 int nsiblings;
833
818 if (!found) { 834 if (!found) {
819 if (add) 835 if (add)
820 goto add; 836 goto add;
@@ -835,8 +851,27 @@ add:
835 info->nl_net->ipv6.rt6_stats->fib_route_nodes++; 851 info->nl_net->ipv6.rt6_stats->fib_route_nodes++;
836 fn->fn_flags |= RTN_RTINFO; 852 fn->fn_flags |= RTN_RTINFO;
837 } 853 }
854 nsiblings = iter->rt6i_nsiblings;
838 fib6_purge_rt(iter, fn, info->nl_net); 855 fib6_purge_rt(iter, fn, info->nl_net);
839 rt6_release(iter); 856 rt6_release(iter);
857
858 if (nsiblings) {
859 /* Replacing an ECMP route, remove all siblings */
860 ins = &rt->dst.rt6_next;
861 iter = *ins;
862 while (iter) {
863 if (rt6_qualify_for_ecmp(iter)) {
864 *ins = iter->dst.rt6_next;
865 fib6_purge_rt(iter, fn, info->nl_net);
866 rt6_release(iter);
867 nsiblings--;
868 } else {
869 ins = &iter->dst.rt6_next;
870 }
871 iter = *ins;
872 }
873 WARN_ON(nsiblings != 0);
874 }
840 } 875 }
841 876
842 return 0; 877 return 0;
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index b5e6cc1d4a73..a38d3ac0f18f 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1246,7 +1246,6 @@ static void ip6gre_tunnel_setup(struct net_device *dev)
1246static int ip6gre_tunnel_init(struct net_device *dev) 1246static int ip6gre_tunnel_init(struct net_device *dev)
1247{ 1247{
1248 struct ip6_tnl *tunnel; 1248 struct ip6_tnl *tunnel;
1249 int i;
1250 1249
1251 tunnel = netdev_priv(dev); 1250 tunnel = netdev_priv(dev);
1252 1251
@@ -1260,16 +1259,10 @@ static int ip6gre_tunnel_init(struct net_device *dev)
1260 if (ipv6_addr_any(&tunnel->parms.raddr)) 1259 if (ipv6_addr_any(&tunnel->parms.raddr))
1261 dev->header_ops = &ip6gre_header_ops; 1260 dev->header_ops = &ip6gre_header_ops;
1262 1261
1263 dev->tstats = alloc_percpu(struct pcpu_sw_netstats); 1262 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1264 if (!dev->tstats) 1263 if (!dev->tstats)
1265 return -ENOMEM; 1264 return -ENOMEM;
1266 1265
1267 for_each_possible_cpu(i) {
1268 struct pcpu_sw_netstats *ip6gre_tunnel_stats;
1269 ip6gre_tunnel_stats = per_cpu_ptr(dev->tstats, i);
1270 u64_stats_init(&ip6gre_tunnel_stats->syncp);
1271 }
1272
1273 return 0; 1266 return 0;
1274} 1267}
1275 1268
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 7fde1f265c90..bc09cb97b840 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -886,22 +886,45 @@ static int ip6_dst_lookup_tail(struct sock *sk,
886#endif 886#endif
887 int err; 887 int err;
888 888
889 if (!*dst) 889 /* The correct way to handle this would be to do
890 *dst = ip6_route_output(net, sk, fl6); 890 * ip6_route_get_saddr, and then ip6_route_output; however,
891 891 * the route-specific preferred source forces the
892 err = (*dst)->error; 892 * ip6_route_output call _before_ ip6_route_get_saddr.
893 if (err) 893 *
894 goto out_err_release; 894 * In source specific routing (no src=any default route),
895 * ip6_route_output will fail given src=any saddr, though, so
896 * that's why we try it again later.
897 */
898 if (ipv6_addr_any(&fl6->saddr) && (!*dst || !(*dst)->error)) {
899 struct rt6_info *rt;
900 bool had_dst = *dst != NULL;
895 901
896 if (ipv6_addr_any(&fl6->saddr)) { 902 if (!had_dst)
897 struct rt6_info *rt = (struct rt6_info *) *dst; 903 *dst = ip6_route_output(net, sk, fl6);
904 rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
898 err = ip6_route_get_saddr(net, rt, &fl6->daddr, 905 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
899 sk ? inet6_sk(sk)->srcprefs : 0, 906 sk ? inet6_sk(sk)->srcprefs : 0,
900 &fl6->saddr); 907 &fl6->saddr);
901 if (err) 908 if (err)
902 goto out_err_release; 909 goto out_err_release;
910
911 /* If we had an erroneous initial result, pretend it
912 * never existed and let the SA-enabled version take
913 * over.
914 */
915 if (!had_dst && (*dst)->error) {
916 dst_release(*dst);
917 *dst = NULL;
918 }
903 } 919 }
904 920
921 if (!*dst)
922 *dst = ip6_route_output(net, sk, fl6);
923
924 err = (*dst)->error;
925 if (err)
926 goto out_err_release;
927
905#ifdef CONFIG_IPV6_OPTIMISTIC_DAD 928#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
906 /* 929 /*
907 * Here if the dst entry we've looked up 930 * Here if the dst entry we've looked up
@@ -1277,8 +1300,10 @@ emsgsize:
1277 1300
1278 /* If this is the first and only packet and device 1301 /* If this is the first and only packet and device
1279 * supports checksum offloading, let's use it. 1302 * supports checksum offloading, let's use it.
1303 * Use transhdrlen, same as IPv4, because partial
1304 * sums only work when transhdrlen is set.
1280 */ 1305 */
1281 if (!skb && sk->sk_protocol == IPPROTO_UDP && 1306 if (transhdrlen && sk->sk_protocol == IPPROTO_UDP &&
1282 length + fragheaderlen < mtu && 1307 length + fragheaderlen < mtu &&
1283 rt->dst.dev->features & NETIF_F_V6_CSUM && 1308 rt->dst.dev->features & NETIF_F_V6_CSUM &&
1284 !exthdrlen) 1309 !exthdrlen)
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 1a732a1d3c8e..62f5b0d0bc9b 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -1275,6 +1275,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
1275 /* overflow check */ 1275 /* overflow check */
1276 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1276 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1277 return -ENOMEM; 1277 return -ENOMEM;
1278 if (tmp.num_counters == 0)
1279 return -EINVAL;
1280
1278 tmp.name[sizeof(tmp.name)-1] = 0; 1281 tmp.name[sizeof(tmp.name)-1] = 0;
1279 1282
1280 newinfo = xt_alloc_table_info(tmp.size); 1283 newinfo = xt_alloc_table_info(tmp.size);
@@ -1822,6 +1825,9 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1822 return -ENOMEM; 1825 return -ENOMEM;
1823 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1826 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1824 return -ENOMEM; 1827 return -ENOMEM;
1828 if (tmp.num_counters == 0)
1829 return -EINVAL;
1830
1825 tmp.name[sizeof(tmp.name)-1] = 0; 1831 tmp.name[sizeof(tmp.name)-1] = 0;
1826 1832
1827 newinfo = xt_alloc_table_info(tmp.size); 1833 newinfo = xt_alloc_table_info(tmp.size);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 5c48293ff062..c73ae5039e46 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2245,9 +2245,10 @@ int ip6_route_get_saddr(struct net *net,
2245 unsigned int prefs, 2245 unsigned int prefs,
2246 struct in6_addr *saddr) 2246 struct in6_addr *saddr)
2247{ 2247{
2248 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry *)rt); 2248 struct inet6_dev *idev =
2249 rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
2249 int err = 0; 2250 int err = 0;
2250 if (rt->rt6i_prefsrc.plen) 2251 if (rt && rt->rt6i_prefsrc.plen)
2251 *saddr = rt->rt6i_prefsrc.addr; 2252 *saddr = rt->rt6i_prefsrc.addr;
2252 else 2253 else
2253 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL, 2254 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
@@ -2503,9 +2504,9 @@ static int ip6_route_multipath(struct fib6_config *cfg, int add)
2503 int attrlen; 2504 int attrlen;
2504 int err = 0, last_err = 0; 2505 int err = 0, last_err = 0;
2505 2506
2507 remaining = cfg->fc_mp_len;
2506beginning: 2508beginning:
2507 rtnh = (struct rtnexthop *)cfg->fc_mp; 2509 rtnh = (struct rtnexthop *)cfg->fc_mp;
2508 remaining = cfg->fc_mp_len;
2509 2510
2510 /* Parse a Multipath Entry */ 2511 /* Parse a Multipath Entry */
2511 while (rtnh_ok(rtnh, remaining)) { 2512 while (rtnh_ok(rtnh, remaining)) {
@@ -2535,15 +2536,19 @@ beginning:
2535 * next hops that have been already added. 2536 * next hops that have been already added.
2536 */ 2537 */
2537 add = 0; 2538 add = 0;
2539 remaining = cfg->fc_mp_len - remaining;
2538 goto beginning; 2540 goto beginning;
2539 } 2541 }
2540 } 2542 }
2541 /* Because each route is added like a single route we remove 2543 /* Because each route is added like a single route we remove
2542 * this flag after the first nexthop (if there is a collision, 2544 * these flags after the first nexthop: if there is a collision,
2543 * we have already fail to add the first nexthop: 2545 * we have already failed to add the first nexthop:
2544 * fib6_add_rt2node() has reject it). 2546 * fib6_add_rt2node() has rejected it; when replacing, old
2547 * nexthops have been replaced by first new, the rest should
2548 * be added to it.
2545 */ 2549 */
2546 cfg->fc_nlinfo.nlh->nlmsg_flags &= ~NLM_F_EXCL; 2550 cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL |
2551 NLM_F_REPLACE);
2547 rtnh = rtnh_next(rtnh, &remaining); 2552 rtnh = rtnh_next(rtnh, &remaining);
2548 } 2553 }
2549 2554
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index ad51df85aa00..3adffb300238 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -914,7 +914,7 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
914 tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale, 914 tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
915 tcp_time_stamp + tcptw->tw_ts_offset, 915 tcp_time_stamp + tcptw->tw_ts_offset,
916 tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw), 916 tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw),
917 tw->tw_tclass, (tw->tw_flowlabel << 12)); 917 tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel));
918 918
919 inet_twsk_put(tw); 919 inet_twsk_put(tw);
920} 920}
@@ -946,7 +946,8 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk, struct sk_buff *skb)
946 &ipv6_hdr(skb)->daddr, tcp_v6_iif(skb)); 946 &ipv6_hdr(skb)->daddr, tcp_v6_iif(skb));
947 if (req) { 947 if (req) {
948 nsk = tcp_check_req(sk, skb, req, false); 948 nsk = tcp_check_req(sk, skb, req, false);
949 reqsk_put(req); 949 if (!nsk)
950 reqsk_put(req);
950 return nsk; 951 return nsk;
951 } 952 }
952 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo, 953 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo,
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 3477c919fcc8..c2ec41617a35 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -731,7 +731,9 @@ static bool __udp_v6_is_mcast_sock(struct net *net, struct sock *sk,
731 (inet->inet_dport && inet->inet_dport != rmt_port) || 731 (inet->inet_dport && inet->inet_dport != rmt_port) ||
732 (!ipv6_addr_any(&sk->sk_v6_daddr) && 732 (!ipv6_addr_any(&sk->sk_v6_daddr) &&
733 !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr)) || 733 !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr)) ||
734 (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)) 734 (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif) ||
735 (!ipv6_addr_any(&sk->sk_v6_rcv_saddr) &&
736 !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, loc_addr)))
735 return false; 737 return false;
736 if (!inet6_mc_check(sk, loc_addr, rmt_addr)) 738 if (!inet6_mc_check(sk, loc_addr, rmt_addr))
737 return false; 739 return false;
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 265e42721a66..ff347a0eebd4 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2495,51 +2495,22 @@ static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2495 struct ieee80211_roc_work *new_roc, 2495 struct ieee80211_roc_work *new_roc,
2496 struct ieee80211_roc_work *cur_roc) 2496 struct ieee80211_roc_work *cur_roc)
2497{ 2497{
2498 unsigned long j = jiffies; 2498 unsigned long now = jiffies;
2499 unsigned long cur_roc_end = cur_roc->hw_start_time + 2499 unsigned long remaining = cur_roc->hw_start_time +
2500 msecs_to_jiffies(cur_roc->duration); 2500 msecs_to_jiffies(cur_roc->duration) -
2501 struct ieee80211_roc_work *next_roc; 2501 now;
2502 int new_dur;
2503 2502
2504 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun)) 2503 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2505 return false; 2504 return false;
2506 2505
2507 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end)) 2506 /* if it doesn't fit entirely, schedule a new one */
2507 if (new_roc->duration > jiffies_to_msecs(remaining))
2508 return false; 2508 return false;
2509 2509
2510 ieee80211_handle_roc_started(new_roc); 2510 ieee80211_handle_roc_started(new_roc);
2511 2511
2512 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j); 2512 /* add to dependents so we send the expired event properly */
2513 2513 list_add_tail(&new_roc->list, &cur_roc->dependents);
2514 /* cur_roc is long enough - add new_roc to the dependents list. */
2515 if (new_dur <= 0) {
2516 list_add_tail(&new_roc->list, &cur_roc->dependents);
2517 return true;
2518 }
2519
2520 new_roc->duration = new_dur;
2521
2522 /*
2523 * if cur_roc was already coalesced before, we might
2524 * want to extend the next roc instead of adding
2525 * a new one.
2526 */
2527 next_roc = list_entry(cur_roc->list.next,
2528 struct ieee80211_roc_work, list);
2529 if (&next_roc->list != &local->roc_list &&
2530 next_roc->chan == new_roc->chan &&
2531 next_roc->sdata == new_roc->sdata &&
2532 !WARN_ON(next_roc->started)) {
2533 list_add_tail(&new_roc->list, &next_roc->dependents);
2534 next_roc->duration = max(next_roc->duration,
2535 new_roc->duration);
2536 next_roc->type = max(next_roc->type, new_roc->type);
2537 return true;
2538 }
2539
2540 /* add right after cur_roc */
2541 list_add(&new_roc->list, &cur_roc->list);
2542
2543 return true; 2514 return true;
2544} 2515}
2545 2516
@@ -2652,17 +2623,9 @@ static int ieee80211_start_roc_work(struct ieee80211_local *local,
2652 * In the offloaded ROC case, if it hasn't begun, add 2623 * In the offloaded ROC case, if it hasn't begun, add
2653 * this new one to the dependent list to be handled 2624 * this new one to the dependent list to be handled
2654 * when the master one begins. If it has begun, 2625 * when the master one begins. If it has begun,
2655 * check that there's still a minimum time left and 2626 * check if it fits entirely within the existing one,
2656 * if so, start this one, transmitting the frame, but 2627 * in which case it will just be dependent as well.
2657 * add it to the list directly after this one with 2628 * Otherwise, schedule it by itself.
2658 * a reduced time so we'll ask the driver to execute
2659 * it right after finishing the previous one, in the
2660 * hope that it'll also be executed right afterwards,
2661 * effectively extending the old one.
2662 * If there's no minimum time left, just add it to the
2663 * normal list.
2664 * TODO: the ROC type is ignored here, assuming that it
2665 * is better to immediately use the current ROC.
2666 */ 2629 */
2667 if (!tmp->hw_begun) { 2630 if (!tmp->hw_begun) {
2668 list_add_tail(&roc->list, &tmp->dependents); 2631 list_add_tail(&roc->list, &tmp->dependents);
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index ab46ab4a7249..c0a9187bc3a9 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -205,6 +205,8 @@ enum ieee80211_packet_rx_flags {
205 * @IEEE80211_RX_CMNTR: received on cooked monitor already 205 * @IEEE80211_RX_CMNTR: received on cooked monitor already
206 * @IEEE80211_RX_BEACON_REPORTED: This frame was already reported 206 * @IEEE80211_RX_BEACON_REPORTED: This frame was already reported
207 * to cfg80211_report_obss_beacon(). 207 * to cfg80211_report_obss_beacon().
208 * @IEEE80211_RX_REORDER_TIMER: this frame is released by the
209 * reorder buffer timeout timer, not the normal RX path
208 * 210 *
209 * These flags are used across handling multiple interfaces 211 * These flags are used across handling multiple interfaces
210 * for a single frame. 212 * for a single frame.
@@ -212,6 +214,7 @@ enum ieee80211_packet_rx_flags {
212enum ieee80211_rx_flags { 214enum ieee80211_rx_flags {
213 IEEE80211_RX_CMNTR = BIT(0), 215 IEEE80211_RX_CMNTR = BIT(0),
214 IEEE80211_RX_BEACON_REPORTED = BIT(1), 216 IEEE80211_RX_BEACON_REPORTED = BIT(1),
217 IEEE80211_RX_REORDER_TIMER = BIT(2),
215}; 218};
216 219
217struct ieee80211_rx_data { 220struct ieee80211_rx_data {
@@ -325,12 +328,6 @@ struct mesh_preq_queue {
325 u8 flags; 328 u8 flags;
326}; 329};
327 330
328#if HZ/100 == 0
329#define IEEE80211_ROC_MIN_LEFT 1
330#else
331#define IEEE80211_ROC_MIN_LEFT (HZ/100)
332#endif
333
334struct ieee80211_roc_work { 331struct ieee80211_roc_work {
335 struct list_head list; 332 struct list_head list;
336 struct list_head dependents; 333 struct list_head dependents;
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index b4ac596a7cb7..84cef600c573 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -522,6 +522,12 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
522 memcpy(sdata->vif.hw_queue, master->vif.hw_queue, 522 memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
523 sizeof(sdata->vif.hw_queue)); 523 sizeof(sdata->vif.hw_queue));
524 sdata->vif.bss_conf.chandef = master->vif.bss_conf.chandef; 524 sdata->vif.bss_conf.chandef = master->vif.bss_conf.chandef;
525
526 mutex_lock(&local->key_mtx);
527 sdata->crypto_tx_tailroom_needed_cnt +=
528 master->crypto_tx_tailroom_needed_cnt;
529 mutex_unlock(&local->key_mtx);
530
525 break; 531 break;
526 } 532 }
527 case NL80211_IFTYPE_AP: 533 case NL80211_IFTYPE_AP:
@@ -819,13 +825,15 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
819 * (because if we remove a STA after ops->remove_interface() 825 * (because if we remove a STA after ops->remove_interface()
820 * the driver will have removed the vif info already!) 826 * the driver will have removed the vif info already!)
821 * 827 *
822 * This is relevant only in WDS mode, in all other modes we've 828 * In WDS mode a station must exist here and be flushed, for
823 * already removed all stations when disconnecting or similar, 829 * AP_VLANs stations may exist since there's nothing else that
824 * so warn otherwise. 830 * would have removed them, but in other modes there shouldn't
831 * be any stations.
825 */ 832 */
826 flushed = sta_info_flush(sdata); 833 flushed = sta_info_flush(sdata);
827 WARN_ON_ONCE((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) || 834 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
828 (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)); 835 ((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
836 (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)));
829 837
830 /* don't count this interface for promisc/allmulti while it is down */ 838 /* don't count this interface for promisc/allmulti while it is down */
831 if (sdata->flags & IEEE80211_SDATA_ALLMULTI) 839 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 2291cd730091..a907f2d5c12d 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -58,6 +58,22 @@ static void assert_key_lock(struct ieee80211_local *local)
58 lockdep_assert_held(&local->key_mtx); 58 lockdep_assert_held(&local->key_mtx);
59} 59}
60 60
61static void
62update_vlan_tailroom_need_count(struct ieee80211_sub_if_data *sdata, int delta)
63{
64 struct ieee80211_sub_if_data *vlan;
65
66 if (sdata->vif.type != NL80211_IFTYPE_AP)
67 return;
68
69 mutex_lock(&sdata->local->mtx);
70
71 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
72 vlan->crypto_tx_tailroom_needed_cnt += delta;
73
74 mutex_unlock(&sdata->local->mtx);
75}
76
61static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata) 77static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata)
62{ 78{
63 /* 79 /*
@@ -79,6 +95,8 @@ static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata)
79 * http://mid.gmane.org/1308590980.4322.19.camel@jlt3.sipsolutions.net 95 * http://mid.gmane.org/1308590980.4322.19.camel@jlt3.sipsolutions.net
80 */ 96 */
81 97
98 update_vlan_tailroom_need_count(sdata, 1);
99
82 if (!sdata->crypto_tx_tailroom_needed_cnt++) { 100 if (!sdata->crypto_tx_tailroom_needed_cnt++) {
83 /* 101 /*
84 * Flush all XMIT packets currently using HW encryption or no 102 * Flush all XMIT packets currently using HW encryption or no
@@ -88,6 +106,15 @@ static void increment_tailroom_need_count(struct ieee80211_sub_if_data *sdata)
88 } 106 }
89} 107}
90 108
109static void decrease_tailroom_need_count(struct ieee80211_sub_if_data *sdata,
110 int delta)
111{
112 WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt < delta);
113
114 update_vlan_tailroom_need_count(sdata, -delta);
115 sdata->crypto_tx_tailroom_needed_cnt -= delta;
116}
117
91static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key) 118static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
92{ 119{
93 struct ieee80211_sub_if_data *sdata; 120 struct ieee80211_sub_if_data *sdata;
@@ -144,7 +171,7 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
144 171
145 if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) || 172 if (!((key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) ||
146 (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM))) 173 (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
147 sdata->crypto_tx_tailroom_needed_cnt--; 174 decrease_tailroom_need_count(sdata, 1);
148 175
149 WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) && 176 WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) &&
150 (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)); 177 (key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV));
@@ -541,7 +568,7 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key,
541 schedule_delayed_work(&sdata->dec_tailroom_needed_wk, 568 schedule_delayed_work(&sdata->dec_tailroom_needed_wk,
542 HZ/2); 569 HZ/2);
543 } else { 570 } else {
544 sdata->crypto_tx_tailroom_needed_cnt--; 571 decrease_tailroom_need_count(sdata, 1);
545 } 572 }
546 } 573 }
547 574
@@ -631,6 +658,7 @@ void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom)
631void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) 658void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
632{ 659{
633 struct ieee80211_key *key; 660 struct ieee80211_key *key;
661 struct ieee80211_sub_if_data *vlan;
634 662
635 ASSERT_RTNL(); 663 ASSERT_RTNL();
636 664
@@ -639,7 +667,14 @@ void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
639 667
640 mutex_lock(&sdata->local->key_mtx); 668 mutex_lock(&sdata->local->key_mtx);
641 669
642 sdata->crypto_tx_tailroom_needed_cnt = 0; 670 WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt ||
671 sdata->crypto_tx_tailroom_pending_dec);
672
673 if (sdata->vif.type == NL80211_IFTYPE_AP) {
674 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
675 WARN_ON_ONCE(vlan->crypto_tx_tailroom_needed_cnt ||
676 vlan->crypto_tx_tailroom_pending_dec);
677 }
643 678
644 list_for_each_entry(key, &sdata->key_list, list) { 679 list_for_each_entry(key, &sdata->key_list, list) {
645 increment_tailroom_need_count(sdata); 680 increment_tailroom_need_count(sdata);
@@ -649,6 +684,22 @@ void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
649 mutex_unlock(&sdata->local->key_mtx); 684 mutex_unlock(&sdata->local->key_mtx);
650} 685}
651 686
687void ieee80211_reset_crypto_tx_tailroom(struct ieee80211_sub_if_data *sdata)
688{
689 struct ieee80211_sub_if_data *vlan;
690
691 mutex_lock(&sdata->local->key_mtx);
692
693 sdata->crypto_tx_tailroom_needed_cnt = 0;
694
695 if (sdata->vif.type == NL80211_IFTYPE_AP) {
696 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
697 vlan->crypto_tx_tailroom_needed_cnt = 0;
698 }
699
700 mutex_unlock(&sdata->local->key_mtx);
701}
702
652void ieee80211_iter_keys(struct ieee80211_hw *hw, 703void ieee80211_iter_keys(struct ieee80211_hw *hw,
653 struct ieee80211_vif *vif, 704 struct ieee80211_vif *vif,
654 void (*iter)(struct ieee80211_hw *hw, 705 void (*iter)(struct ieee80211_hw *hw,
@@ -688,8 +739,8 @@ static void ieee80211_free_keys_iface(struct ieee80211_sub_if_data *sdata,
688{ 739{
689 struct ieee80211_key *key, *tmp; 740 struct ieee80211_key *key, *tmp;
690 741
691 sdata->crypto_tx_tailroom_needed_cnt -= 742 decrease_tailroom_need_count(sdata,
692 sdata->crypto_tx_tailroom_pending_dec; 743 sdata->crypto_tx_tailroom_pending_dec);
693 sdata->crypto_tx_tailroom_pending_dec = 0; 744 sdata->crypto_tx_tailroom_pending_dec = 0;
694 745
695 ieee80211_debugfs_key_remove_mgmt_default(sdata); 746 ieee80211_debugfs_key_remove_mgmt_default(sdata);
@@ -709,6 +760,7 @@ void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
709{ 760{
710 struct ieee80211_local *local = sdata->local; 761 struct ieee80211_local *local = sdata->local;
711 struct ieee80211_sub_if_data *vlan; 762 struct ieee80211_sub_if_data *vlan;
763 struct ieee80211_sub_if_data *master;
712 struct ieee80211_key *key, *tmp; 764 struct ieee80211_key *key, *tmp;
713 LIST_HEAD(keys); 765 LIST_HEAD(keys);
714 766
@@ -728,8 +780,20 @@ void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
728 list_for_each_entry_safe(key, tmp, &keys, list) 780 list_for_each_entry_safe(key, tmp, &keys, list)
729 __ieee80211_key_destroy(key, false); 781 __ieee80211_key_destroy(key, false);
730 782
731 WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt || 783 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
732 sdata->crypto_tx_tailroom_pending_dec); 784 if (sdata->bss) {
785 master = container_of(sdata->bss,
786 struct ieee80211_sub_if_data,
787 u.ap);
788
789 WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt !=
790 master->crypto_tx_tailroom_needed_cnt);
791 }
792 } else {
793 WARN_ON_ONCE(sdata->crypto_tx_tailroom_needed_cnt ||
794 sdata->crypto_tx_tailroom_pending_dec);
795 }
796
733 if (sdata->vif.type == NL80211_IFTYPE_AP) { 797 if (sdata->vif.type == NL80211_IFTYPE_AP) {
734 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 798 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
735 WARN_ON_ONCE(vlan->crypto_tx_tailroom_needed_cnt || 799 WARN_ON_ONCE(vlan->crypto_tx_tailroom_needed_cnt ||
@@ -793,8 +857,8 @@ void ieee80211_delayed_tailroom_dec(struct work_struct *wk)
793 */ 857 */
794 858
795 mutex_lock(&sdata->local->key_mtx); 859 mutex_lock(&sdata->local->key_mtx);
796 sdata->crypto_tx_tailroom_needed_cnt -= 860 decrease_tailroom_need_count(sdata,
797 sdata->crypto_tx_tailroom_pending_dec; 861 sdata->crypto_tx_tailroom_pending_dec);
798 sdata->crypto_tx_tailroom_pending_dec = 0; 862 sdata->crypto_tx_tailroom_pending_dec = 0;
799 mutex_unlock(&sdata->local->key_mtx); 863 mutex_unlock(&sdata->local->key_mtx);
800} 864}
diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index c5a31835be0e..96557dd1e77d 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -161,6 +161,7 @@ void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
161void ieee80211_free_sta_keys(struct ieee80211_local *local, 161void ieee80211_free_sta_keys(struct ieee80211_local *local,
162 struct sta_info *sta); 162 struct sta_info *sta);
163void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata); 163void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
164void ieee80211_reset_crypto_tx_tailroom(struct ieee80211_sub_if_data *sdata);
164 165
165#define key_mtx_dereference(local, ref) \ 166#define key_mtx_dereference(local, ref) \
166 rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx))) 167 rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx)))
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 260eed45b6d2..5793f75c5ffd 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2121,7 +2121,8 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2121 /* deliver to local stack */ 2121 /* deliver to local stack */
2122 skb->protocol = eth_type_trans(skb, dev); 2122 skb->protocol = eth_type_trans(skb, dev);
2123 memset(skb->cb, 0, sizeof(skb->cb)); 2123 memset(skb->cb, 0, sizeof(skb->cb));
2124 if (rx->local->napi) 2124 if (!(rx->flags & IEEE80211_RX_REORDER_TIMER) &&
2125 rx->local->napi)
2125 napi_gro_receive(rx->local->napi, skb); 2126 napi_gro_receive(rx->local->napi, skb);
2126 else 2127 else
2127 netif_receive_skb(skb); 2128 netif_receive_skb(skb);
@@ -3231,7 +3232,7 @@ void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3231 /* This is OK -- must be QoS data frame */ 3232 /* This is OK -- must be QoS data frame */
3232 .security_idx = tid, 3233 .security_idx = tid,
3233 .seqno_idx = tid, 3234 .seqno_idx = tid,
3234 .flags = 0, 3235 .flags = IEEE80211_RX_REORDER_TIMER,
3235 }; 3236 };
3236 struct tid_ampdu_rx *tid_agg_rx; 3237 struct tid_ampdu_rx *tid_agg_rx;
3237 3238
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 12971b71d0fa..2880f2ae99ab 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -66,6 +66,7 @@
66 66
67static const struct rhashtable_params sta_rht_params = { 67static const struct rhashtable_params sta_rht_params = {
68 .nelem_hint = 3, /* start small */ 68 .nelem_hint = 3, /* start small */
69 .automatic_shrinking = true,
69 .head_offset = offsetof(struct sta_info, hash_node), 70 .head_offset = offsetof(struct sta_info, hash_node),
70 .key_offset = offsetof(struct sta_info, sta.addr), 71 .key_offset = offsetof(struct sta_info, sta.addr),
71 .key_len = ETH_ALEN, 72 .key_len = ETH_ALEN,
@@ -157,8 +158,24 @@ struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
157 const u8 *addr) 158 const u8 *addr)
158{ 159{
159 struct ieee80211_local *local = sdata->local; 160 struct ieee80211_local *local = sdata->local;
161 struct sta_info *sta;
162 struct rhash_head *tmp;
163 const struct bucket_table *tbl;
164
165 rcu_read_lock();
166 tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash);
160 167
161 return rhashtable_lookup_fast(&local->sta_hash, addr, sta_rht_params); 168 for_each_sta_info(local, tbl, addr, sta, tmp) {
169 if (sta->sdata == sdata) {
170 rcu_read_unlock();
171 /* this is safe as the caller must already hold
172 * another rcu read section or the mutex
173 */
174 return sta;
175 }
176 }
177 rcu_read_unlock();
178 return NULL;
162} 179}
163 180
164/* 181/*
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 79412f16b61d..b864ebc6ab8f 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -2023,6 +2023,9 @@ int ieee80211_reconfig(struct ieee80211_local *local)
2023 2023
2024 /* add back keys */ 2024 /* add back keys */
2025 list_for_each_entry(sdata, &local->interfaces, list) 2025 list_for_each_entry(sdata, &local->interfaces, list)
2026 ieee80211_reset_crypto_tx_tailroom(sdata);
2027
2028 list_for_each_entry(sdata, &local->interfaces, list)
2026 if (ieee80211_sdata_running(sdata)) 2029 if (ieee80211_sdata_running(sdata))
2027 ieee80211_enable_keys(sdata); 2030 ieee80211_enable_keys(sdata);
2028 2031
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index a4220e92f0cc..efa3f48f1ec5 100644
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -98,8 +98,7 @@ static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
98 98
99 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 99 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
100 100
101 if (WARN_ON(skb_tailroom(skb) < IEEE80211_WEP_ICV_LEN || 101 if (WARN_ON(skb_headroom(skb) < IEEE80211_WEP_IV_LEN))
102 skb_headroom(skb) < IEEE80211_WEP_IV_LEN))
103 return NULL; 102 return NULL;
104 103
105 hdrlen = ieee80211_hdrlen(hdr->frame_control); 104 hdrlen = ieee80211_hdrlen(hdr->frame_control);
@@ -167,6 +166,9 @@ int ieee80211_wep_encrypt(struct ieee80211_local *local,
167 size_t len; 166 size_t len;
168 u8 rc4key[3 + WLAN_KEY_LEN_WEP104]; 167 u8 rc4key[3 + WLAN_KEY_LEN_WEP104];
169 168
169 if (WARN_ON(skb_tailroom(skb) < IEEE80211_WEP_ICV_LEN))
170 return -1;
171
170 iv = ieee80211_wep_add_iv(local, skb, keylen, keyidx); 172 iv = ieee80211_wep_add_iv(local, skb, keylen, keyidx);
171 if (!iv) 173 if (!iv)
172 return -1; 174 return -1;
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 5d9f68c75e5f..70be9c799f8a 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -22,13 +22,14 @@
22 22
23static struct net_device * 23static struct net_device *
24ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy, 24ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
25 const char *name, int type) 25 const char *name,
26 unsigned char name_assign_type, int type)
26{ 27{
27 struct ieee802154_local *local = wpan_phy_priv(wpan_phy); 28 struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
28 struct net_device *dev; 29 struct net_device *dev;
29 30
30 rtnl_lock(); 31 rtnl_lock();
31 dev = ieee802154_if_add(local, name, type, 32 dev = ieee802154_if_add(local, name, name_assign_type, type,
32 cpu_to_le64(0x0000000000000000ULL)); 33 cpu_to_le64(0x0000000000000000ULL));
33 rtnl_unlock(); 34 rtnl_unlock();
34 35
@@ -45,12 +46,14 @@ static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy,
45 46
46static int 47static int
47ieee802154_add_iface(struct wpan_phy *phy, const char *name, 48ieee802154_add_iface(struct wpan_phy *phy, const char *name,
49 unsigned char name_assign_type,
48 enum nl802154_iftype type, __le64 extended_addr) 50 enum nl802154_iftype type, __le64 extended_addr)
49{ 51{
50 struct ieee802154_local *local = wpan_phy_priv(phy); 52 struct ieee802154_local *local = wpan_phy_priv(phy);
51 struct net_device *err; 53 struct net_device *err;
52 54
53 err = ieee802154_if_add(local, name, type, extended_addr); 55 err = ieee802154_if_add(local, name, name_assign_type, type,
56 extended_addr);
54 return PTR_ERR_OR_ZERO(err); 57 return PTR_ERR_OR_ZERO(err);
55} 58}
56 59
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h
index bebd70ffc7a3..127ba18386fc 100644
--- a/net/mac802154/ieee802154_i.h
+++ b/net/mac802154/ieee802154_i.h
@@ -182,7 +182,8 @@ void ieee802154_iface_exit(void);
182void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); 182void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata);
183struct net_device * 183struct net_device *
184ieee802154_if_add(struct ieee802154_local *local, const char *name, 184ieee802154_if_add(struct ieee802154_local *local, const char *name,
185 enum nl802154_iftype type, __le64 extended_addr); 185 unsigned char name_assign_type, enum nl802154_iftype type,
186 __le64 extended_addr);
186void ieee802154_remove_interfaces(struct ieee802154_local *local); 187void ieee802154_remove_interfaces(struct ieee802154_local *local);
187 188
188#endif /* __IEEE802154_I_H */ 189#endif /* __IEEE802154_I_H */
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index 38b56f9d9386..91b75abbd1a1 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -522,7 +522,8 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata,
522 522
523struct net_device * 523struct net_device *
524ieee802154_if_add(struct ieee802154_local *local, const char *name, 524ieee802154_if_add(struct ieee802154_local *local, const char *name,
525 enum nl802154_iftype type, __le64 extended_addr) 525 unsigned char name_assign_type, enum nl802154_iftype type,
526 __le64 extended_addr)
526{ 527{
527 struct net_device *ndev = NULL; 528 struct net_device *ndev = NULL;
528 struct ieee802154_sub_if_data *sdata = NULL; 529 struct ieee802154_sub_if_data *sdata = NULL;
@@ -531,7 +532,7 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
531 ASSERT_RTNL(); 532 ASSERT_RTNL();
532 533
533 ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, name, 534 ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, name,
534 NET_NAME_UNKNOWN, ieee802154_if_setup); 535 name_assign_type, ieee802154_if_setup);
535 if (!ndev) 536 if (!ndev)
536 return ERR_PTR(-ENOMEM); 537 return ERR_PTR(-ENOMEM);
537 538
diff --git a/net/mac802154/llsec.c b/net/mac802154/llsec.c
index dcf73958133a..5b2be12832e6 100644
--- a/net/mac802154/llsec.c
+++ b/net/mac802154/llsec.c
@@ -134,7 +134,7 @@ llsec_key_alloc(const struct ieee802154_llsec_key *template)
134 for (i = 0; i < ARRAY_SIZE(key->tfm); i++) { 134 for (i = 0; i < ARRAY_SIZE(key->tfm); i++) {
135 key->tfm[i] = crypto_alloc_aead("ccm(aes)", 0, 135 key->tfm[i] = crypto_alloc_aead("ccm(aes)", 0,
136 CRYPTO_ALG_ASYNC); 136 CRYPTO_ALG_ASYNC);
137 if (!key->tfm[i]) 137 if (IS_ERR(key->tfm[i]))
138 goto err_tfm; 138 goto err_tfm;
139 if (crypto_aead_setkey(key->tfm[i], template->key, 139 if (crypto_aead_setkey(key->tfm[i], template->key,
140 IEEE802154_LLSEC_KEY_SIZE)) 140 IEEE802154_LLSEC_KEY_SIZE))
@@ -144,7 +144,7 @@ llsec_key_alloc(const struct ieee802154_llsec_key *template)
144 } 144 }
145 145
146 key->tfm0 = crypto_alloc_blkcipher("ctr(aes)", 0, CRYPTO_ALG_ASYNC); 146 key->tfm0 = crypto_alloc_blkcipher("ctr(aes)", 0, CRYPTO_ALG_ASYNC);
147 if (!key->tfm0) 147 if (IS_ERR(key->tfm0))
148 goto err_tfm; 148 goto err_tfm;
149 149
150 if (crypto_blkcipher_setkey(key->tfm0, template->key, 150 if (crypto_blkcipher_setkey(key->tfm0, template->key,
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 8500378c8318..08cb32dc8fd3 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -161,18 +161,21 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
161 161
162 rtnl_lock(); 162 rtnl_lock();
163 163
164 dev = ieee802154_if_add(local, "wpan%d", NL802154_IFTYPE_NODE, 164 dev = ieee802154_if_add(local, "wpan%d", NET_NAME_ENUM,
165 NL802154_IFTYPE_NODE,
165 cpu_to_le64(0x0000000000000000ULL)); 166 cpu_to_le64(0x0000000000000000ULL));
166 if (IS_ERR(dev)) { 167 if (IS_ERR(dev)) {
167 rtnl_unlock(); 168 rtnl_unlock();
168 rc = PTR_ERR(dev); 169 rc = PTR_ERR(dev);
169 goto out_wq; 170 goto out_phy;
170 } 171 }
171 172
172 rtnl_unlock(); 173 rtnl_unlock();
173 174
174 return 0; 175 return 0;
175 176
177out_phy:
178 wpan_phy_unregister(local->phy);
176out_wq: 179out_wq:
177 destroy_workqueue(local->workqueue); 180 destroy_workqueue(local->workqueue);
178out: 181out:
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index db8a2ea6d4de..7b3f732269e4 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -53,6 +53,11 @@ static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
53 return rt; 53 return rt;
54} 54}
55 55
56static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)
57{
58 return rcu_dereference_rtnl(dev->mpls_ptr);
59}
60
56static bool mpls_output_possible(const struct net_device *dev) 61static bool mpls_output_possible(const struct net_device *dev)
57{ 62{
58 return dev && (dev->flags & IFF_UP) && netif_carrier_ok(dev); 63 return dev && (dev->flags & IFF_UP) && netif_carrier_ok(dev);
@@ -136,6 +141,7 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
136 struct mpls_route *rt; 141 struct mpls_route *rt;
137 struct mpls_entry_decoded dec; 142 struct mpls_entry_decoded dec;
138 struct net_device *out_dev; 143 struct net_device *out_dev;
144 struct mpls_dev *mdev;
139 unsigned int hh_len; 145 unsigned int hh_len;
140 unsigned int new_header_size; 146 unsigned int new_header_size;
141 unsigned int mtu; 147 unsigned int mtu;
@@ -143,6 +149,10 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
143 149
144 /* Careful this entire function runs inside of an rcu critical section */ 150 /* Careful this entire function runs inside of an rcu critical section */
145 151
152 mdev = mpls_dev_get(dev);
153 if (!mdev || !mdev->input_enabled)
154 goto drop;
155
146 if (skb->pkt_type != PACKET_HOST) 156 if (skb->pkt_type != PACKET_HOST)
147 goto drop; 157 goto drop;
148 158
@@ -352,9 +362,9 @@ static int mpls_route_add(struct mpls_route_config *cfg)
352 if (!dev) 362 if (!dev)
353 goto errout; 363 goto errout;
354 364
355 /* For now just support ethernet devices */ 365 /* Ensure this is a supported device */
356 err = -EINVAL; 366 err = -EINVAL;
357 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK)) 367 if (!mpls_dev_get(dev))
358 goto errout; 368 goto errout;
359 369
360 err = -EINVAL; 370 err = -EINVAL;
@@ -428,10 +438,89 @@ errout:
428 return err; 438 return err;
429} 439}
430 440
441#define MPLS_PERDEV_SYSCTL_OFFSET(field) \
442 (&((struct mpls_dev *)0)->field)
443
444static const struct ctl_table mpls_dev_table[] = {
445 {
446 .procname = "input",
447 .maxlen = sizeof(int),
448 .mode = 0644,
449 .proc_handler = proc_dointvec,
450 .data = MPLS_PERDEV_SYSCTL_OFFSET(input_enabled),
451 },
452 { }
453};
454
455static int mpls_dev_sysctl_register(struct net_device *dev,
456 struct mpls_dev *mdev)
457{
458 char path[sizeof("net/mpls/conf/") + IFNAMSIZ];
459 struct ctl_table *table;
460 int i;
461
462 table = kmemdup(&mpls_dev_table, sizeof(mpls_dev_table), GFP_KERNEL);
463 if (!table)
464 goto out;
465
466 /* Table data contains only offsets relative to the base of
467 * the mdev at this point, so make them absolute.
468 */
469 for (i = 0; i < ARRAY_SIZE(mpls_dev_table); i++)
470 table[i].data = (char *)mdev + (uintptr_t)table[i].data;
471
472 snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name);
473
474 mdev->sysctl = register_net_sysctl(dev_net(dev), path, table);
475 if (!mdev->sysctl)
476 goto free;
477
478 return 0;
479
480free:
481 kfree(table);
482out:
483 return -ENOBUFS;
484}
485
486static void mpls_dev_sysctl_unregister(struct mpls_dev *mdev)
487{
488 struct ctl_table *table;
489
490 table = mdev->sysctl->ctl_table_arg;
491 unregister_net_sysctl_table(mdev->sysctl);
492 kfree(table);
493}
494
495static struct mpls_dev *mpls_add_dev(struct net_device *dev)
496{
497 struct mpls_dev *mdev;
498 int err = -ENOMEM;
499
500 ASSERT_RTNL();
501
502 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
503 if (!mdev)
504 return ERR_PTR(err);
505
506 err = mpls_dev_sysctl_register(dev, mdev);
507 if (err)
508 goto free;
509
510 rcu_assign_pointer(dev->mpls_ptr, mdev);
511
512 return mdev;
513
514free:
515 kfree(mdev);
516 return ERR_PTR(err);
517}
518
431static void mpls_ifdown(struct net_device *dev) 519static void mpls_ifdown(struct net_device *dev)
432{ 520{
433 struct mpls_route __rcu **platform_label; 521 struct mpls_route __rcu **platform_label;
434 struct net *net = dev_net(dev); 522 struct net *net = dev_net(dev);
523 struct mpls_dev *mdev;
435 unsigned index; 524 unsigned index;
436 525
437 platform_label = rtnl_dereference(net->mpls.platform_label); 526 platform_label = rtnl_dereference(net->mpls.platform_label);
@@ -443,14 +532,35 @@ static void mpls_ifdown(struct net_device *dev)
443 continue; 532 continue;
444 rt->rt_dev = NULL; 533 rt->rt_dev = NULL;
445 } 534 }
535
536 mdev = mpls_dev_get(dev);
537 if (!mdev)
538 return;
539
540 mpls_dev_sysctl_unregister(mdev);
541
542 RCU_INIT_POINTER(dev->mpls_ptr, NULL);
543
544 kfree(mdev);
446} 545}
447 546
448static int mpls_dev_notify(struct notifier_block *this, unsigned long event, 547static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
449 void *ptr) 548 void *ptr)
450{ 549{
451 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 550 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
551 struct mpls_dev *mdev;
452 552
453 switch(event) { 553 switch(event) {
554 case NETDEV_REGISTER:
555 /* For now just support ethernet devices */
556 if ((dev->type == ARPHRD_ETHER) ||
557 (dev->type == ARPHRD_LOOPBACK)) {
558 mdev = mpls_add_dev(dev);
559 if (IS_ERR(mdev))
560 return notifier_from_errno(PTR_ERR(mdev));
561 }
562 break;
563
454 case NETDEV_UNREGISTER: 564 case NETDEV_UNREGISTER:
455 mpls_ifdown(dev); 565 mpls_ifdown(dev);
456 break; 566 break;
@@ -536,6 +646,15 @@ int nla_get_labels(const struct nlattr *nla,
536 if ((dec.bos != bos) || dec.ttl || dec.tc) 646 if ((dec.bos != bos) || dec.ttl || dec.tc)
537 return -EINVAL; 647 return -EINVAL;
538 648
649 switch (dec.label) {
650 case MPLS_LABEL_IMPLNULL:
651 /* RFC3032: This is a label that an LSR may
652 * assign and distribute, but which never
653 * actually appears in the encapsulation.
654 */
655 return -EINVAL;
656 }
657
539 label[i] = dec.label; 658 label[i] = dec.label;
540 } 659 }
541 *labels = nla_labels; 660 *labels = nla_labels;
@@ -816,7 +935,7 @@ static int resize_platform_label_table(struct net *net, size_t limit)
816 } 935 }
817 936
818 /* In case the predefined labels need to be populated */ 937 /* In case the predefined labels need to be populated */
819 if (limit > LABEL_IPV4_EXPLICIT_NULL) { 938 if (limit > MPLS_LABEL_IPV4NULL) {
820 struct net_device *lo = net->loopback_dev; 939 struct net_device *lo = net->loopback_dev;
821 rt0 = mpls_rt_alloc(lo->addr_len); 940 rt0 = mpls_rt_alloc(lo->addr_len);
822 if (!rt0) 941 if (!rt0)
@@ -826,7 +945,7 @@ static int resize_platform_label_table(struct net *net, size_t limit)
826 rt0->rt_via_table = NEIGH_LINK_TABLE; 945 rt0->rt_via_table = NEIGH_LINK_TABLE;
827 memcpy(rt0->rt_via, lo->dev_addr, lo->addr_len); 946 memcpy(rt0->rt_via, lo->dev_addr, lo->addr_len);
828 } 947 }
829 if (limit > LABEL_IPV6_EXPLICIT_NULL) { 948 if (limit > MPLS_LABEL_IPV6NULL) {
830 struct net_device *lo = net->loopback_dev; 949 struct net_device *lo = net->loopback_dev;
831 rt2 = mpls_rt_alloc(lo->addr_len); 950 rt2 = mpls_rt_alloc(lo->addr_len);
832 if (!rt2) 951 if (!rt2)
@@ -854,15 +973,15 @@ static int resize_platform_label_table(struct net *net, size_t limit)
854 memcpy(labels, old, cp_size); 973 memcpy(labels, old, cp_size);
855 974
856 /* If needed set the predefined labels */ 975 /* If needed set the predefined labels */
857 if ((old_limit <= LABEL_IPV6_EXPLICIT_NULL) && 976 if ((old_limit <= MPLS_LABEL_IPV6NULL) &&
858 (limit > LABEL_IPV6_EXPLICIT_NULL)) { 977 (limit > MPLS_LABEL_IPV6NULL)) {
859 RCU_INIT_POINTER(labels[LABEL_IPV6_EXPLICIT_NULL], rt2); 978 RCU_INIT_POINTER(labels[MPLS_LABEL_IPV6NULL], rt2);
860 rt2 = NULL; 979 rt2 = NULL;
861 } 980 }
862 981
863 if ((old_limit <= LABEL_IPV4_EXPLICIT_NULL) && 982 if ((old_limit <= MPLS_LABEL_IPV4NULL) &&
864 (limit > LABEL_IPV4_EXPLICIT_NULL)) { 983 (limit > MPLS_LABEL_IPV4NULL)) {
865 RCU_INIT_POINTER(labels[LABEL_IPV4_EXPLICIT_NULL], rt0); 984 RCU_INIT_POINTER(labels[MPLS_LABEL_IPV4NULL], rt0);
866 rt0 = NULL; 985 rt0 = NULL;
867 } 986 }
868 987
@@ -912,7 +1031,7 @@ static int mpls_platform_labels(struct ctl_table *table, int write,
912 return ret; 1031 return ret;
913} 1032}
914 1033
915static struct ctl_table mpls_table[] = { 1034static const struct ctl_table mpls_table[] = {
916 { 1035 {
917 .procname = "platform_labels", 1036 .procname = "platform_labels",
918 .data = NULL, 1037 .data = NULL,
diff --git a/net/mpls/internal.h b/net/mpls/internal.h
index fb6de92052c4..b064c345042c 100644
--- a/net/mpls/internal.h
+++ b/net/mpls/internal.h
@@ -1,16 +1,6 @@
1#ifndef MPLS_INTERNAL_H 1#ifndef MPLS_INTERNAL_H
2#define MPLS_INTERNAL_H 2#define MPLS_INTERNAL_H
3 3
4#define LABEL_IPV4_EXPLICIT_NULL 0 /* RFC3032 */
5#define LABEL_ROUTER_ALERT_LABEL 1 /* RFC3032 */
6#define LABEL_IPV6_EXPLICIT_NULL 2 /* RFC3032 */
7#define LABEL_IMPLICIT_NULL 3 /* RFC3032 */
8#define LABEL_ENTROPY_INDICATOR 7 /* RFC6790 */
9#define LABEL_GAL 13 /* RFC5586 */
10#define LABEL_OAM_ALERT 14 /* RFC3429 */
11#define LABEL_EXTENSION 15 /* RFC7274 */
12
13
14struct mpls_shim_hdr { 4struct mpls_shim_hdr {
15 __be32 label_stack_entry; 5 __be32 label_stack_entry;
16}; 6};
@@ -22,6 +12,12 @@ struct mpls_entry_decoded {
22 u8 bos; 12 u8 bos;
23}; 13};
24 14
15struct mpls_dev {
16 int input_enabled;
17
18 struct ctl_table_header *sysctl;
19};
20
25struct sk_buff; 21struct sk_buff;
26 22
27static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) 23static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index f70e34a68f70..a0f3e6a3c7d1 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -863,6 +863,7 @@ config NETFILTER_XT_TARGET_TPROXY
863 depends on NETFILTER_XTABLES 863 depends on NETFILTER_XTABLES
864 depends on NETFILTER_ADVANCED 864 depends on NETFILTER_ADVANCED
865 depends on (IPV6 || IPV6=n) 865 depends on (IPV6 || IPV6=n)
866 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
866 depends on IP_NF_MANGLE 867 depends on IP_NF_MANGLE
867 select NF_DEFRAG_IPV4 868 select NF_DEFRAG_IPV4
868 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES 869 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES
@@ -1356,6 +1357,7 @@ config NETFILTER_XT_MATCH_SOCKET
1356 depends on NETFILTER_ADVANCED 1357 depends on NETFILTER_ADVANCED
1357 depends on !NF_CONNTRACK || NF_CONNTRACK 1358 depends on !NF_CONNTRACK || NF_CONNTRACK
1358 depends on (IPV6 || IPV6=n) 1359 depends on (IPV6 || IPV6=n)
1360 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
1359 select NF_DEFRAG_IPV4 1361 select NF_DEFRAG_IPV4
1360 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES 1362 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES
1361 help 1363 help
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 49532672f66d..285eae3a1454 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -3823,6 +3823,9 @@ static void __net_exit ip_vs_control_net_cleanup_sysctl(struct net *net)
3823 cancel_work_sync(&ipvs->defense_work.work); 3823 cancel_work_sync(&ipvs->defense_work.work);
3824 unregister_net_sysctl_table(ipvs->sysctl_hdr); 3824 unregister_net_sysctl_table(ipvs->sysctl_hdr);
3825 ip_vs_stop_estimator(net, &ipvs->tot_stats); 3825 ip_vs_stop_estimator(net, &ipvs->tot_stats);
3826
3827 if (!net_eq(net, &init_net))
3828 kfree(ipvs->sysctl_tbl);
3826} 3829}
3827 3830
3828#else 3831#else
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index 5caa0c41bf26..70383de72054 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -202,7 +202,7 @@ static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
202 * sES -> sES :-) 202 * sES -> sES :-)
203 * sFW -> sCW Normal close request answered by ACK. 203 * sFW -> sCW Normal close request answered by ACK.
204 * sCW -> sCW 204 * sCW -> sCW
205 * sLA -> sTW Last ACK detected. 205 * sLA -> sTW Last ACK detected (RFC5961 challenged)
206 * sTW -> sTW Retransmitted last ACK. Remain in the same state. 206 * sTW -> sTW Retransmitted last ACK. Remain in the same state.
207 * sCL -> sCL 207 * sCL -> sCL
208 */ 208 */
@@ -261,7 +261,7 @@ static const u8 tcp_conntracks[2][6][TCP_CONNTRACK_MAX] = {
261 * sES -> sES :-) 261 * sES -> sES :-)
262 * sFW -> sCW Normal close request answered by ACK. 262 * sFW -> sCW Normal close request answered by ACK.
263 * sCW -> sCW 263 * sCW -> sCW
264 * sLA -> sTW Last ACK detected. 264 * sLA -> sTW Last ACK detected (RFC5961 challenged)
265 * sTW -> sTW Retransmitted last ACK. 265 * sTW -> sTW Retransmitted last ACK.
266 * sCL -> sCL 266 * sCL -> sCL
267 */ 267 */
@@ -906,6 +906,7 @@ static int tcp_packet(struct nf_conn *ct,
906 1 : ct->proto.tcp.last_win; 906 1 : ct->proto.tcp.last_win;
907 ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_scale = 907 ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_scale =
908 ct->proto.tcp.last_wscale; 908 ct->proto.tcp.last_wscale;
909 ct->proto.tcp.last_flags &= ~IP_CT_EXP_CHALLENGE_ACK;
909 ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags = 910 ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags =
910 ct->proto.tcp.last_flags; 911 ct->proto.tcp.last_flags;
911 memset(&ct->proto.tcp.seen[dir], 0, 912 memset(&ct->proto.tcp.seen[dir], 0,
@@ -923,7 +924,9 @@ static int tcp_packet(struct nf_conn *ct,
923 * may be in sync but we are not. In that case, we annotate 924 * may be in sync but we are not. In that case, we annotate
924 * the TCP options and let the packet go through. If it is a 925 * the TCP options and let the packet go through. If it is a
925 * valid SYN packet, the server will reply with a SYN/ACK, and 926 * valid SYN packet, the server will reply with a SYN/ACK, and
926 * then we'll get in sync. Otherwise, the server ignores it. */ 927 * then we'll get in sync. Otherwise, the server potentially
928 * responds with a challenge ACK if implementing RFC5961.
929 */
927 if (index == TCP_SYN_SET && dir == IP_CT_DIR_ORIGINAL) { 930 if (index == TCP_SYN_SET && dir == IP_CT_DIR_ORIGINAL) {
928 struct ip_ct_tcp_state seen = {}; 931 struct ip_ct_tcp_state seen = {};
929 932
@@ -939,6 +942,13 @@ static int tcp_packet(struct nf_conn *ct,
939 ct->proto.tcp.last_flags |= 942 ct->proto.tcp.last_flags |=
940 IP_CT_TCP_FLAG_SACK_PERM; 943 IP_CT_TCP_FLAG_SACK_PERM;
941 } 944 }
945 /* Mark the potential for RFC5961 challenge ACK,
946 * this pose a special problem for LAST_ACK state
947 * as ACK is intrepretated as ACKing last FIN.
948 */
949 if (old_state == TCP_CONNTRACK_LAST_ACK)
950 ct->proto.tcp.last_flags |=
951 IP_CT_EXP_CHALLENGE_ACK;
942 } 952 }
943 spin_unlock_bh(&ct->lock); 953 spin_unlock_bh(&ct->lock);
944 if (LOG_INVALID(net, IPPROTO_TCP)) 954 if (LOG_INVALID(net, IPPROTO_TCP))
@@ -970,6 +980,25 @@ static int tcp_packet(struct nf_conn *ct,
970 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, 980 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
971 "nf_ct_tcp: invalid state "); 981 "nf_ct_tcp: invalid state ");
972 return -NF_ACCEPT; 982 return -NF_ACCEPT;
983 case TCP_CONNTRACK_TIME_WAIT:
984 /* RFC5961 compliance cause stack to send "challenge-ACK"
985 * e.g. in response to spurious SYNs. Conntrack MUST
986 * not believe this ACK is acking last FIN.
987 */
988 if (old_state == TCP_CONNTRACK_LAST_ACK &&
989 index == TCP_ACK_SET &&
990 ct->proto.tcp.last_dir != dir &&
991 ct->proto.tcp.last_index == TCP_SYN_SET &&
992 (ct->proto.tcp.last_flags & IP_CT_EXP_CHALLENGE_ACK)) {
993 /* Detected RFC5961 challenge ACK */
994 ct->proto.tcp.last_flags &= ~IP_CT_EXP_CHALLENGE_ACK;
995 spin_unlock_bh(&ct->lock);
996 if (LOG_INVALID(net, IPPROTO_TCP))
997 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
998 "nf_ct_tcp: challenge-ACK ignored ");
999 return NF_ACCEPT; /* Don't change state */
1000 }
1001 break;
973 case TCP_CONNTRACK_CLOSE: 1002 case TCP_CONNTRACK_CLOSE:
974 if (index == TCP_RST_SET 1003 if (index == TCP_RST_SET
975 && (ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_MAXACK_SET) 1004 && (ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_MAXACK_SET)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 78af83bc9c8e..34ded09317e7 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4340,7 +4340,6 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
4340 case NFT_CONTINUE: 4340 case NFT_CONTINUE:
4341 case NFT_BREAK: 4341 case NFT_BREAK:
4342 case NFT_RETURN: 4342 case NFT_RETURN:
4343 desc->len = sizeof(data->verdict);
4344 break; 4343 break;
4345 case NFT_JUMP: 4344 case NFT_JUMP:
4346 case NFT_GOTO: 4345 case NFT_GOTO:
@@ -4355,10 +4354,10 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
4355 4354
4356 chain->use++; 4355 chain->use++;
4357 data->verdict.chain = chain; 4356 data->verdict.chain = chain;
4358 desc->len = sizeof(data);
4359 break; 4357 break;
4360 } 4358 }
4361 4359
4360 desc->len = sizeof(data->verdict);
4362 desc->type = NFT_DATA_VERDICT; 4361 desc->type = NFT_DATA_VERDICT;
4363 return 0; 4362 return 0;
4364} 4363}
@@ -4473,9 +4472,9 @@ EXPORT_SYMBOL_GPL(nft_data_init);
4473 */ 4472 */
4474void nft_data_uninit(const struct nft_data *data, enum nft_data_types type) 4473void nft_data_uninit(const struct nft_data *data, enum nft_data_types type)
4475{ 4474{
4476 switch (type) { 4475 if (type < NFT_DATA_VERDICT)
4477 case NFT_DATA_VALUE:
4478 return; 4476 return;
4477 switch (type) {
4479 case NFT_DATA_VERDICT: 4478 case NFT_DATA_VERDICT:
4480 return nft_verdict_uninit(data); 4479 return nft_verdict_uninit(data);
4481 default: 4480 default:
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 3ad91266c821..4ef1fae8445e 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -1073,7 +1073,13 @@ static struct pernet_operations nfnl_log_net_ops = {
1073 1073
1074static int __init nfnetlink_log_init(void) 1074static int __init nfnetlink_log_init(void)
1075{ 1075{
1076 int status = -ENOMEM; 1076 int status;
1077
1078 status = register_pernet_subsys(&nfnl_log_net_ops);
1079 if (status < 0) {
1080 pr_err("failed to register pernet ops\n");
1081 goto out;
1082 }
1077 1083
1078 netlink_register_notifier(&nfulnl_rtnl_notifier); 1084 netlink_register_notifier(&nfulnl_rtnl_notifier);
1079 status = nfnetlink_subsys_register(&nfulnl_subsys); 1085 status = nfnetlink_subsys_register(&nfulnl_subsys);
@@ -1088,28 +1094,23 @@ static int __init nfnetlink_log_init(void)
1088 goto cleanup_subsys; 1094 goto cleanup_subsys;
1089 } 1095 }
1090 1096
1091 status = register_pernet_subsys(&nfnl_log_net_ops);
1092 if (status < 0) {
1093 pr_err("failed to register pernet ops\n");
1094 goto cleanup_logger;
1095 }
1096 return status; 1097 return status;
1097 1098
1098cleanup_logger:
1099 nf_log_unregister(&nfulnl_logger);
1100cleanup_subsys: 1099cleanup_subsys:
1101 nfnetlink_subsys_unregister(&nfulnl_subsys); 1100 nfnetlink_subsys_unregister(&nfulnl_subsys);
1102cleanup_netlink_notifier: 1101cleanup_netlink_notifier:
1103 netlink_unregister_notifier(&nfulnl_rtnl_notifier); 1102 netlink_unregister_notifier(&nfulnl_rtnl_notifier);
1103 unregister_pernet_subsys(&nfnl_log_net_ops);
1104out:
1104 return status; 1105 return status;
1105} 1106}
1106 1107
1107static void __exit nfnetlink_log_fini(void) 1108static void __exit nfnetlink_log_fini(void)
1108{ 1109{
1109 unregister_pernet_subsys(&nfnl_log_net_ops);
1110 nf_log_unregister(&nfulnl_logger); 1110 nf_log_unregister(&nfulnl_logger);
1111 nfnetlink_subsys_unregister(&nfulnl_subsys); 1111 nfnetlink_subsys_unregister(&nfulnl_subsys);
1112 netlink_unregister_notifier(&nfulnl_rtnl_notifier); 1112 netlink_unregister_notifier(&nfulnl_rtnl_notifier);
1113 unregister_pernet_subsys(&nfnl_log_net_ops);
1113} 1114}
1114 1115
1115MODULE_DESCRIPTION("netfilter userspace logging"); 1116MODULE_DESCRIPTION("netfilter userspace logging");
diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
index 0b98c7420239..11c7682fa0ea 100644
--- a/net/netfilter/nfnetlink_queue_core.c
+++ b/net/netfilter/nfnetlink_queue_core.c
@@ -1317,7 +1317,13 @@ static struct pernet_operations nfnl_queue_net_ops = {
1317 1317
1318static int __init nfnetlink_queue_init(void) 1318static int __init nfnetlink_queue_init(void)
1319{ 1319{
1320 int status = -ENOMEM; 1320 int status;
1321
1322 status = register_pernet_subsys(&nfnl_queue_net_ops);
1323 if (status < 0) {
1324 pr_err("nf_queue: failed to register pernet ops\n");
1325 goto out;
1326 }
1321 1327
1322 netlink_register_notifier(&nfqnl_rtnl_notifier); 1328 netlink_register_notifier(&nfqnl_rtnl_notifier);
1323 status = nfnetlink_subsys_register(&nfqnl_subsys); 1329 status = nfnetlink_subsys_register(&nfqnl_subsys);
@@ -1326,19 +1332,13 @@ static int __init nfnetlink_queue_init(void)
1326 goto cleanup_netlink_notifier; 1332 goto cleanup_netlink_notifier;
1327 } 1333 }
1328 1334
1329 status = register_pernet_subsys(&nfnl_queue_net_ops);
1330 if (status < 0) {
1331 pr_err("nf_queue: failed to register pernet ops\n");
1332 goto cleanup_subsys;
1333 }
1334 register_netdevice_notifier(&nfqnl_dev_notifier); 1335 register_netdevice_notifier(&nfqnl_dev_notifier);
1335 nf_register_queue_handler(&nfqh); 1336 nf_register_queue_handler(&nfqh);
1336 return status; 1337 return status;
1337 1338
1338cleanup_subsys:
1339 nfnetlink_subsys_unregister(&nfqnl_subsys);
1340cleanup_netlink_notifier: 1339cleanup_netlink_notifier:
1341 netlink_unregister_notifier(&nfqnl_rtnl_notifier); 1340 netlink_unregister_notifier(&nfqnl_rtnl_notifier);
1341out:
1342 return status; 1342 return status;
1343} 1343}
1344 1344
@@ -1346,9 +1346,9 @@ static void __exit nfnetlink_queue_fini(void)
1346{ 1346{
1347 nf_unregister_queue_handler(); 1347 nf_unregister_queue_handler();
1348 unregister_netdevice_notifier(&nfqnl_dev_notifier); 1348 unregister_netdevice_notifier(&nfqnl_dev_notifier);
1349 unregister_pernet_subsys(&nfnl_queue_net_ops);
1350 nfnetlink_subsys_unregister(&nfqnl_subsys); 1349 nfnetlink_subsys_unregister(&nfqnl_subsys);
1351 netlink_unregister_notifier(&nfqnl_rtnl_notifier); 1350 netlink_unregister_notifier(&nfqnl_rtnl_notifier);
1351 unregister_pernet_subsys(&nfnl_queue_net_ops);
1352 1352
1353 rcu_barrier(); /* Wait for completion of call_rcu()'s */ 1353 rcu_barrier(); /* Wait for completion of call_rcu()'s */
1354} 1354}
diff --git a/net/netfilter/nft_reject.c b/net/netfilter/nft_reject.c
index 57d3e1af5630..0522fc9bfb0a 100644
--- a/net/netfilter/nft_reject.c
+++ b/net/netfilter/nft_reject.c
@@ -63,6 +63,8 @@ int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
63 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code)) 63 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
64 goto nla_put_failure; 64 goto nla_put_failure;
65 break; 65 break;
66 default:
67 break;
66 } 68 }
67 69
68 return 0; 70 return 0;
diff --git a/net/netfilter/nft_reject_inet.c b/net/netfilter/nft_reject_inet.c
index 62cabee42fbe..635dbba93d01 100644
--- a/net/netfilter/nft_reject_inet.c
+++ b/net/netfilter/nft_reject_inet.c
@@ -108,6 +108,8 @@ static int nft_reject_inet_dump(struct sk_buff *skb,
108 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code)) 108 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
109 goto nla_put_failure; 109 goto nla_put_failure;
110 break; 110 break;
111 default:
112 break;
111 } 113 }
112 114
113 return 0; 115 return 0;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 19909d0786a2..bf6e76643f78 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -89,7 +89,7 @@ static inline int netlink_is_kernel(struct sock *sk)
89 return nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET; 89 return nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET;
90} 90}
91 91
92struct netlink_table *nl_table; 92struct netlink_table *nl_table __read_mostly;
93EXPORT_SYMBOL_GPL(nl_table); 93EXPORT_SYMBOL_GPL(nl_table);
94 94
95static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait); 95static DECLARE_WAIT_QUEUE_HEAD(nl_table_wait);
@@ -1081,6 +1081,7 @@ static int netlink_insert(struct sock *sk, u32 portid)
1081 if (err) { 1081 if (err) {
1082 if (err == -EEXIST) 1082 if (err == -EEXIST)
1083 err = -EADDRINUSE; 1083 err = -EADDRINUSE;
1084 nlk_sk(sk)->portid = 0;
1084 sock_put(sk); 1085 sock_put(sk);
1085 } 1086 }
1086 1087
@@ -1629,13 +1630,11 @@ static struct sk_buff *netlink_alloc_large_skb(unsigned int size,
1629 if (data == NULL) 1630 if (data == NULL)
1630 return NULL; 1631 return NULL;
1631 1632
1632 skb = build_skb(data, size); 1633 skb = __build_skb(data, size);
1633 if (skb == NULL) 1634 if (skb == NULL)
1634 vfree(data); 1635 vfree(data);
1635 else { 1636 else
1636 skb->head_frag = 0;
1637 skb->destructor = netlink_skb_destructor; 1637 skb->destructor = netlink_skb_destructor;
1638 }
1639 1638
1640 return skb; 1639 return skb;
1641} 1640}
@@ -3141,7 +3140,6 @@ static const struct rhashtable_params netlink_rhashtable_params = {
3141 .key_len = netlink_compare_arg_len, 3140 .key_len = netlink_compare_arg_len,
3142 .obj_hashfn = netlink_hash, 3141 .obj_hashfn = netlink_hash,
3143 .obj_cmpfn = netlink_compare, 3142 .obj_cmpfn = netlink_compare,
3144 .max_size = 65536,
3145 .automatic_shrinking = true, 3143 .automatic_shrinking = true,
3146}; 3144};
3147 3145
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 5102c3cc4eec..b5989c6ee551 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2311,11 +2311,14 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2311 tlen = dev->needed_tailroom; 2311 tlen = dev->needed_tailroom;
2312 skb = sock_alloc_send_skb(&po->sk, 2312 skb = sock_alloc_send_skb(&po->sk,
2313 hlen + tlen + sizeof(struct sockaddr_ll), 2313 hlen + tlen + sizeof(struct sockaddr_ll),
2314 0, &err); 2314 !need_wait, &err);
2315 2315
2316 if (unlikely(skb == NULL)) 2316 if (unlikely(skb == NULL)) {
2317 /* we assume the socket was initially writeable ... */
2318 if (likely(len_sum > 0))
2319 err = len_sum;
2317 goto out_status; 2320 goto out_status;
2318 2321 }
2319 tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto, 2322 tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
2320 addr, hlen); 2323 addr, hlen);
2321 if (tp_len > dev->mtu + dev->hard_header_len) { 2324 if (tp_len > dev->mtu + dev->hard_header_len) {
diff --git a/net/rds/connection.c b/net/rds/connection.c
index 14f041398ca1..da6da57e5f36 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -126,7 +126,10 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
126 struct rds_transport *loop_trans; 126 struct rds_transport *loop_trans;
127 unsigned long flags; 127 unsigned long flags;
128 int ret; 128 int ret;
129 struct rds_transport *otrans = trans;
129 130
131 if (!is_outgoing && otrans->t_type == RDS_TRANS_TCP)
132 goto new_conn;
130 rcu_read_lock(); 133 rcu_read_lock();
131 conn = rds_conn_lookup(head, laddr, faddr, trans); 134 conn = rds_conn_lookup(head, laddr, faddr, trans);
132 if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport && 135 if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport &&
@@ -142,6 +145,7 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
142 if (conn) 145 if (conn)
143 goto out; 146 goto out;
144 147
148new_conn:
145 conn = kmem_cache_zalloc(rds_conn_slab, gfp); 149 conn = kmem_cache_zalloc(rds_conn_slab, gfp);
146 if (!conn) { 150 if (!conn) {
147 conn = ERR_PTR(-ENOMEM); 151 conn = ERR_PTR(-ENOMEM);
@@ -230,13 +234,22 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
230 /* Creating normal conn */ 234 /* Creating normal conn */
231 struct rds_connection *found; 235 struct rds_connection *found;
232 236
233 found = rds_conn_lookup(head, laddr, faddr, trans); 237 if (!is_outgoing && otrans->t_type == RDS_TRANS_TCP)
238 found = NULL;
239 else
240 found = rds_conn_lookup(head, laddr, faddr, trans);
234 if (found) { 241 if (found) {
235 trans->conn_free(conn->c_transport_data); 242 trans->conn_free(conn->c_transport_data);
236 kmem_cache_free(rds_conn_slab, conn); 243 kmem_cache_free(rds_conn_slab, conn);
237 conn = found; 244 conn = found;
238 } else { 245 } else {
239 hlist_add_head_rcu(&conn->c_hash_node, head); 246 if ((is_outgoing && otrans->t_type == RDS_TRANS_TCP) ||
247 (otrans->t_type != RDS_TRANS_TCP)) {
248 /* Only the active side should be added to
249 * reconnect list for TCP.
250 */
251 hlist_add_head_rcu(&conn->c_hash_node, head);
252 }
240 rds_cong_add_conn(conn); 253 rds_cong_add_conn(conn);
241 rds_conn_count++; 254 rds_conn_count++;
242 } 255 }
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index 31b74f5e61ad..8a09ee7db3c1 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -183,8 +183,17 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even
183 183
184 /* If the peer gave us the last packet it saw, process this as if 184 /* If the peer gave us the last packet it saw, process this as if
185 * we had received a regular ACK. */ 185 * we had received a regular ACK. */
186 if (dp && dp->dp_ack_seq) 186 if (dp) {
187 rds_send_drop_acked(conn, be64_to_cpu(dp->dp_ack_seq), NULL); 187 /* dp structure start is not guaranteed to be 8 bytes aligned.
188 * Since dp_ack_seq is 64-bit extended load operations can be
189 * used so go through get_unaligned to avoid unaligned errors.
190 */
191 __be64 dp_ack_seq = get_unaligned(&dp->dp_ack_seq);
192
193 if (dp_ack_seq)
194 rds_send_drop_acked(conn, be64_to_cpu(dp_ack_seq),
195 NULL);
196 }
188 197
189 rds_connect_complete(conn); 198 rds_connect_complete(conn);
190} 199}
diff --git a/net/rds/tcp_connect.c b/net/rds/tcp_connect.c
index f9f564a6c960..973109c7b8e8 100644
--- a/net/rds/tcp_connect.c
+++ b/net/rds/tcp_connect.c
@@ -62,6 +62,7 @@ void rds_tcp_state_change(struct sock *sk)
62 case TCP_ESTABLISHED: 62 case TCP_ESTABLISHED:
63 rds_connect_complete(conn); 63 rds_connect_complete(conn);
64 break; 64 break;
65 case TCP_CLOSE_WAIT:
65 case TCP_CLOSE: 66 case TCP_CLOSE:
66 rds_conn_drop(conn); 67 rds_conn_drop(conn);
67 default: 68 default:
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 23ab4dcd1d9f..0da49e34495f 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -45,12 +45,45 @@ static void rds_tcp_accept_worker(struct work_struct *work);
45static DECLARE_WORK(rds_tcp_listen_work, rds_tcp_accept_worker); 45static DECLARE_WORK(rds_tcp_listen_work, rds_tcp_accept_worker);
46static struct socket *rds_tcp_listen_sock; 46static struct socket *rds_tcp_listen_sock;
47 47
48static int rds_tcp_keepalive(struct socket *sock)
49{
50 /* values below based on xs_udp_default_timeout */
51 int keepidle = 5; /* send a probe 'keepidle' secs after last data */
52 int keepcnt = 5; /* number of unack'ed probes before declaring dead */
53 int keepalive = 1;
54 int ret = 0;
55
56 ret = kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
57 (char *)&keepalive, sizeof(keepalive));
58 if (ret < 0)
59 goto bail;
60
61 ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT,
62 (char *)&keepcnt, sizeof(keepcnt));
63 if (ret < 0)
64 goto bail;
65
66 ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE,
67 (char *)&keepidle, sizeof(keepidle));
68 if (ret < 0)
69 goto bail;
70
71 /* KEEPINTVL is the interval between successive probes. We follow
72 * the model in xs_tcp_finish_connecting() and re-use keepidle.
73 */
74 ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL,
75 (char *)&keepidle, sizeof(keepidle));
76bail:
77 return ret;
78}
79
48static int rds_tcp_accept_one(struct socket *sock) 80static int rds_tcp_accept_one(struct socket *sock)
49{ 81{
50 struct socket *new_sock = NULL; 82 struct socket *new_sock = NULL;
51 struct rds_connection *conn; 83 struct rds_connection *conn;
52 int ret; 84 int ret;
53 struct inet_sock *inet; 85 struct inet_sock *inet;
86 struct rds_tcp_connection *rs_tcp;
54 87
55 ret = sock_create_lite(sock->sk->sk_family, sock->sk->sk_type, 88 ret = sock_create_lite(sock->sk->sk_family, sock->sk->sk_type,
56 sock->sk->sk_protocol, &new_sock); 89 sock->sk->sk_protocol, &new_sock);
@@ -63,6 +96,10 @@ static int rds_tcp_accept_one(struct socket *sock)
63 if (ret < 0) 96 if (ret < 0)
64 goto out; 97 goto out;
65 98
99 ret = rds_tcp_keepalive(new_sock);
100 if (ret < 0)
101 goto out;
102
66 rds_tcp_tune(new_sock); 103 rds_tcp_tune(new_sock);
67 104
68 inet = inet_sk(new_sock->sk); 105 inet = inet_sk(new_sock->sk);
@@ -77,6 +114,15 @@ static int rds_tcp_accept_one(struct socket *sock)
77 ret = PTR_ERR(conn); 114 ret = PTR_ERR(conn);
78 goto out; 115 goto out;
79 } 116 }
117 /* An incoming SYN request came in, and TCP just accepted it.
118 * We always create a new conn for listen side of TCP, and do not
119 * add it to the c_hash_list.
120 *
121 * If the client reboots, this conn will need to be cleaned up.
122 * rds_tcp_state_change() will do that cleanup
123 */
124 rs_tcp = (struct rds_tcp_connection *)conn->c_transport_data;
125 WARN_ON(!rs_tcp || rs_tcp->t_sock);
80 126
81 /* 127 /*
82 * see the comment above rds_queue_delayed_reconnect() 128 * see the comment above rds_queue_delayed_reconnect()
diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index 8e472518f9f6..295d14bd6c67 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -63,7 +63,6 @@ static int tcf_connmark(struct sk_buff *skb, const struct tc_action *a,
63 skb->mark = c->mark; 63 skb->mark = c->mark;
64 /* using overlimits stats to count how many packets marked */ 64 /* using overlimits stats to count how many packets marked */
65 ca->tcf_qstats.overlimits++; 65 ca->tcf_qstats.overlimits++;
66 nf_ct_put(c);
67 goto out; 66 goto out;
68 } 67 }
69 68
@@ -82,7 +81,6 @@ static int tcf_connmark(struct sk_buff *skb, const struct tc_action *a,
82 nf_ct_put(c); 81 nf_ct_put(c);
83 82
84out: 83out:
85 skb->nfct = NULL;
86 spin_unlock(&ca->tcf_lock); 84 spin_unlock(&ca->tcf_lock);
87 return ca->tcf_action; 85 return ca->tcf_action;
88} 86}
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 8b0470e418dc..a75864d93142 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -81,6 +81,11 @@ int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
81 struct tcf_proto_ops *t; 81 struct tcf_proto_ops *t;
82 int rc = -ENOENT; 82 int rc = -ENOENT;
83 83
84 /* Wait for outstanding call_rcu()s, if any, from a
85 * tcf_proto_ops's destroy() handler.
86 */
87 rcu_barrier();
88
84 write_lock(&cls_mod_lock); 89 write_lock(&cls_mod_lock);
85 list_for_each_entry(t, &tcf_proto_base, head) { 90 list_for_each_entry(t, &tcf_proto_base, head) {
86 if (t == ops) { 91 if (t == ops) {
@@ -308,12 +313,11 @@ replay:
308 case RTM_DELTFILTER: 313 case RTM_DELTFILTER:
309 err = tp->ops->delete(tp, fh); 314 err = tp->ops->delete(tp, fh);
310 if (err == 0) { 315 if (err == 0) {
311 tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER); 316 struct tcf_proto *next = rtnl_dereference(tp->next);
312 if (tcf_destroy(tp, false)) {
313 struct tcf_proto *next = rtnl_dereference(tp->next);
314 317
318 tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER);
319 if (tcf_destroy(tp, false))
315 RCU_INIT_POINTER(*back, next); 320 RCU_INIT_POINTER(*back, next);
316 }
317 } 321 }
318 goto errout; 322 goto errout;
319 case RTM_GETTFILTER: 323 case RTM_GETTFILTER:
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index ad9eed70bc8f..1e1c89e51a11 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -815,10 +815,8 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
815 if (dev->flags & IFF_UP) 815 if (dev->flags & IFF_UP)
816 dev_deactivate(dev); 816 dev_deactivate(dev);
817 817
818 if (new && new->ops->attach) { 818 if (new && new->ops->attach)
819 new->ops->attach(new); 819 goto skip;
820 num_q = 0;
821 }
822 820
823 for (i = 0; i < num_q; i++) { 821 for (i = 0; i < num_q; i++) {
824 struct netdev_queue *dev_queue = dev_ingress_queue(dev); 822 struct netdev_queue *dev_queue = dev_ingress_queue(dev);
@@ -834,12 +832,16 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent,
834 qdisc_destroy(old); 832 qdisc_destroy(old);
835 } 833 }
836 834
835skip:
837 if (!ingress) { 836 if (!ingress) {
838 notify_and_destroy(net, skb, n, classid, 837 notify_and_destroy(net, skb, n, classid,
839 dev->qdisc, new); 838 dev->qdisc, new);
840 if (new && !new->ops->attach) 839 if (new && !new->ops->attach)
841 atomic_inc(&new->refcnt); 840 atomic_inc(&new->refcnt);
842 dev->qdisc = new ? : &noop_qdisc; 841 dev->qdisc = new ? : &noop_qdisc;
842
843 if (new && new->ops->attach)
844 new->ops->attach(new);
843 } else { 845 } else {
844 notify_and_destroy(net, skb, n, classid, old, new); 846 notify_and_destroy(net, skb, n, classid, old, new);
845 } 847 }
diff --git a/net/sched/sch_codel.c b/net/sched/sch_codel.c
index de28f8e968e8..7a0bdb16ac92 100644
--- a/net/sched/sch_codel.c
+++ b/net/sched/sch_codel.c
@@ -164,7 +164,7 @@ static int codel_init(struct Qdisc *sch, struct nlattr *opt)
164 164
165 sch->limit = DEFAULT_CODEL_LIMIT; 165 sch->limit = DEFAULT_CODEL_LIMIT;
166 166
167 codel_params_init(&q->params); 167 codel_params_init(&q->params, sch);
168 codel_vars_init(&q->vars); 168 codel_vars_init(&q->vars);
169 codel_stats_init(&q->stats); 169 codel_stats_init(&q->stats);
170 170
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index 1e52decb7b59..c244c45b78d7 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -391,7 +391,7 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
391 q->perturbation = prandom_u32(); 391 q->perturbation = prandom_u32();
392 INIT_LIST_HEAD(&q->new_flows); 392 INIT_LIST_HEAD(&q->new_flows);
393 INIT_LIST_HEAD(&q->old_flows); 393 INIT_LIST_HEAD(&q->old_flows);
394 codel_params_init(&q->cparams); 394 codel_params_init(&q->cparams, sch);
395 codel_stats_init(&q->cstats); 395 codel_stats_init(&q->cstats);
396 q->cparams.ecn = true; 396 q->cparams.ecn = true;
397 397
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index a4ca4517cdc8..634529e0ce6b 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -229,7 +229,7 @@ static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch)
229 break; 229 break;
230 } 230 }
231 231
232 if (q->backlog + qdisc_pkt_len(skb) <= q->limit) { 232 if (gred_backlog(t, q, sch) + qdisc_pkt_len(skb) <= q->limit) {
233 q->backlog += qdisc_pkt_len(skb); 233 q->backlog += qdisc_pkt_len(skb);
234 return qdisc_enqueue_tail(skb, sch); 234 return qdisc_enqueue_tail(skb, sch);
235 } 235 }
@@ -553,7 +553,7 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
553 553
554 opt.limit = q->limit; 554 opt.limit = q->limit;
555 opt.DP = q->DP; 555 opt.DP = q->DP;
556 opt.backlog = q->backlog; 556 opt.backlog = gred_backlog(table, q, sch);
557 opt.prio = q->prio; 557 opt.prio = q->prio;
558 opt.qth_min = q->parms.qth_min >> q->parms.Wlog; 558 opt.qth_min = q->parms.qth_min >> q->parms.Wlog;
559 opt.qth_max = q->parms.qth_max >> q->parms.Wlog; 559 opt.qth_max = q->parms.qth_max >> q->parms.Wlog;
diff --git a/net/sunrpc/auth_gss/gss_rpc_xdr.c b/net/sunrpc/auth_gss/gss_rpc_xdr.c
index 1ec19f6f0c2b..eeeba5adee6d 100644
--- a/net/sunrpc/auth_gss/gss_rpc_xdr.c
+++ b/net/sunrpc/auth_gss/gss_rpc_xdr.c
@@ -793,20 +793,26 @@ int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
793{ 793{
794 u32 value_follows; 794 u32 value_follows;
795 int err; 795 int err;
796 struct page *scratch;
797
798 scratch = alloc_page(GFP_KERNEL);
799 if (!scratch)
800 return -ENOMEM;
801 xdr_set_scratch_buffer(xdr, page_address(scratch), PAGE_SIZE);
796 802
797 /* res->status */ 803 /* res->status */
798 err = gssx_dec_status(xdr, &res->status); 804 err = gssx_dec_status(xdr, &res->status);
799 if (err) 805 if (err)
800 return err; 806 goto out_free;
801 807
802 /* res->context_handle */ 808 /* res->context_handle */
803 err = gssx_dec_bool(xdr, &value_follows); 809 err = gssx_dec_bool(xdr, &value_follows);
804 if (err) 810 if (err)
805 return err; 811 goto out_free;
806 if (value_follows) { 812 if (value_follows) {
807 err = gssx_dec_ctx(xdr, res->context_handle); 813 err = gssx_dec_ctx(xdr, res->context_handle);
808 if (err) 814 if (err)
809 return err; 815 goto out_free;
810 } else { 816 } else {
811 res->context_handle = NULL; 817 res->context_handle = NULL;
812 } 818 }
@@ -814,11 +820,11 @@ int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
814 /* res->output_token */ 820 /* res->output_token */
815 err = gssx_dec_bool(xdr, &value_follows); 821 err = gssx_dec_bool(xdr, &value_follows);
816 if (err) 822 if (err)
817 return err; 823 goto out_free;
818 if (value_follows) { 824 if (value_follows) {
819 err = gssx_dec_buffer(xdr, res->output_token); 825 err = gssx_dec_buffer(xdr, res->output_token);
820 if (err) 826 if (err)
821 return err; 827 goto out_free;
822 } else { 828 } else {
823 res->output_token = NULL; 829 res->output_token = NULL;
824 } 830 }
@@ -826,14 +832,17 @@ int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
826 /* res->delegated_cred_handle */ 832 /* res->delegated_cred_handle */
827 err = gssx_dec_bool(xdr, &value_follows); 833 err = gssx_dec_bool(xdr, &value_follows);
828 if (err) 834 if (err)
829 return err; 835 goto out_free;
830 if (value_follows) { 836 if (value_follows) {
831 /* we do not support upcall servers sending this data. */ 837 /* we do not support upcall servers sending this data. */
832 return -EINVAL; 838 err = -EINVAL;
839 goto out_free;
833 } 840 }
834 841
835 /* res->options */ 842 /* res->options */
836 err = gssx_dec_option_array(xdr, &res->options); 843 err = gssx_dec_option_array(xdr, &res->options);
837 844
845out_free:
846 __free_page(scratch);
838 return err; 847 return err;
839} 848}
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 46568b85c333..055453d48668 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -338,7 +338,7 @@ int netdev_switch_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
338 fi, tos, type, nlflags, 338 fi, tos, type, nlflags,
339 tb_id); 339 tb_id);
340 if (!err) 340 if (!err)
341 fi->fib_flags |= RTNH_F_EXTERNAL; 341 fi->fib_flags |= RTNH_F_OFFLOAD;
342 } 342 }
343 343
344 return err; 344 return err;
@@ -364,7 +364,7 @@ int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
364 const struct swdev_ops *ops; 364 const struct swdev_ops *ops;
365 int err = 0; 365 int err = 0;
366 366
367 if (!(fi->fib_flags & RTNH_F_EXTERNAL)) 367 if (!(fi->fib_flags & RTNH_F_OFFLOAD))
368 return 0; 368 return 0;
369 369
370 dev = netdev_switch_get_dev_by_nhs(fi); 370 dev = netdev_switch_get_dev_by_nhs(fi);
@@ -376,7 +376,7 @@ int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
376 err = ops->swdev_fib_ipv4_del(dev, htonl(dst), dst_len, 376 err = ops->swdev_fib_ipv4_del(dev, htonl(dst), dst_len,
377 fi, tos, type, tb_id); 377 fi, tos, type, tb_id);
378 if (!err) 378 if (!err)
379 fi->fib_flags &= ~RTNH_F_EXTERNAL; 379 fi->fib_flags &= ~RTNH_F_OFFLOAD;
380 } 380 }
381 381
382 return err; 382 return err;
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 3613e72e858e..70e3dacbf84a 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -591,14 +591,14 @@ void tipc_bearer_stop(struct net *net)
591 591
592/* Caller should hold rtnl_lock to protect the bearer */ 592/* Caller should hold rtnl_lock to protect the bearer */
593static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg, 593static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
594 struct tipc_bearer *bearer) 594 struct tipc_bearer *bearer, int nlflags)
595{ 595{
596 void *hdr; 596 void *hdr;
597 struct nlattr *attrs; 597 struct nlattr *attrs;
598 struct nlattr *prop; 598 struct nlattr *prop;
599 599
600 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, 600 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
601 NLM_F_MULTI, TIPC_NL_BEARER_GET); 601 nlflags, TIPC_NL_BEARER_GET);
602 if (!hdr) 602 if (!hdr)
603 return -EMSGSIZE; 603 return -EMSGSIZE;
604 604
@@ -657,7 +657,7 @@ int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb)
657 if (!bearer) 657 if (!bearer)
658 continue; 658 continue;
659 659
660 err = __tipc_nl_add_bearer(&msg, bearer); 660 err = __tipc_nl_add_bearer(&msg, bearer, NLM_F_MULTI);
661 if (err) 661 if (err)
662 break; 662 break;
663 } 663 }
@@ -705,7 +705,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
705 goto err_out; 705 goto err_out;
706 } 706 }
707 707
708 err = __tipc_nl_add_bearer(&msg, bearer); 708 err = __tipc_nl_add_bearer(&msg, bearer, 0);
709 if (err) 709 if (err)
710 goto err_out; 710 goto err_out;
711 rtnl_unlock(); 711 rtnl_unlock();
@@ -857,14 +857,14 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
857} 857}
858 858
859static int __tipc_nl_add_media(struct tipc_nl_msg *msg, 859static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
860 struct tipc_media *media) 860 struct tipc_media *media, int nlflags)
861{ 861{
862 void *hdr; 862 void *hdr;
863 struct nlattr *attrs; 863 struct nlattr *attrs;
864 struct nlattr *prop; 864 struct nlattr *prop;
865 865
866 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, 866 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
867 NLM_F_MULTI, TIPC_NL_MEDIA_GET); 867 nlflags, TIPC_NL_MEDIA_GET);
868 if (!hdr) 868 if (!hdr)
869 return -EMSGSIZE; 869 return -EMSGSIZE;
870 870
@@ -916,7 +916,8 @@ int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb)
916 916
917 rtnl_lock(); 917 rtnl_lock();
918 for (; media_info_array[i] != NULL; i++) { 918 for (; media_info_array[i] != NULL; i++) {
919 err = __tipc_nl_add_media(&msg, media_info_array[i]); 919 err = __tipc_nl_add_media(&msg, media_info_array[i],
920 NLM_F_MULTI);
920 if (err) 921 if (err)
921 break; 922 break;
922 } 923 }
@@ -963,7 +964,7 @@ int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
963 goto err_out; 964 goto err_out;
964 } 965 }
965 966
966 err = __tipc_nl_add_media(&msg, media); 967 err = __tipc_nl_add_media(&msg, media, 0);
967 if (err) 968 if (err)
968 goto err_out; 969 goto err_out;
969 rtnl_unlock(); 970 rtnl_unlock();
diff --git a/net/tipc/link.c b/net/tipc/link.c
index a6b30df6ec02..43a515dc97b0 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -1145,11 +1145,8 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr)
1145 } 1145 }
1146 /* Synchronize with parallel link if applicable */ 1146 /* Synchronize with parallel link if applicable */
1147 if (unlikely((l_ptr->flags & LINK_SYNCHING) && !msg_dup(msg))) { 1147 if (unlikely((l_ptr->flags & LINK_SYNCHING) && !msg_dup(msg))) {
1148 link_handle_out_of_seq_msg(l_ptr, skb); 1148 if (!link_synch(l_ptr))
1149 if (link_synch(l_ptr)) 1149 goto unlock;
1150 link_retrieve_defq(l_ptr, &head);
1151 skb = NULL;
1152 goto unlock;
1153 } 1150 }
1154 l_ptr->next_in_no++; 1151 l_ptr->next_in_no++;
1155 if (unlikely(!skb_queue_empty(&l_ptr->deferdq))) 1152 if (unlikely(!skb_queue_empty(&l_ptr->deferdq)))
@@ -2013,7 +2010,7 @@ msg_full:
2013 2010
2014/* Caller should hold appropriate locks to protect the link */ 2011/* Caller should hold appropriate locks to protect the link */
2015static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, 2012static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2016 struct tipc_link *link) 2013 struct tipc_link *link, int nlflags)
2017{ 2014{
2018 int err; 2015 int err;
2019 void *hdr; 2016 void *hdr;
@@ -2022,7 +2019,7 @@ static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2022 struct tipc_net *tn = net_generic(net, tipc_net_id); 2019 struct tipc_net *tn = net_generic(net, tipc_net_id);
2023 2020
2024 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, 2021 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
2025 NLM_F_MULTI, TIPC_NL_LINK_GET); 2022 nlflags, TIPC_NL_LINK_GET);
2026 if (!hdr) 2023 if (!hdr)
2027 return -EMSGSIZE; 2024 return -EMSGSIZE;
2028 2025
@@ -2095,7 +2092,7 @@ static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
2095 if (!node->links[i]) 2092 if (!node->links[i])
2096 continue; 2093 continue;
2097 2094
2098 err = __tipc_nl_add_link(net, msg, node->links[i]); 2095 err = __tipc_nl_add_link(net, msg, node->links[i], NLM_F_MULTI);
2099 if (err) 2096 if (err)
2100 return err; 2097 return err;
2101 } 2098 }
@@ -2143,7 +2140,6 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
2143 err = __tipc_nl_add_node_links(net, &msg, node, 2140 err = __tipc_nl_add_node_links(net, &msg, node,
2144 &prev_link); 2141 &prev_link);
2145 tipc_node_unlock(node); 2142 tipc_node_unlock(node);
2146 tipc_node_put(node);
2147 if (err) 2143 if (err)
2148 goto out; 2144 goto out;
2149 2145
@@ -2210,7 +2206,7 @@ int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info)
2210 goto err_out; 2206 goto err_out;
2211 } 2207 }
2212 2208
2213 err = __tipc_nl_add_link(net, &msg, link); 2209 err = __tipc_nl_add_link(net, &msg, link, 0);
2214 if (err) 2210 if (err)
2215 goto err_out; 2211 goto err_out;
2216 2212
diff --git a/net/tipc/server.c b/net/tipc/server.c
index ab6183cdb121..77ff03ed1e18 100644
--- a/net/tipc/server.c
+++ b/net/tipc/server.c
@@ -102,7 +102,7 @@ static void tipc_conn_kref_release(struct kref *kref)
102 } 102 }
103 saddr->scope = -TIPC_NODE_SCOPE; 103 saddr->scope = -TIPC_NODE_SCOPE;
104 kernel_bind(sock, (struct sockaddr *)saddr, sizeof(*saddr)); 104 kernel_bind(sock, (struct sockaddr *)saddr, sizeof(*saddr));
105 sk_release_kernel(sk); 105 sock_release(sock);
106 con->sock = NULL; 106 con->sock = NULL;
107 } 107 }
108 108
@@ -321,12 +321,9 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
321 struct socket *sock = NULL; 321 struct socket *sock = NULL;
322 int ret; 322 int ret;
323 323
324 ret = sock_create_kern(AF_TIPC, SOCK_SEQPACKET, 0, &sock); 324 ret = __sock_create(s->net, AF_TIPC, SOCK_SEQPACKET, 0, &sock, 1);
325 if (ret < 0) 325 if (ret < 0)
326 return NULL; 326 return NULL;
327
328 sk_change_net(sock->sk, s->net);
329
330 ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE, 327 ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE,
331 (char *)&s->imp, sizeof(s->imp)); 328 (char *)&s->imp, sizeof(s->imp));
332 if (ret < 0) 329 if (ret < 0)
@@ -376,7 +373,7 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
376 373
377create_err: 374create_err:
378 kernel_sock_shutdown(sock, SHUT_RDWR); 375 kernel_sock_shutdown(sock, SHUT_RDWR);
379 sk_release_kernel(sock->sk); 376 sock_release(sock);
380 return NULL; 377 return NULL;
381} 378}
382 379
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index ee90d74d7516..9074b5cede38 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1764,13 +1764,14 @@ static int tipc_sk_enqueue(struct sk_buff_head *inputq, struct sock *sk,
1764int tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq) 1764int tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq)
1765{ 1765{
1766 u32 dnode, dport = 0; 1766 u32 dnode, dport = 0;
1767 int err = -TIPC_ERR_NO_PORT; 1767 int err;
1768 struct sk_buff *skb; 1768 struct sk_buff *skb;
1769 struct tipc_sock *tsk; 1769 struct tipc_sock *tsk;
1770 struct tipc_net *tn; 1770 struct tipc_net *tn;
1771 struct sock *sk; 1771 struct sock *sk;
1772 1772
1773 while (skb_queue_len(inputq)) { 1773 while (skb_queue_len(inputq)) {
1774 err = -TIPC_ERR_NO_PORT;
1774 skb = NULL; 1775 skb = NULL;
1775 dport = tipc_skb_peek_port(inputq, dport); 1776 dport = tipc_skb_peek_port(inputq, dport);
1776 tsk = tipc_sk_lookup(net, dport); 1777 tsk = tipc_sk_lookup(net, dport);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 5266ea7b922b..06430598cf51 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1880,6 +1880,10 @@ static long unix_stream_data_wait(struct sock *sk, long timeo,
1880 unix_state_unlock(sk); 1880 unix_state_unlock(sk);
1881 timeo = freezable_schedule_timeout(timeo); 1881 timeo = freezable_schedule_timeout(timeo);
1882 unix_state_lock(sk); 1882 unix_state_lock(sk);
1883
1884 if (sock_flag(sk, SOCK_DEAD))
1885 break;
1886
1883 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags); 1887 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1884 } 1888 }
1885 1889
@@ -1939,6 +1943,10 @@ static int unix_stream_recvmsg(struct socket *sock, struct msghdr *msg,
1939 struct sk_buff *skb, *last; 1943 struct sk_buff *skb, *last;
1940 1944
1941 unix_state_lock(sk); 1945 unix_state_lock(sk);
1946 if (sock_flag(sk, SOCK_DEAD)) {
1947 err = -ECONNRESET;
1948 goto unlock;
1949 }
1942 last = skb = skb_peek(&sk->sk_receive_queue); 1950 last = skb = skb_peek(&sk->sk_receive_queue);
1943again: 1951again:
1944 if (skb == NULL) { 1952 if (skb == NULL) {
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 99f7012b23b9..a73a226f2d33 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -95,39 +95,36 @@ static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait);
95 95
96unsigned int unix_tot_inflight; 96unsigned int unix_tot_inflight;
97 97
98
99struct sock *unix_get_socket(struct file *filp) 98struct sock *unix_get_socket(struct file *filp)
100{ 99{
101 struct sock *u_sock = NULL; 100 struct sock *u_sock = NULL;
102 struct inode *inode = file_inode(filp); 101 struct inode *inode = file_inode(filp);
103 102
104 /* 103 /* Socket ? */
105 * Socket ?
106 */
107 if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) { 104 if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) {
108 struct socket *sock = SOCKET_I(inode); 105 struct socket *sock = SOCKET_I(inode);
109 struct sock *s = sock->sk; 106 struct sock *s = sock->sk;
110 107
111 /* 108 /* PF_UNIX ? */
112 * PF_UNIX ?
113 */
114 if (s && sock->ops && sock->ops->family == PF_UNIX) 109 if (s && sock->ops && sock->ops->family == PF_UNIX)
115 u_sock = s; 110 u_sock = s;
116 } 111 }
117 return u_sock; 112 return u_sock;
118} 113}
119 114
120/* 115/* Keep the number of times in flight count for the file
121 * Keep the number of times in flight count for the file 116 * descriptor if it is for an AF_UNIX socket.
122 * descriptor if it is for an AF_UNIX socket.
123 */ 117 */
124 118
125void unix_inflight(struct file *fp) 119void unix_inflight(struct file *fp)
126{ 120{
127 struct sock *s = unix_get_socket(fp); 121 struct sock *s = unix_get_socket(fp);
122
128 if (s) { 123 if (s) {
129 struct unix_sock *u = unix_sk(s); 124 struct unix_sock *u = unix_sk(s);
125
130 spin_lock(&unix_gc_lock); 126 spin_lock(&unix_gc_lock);
127
131 if (atomic_long_inc_return(&u->inflight) == 1) { 128 if (atomic_long_inc_return(&u->inflight) == 1) {
132 BUG_ON(!list_empty(&u->link)); 129 BUG_ON(!list_empty(&u->link));
133 list_add_tail(&u->link, &gc_inflight_list); 130 list_add_tail(&u->link, &gc_inflight_list);
@@ -142,10 +139,13 @@ void unix_inflight(struct file *fp)
142void unix_notinflight(struct file *fp) 139void unix_notinflight(struct file *fp)
143{ 140{
144 struct sock *s = unix_get_socket(fp); 141 struct sock *s = unix_get_socket(fp);
142
145 if (s) { 143 if (s) {
146 struct unix_sock *u = unix_sk(s); 144 struct unix_sock *u = unix_sk(s);
145
147 spin_lock(&unix_gc_lock); 146 spin_lock(&unix_gc_lock);
148 BUG_ON(list_empty(&u->link)); 147 BUG_ON(list_empty(&u->link));
148
149 if (atomic_long_dec_and_test(&u->inflight)) 149 if (atomic_long_dec_and_test(&u->inflight))
150 list_del_init(&u->link); 150 list_del_init(&u->link);
151 unix_tot_inflight--; 151 unix_tot_inflight--;
@@ -161,32 +161,27 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *),
161 161
162 spin_lock(&x->sk_receive_queue.lock); 162 spin_lock(&x->sk_receive_queue.lock);
163 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 163 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) {
164 /* 164 /* Do we have file descriptors ? */
165 * Do we have file descriptors ?
166 */
167 if (UNIXCB(skb).fp) { 165 if (UNIXCB(skb).fp) {
168 bool hit = false; 166 bool hit = false;
169 /* 167 /* Process the descriptors of this socket */
170 * Process the descriptors of this socket
171 */
172 int nfd = UNIXCB(skb).fp->count; 168 int nfd = UNIXCB(skb).fp->count;
173 struct file **fp = UNIXCB(skb).fp->fp; 169 struct file **fp = UNIXCB(skb).fp->fp;
170
174 while (nfd--) { 171 while (nfd--) {
175 /* 172 /* Get the socket the fd matches if it indeed does so */
176 * Get the socket the fd matches
177 * if it indeed does so
178 */
179 struct sock *sk = unix_get_socket(*fp++); 173 struct sock *sk = unix_get_socket(*fp++);
174
180 if (sk) { 175 if (sk) {
181 struct unix_sock *u = unix_sk(sk); 176 struct unix_sock *u = unix_sk(sk);
182 177
183 /* 178 /* Ignore non-candidates, they could
184 * Ignore non-candidates, they could
185 * have been added to the queues after 179 * have been added to the queues after
186 * starting the garbage collection 180 * starting the garbage collection
187 */ 181 */
188 if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) { 182 if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) {
189 hit = true; 183 hit = true;
184
190 func(u); 185 func(u);
191 } 186 }
192 } 187 }
@@ -203,24 +198,22 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *),
203static void scan_children(struct sock *x, void (*func)(struct unix_sock *), 198static void scan_children(struct sock *x, void (*func)(struct unix_sock *),
204 struct sk_buff_head *hitlist) 199 struct sk_buff_head *hitlist)
205{ 200{
206 if (x->sk_state != TCP_LISTEN) 201 if (x->sk_state != TCP_LISTEN) {
207 scan_inflight(x, func, hitlist); 202 scan_inflight(x, func, hitlist);
208 else { 203 } else {
209 struct sk_buff *skb; 204 struct sk_buff *skb;
210 struct sk_buff *next; 205 struct sk_buff *next;
211 struct unix_sock *u; 206 struct unix_sock *u;
212 LIST_HEAD(embryos); 207 LIST_HEAD(embryos);
213 208
214 /* 209 /* For a listening socket collect the queued embryos
215 * For a listening socket collect the queued embryos
216 * and perform a scan on them as well. 210 * and perform a scan on them as well.
217 */ 211 */
218 spin_lock(&x->sk_receive_queue.lock); 212 spin_lock(&x->sk_receive_queue.lock);
219 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 213 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) {
220 u = unix_sk(skb->sk); 214 u = unix_sk(skb->sk);
221 215
222 /* 216 /* An embryo cannot be in-flight, so it's safe
223 * An embryo cannot be in-flight, so it's safe
224 * to use the list link. 217 * to use the list link.
225 */ 218 */
226 BUG_ON(!list_empty(&u->link)); 219 BUG_ON(!list_empty(&u->link));
@@ -249,8 +242,7 @@ static void inc_inflight(struct unix_sock *usk)
249static void inc_inflight_move_tail(struct unix_sock *u) 242static void inc_inflight_move_tail(struct unix_sock *u)
250{ 243{
251 atomic_long_inc(&u->inflight); 244 atomic_long_inc(&u->inflight);
252 /* 245 /* If this still might be part of a cycle, move it to the end
253 * If this still might be part of a cycle, move it to the end
254 * of the list, so that it's checked even if it was already 246 * of the list, so that it's checked even if it was already
255 * passed over 247 * passed over
256 */ 248 */
@@ -263,8 +255,7 @@ static bool gc_in_progress;
263 255
264void wait_for_unix_gc(void) 256void wait_for_unix_gc(void)
265{ 257{
266 /* 258 /* If number of inflight sockets is insane,
267 * If number of inflight sockets is insane,
268 * force a garbage collect right now. 259 * force a garbage collect right now.
269 */ 260 */
270 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress) 261 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress)
@@ -288,8 +279,7 @@ void unix_gc(void)
288 goto out; 279 goto out;
289 280
290 gc_in_progress = true; 281 gc_in_progress = true;
291 /* 282 /* First, select candidates for garbage collection. Only
292 * First, select candidates for garbage collection. Only
293 * in-flight sockets are considered, and from those only ones 283 * in-flight sockets are considered, and from those only ones
294 * which don't have any external reference. 284 * which don't have any external reference.
295 * 285 *
@@ -320,15 +310,13 @@ void unix_gc(void)
320 } 310 }
321 } 311 }
322 312
323 /* 313 /* Now remove all internal in-flight reference to children of
324 * Now remove all internal in-flight reference to children of
325 * the candidates. 314 * the candidates.
326 */ 315 */
327 list_for_each_entry(u, &gc_candidates, link) 316 list_for_each_entry(u, &gc_candidates, link)
328 scan_children(&u->sk, dec_inflight, NULL); 317 scan_children(&u->sk, dec_inflight, NULL);
329 318
330 /* 319 /* Restore the references for children of all candidates,
331 * Restore the references for children of all candidates,
332 * which have remaining references. Do this recursively, so 320 * which have remaining references. Do this recursively, so
333 * only those remain, which form cyclic references. 321 * only those remain, which form cyclic references.
334 * 322 *
@@ -350,8 +338,7 @@ void unix_gc(void)
350 } 338 }
351 list_del(&cursor); 339 list_del(&cursor);
352 340
353 /* 341 /* not_cycle_list contains those sockets which do not make up a
354 * not_cycle_list contains those sockets which do not make up a
355 * cycle. Restore these to the inflight list. 342 * cycle. Restore these to the inflight list.
356 */ 343 */
357 while (!list_empty(&not_cycle_list)) { 344 while (!list_empty(&not_cycle_list)) {
@@ -360,8 +347,7 @@ void unix_gc(void)
360 list_move_tail(&u->link, &gc_inflight_list); 347 list_move_tail(&u->link, &gc_inflight_list);
361 } 348 }
362 349
363 /* 350 /* Now gc_candidates contains only garbage. Restore original
364 * Now gc_candidates contains only garbage. Restore original
365 * inflight counters for these as well, and remove the skbuffs 351 * inflight counters for these as well, and remove the skbuffs
366 * which are creating the cycle(s). 352 * which are creating the cycle(s).
367 */ 353 */
diff --git a/scripts/gdb/linux/modules.py b/scripts/gdb/linux/modules.py
index a1504c4f1900..25db8cff44a2 100644
--- a/scripts/gdb/linux/modules.py
+++ b/scripts/gdb/linux/modules.py
@@ -73,18 +73,11 @@ class LxLsmod(gdb.Command):
73 " " if utils.get_long_type().sizeof == 8 else "")) 73 " " if utils.get_long_type().sizeof == 8 else ""))
74 74
75 for module in module_list(): 75 for module in module_list():
76 ref = 0
77 module_refptr = module['refptr']
78 for cpu in cpus.cpu_list("cpu_possible_mask"):
79 refptr = cpus.per_cpu(module_refptr, cpu)
80 ref += refptr['incs']
81 ref -= refptr['decs']
82
83 gdb.write("{address} {name:<19} {size:>8} {ref}".format( 76 gdb.write("{address} {name:<19} {size:>8} {ref}".format(
84 address=str(module['module_core']).split()[0], 77 address=str(module['module_core']).split()[0],
85 name=module['name'].string(), 78 name=module['name'].string(),
86 size=str(module['core_size']), 79 size=str(module['core_size']),
87 ref=str(ref))) 80 ref=str(module['refcnt']['counter'])))
88 81
89 source_list = module['source_list'] 82 source_list = module['source_list']
90 t = self._module_use_type.get_type().pointer() 83 t = self._module_use_type.get_type().pointer()
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index cf4cedf2b420..6dad042630d8 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -916,7 +916,6 @@ static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev)
916{ 916{
917 struct ac97c_platform_data *pdata; 917 struct ac97c_platform_data *pdata;
918 struct device_node *node = dev->of_node; 918 struct device_node *node = dev->of_node;
919 const struct of_device_id *match;
920 919
921 if (!node) { 920 if (!node) {
922 dev_err(dev, "Device does not have associated DT data\n"); 921 dev_err(dev, "Device does not have associated DT data\n");
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index ac6b33f3779c..7d45645f10ba 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -339,7 +339,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
339 if (delta > new_hw_ptr) { 339 if (delta > new_hw_ptr) {
340 /* check for double acknowledged interrupts */ 340 /* check for double acknowledged interrupts */
341 hdelta = curr_jiffies - runtime->hw_ptr_jiffies; 341 hdelta = curr_jiffies - runtime->hw_ptr_jiffies;
342 if (hdelta > runtime->hw_ptr_buffer_jiffies/2) { 342 if (hdelta > runtime->hw_ptr_buffer_jiffies/2 + 1) {
343 hw_base += runtime->buffer_size; 343 hw_base += runtime->buffer_size;
344 if (hw_base >= runtime->boundary) { 344 if (hw_base >= runtime->boundary) {
345 hw_base = 0; 345 hw_base = 0;
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index 37d0220a094c..db7a2e5e4a14 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -183,8 +183,10 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci,
183 } 183 }
184#endif 184#endif
185 185
186 strcpy(card->driver, emu->card_capabilities->driver); 186 strlcpy(card->driver, emu->card_capabilities->driver,
187 strcpy(card->shortname, emu->card_capabilities->name); 187 sizeof(card->driver));
188 strlcpy(card->shortname, emu->card_capabilities->name,
189 sizeof(card->shortname));
188 snprintf(card->longname, sizeof(card->longname), 190 snprintf(card->longname, sizeof(card->longname),
189 "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i", 191 "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i",
190 card->shortname, emu->revision, emu->serial, emu->port, emu->irq); 192 card->shortname, emu->revision, emu->serial, emu->port, emu->irq);
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index 874cd76c7b7f..d2c7ea3a7610 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -415,7 +415,7 @@ start_voice(struct snd_emux_voice *vp)
415 snd_emu10k1_ptr_write(hw, Z2, ch, 0); 415 snd_emu10k1_ptr_write(hw, Z2, ch, 0);
416 416
417 /* invalidate maps */ 417 /* invalidate maps */
418 temp = (hw->silent_page.addr << 1) | MAP_PTI_MASK; 418 temp = (hw->silent_page.addr << hw->address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
419 snd_emu10k1_ptr_write(hw, MAPA, ch, temp); 419 snd_emu10k1_ptr_write(hw, MAPA, ch, temp);
420 snd_emu10k1_ptr_write(hw, MAPB, ch, temp); 420 snd_emu10k1_ptr_write(hw, MAPB, ch, temp);
421#if 0 421#if 0
@@ -436,7 +436,7 @@ start_voice(struct snd_emux_voice *vp)
436 snd_emu10k1_ptr_write(hw, CDF, ch, sample); 436 snd_emu10k1_ptr_write(hw, CDF, ch, sample);
437 437
438 /* invalidate maps */ 438 /* invalidate maps */
439 temp = ((unsigned int)hw->silent_page.addr << 1) | MAP_PTI_MASK; 439 temp = ((unsigned int)hw->silent_page.addr << hw_address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
440 snd_emu10k1_ptr_write(hw, MAPA, ch, temp); 440 snd_emu10k1_ptr_write(hw, MAPA, ch, temp);
441 snd_emu10k1_ptr_write(hw, MAPB, ch, temp); 441 snd_emu10k1_ptr_write(hw, MAPB, ch, temp);
442 442
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 54079f5d5673..a4548147c621 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -282,7 +282,7 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
282 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */ 282 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
283 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */ 283 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
284 284
285 silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK; 285 silent_page = (emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
286 for (ch = 0; ch < NUM_G; ch++) { 286 for (ch = 0; ch < NUM_G; ch++) {
287 snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page); 287 snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
288 snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page); 288 snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
@@ -348,6 +348,11 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
348 outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG); 348 outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
349 } 349 }
350 350
351 if (emu->address_mode == 0) {
352 /* use 16M in 4G */
353 outl(inl(emu->port + HCFG) | HCFG_EXPANDED_MEM, emu->port + HCFG);
354 }
355
351 return 0; 356 return 0;
352} 357}
353 358
@@ -1446,7 +1451,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1446 * 1451 *
1447 */ 1452 */
1448 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102, 1453 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
1449 .driver = "Audigy2", .name = "SB Audigy 2 ZS Notebook [SB0530]", 1454 .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
1450 .id = "Audigy2", 1455 .id = "Audigy2",
1451 .emu10k2_chip = 1, 1456 .emu10k2_chip = 1,
1452 .ca0108_chip = 1, 1457 .ca0108_chip = 1,
@@ -1596,7 +1601,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
1596 .adc_1361t = 1, /* 24 bit capture instead of 16bit */ 1601 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
1597 .ac97_chip = 1} , 1602 .ac97_chip = 1} ,
1598 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102, 1603 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
1599 .driver = "Audigy2", .name = "SB Audigy 2 Platinum EX [SB0280]", 1604 .driver = "Audigy2", .name = "Audigy 2 Platinum EX [SB0280]",
1600 .id = "Audigy2", 1605 .id = "Audigy2",
1601 .emu10k2_chip = 1, 1606 .emu10k2_chip = 1,
1602 .ca0102_chip = 1, 1607 .ca0102_chip = 1,
@@ -1902,8 +1907,10 @@ int snd_emu10k1_create(struct snd_card *card,
1902 1907
1903 is_audigy = emu->audigy = c->emu10k2_chip; 1908 is_audigy = emu->audigy = c->emu10k2_chip;
1904 1909
1910 /* set addressing mode */
1911 emu->address_mode = is_audigy ? 0 : 1;
1905 /* set the DMA transfer mask */ 1912 /* set the DMA transfer mask */
1906 emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK; 1913 emu->dma_mask = emu->address_mode ? EMU10K1_DMA_MASK : AUDIGY_DMA_MASK;
1907 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 || 1914 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
1908 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) { 1915 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
1909 dev_err(card->dev, 1916 dev_err(card->dev,
@@ -1928,7 +1935,7 @@ int snd_emu10k1_create(struct snd_card *card,
1928 1935
1929 emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT; 1936 emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
1930 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1937 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1931 32 * 1024, &emu->ptb_pages) < 0) { 1938 (emu->address_mode ? 32 : 16) * 1024, &emu->ptb_pages) < 0) {
1932 err = -ENOMEM; 1939 err = -ENOMEM;
1933 goto error; 1940 goto error;
1934 } 1941 }
@@ -2027,8 +2034,8 @@ int snd_emu10k1_create(struct snd_card *card,
2027 2034
2028 /* Clear silent pages and set up pointers */ 2035 /* Clear silent pages and set up pointers */
2029 memset(emu->silent_page.area, 0, PAGE_SIZE); 2036 memset(emu->silent_page.area, 0, PAGE_SIZE);
2030 silent_page = emu->silent_page.addr << 1; 2037 silent_page = emu->silent_page.addr << emu->address_mode;
2031 for (idx = 0; idx < MAXPAGES; idx++) 2038 for (idx = 0; idx < (emu->address_mode ? MAXPAGES1 : MAXPAGES0); idx++)
2032 ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx); 2039 ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
2033 2040
2034 /* set up voice indices */ 2041 /* set up voice indices */
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index 0dc07385af0e..14a305bd8a98 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -380,7 +380,7 @@ static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
380 snd_emu10k1_ptr_write(emu, Z1, voice, 0); 380 snd_emu10k1_ptr_write(emu, Z1, voice, 0);
381 snd_emu10k1_ptr_write(emu, Z2, voice, 0); 381 snd_emu10k1_ptr_write(emu, Z2, voice, 0);
382 /* invalidate maps */ 382 /* invalidate maps */
383 silent_page = ((unsigned int)emu->silent_page.addr << 1) | MAP_PTI_MASK; 383 silent_page = ((unsigned int)emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
384 snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page); 384 snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page);
385 snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page); 385 snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page);
386 /* modulation envelope */ 386 /* modulation envelope */
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index c68e6dd2fa67..4f1f69be1865 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -34,10 +34,11 @@
34 * aligned pages in others 34 * aligned pages in others
35 */ 35 */
36#define __set_ptb_entry(emu,page,addr) \ 36#define __set_ptb_entry(emu,page,addr) \
37 (((u32 *)(emu)->ptb_pages.area)[page] = cpu_to_le32(((addr) << 1) | (page))) 37 (((u32 *)(emu)->ptb_pages.area)[page] = cpu_to_le32(((addr) << (emu->address_mode)) | (page)))
38 38
39#define UNIT_PAGES (PAGE_SIZE / EMUPAGESIZE) 39#define UNIT_PAGES (PAGE_SIZE / EMUPAGESIZE)
40#define MAX_ALIGN_PAGES (MAXPAGES / UNIT_PAGES) 40#define MAX_ALIGN_PAGES0 (MAXPAGES0 / UNIT_PAGES)
41#define MAX_ALIGN_PAGES1 (MAXPAGES1 / UNIT_PAGES)
41/* get aligned page from offset address */ 42/* get aligned page from offset address */
42#define get_aligned_page(offset) ((offset) >> PAGE_SHIFT) 43#define get_aligned_page(offset) ((offset) >> PAGE_SHIFT)
43/* get offset address from aligned page */ 44/* get offset address from aligned page */
@@ -124,7 +125,7 @@ static int search_empty_map_area(struct snd_emu10k1 *emu, int npages, struct lis
124 } 125 }
125 page = blk->mapped_page + blk->pages; 126 page = blk->mapped_page + blk->pages;
126 } 127 }
127 size = MAX_ALIGN_PAGES - page; 128 size = (emu->address_mode ? MAX_ALIGN_PAGES1 : MAX_ALIGN_PAGES0) - page;
128 if (size >= max_size) { 129 if (size >= max_size) {
129 *nextp = pos; 130 *nextp = pos;
130 return page; 131 return page;
@@ -181,7 +182,7 @@ static int unmap_memblk(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk)
181 q = get_emu10k1_memblk(p, mapped_link); 182 q = get_emu10k1_memblk(p, mapped_link);
182 end_page = q->mapped_page; 183 end_page = q->mapped_page;
183 } else 184 } else
184 end_page = MAX_ALIGN_PAGES; 185 end_page = (emu->address_mode ? MAX_ALIGN_PAGES1 : MAX_ALIGN_PAGES0);
185 186
186 /* remove links */ 187 /* remove links */
187 list_del(&blk->mapped_link); 188 list_del(&blk->mapped_link);
@@ -307,7 +308,7 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
307 if (snd_BUG_ON(!emu)) 308 if (snd_BUG_ON(!emu))
308 return NULL; 309 return NULL;
309 if (snd_BUG_ON(runtime->dma_bytes <= 0 || 310 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
310 runtime->dma_bytes >= MAXPAGES * EMUPAGESIZE)) 311 runtime->dma_bytes >= (emu->address_mode ? MAXPAGES1 : MAXPAGES0) * EMUPAGESIZE))
311 return NULL; 312 return NULL;
312 hdr = emu->memhdr; 313 hdr = emu->memhdr;
313 if (snd_BUG_ON(!hdr)) 314 if (snd_BUG_ON(!hdr))
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 873ed1bce12b..b49feff0a319 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -873,14 +873,15 @@ struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
873 struct hda_pcm *pcm; 873 struct hda_pcm *pcm;
874 va_list args; 874 va_list args;
875 875
876 va_start(args, fmt);
877 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 876 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
878 if (!pcm) 877 if (!pcm)
879 return NULL; 878 return NULL;
880 879
881 pcm->codec = codec; 880 pcm->codec = codec;
882 kref_init(&pcm->kref); 881 kref_init(&pcm->kref);
882 va_start(args, fmt);
883 pcm->name = kvasprintf(GFP_KERNEL, fmt, args); 883 pcm->name = kvasprintf(GFP_KERNEL, fmt, args);
884 va_end(args);
884 if (!pcm->name) { 885 if (!pcm->name) {
885 kfree(pcm); 886 kfree(pcm);
886 return NULL; 887 return NULL;
@@ -2082,6 +2083,16 @@ static struct snd_kcontrol_new vmaster_mute_mode = {
2082 .put = vmaster_mute_mode_put, 2083 .put = vmaster_mute_mode_put,
2083}; 2084};
2084 2085
2086/* meta hook to call each driver's vmaster hook */
2087static void vmaster_hook(void *private_data, int enabled)
2088{
2089 struct hda_vmaster_mute_hook *hook = private_data;
2090
2091 if (hook->mute_mode != HDA_VMUTE_FOLLOW_MASTER)
2092 enabled = hook->mute_mode;
2093 hook->hook(hook->codec, enabled);
2094}
2095
2085/** 2096/**
2086 * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED 2097 * snd_hda_add_vmaster_hook - Add a vmaster hook for mute-LED
2087 * @codec: the HDA codec 2098 * @codec: the HDA codec
@@ -2100,9 +2111,9 @@ int snd_hda_add_vmaster_hook(struct hda_codec *codec,
2100 2111
2101 if (!hook->hook || !hook->sw_kctl) 2112 if (!hook->hook || !hook->sw_kctl)
2102 return 0; 2113 return 0;
2103 snd_ctl_add_vmaster_hook(hook->sw_kctl, hook->hook, codec);
2104 hook->codec = codec; 2114 hook->codec = codec;
2105 hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER; 2115 hook->mute_mode = HDA_VMUTE_FOLLOW_MASTER;
2116 snd_ctl_add_vmaster_hook(hook->sw_kctl, vmaster_hook, hook);
2106 if (!expose_enum_ctl) 2117 if (!expose_enum_ctl)
2107 return 0; 2118 return 0;
2108 kctl = snd_ctl_new1(&vmaster_mute_mode, hook); 2119 kctl = snd_ctl_new1(&vmaster_mute_mode, hook);
@@ -2128,14 +2139,7 @@ void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook)
2128 */ 2139 */
2129 if (hook->codec->bus->shutdown) 2140 if (hook->codec->bus->shutdown)
2130 return; 2141 return;
2131 switch (hook->mute_mode) { 2142 snd_ctl_sync_vmaster_hook(hook->sw_kctl);
2132 case HDA_VMUTE_FOLLOW_MASTER:
2133 snd_ctl_sync_vmaster_hook(hook->sw_kctl);
2134 break;
2135 default:
2136 hook->hook(hook->codec, hook->mute_mode);
2137 break;
2138 }
2139} 2143}
2140EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook); 2144EXPORT_SYMBOL_GPL(snd_hda_sync_vmaster_hook);
2141 2145
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 3d2597b7037b..ac0db1679f09 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -844,8 +844,16 @@ static hda_nid_t path_power_update(struct hda_codec *codec,
844 snd_hda_codec_write(codec, nid, 0, 844 snd_hda_codec_write(codec, nid, 0,
845 AC_VERB_SET_POWER_STATE, state); 845 AC_VERB_SET_POWER_STATE, state);
846 changed = nid; 846 changed = nid;
847 /* all known codecs seem to be capable to handl
848 * widgets state even in D3, so far.
849 * if any new codecs need to restore the widget
850 * states after D0 transition, call the function
851 * below.
852 */
853#if 0 /* disabled */
847 if (state == AC_PWRST_D0) 854 if (state == AC_PWRST_D0)
848 snd_hdac_regmap_sync_node(&codec->core, nid); 855 snd_hdac_regmap_sync_node(&codec->core, nid);
856#endif
849 } 857 }
850 } 858 }
851 return changed; 859 return changed;
@@ -3259,7 +3267,8 @@ static int create_input_ctls(struct hda_codec *codec)
3259 val = PIN_IN; 3267 val = PIN_IN;
3260 if (cfg->inputs[i].type == AUTO_PIN_MIC) 3268 if (cfg->inputs[i].type == AUTO_PIN_MIC)
3261 val |= snd_hda_get_default_vref(codec, pin); 3269 val |= snd_hda_get_default_vref(codec, pin);
3262 if (pin != spec->hp_mic_pin) 3270 if (pin != spec->hp_mic_pin &&
3271 !snd_hda_codec_get_pin_target(codec, pin))
3263 set_pin_target(codec, pin, val, false); 3272 set_pin_target(codec, pin, val, false);
3264 3273
3265 if (mixer) { 3274 if (mixer) {
@@ -4917,9 +4926,12 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4917 dig_only: 4926 dig_only:
4918 parse_digital(codec); 4927 parse_digital(codec);
4919 4928
4920 if (spec->power_down_unused || codec->power_save_node) 4929 if (spec->power_down_unused || codec->power_save_node) {
4921 if (!codec->power_filter) 4930 if (!codec->power_filter)
4922 codec->power_filter = snd_hda_gen_path_power_filter; 4931 codec->power_filter = snd_hda_gen_path_power_filter;
4932 if (!codec->patch_ops.stream_pm)
4933 codec->patch_ops.stream_pm = snd_hda_gen_stream_pm;
4934 }
4923 4935
4924 if (!spec->no_analog && spec->beep_nid) { 4936 if (!spec->no_analog && spec->beep_nid) {
4925 err = snd_hda_attach_beep_device(codec, spec->beep_nid); 4937 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 34040d26c94f..fea198c58196 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -2089,6 +2089,8 @@ static const struct pci_device_id azx_ids[] = {
2089 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS }, 2089 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2090 { PCI_DEVICE(0x1002, 0xaab0), 2090 { PCI_DEVICE(0x1002, 0xaab0),
2091 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS }, 2091 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2092 { PCI_DEVICE(0x1002, 0xaac8),
2093 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2092 /* VIA VT8251/VT8237A */ 2094 /* VIA VT8251/VT8237A */
2093 { PCI_DEVICE(0x1106, 0x3288), 2095 { PCI_DEVICE(0x1106, 0x3288),
2094 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA }, 2096 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA },
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index f8f0dfbef149..78b719b5b34d 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -968,6 +968,14 @@ static const struct hda_codec_preset snd_hda_preset_conexant[] = {
968 .patch = patch_conexant_auto }, 968 .patch = patch_conexant_auto },
969 { .id = 0x14f150b9, .name = "CX20665", 969 { .id = 0x14f150b9, .name = "CX20665",
970 .patch = patch_conexant_auto }, 970 .patch = patch_conexant_auto },
971 { .id = 0x14f150f1, .name = "CX20721",
972 .patch = patch_conexant_auto },
973 { .id = 0x14f150f2, .name = "CX20722",
974 .patch = patch_conexant_auto },
975 { .id = 0x14f150f3, .name = "CX20723",
976 .patch = patch_conexant_auto },
977 { .id = 0x14f150f4, .name = "CX20724",
978 .patch = patch_conexant_auto },
971 { .id = 0x14f1510f, .name = "CX20751/2", 979 { .id = 0x14f1510f, .name = "CX20751/2",
972 .patch = patch_conexant_auto }, 980 .patch = patch_conexant_auto },
973 { .id = 0x14f15110, .name = "CX20751/2", 981 { .id = 0x14f15110, .name = "CX20751/2",
@@ -1002,6 +1010,10 @@ MODULE_ALIAS("snd-hda-codec-id:14f150ab");
1002MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 1010MODULE_ALIAS("snd-hda-codec-id:14f150ac");
1003MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 1011MODULE_ALIAS("snd-hda-codec-id:14f150b8");
1004MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 1012MODULE_ALIAS("snd-hda-codec-id:14f150b9");
1013MODULE_ALIAS("snd-hda-codec-id:14f150f1");
1014MODULE_ALIAS("snd-hda-codec-id:14f150f2");
1015MODULE_ALIAS("snd-hda-codec-id:14f150f3");
1016MODULE_ALIAS("snd-hda-codec-id:14f150f4");
1005MODULE_ALIAS("snd-hda-codec-id:14f1510f"); 1017MODULE_ALIAS("snd-hda-codec-id:14f1510f");
1006MODULE_ALIAS("snd-hda-codec-id:14f15110"); 1018MODULE_ALIAS("snd-hda-codec-id:14f15110");
1007MODULE_ALIAS("snd-hda-codec-id:14f15111"); 1019MODULE_ALIAS("snd-hda-codec-id:14f15111");
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 06199e4e930f..464168426465 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -883,6 +883,8 @@ static struct alc_codec_rename_pci_table rename_pci_tbl[] = {
883 { 0x10ec0668, 0x1028, 0, "ALC3661" }, 883 { 0x10ec0668, 0x1028, 0, "ALC3661" },
884 { 0x10ec0275, 0x1028, 0, "ALC3260" }, 884 { 0x10ec0275, 0x1028, 0, "ALC3260" },
885 { 0x10ec0899, 0x1028, 0, "ALC3861" }, 885 { 0x10ec0899, 0x1028, 0, "ALC3861" },
886 { 0x10ec0298, 0x1028, 0, "ALC3266" },
887 { 0x10ec0256, 0x1028, 0, "ALC3246" },
886 { 0x10ec0670, 0x1025, 0, "ALC669X" }, 888 { 0x10ec0670, 0x1025, 0, "ALC669X" },
887 { 0x10ec0676, 0x1025, 0, "ALC679X" }, 889 { 0x10ec0676, 0x1025, 0, "ALC679X" },
888 { 0x10ec0282, 0x1043, 0, "ALC3229" }, 890 { 0x10ec0282, 0x1043, 0, "ALC3229" },
@@ -3673,6 +3675,10 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3673 alc_process_coef_fw(codec, coef0293); 3675 alc_process_coef_fw(codec, coef0293);
3674 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); 3676 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3675 break; 3677 break;
3678 case 0x10ec0662:
3679 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
3680 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3681 break;
3676 case 0x10ec0668: 3682 case 0x10ec0668:
3677 alc_write_coef_idx(codec, 0x11, 0x0001); 3683 alc_write_coef_idx(codec, 0x11, 0x0001);
3678 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0); 3684 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
@@ -3738,7 +3744,6 @@ static void alc_headset_mode_default(struct hda_codec *codec)
3738 case 0x10ec0288: 3744 case 0x10ec0288:
3739 alc_process_coef_fw(codec, coef0288); 3745 alc_process_coef_fw(codec, coef0288);
3740 break; 3746 break;
3741 break;
3742 case 0x10ec0292: 3747 case 0x10ec0292:
3743 alc_process_coef_fw(codec, coef0292); 3748 alc_process_coef_fw(codec, coef0292);
3744 break; 3749 break;
@@ -4012,7 +4017,7 @@ static void alc_update_headset_mode(struct hda_codec *codec)
4012 if (new_headset_mode != ALC_HEADSET_MODE_MIC) { 4017 if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
4013 snd_hda_set_pin_ctl_cache(codec, hp_pin, 4018 snd_hda_set_pin_ctl_cache(codec, hp_pin,
4014 AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN); 4019 AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
4015 if (spec->headphone_mic_pin) 4020 if (spec->headphone_mic_pin && spec->headphone_mic_pin != hp_pin)
4016 snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin, 4021 snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
4017 PIN_VREFHIZ); 4022 PIN_VREFHIZ);
4018 } 4023 }
@@ -4190,11 +4195,18 @@ static void alc_shutup_dell_xps13(struct hda_codec *codec)
4190static void alc_fixup_dell_xps13(struct hda_codec *codec, 4195static void alc_fixup_dell_xps13(struct hda_codec *codec,
4191 const struct hda_fixup *fix, int action) 4196 const struct hda_fixup *fix, int action)
4192{ 4197{
4193 if (action == HDA_FIXUP_ACT_PROBE) { 4198 struct alc_spec *spec = codec->spec;
4194 struct alc_spec *spec = codec->spec; 4199 struct hda_input_mux *imux = &spec->gen.input_mux;
4195 struct hda_input_mux *imux = &spec->gen.input_mux; 4200 int i;
4196 int i;
4197 4201
4202 switch (action) {
4203 case HDA_FIXUP_ACT_PRE_PROBE:
4204 /* mic pin 0x19 must be initialized with Vref Hi-Z, otherwise
4205 * it causes a click noise at start up
4206 */
4207 snd_hda_codec_set_pin_target(codec, 0x19, PIN_VREFHIZ);
4208 break;
4209 case HDA_FIXUP_ACT_PROBE:
4198 spec->shutup = alc_shutup_dell_xps13; 4210 spec->shutup = alc_shutup_dell_xps13;
4199 4211
4200 /* Make the internal mic the default input source. */ 4212 /* Make the internal mic the default input source. */
@@ -4204,9 +4216,27 @@ static void alc_fixup_dell_xps13(struct hda_codec *codec,
4204 break; 4216 break;
4205 } 4217 }
4206 } 4218 }
4219 break;
4207 } 4220 }
4208} 4221}
4209 4222
4223static void alc_fixup_headset_mode_alc662(struct hda_codec *codec,
4224 const struct hda_fixup *fix, int action)
4225{
4226 struct alc_spec *spec = codec->spec;
4227
4228 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4229 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
4230 spec->gen.hp_mic = 1; /* Mic-in is same pin as headphone */
4231
4232 /* Disable boost for mic-in permanently. (This code is only called
4233 from quirks that guarantee that the headphone is at NID 0x1b.) */
4234 snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000);
4235 snd_hda_override_wcaps(codec, 0x1b, get_wcaps(codec, 0x1b) & ~AC_WCAP_IN_AMP);
4236 } else
4237 alc_fixup_headset_mode(codec, fix, action);
4238}
4239
4210static void alc_fixup_headset_mode_alc668(struct hda_codec *codec, 4240static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
4211 const struct hda_fixup *fix, int action) 4241 const struct hda_fixup *fix, int action)
4212{ 4242{
@@ -5111,6 +5141,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5111 SND_PCI_QUIRK(0x104d, 0x9099, "Sony VAIO S13", ALC275_FIXUP_SONY_DISABLE_AAMIX), 5141 SND_PCI_QUIRK(0x104d, 0x9099, "Sony VAIO S13", ALC275_FIXUP_SONY_DISABLE_AAMIX),
5112 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK), 5142 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
5113 SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN), 5143 SND_PCI_QUIRK(0x10cf, 0x15dc, "Lifebook T731", ALC269_FIXUP_LIFEBOOK_HP_PIN),
5144 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
5114 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC), 5145 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
5115 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC), 5146 SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
5116 SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_BXBT2807_MIC), 5147 SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_BXBT2807_MIC),
@@ -5140,6 +5171,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5140 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5171 SND_PCI_QUIRK(0x17aa, 0x5026, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
5141 SND_PCI_QUIRK(0x17aa, 0x5034, "Thinkpad T450", ALC292_FIXUP_TPT440_DOCK), 5172 SND_PCI_QUIRK(0x17aa, 0x5034, "Thinkpad T450", ALC292_FIXUP_TPT440_DOCK),
5142 SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK), 5173 SND_PCI_QUIRK(0x17aa, 0x5036, "Thinkpad T450s", ALC292_FIXUP_TPT440_DOCK),
5174 SND_PCI_QUIRK(0x17aa, 0x503c, "Thinkpad L450", ALC292_FIXUP_TPT440_DOCK),
5143 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5175 SND_PCI_QUIRK(0x17aa, 0x5109, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
5144 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), 5176 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
5145 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), 5177 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
@@ -5337,6 +5369,13 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5337 {0x17, 0x40000000}, 5369 {0x17, 0x40000000},
5338 {0x1d, 0x40700001}, 5370 {0x1d, 0x40700001},
5339 {0x21, 0x02211050}), 5371 {0x21, 0x02211050}),
5372 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell Inspiron 5548", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5373 ALC255_STANDARD_PINS,
5374 {0x12, 0x90a60180},
5375 {0x14, 0x90170130},
5376 {0x17, 0x40000000},
5377 {0x1d, 0x40700001},
5378 {0x21, 0x02211040}),
5340 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5379 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5341 ALC256_STANDARD_PINS, 5380 ALC256_STANDARD_PINS,
5342 {0x13, 0x40000000}), 5381 {0x13, 0x40000000}),
@@ -5590,7 +5629,8 @@ static int patch_alc269(struct hda_codec *codec)
5590 5629
5591 spec = codec->spec; 5630 spec = codec->spec;
5592 spec->gen.shared_mic_vref_pin = 0x18; 5631 spec->gen.shared_mic_vref_pin = 0x18;
5593 codec->power_save_node = 1; 5632 if (codec->core.vendor_id != 0x10ec0292)
5633 codec->power_save_node = 1;
5594 5634
5595 snd_hda_pick_fixup(codec, alc269_fixup_models, 5635 snd_hda_pick_fixup(codec, alc269_fixup_models,
5596 alc269_fixup_tbl, alc269_fixups); 5636 alc269_fixup_tbl, alc269_fixups);
@@ -6071,7 +6111,9 @@ enum {
6071 ALC662_FIXUP_NO_JACK_DETECT, 6111 ALC662_FIXUP_NO_JACK_DETECT,
6072 ALC662_FIXUP_ZOTAC_Z68, 6112 ALC662_FIXUP_ZOTAC_Z68,
6073 ALC662_FIXUP_INV_DMIC, 6113 ALC662_FIXUP_INV_DMIC,
6114 ALC662_FIXUP_DELL_MIC_NO_PRESENCE,
6074 ALC668_FIXUP_DELL_MIC_NO_PRESENCE, 6115 ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
6116 ALC662_FIXUP_HEADSET_MODE,
6075 ALC668_FIXUP_HEADSET_MODE, 6117 ALC668_FIXUP_HEADSET_MODE,
6076 ALC662_FIXUP_BASS_MODE4_CHMAP, 6118 ALC662_FIXUP_BASS_MODE4_CHMAP,
6077 ALC662_FIXUP_BASS_16, 6119 ALC662_FIXUP_BASS_16,
@@ -6264,6 +6306,20 @@ static const struct hda_fixup alc662_fixups[] = {
6264 .chained = true, 6306 .chained = true,
6265 .chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE 6307 .chain_id = ALC668_FIXUP_DELL_MIC_NO_PRESENCE
6266 }, 6308 },
6309 [ALC662_FIXUP_DELL_MIC_NO_PRESENCE] = {
6310 .type = HDA_FIXUP_PINS,
6311 .v.pins = (const struct hda_pintbl[]) {
6312 { 0x19, 0x03a1113c }, /* use as headset mic, without its own jack detect */
6313 /* headphone mic by setting pin control of 0x1b (headphone out) to in + vref_50 */
6314 { }
6315 },
6316 .chained = true,
6317 .chain_id = ALC662_FIXUP_HEADSET_MODE
6318 },
6319 [ALC662_FIXUP_HEADSET_MODE] = {
6320 .type = HDA_FIXUP_FUNC,
6321 .v.func = alc_fixup_headset_mode_alc662,
6322 },
6267 [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = { 6323 [ALC668_FIXUP_DELL_MIC_NO_PRESENCE] = {
6268 .type = HDA_FIXUP_PINS, 6324 .type = HDA_FIXUP_PINS,
6269 .v.pins = (const struct hda_pintbl[]) { 6325 .v.pins = (const struct hda_pintbl[]) {
@@ -6415,6 +6471,18 @@ static const struct hda_model_fixup alc662_fixup_models[] = {
6415}; 6471};
6416 6472
6417static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = { 6473static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = {
6474 SND_HDA_PIN_QUIRK(0x10ec0662, 0x1028, "Dell", ALC662_FIXUP_DELL_MIC_NO_PRESENCE,
6475 {0x12, 0x4004c000},
6476 {0x14, 0x01014010},
6477 {0x15, 0x411111f0},
6478 {0x16, 0x411111f0},
6479 {0x18, 0x01a19020},
6480 {0x19, 0x411111f0},
6481 {0x1a, 0x0181302f},
6482 {0x1b, 0x0221401f},
6483 {0x1c, 0x411111f0},
6484 {0x1d, 0x4054c601},
6485 {0x1e, 0x411111f0}),
6418 SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE, 6486 SND_HDA_PIN_QUIRK(0x10ec0668, 0x1028, "Dell", ALC668_FIXUP_AUTO_MUTE,
6419 {0x12, 0x99a30130}, 6487 {0x12, 0x99a30130},
6420 {0x14, 0x90170110}, 6488 {0x14, 0x90170110},
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 43c99ce4a520..6833c74ed6ff 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -4403,7 +4403,6 @@ static const struct hda_codec_ops stac_patch_ops = {
4403#ifdef CONFIG_PM 4403#ifdef CONFIG_PM
4404 .suspend = stac_suspend, 4404 .suspend = stac_suspend,
4405#endif 4405#endif
4406 .stream_pm = snd_hda_gen_stream_pm,
4407 .reboot_notify = stac_shutup, 4406 .reboot_notify = stac_shutup,
4408}; 4407};
4409 4408
@@ -4697,7 +4696,8 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4697 return err; 4696 return err;
4698 4697
4699 spec = codec->spec; 4698 spec = codec->spec;
4700 codec->power_save_node = 1; 4699 /* disabled power_save_node since it causes noises on a Dell machine */
4700 /* codec->power_save_node = 1; */
4701 spec->linear_tone_beep = 0; 4701 spec->linear_tone_beep = 0;
4702 spec->gen.own_eapd_ctl = 1; 4702 spec->gen.own_eapd_ctl = 1;
4703 spec->gen.power_down_unused = 1; 4703 spec->gen.power_down_unused = 1;
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index e7d08806f3e9..c3152072d682 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -6,27 +6,22 @@ config SND_ATMEL_SOC
6 the ATMEL SSC interface. You will also need 6 the ATMEL SSC interface. You will also need
7 to select the audio interfaces to support below. 7 to select the audio interfaces to support below.
8 8
9if SND_ATMEL_SOC
10
9config SND_ATMEL_SOC_PDC 11config SND_ATMEL_SOC_PDC
10 tristate 12 bool
11 depends on SND_ATMEL_SOC
12 13
13config SND_ATMEL_SOC_DMA 14config SND_ATMEL_SOC_DMA
14 tristate 15 bool
15 depends on SND_ATMEL_SOC
16 select SND_SOC_GENERIC_DMAENGINE_PCM 16 select SND_SOC_GENERIC_DMAENGINE_PCM
17 17
18config SND_ATMEL_SOC_SSC 18config SND_ATMEL_SOC_SSC
19 tristate 19 tristate
20 depends on SND_ATMEL_SOC
21 help
22 Say Y or M if you want to add support for codecs the
23 ATMEL SSC interface. You will also needs to select the individual
24 machine drivers to support below.
25 20
26config SND_AT91_SOC_SAM9G20_WM8731 21config SND_AT91_SOC_SAM9G20_WM8731
27 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board" 22 tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board"
28 depends on ARCH_AT91 || COMPILE_TEST 23 depends on ARCH_AT91 || COMPILE_TEST
29 depends on ATMEL_SSC && SND_ATMEL_SOC && SND_SOC_I2C_AND_SPI 24 depends on ATMEL_SSC && SND_SOC_I2C_AND_SPI
30 select SND_ATMEL_SOC_PDC 25 select SND_ATMEL_SOC_PDC
31 select SND_ATMEL_SOC_SSC 26 select SND_ATMEL_SOC_SSC
32 select SND_SOC_WM8731 27 select SND_SOC_WM8731
@@ -37,7 +32,7 @@ config SND_AT91_SOC_SAM9G20_WM8731
37config SND_ATMEL_SOC_WM8904 32config SND_ATMEL_SOC_WM8904
38 tristate "Atmel ASoC driver for boards using WM8904 codec" 33 tristate "Atmel ASoC driver for boards using WM8904 codec"
39 depends on ARCH_AT91 || COMPILE_TEST 34 depends on ARCH_AT91 || COMPILE_TEST
40 depends on ATMEL_SSC && SND_ATMEL_SOC && I2C 35 depends on ATMEL_SSC && I2C
41 select SND_ATMEL_SOC_SSC 36 select SND_ATMEL_SOC_SSC
42 select SND_ATMEL_SOC_DMA 37 select SND_ATMEL_SOC_DMA
43 select SND_SOC_WM8904 38 select SND_SOC_WM8904
@@ -48,10 +43,11 @@ config SND_ATMEL_SOC_WM8904
48config SND_AT91_SOC_SAM9X5_WM8731 43config SND_AT91_SOC_SAM9X5_WM8731
49 tristate "SoC Audio support for WM8731-based at91sam9x5 board" 44 tristate "SoC Audio support for WM8731-based at91sam9x5 board"
50 depends on ARCH_AT91 || COMPILE_TEST 45 depends on ARCH_AT91 || COMPILE_TEST
51 depends on ATMEL_SSC && SND_ATMEL_SOC && SND_SOC_I2C_AND_SPI 46 depends on ATMEL_SSC && SND_SOC_I2C_AND_SPI
52 select SND_ATMEL_SOC_SSC 47 select SND_ATMEL_SOC_SSC
53 select SND_ATMEL_SOC_DMA 48 select SND_ATMEL_SOC_DMA
54 select SND_SOC_WM8731 49 select SND_SOC_WM8731
55 help 50 help
56 Say Y if you want to add support for audio SoC on an 51 Say Y if you want to add support for audio SoC on an
57 at91sam9x5 based board that is using WM8731 codec. 52 at91sam9x5 based board that is using WM8731 codec.
53endif
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile
index b327e5cc8de3..4fa7ac91f972 100644
--- a/sound/soc/atmel/Makefile
+++ b/sound/soc/atmel/Makefile
@@ -1,10 +1,8 @@
1# AT91 Platform Support 1# AT91 Platform Support
2snd-soc-atmel-pcm-pdc-objs := atmel-pcm-pdc.o 2snd-soc-atmel-pcm-$(CONFIG_SND_ATMEL_SOC_PDC) := atmel-pcm-pdc.o
3snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o 3snd-soc-atmel-pcm-$(CONFIG_SND_ATMEL_SOC_DMA) += atmel-pcm-dma.o
4snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o 4snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o $(snd-soc-atmel-pcm-y)
5 5
6obj-$(CONFIG_SND_ATMEL_SOC_PDC) += snd-soc-atmel-pcm-pdc.o
7obj-$(CONFIG_SND_ATMEL_SOC_DMA) += snd-soc-atmel-pcm-dma.o
8obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o 6obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
9 7
10# AT91 Machine Support 8# AT91 Machine Support
diff --git a/sound/soc/atmel/atmel-pcm-dma.c b/sound/soc/atmel/atmel-pcm-dma.c
index b6625c8c411b..dd57a9eac171 100644
--- a/sound/soc/atmel/atmel-pcm-dma.c
+++ b/sound/soc/atmel/atmel-pcm-dma.c
@@ -124,8 +124,7 @@ static const struct snd_dmaengine_pcm_config atmel_dmaengine_pcm_config = {
124 124
125int atmel_pcm_dma_platform_register(struct device *dev) 125int atmel_pcm_dma_platform_register(struct device *dev)
126{ 126{
127 return snd_dmaengine_pcm_register(dev, &atmel_dmaengine_pcm_config, 127 return snd_dmaengine_pcm_register(dev, &atmel_dmaengine_pcm_config, 0);
128 SND_DMAENGINE_PCM_FLAG_NO_RESIDUE);
129} 128}
130EXPORT_SYMBOL(atmel_pcm_dma_platform_register); 129EXPORT_SYMBOL(atmel_pcm_dma_platform_register);
131 130
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 8de836165cf2..d7469cdd90dc 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -95,8 +95,9 @@ static const struct snd_soc_dapm_widget at91sam9g20ek_dapm_widgets[] = {
95 95
96static const struct snd_soc_dapm_route intercon[] = { 96static const struct snd_soc_dapm_route intercon[] = {
97 97
98 /* speaker connected to LHPOUT */ 98 /* speaker connected to LHPOUT/RHPOUT */
99 {"Ext Spk", NULL, "LHPOUT"}, 99 {"Ext Spk", NULL, "LHPOUT"},
100 {"Ext Spk", NULL, "RHPOUT"},
100 101
101 /* mic is connected to Mic Jack, with WM8731 Mic Bias */ 102 /* mic is connected to Mic Jack, with WM8731 Mic Bias */
102 {"MICIN", NULL, "Mic Bias"}, 103 {"MICIN", NULL, "Mic Bias"},
@@ -108,9 +109,7 @@ static const struct snd_soc_dapm_route intercon[] = {
108 */ 109 */
109static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd) 110static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
110{ 111{
111 struct snd_soc_codec *codec = rtd->codec;
112 struct snd_soc_dai *codec_dai = rtd->codec_dai; 112 struct snd_soc_dai *codec_dai = rtd->codec_dai;
113 struct snd_soc_dapm_context *dapm = &codec->dapm;
114 int ret; 113 int ret;
115 114
116 printk(KERN_DEBUG 115 printk(KERN_DEBUG
@@ -124,10 +123,6 @@ static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
124 return ret; 123 return ret;
125 } 124 }
126 125
127 /* not connected */
128 snd_soc_dapm_nc_pin(dapm, "RLINEIN");
129 snd_soc_dapm_nc_pin(dapm, "LLINEIN");
130
131#ifndef ENABLE_MIC_INPUT 126#ifndef ENABLE_MIC_INPUT
132 snd_soc_dapm_nc_pin(&rtd->card->dapm, "Int Mic"); 127 snd_soc_dapm_nc_pin(&rtd->card->dapm, "Int Mic");
133#endif 128#endif
@@ -158,6 +153,7 @@ static struct snd_soc_card snd_soc_at91sam9g20ek = {
158 .num_dapm_widgets = ARRAY_SIZE(at91sam9g20ek_dapm_widgets), 153 .num_dapm_widgets = ARRAY_SIZE(at91sam9g20ek_dapm_widgets),
159 .dapm_routes = intercon, 154 .dapm_routes = intercon,
160 .num_dapm_routes = ARRAY_SIZE(intercon), 155 .num_dapm_routes = ARRAY_SIZE(intercon),
156 .fully_routed = true,
161}; 157};
162 158
163static int at91sam9g20ek_audio_probe(struct platform_device *pdev) 159static int at91sam9g20ek_audio_probe(struct platform_device *pdev)
diff --git a/sound/soc/au1x/db1200.c b/sound/soc/au1x/db1200.c
index c75995f2779c..58c3164802b8 100644
--- a/sound/soc/au1x/db1200.c
+++ b/sound/soc/au1x/db1200.c
@@ -21,7 +21,7 @@
21#include "../codecs/wm8731.h" 21#include "../codecs/wm8731.h"
22#include "psc.h" 22#include "psc.h"
23 23
24static struct platform_device_id db1200_pids[] = { 24static const struct platform_device_id db1200_pids[] = {
25 { 25 {
26 .name = "db1200-ac97", 26 .name = "db1200-ac97",
27 .driver_data = 0, 27 .driver_data = 0,
diff --git a/sound/soc/cirrus/ep93xx-pcm.c b/sound/soc/cirrus/ep93xx-pcm.c
index 5f664471d99e..67a73330db5e 100644
--- a/sound/soc/cirrus/ep93xx-pcm.c
+++ b/sound/soc/cirrus/ep93xx-pcm.c
@@ -60,7 +60,6 @@ int devm_ep93xx_pcm_platform_register(struct device *dev)
60{ 60{
61 return devm_snd_dmaengine_pcm_register(dev, 61 return devm_snd_dmaengine_pcm_register(dev,
62 &ep93xx_dmaengine_pcm_config, 62 &ep93xx_dmaengine_pcm_config,
63 SND_DMAENGINE_PCM_FLAG_NO_RESIDUE |
64 SND_DMAENGINE_PCM_FLAG_NO_DT | 63 SND_DMAENGINE_PCM_FLAG_NO_DT |
65 SND_DMAENGINE_PCM_FLAG_COMPAT); 64 SND_DMAENGINE_PCM_FLAG_COMPAT);
66} 65}
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index a0f265327fdf..38b3dad9d48a 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -1140,7 +1140,7 @@ static int pm860x_set_bias_level(struct snd_soc_codec *codec,
1140 break; 1140 break;
1141 1141
1142 case SND_SOC_BIAS_STANDBY: 1142 case SND_SOC_BIAS_STANDBY:
1143 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1143 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1144 /* Enable Audio PLL & Audio section */ 1144 /* Enable Audio PLL & Audio section */
1145 data = AUDIO_PLL | AUDIO_SECTION_ON; 1145 data = AUDIO_PLL | AUDIO_SECTION_ON;
1146 pm860x_reg_write(pm860x->i2c, REG_MISC2, data); 1146 pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
@@ -1156,7 +1156,6 @@ static int pm860x_set_bias_level(struct snd_soc_codec *codec,
1156 pm860x_set_bits(pm860x->i2c, REG_MISC2, data, 0); 1156 pm860x_set_bits(pm860x->i2c, REG_MISC2, data, 0);
1157 break; 1157 break;
1158 } 1158 }
1159 codec->dapm.bias_level = level;
1160 return 0; 1159 return 0;
1161} 1160}
1162 1161
@@ -1187,16 +1186,16 @@ static struct snd_soc_dai_driver pm860x_dai[] = {
1187 .channels_min = 2, 1186 .channels_min = 2,
1188 .channels_max = 2, 1187 .channels_max = 2,
1189 .rates = PM860X_RATES, 1188 .rates = PM860X_RATES,
1190 .formats = SNDRV_PCM_FORMAT_S16_LE | \ 1189 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1191 SNDRV_PCM_FORMAT_S18_3LE, 1190 SNDRV_PCM_FMTBIT_S18_3LE,
1192 }, 1191 },
1193 .capture = { 1192 .capture = {
1194 .stream_name = "PCM Capture", 1193 .stream_name = "PCM Capture",
1195 .channels_min = 2, 1194 .channels_min = 2,
1196 .channels_max = 2, 1195 .channels_max = 2,
1197 .rates = PM860X_RATES, 1196 .rates = PM860X_RATES,
1198 .formats = SNDRV_PCM_FORMAT_S16_LE | \ 1197 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1199 SNDRV_PCM_FORMAT_S18_3LE, 1198 SNDRV_PCM_FMTBIT_S18_3LE,
1200 }, 1199 },
1201 .ops = &pm860x_pcm_dai_ops, 1200 .ops = &pm860x_pcm_dai_ops,
1202 }, { 1201 }, {
@@ -1208,16 +1207,16 @@ static struct snd_soc_dai_driver pm860x_dai[] = {
1208 .channels_min = 2, 1207 .channels_min = 2,
1209 .channels_max = 2, 1208 .channels_max = 2,
1210 .rates = SNDRV_PCM_RATE_8000_48000, 1209 .rates = SNDRV_PCM_RATE_8000_48000,
1211 .formats = SNDRV_PCM_FORMAT_S16_LE | \ 1210 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1212 SNDRV_PCM_FORMAT_S18_3LE, 1211 SNDRV_PCM_FMTBIT_S18_3LE,
1213 }, 1212 },
1214 .capture = { 1213 .capture = {
1215 .stream_name = "I2S Capture", 1214 .stream_name = "I2S Capture",
1216 .channels_min = 2, 1215 .channels_min = 2,
1217 .channels_max = 2, 1216 .channels_max = 2,
1218 .rates = SNDRV_PCM_RATE_8000_48000, 1217 .rates = SNDRV_PCM_RATE_8000_48000,
1219 .formats = SNDRV_PCM_FORMAT_S16_LE | \ 1218 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1220 SNDRV_PCM_FORMAT_S18_3LE, 1219 SNDRV_PCM_FMTBIT_S18_3LE,
1221 }, 1220 },
1222 .ops = &pm860x_i2s_dai_ops, 1221 .ops = &pm860x_i2s_dai_ops,
1223 }, 1222 },
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 061c46587628..e0b375ec937e 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -16,7 +16,7 @@ config SND_SOC_ALL_CODECS
16 select SND_SOC_88PM860X if MFD_88PM860X 16 select SND_SOC_88PM860X if MFD_88PM860X
17 select SND_SOC_L3 17 select SND_SOC_L3
18 select SND_SOC_AB8500_CODEC if ABX500_CORE 18 select SND_SOC_AB8500_CODEC if ABX500_CORE
19 select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS 19 select SND_SOC_AC97_CODEC
20 select SND_SOC_AD1836 if SPI_MASTER 20 select SND_SOC_AD1836 if SPI_MASTER
21 select SND_SOC_AD193X_SPI if SPI_MASTER 21 select SND_SOC_AD193X_SPI if SPI_MASTER
22 select SND_SOC_AD193X_I2C if I2C 22 select SND_SOC_AD193X_I2C if I2C
@@ -54,7 +54,7 @@ config SND_SOC_ALL_CODECS
54 select SND_SOC_CS4271_SPI if SPI_MASTER 54 select SND_SOC_CS4271_SPI if SPI_MASTER
55 select SND_SOC_CS42XX8_I2C if I2C 55 select SND_SOC_CS42XX8_I2C if I2C
56 select SND_SOC_CX20442 if TTY 56 select SND_SOC_CX20442 if TTY
57 select SND_SOC_DA7210 if I2C 57 select SND_SOC_DA7210 if SND_SOC_I2C_AND_SPI
58 select SND_SOC_DA7213 if I2C 58 select SND_SOC_DA7213 if I2C
59 select SND_SOC_DA732X if I2C 59 select SND_SOC_DA732X if I2C
60 select SND_SOC_DA9055 if I2C 60 select SND_SOC_DA9055 if I2C
@@ -211,8 +211,9 @@ config SND_SOC_AB8500_CODEC
211 tristate 211 tristate
212 212
213config SND_SOC_AC97_CODEC 213config SND_SOC_AC97_CODEC
214 tristate 214 tristate "Build generic ASoC AC97 CODEC driver"
215 select SND_AC97_CODEC 215 select SND_AC97_CODEC
216 select SND_SOC_AC97_BUS
216 217
217config SND_SOC_AD1836 218config SND_SOC_AD1836
218 tristate 219 tristate
diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c
index 88ca9cb0ce79..c7d243db010a 100644
--- a/sound/soc/codecs/ab8500-codec.c
+++ b/sound/soc/codecs/ab8500-codec.c
@@ -1209,6 +1209,7 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1209 struct snd_ctl_elem_value *ucontrol) 1209 struct snd_ctl_elem_value *ucontrol)
1210{ 1210{
1211 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 1211 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
1212 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1212 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev); 1213 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
1213 struct device *dev = codec->dev; 1214 struct device *dev = codec->dev;
1214 bool apply_fir, apply_iir; 1215 bool apply_fir, apply_iir;
@@ -1234,15 +1235,14 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1234 apply_fir = req == ANC_APPLY_FIR || req == ANC_APPLY_FIR_IIR; 1235 apply_fir = req == ANC_APPLY_FIR || req == ANC_APPLY_FIR_IIR;
1235 apply_iir = req == ANC_APPLY_IIR || req == ANC_APPLY_FIR_IIR; 1236 apply_iir = req == ANC_APPLY_IIR || req == ANC_APPLY_FIR_IIR;
1236 1237
1237 status = snd_soc_dapm_force_enable_pin(&codec->dapm, 1238 status = snd_soc_dapm_force_enable_pin(dapm, "ANC Configure Input");
1238 "ANC Configure Input");
1239 if (status < 0) { 1239 if (status < 0) {
1240 dev_err(dev, 1240 dev_err(dev,
1241 "%s: ERROR: Failed to enable power (status = %d)!\n", 1241 "%s: ERROR: Failed to enable power (status = %d)!\n",
1242 __func__, status); 1242 __func__, status);
1243 goto cleanup; 1243 goto cleanup;
1244 } 1244 }
1245 snd_soc_dapm_sync(&codec->dapm); 1245 snd_soc_dapm_sync(dapm);
1246 1246
1247 anc_configure(codec, apply_fir, apply_iir); 1247 anc_configure(codec, apply_fir, apply_iir);
1248 1248
@@ -1259,8 +1259,8 @@ static int anc_status_control_put(struct snd_kcontrol *kcontrol,
1259 drvdata->anc_status = ANC_IIR_CONFIGURED; 1259 drvdata->anc_status = ANC_IIR_CONFIGURED;
1260 } 1260 }
1261 1261
1262 status = snd_soc_dapm_disable_pin(&codec->dapm, "ANC Configure Input"); 1262 status = snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
1263 snd_soc_dapm_sync(&codec->dapm); 1263 snd_soc_dapm_sync(dapm);
1264 1264
1265cleanup: 1265cleanup:
1266 mutex_unlock(&drvdata->ctrl_lock); 1266 mutex_unlock(&drvdata->ctrl_lock);
@@ -1947,6 +1947,7 @@ static int ab8500_audio_init_audioblock(struct snd_soc_codec *codec)
1947static int ab8500_audio_setup_mics(struct snd_soc_codec *codec, 1947static int ab8500_audio_setup_mics(struct snd_soc_codec *codec,
1948 struct amic_settings *amics) 1948 struct amic_settings *amics)
1949{ 1949{
1950 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1950 u8 value8; 1951 u8 value8;
1951 unsigned int value; 1952 unsigned int value;
1952 int status; 1953 int status;
@@ -1973,15 +1974,15 @@ static int ab8500_audio_setup_mics(struct snd_soc_codec *codec,
1973 dev_dbg(codec->dev, "%s: Mic 1a regulator: %s\n", __func__, 1974 dev_dbg(codec->dev, "%s: Mic 1a regulator: %s\n", __func__,
1974 amic_micbias_str(amics->mic1a_micbias)); 1975 amic_micbias_str(amics->mic1a_micbias));
1975 route = &ab8500_dapm_routes_mic1a_vamicx[amics->mic1a_micbias]; 1976 route = &ab8500_dapm_routes_mic1a_vamicx[amics->mic1a_micbias];
1976 status = snd_soc_dapm_add_routes(&codec->dapm, route, 1); 1977 status = snd_soc_dapm_add_routes(dapm, route, 1);
1977 dev_dbg(codec->dev, "%s: Mic 1b regulator: %s\n", __func__, 1978 dev_dbg(codec->dev, "%s: Mic 1b regulator: %s\n", __func__,
1978 amic_micbias_str(amics->mic1b_micbias)); 1979 amic_micbias_str(amics->mic1b_micbias));
1979 route = &ab8500_dapm_routes_mic1b_vamicx[amics->mic1b_micbias]; 1980 route = &ab8500_dapm_routes_mic1b_vamicx[amics->mic1b_micbias];
1980 status |= snd_soc_dapm_add_routes(&codec->dapm, route, 1); 1981 status |= snd_soc_dapm_add_routes(dapm, route, 1);
1981 dev_dbg(codec->dev, "%s: Mic 2 regulator: %s\n", __func__, 1982 dev_dbg(codec->dev, "%s: Mic 2 regulator: %s\n", __func__,
1982 amic_micbias_str(amics->mic2_micbias)); 1983 amic_micbias_str(amics->mic2_micbias));
1983 route = &ab8500_dapm_routes_mic2_vamicx[amics->mic2_micbias]; 1984 route = &ab8500_dapm_routes_mic2_vamicx[amics->mic2_micbias];
1984 status |= snd_soc_dapm_add_routes(&codec->dapm, route, 1); 1985 status |= snd_soc_dapm_add_routes(dapm, route, 1);
1985 if (status < 0) { 1986 if (status < 0) {
1986 dev_err(codec->dev, 1987 dev_err(codec->dev,
1987 "%s: Failed to add AMic-regulator DAPM-routes (%d).\n", 1988 "%s: Failed to add AMic-regulator DAPM-routes (%d).\n",
@@ -2461,6 +2462,7 @@ static void ab8500_codec_of_probe(struct device *dev, struct device_node *np,
2461 2462
2462static int ab8500_codec_probe(struct snd_soc_codec *codec) 2463static int ab8500_codec_probe(struct snd_soc_codec *codec)
2463{ 2464{
2465 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2464 struct device *dev = codec->dev; 2466 struct device *dev = codec->dev;
2465 struct device_node *np = dev->of_node; 2467 struct device_node *np = dev->of_node;
2466 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev); 2468 struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev);
@@ -2541,7 +2543,7 @@ static int ab8500_codec_probe(struct snd_soc_codec *codec)
2541 &ab8500_filter_controls[AB8500_FILTER_SID_FIR].private_value; 2543 &ab8500_filter_controls[AB8500_FILTER_SID_FIR].private_value;
2542 drvdata->sid_fir_values = (long *)fc->value; 2544 drvdata->sid_fir_values = (long *)fc->value;
2543 2545
2544 (void)snd_soc_dapm_disable_pin(&codec->dapm, "ANC Configure Input"); 2546 snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
2545 2547
2546 mutex_init(&drvdata->ctrl_lock); 2548 mutex_init(&drvdata->ctrl_lock);
2547 2549
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index d0ac723eee32..5b3224c63943 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -44,10 +44,6 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
44 return snd_ac97_set_rate(ac97, reg, substream->runtime->rate); 44 return snd_ac97_set_rate(ac97, reg, substream->runtime->rate);
45} 45}
46 46
47#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
48 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
49 SNDRV_PCM_RATE_48000)
50
51static const struct snd_soc_dai_ops ac97_dai_ops = { 47static const struct snd_soc_dai_ops ac97_dai_ops = {
52 .prepare = ac97_prepare, 48 .prepare = ac97_prepare,
53}; 49};
@@ -58,13 +54,13 @@ static struct snd_soc_dai_driver ac97_dai = {
58 .stream_name = "AC97 Playback", 54 .stream_name = "AC97 Playback",
59 .channels_min = 1, 55 .channels_min = 1,
60 .channels_max = 2, 56 .channels_max = 2,
61 .rates = STD_AC97_RATES, 57 .rates = SNDRV_PCM_RATE_KNOT,
62 .formats = SND_SOC_STD_AC97_FMTS,}, 58 .formats = SND_SOC_STD_AC97_FMTS,},
63 .capture = { 59 .capture = {
64 .stream_name = "AC97 Capture", 60 .stream_name = "AC97 Capture",
65 .channels_min = 1, 61 .channels_min = 1,
66 .channels_max = 2, 62 .channels_max = 2,
67 .rates = STD_AC97_RATES, 63 .rates = SNDRV_PCM_RATE_KNOT,
68 .formats = SND_SOC_STD_AC97_FMTS,}, 64 .formats = SND_SOC_STD_AC97_FMTS,},
69 .ops = &ac97_dai_ops, 65 .ops = &ac97_dai_ops,
70}; 66};
diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c
index 685998dd086e..95f0bec26a1b 100644
--- a/sound/soc/codecs/ad1836.c
+++ b/sound/soc/codecs/ad1836.c
@@ -251,7 +251,7 @@ static int ad1836_resume(struct snd_soc_codec *codec)
251static int ad1836_probe(struct snd_soc_codec *codec) 251static int ad1836_probe(struct snd_soc_codec *codec)
252{ 252{
253 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); 253 struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
254 struct snd_soc_dapm_context *dapm = &codec->dapm; 254 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
255 int num_dacs, num_adcs; 255 int num_dacs, num_adcs;
256 int ret = 0; 256 int ret = 0;
257 int i; 257 int i;
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
index 783dcb57043a..a43160254929 100644
--- a/sound/soc/codecs/adau1373.c
+++ b/sound/soc/codecs/adau1373.c
@@ -1444,7 +1444,6 @@ static int adau1373_set_bias_level(struct snd_soc_codec *codec,
1444 ADAU1373_PWDN_CTRL3_PWR_EN, 0); 1444 ADAU1373_PWDN_CTRL3_PWR_EN, 0);
1445 break; 1445 break;
1446 } 1446 }
1447 codec->dapm.bias_level = level;
1448 return 0; 1447 return 0;
1449} 1448}
1450 1449
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
index d4e219b6b98f..ff7f846e3b76 100644
--- a/sound/soc/codecs/adau1701.c
+++ b/sound/soc/codecs/adau1701.c
@@ -16,6 +16,7 @@
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/of_gpio.h> 17#include <linux/of_gpio.h>
18#include <linux/of_device.h> 18#include <linux/of_device.h>
19#include <linux/regulator/consumer.h>
19#include <linux/regmap.h> 20#include <linux/regmap.h>
20#include <sound/core.h> 21#include <sound/core.h>
21#include <sound/pcm.h> 22#include <sound/pcm.h>
@@ -101,6 +102,10 @@
101 102
102#define ADAU1701_FIRMWARE "adau1701.bin" 103#define ADAU1701_FIRMWARE "adau1701.bin"
103 104
105static const char * const supply_names[] = {
106 "dvdd", "avdd"
107};
108
104struct adau1701 { 109struct adau1701 {
105 int gpio_nreset; 110 int gpio_nreset;
106 int gpio_pll_mode[2]; 111 int gpio_pll_mode[2];
@@ -112,6 +117,7 @@ struct adau1701 {
112 u8 pin_config[12]; 117 u8 pin_config[12];
113 118
114 struct sigmadsp *sigmadsp; 119 struct sigmadsp *sigmadsp;
120 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
115}; 121};
116 122
117static const struct snd_kcontrol_new adau1701_controls[] = { 123static const struct snd_kcontrol_new adau1701_controls[] = {
@@ -565,7 +571,6 @@ static int adau1701_set_bias_level(struct snd_soc_codec *codec,
565 break; 571 break;
566 } 572 }
567 573
568 codec->dapm.bias_level = level;
569 return 0; 574 return 0;
570} 575}
571 576
@@ -669,6 +674,13 @@ static int adau1701_probe(struct snd_soc_codec *codec)
669 if (ret) 674 if (ret)
670 return ret; 675 return ret;
671 676
677 ret = regulator_bulk_enable(ARRAY_SIZE(adau1701->supplies),
678 adau1701->supplies);
679 if (ret < 0) {
680 dev_err(codec->dev, "Failed to enable regulators: %d\n", ret);
681 return ret;
682 }
683
672 /* 684 /*
673 * Let the pll_clkdiv variable default to something that won't happen 685 * Let the pll_clkdiv variable default to something that won't happen
674 * at runtime. That way, we can postpone the firmware download from 686 * at runtime. That way, we can postpone the firmware download from
@@ -680,7 +692,7 @@ static int adau1701_probe(struct snd_soc_codec *codec)
680 /* initalize with pre-configured pll mode settings */ 692 /* initalize with pre-configured pll mode settings */
681 ret = adau1701_reset(codec, adau1701->pll_clkdiv, 0); 693 ret = adau1701_reset(codec, adau1701->pll_clkdiv, 0);
682 if (ret < 0) 694 if (ret < 0)
683 return ret; 695 goto exit_regulators_disable;
684 696
685 /* set up pin config */ 697 /* set up pin config */
686 val = 0; 698 val = 0;
@@ -696,10 +708,60 @@ static int adau1701_probe(struct snd_soc_codec *codec)
696 regmap_write(adau1701->regmap, ADAU1701_PINCONF_1, val); 708 regmap_write(adau1701->regmap, ADAU1701_PINCONF_1, val);
697 709
698 return 0; 710 return 0;
711
712exit_regulators_disable:
713
714 regulator_bulk_disable(ARRAY_SIZE(adau1701->supplies), adau1701->supplies);
715 return ret;
699} 716}
700 717
718static int adau1701_remove(struct snd_soc_codec *codec)
719{
720 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
721
722 if (gpio_is_valid(adau1701->gpio_nreset))
723 gpio_set_value_cansleep(adau1701->gpio_nreset, 0);
724
725 regulator_bulk_disable(ARRAY_SIZE(adau1701->supplies), adau1701->supplies);
726
727 return 0;
728}
729
730#ifdef CONFIG_PM
731static int adau1701_suspend(struct snd_soc_codec *codec)
732{
733 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
734
735 regulator_bulk_disable(ARRAY_SIZE(adau1701->supplies),
736 adau1701->supplies);
737
738 return 0;
739}
740
741static int adau1701_resume(struct snd_soc_codec *codec)
742{
743 struct adau1701 *adau1701 = snd_soc_codec_get_drvdata(codec);
744 int ret;
745
746 ret = regulator_bulk_enable(ARRAY_SIZE(adau1701->supplies),
747 adau1701->supplies);
748 if (ret < 0) {
749 dev_err(codec->dev, "Failed to enable regulators: %d\n", ret);
750 return ret;
751 }
752
753 return adau1701_reset(codec, adau1701->pll_clkdiv, 0);
754}
755#else
756#define adau1701_resume NULL
757#define adau1701_suspend NULL
758#endif /* CONFIG_PM */
759
701static struct snd_soc_codec_driver adau1701_codec_drv = { 760static struct snd_soc_codec_driver adau1701_codec_drv = {
702 .probe = adau1701_probe, 761 .probe = adau1701_probe,
762 .remove = adau1701_remove,
763 .resume = adau1701_resume,
764 .suspend = adau1701_suspend,
703 .set_bias_level = adau1701_set_bias_level, 765 .set_bias_level = adau1701_set_bias_level,
704 .idle_bias_off = true, 766 .idle_bias_off = true,
705 767
@@ -730,32 +792,58 @@ static int adau1701_i2c_probe(struct i2c_client *client,
730 struct device *dev = &client->dev; 792 struct device *dev = &client->dev;
731 int gpio_nreset = -EINVAL; 793 int gpio_nreset = -EINVAL;
732 int gpio_pll_mode[2] = { -EINVAL, -EINVAL }; 794 int gpio_pll_mode[2] = { -EINVAL, -EINVAL };
733 int ret; 795 int ret, i;
734 796
735 adau1701 = devm_kzalloc(dev, sizeof(*adau1701), GFP_KERNEL); 797 adau1701 = devm_kzalloc(dev, sizeof(*adau1701), GFP_KERNEL);
736 if (!adau1701) 798 if (!adau1701)
737 return -ENOMEM; 799 return -ENOMEM;
738 800
801 for (i = 0; i < ARRAY_SIZE(supply_names); i++)
802 adau1701->supplies[i].supply = supply_names[i];
803
804 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(adau1701->supplies),
805 adau1701->supplies);
806 if (ret < 0) {
807 dev_err(dev, "Failed to get regulators: %d\n", ret);
808 return ret;
809 }
810
811 ret = regulator_bulk_enable(ARRAY_SIZE(adau1701->supplies),
812 adau1701->supplies);
813 if (ret < 0) {
814 dev_err(dev, "Failed to enable regulators: %d\n", ret);
815 return ret;
816 }
817
739 adau1701->client = client; 818 adau1701->client = client;
740 adau1701->regmap = devm_regmap_init(dev, NULL, client, 819 adau1701->regmap = devm_regmap_init(dev, NULL, client,
741 &adau1701_regmap); 820 &adau1701_regmap);
742 if (IS_ERR(adau1701->regmap)) 821 if (IS_ERR(adau1701->regmap)) {
743 return PTR_ERR(adau1701->regmap); 822 ret = PTR_ERR(adau1701->regmap);
823 goto exit_regulators_disable;
824 }
825
744 826
745 if (dev->of_node) { 827 if (dev->of_node) {
746 gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0); 828 gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0);
747 if (gpio_nreset < 0 && gpio_nreset != -ENOENT) 829 if (gpio_nreset < 0 && gpio_nreset != -ENOENT) {
748 return gpio_nreset; 830 ret = gpio_nreset;
831 goto exit_regulators_disable;
832 }
749 833
750 gpio_pll_mode[0] = of_get_named_gpio(dev->of_node, 834 gpio_pll_mode[0] = of_get_named_gpio(dev->of_node,
751 "adi,pll-mode-gpios", 0); 835 "adi,pll-mode-gpios", 0);
752 if (gpio_pll_mode[0] < 0 && gpio_pll_mode[0] != -ENOENT) 836 if (gpio_pll_mode[0] < 0 && gpio_pll_mode[0] != -ENOENT) {
753 return gpio_pll_mode[0]; 837 ret = gpio_pll_mode[0];
838 goto exit_regulators_disable;
839 }
754 840
755 gpio_pll_mode[1] = of_get_named_gpio(dev->of_node, 841 gpio_pll_mode[1] = of_get_named_gpio(dev->of_node,
756 "adi,pll-mode-gpios", 1); 842 "adi,pll-mode-gpios", 1);
757 if (gpio_pll_mode[1] < 0 && gpio_pll_mode[1] != -ENOENT) 843 if (gpio_pll_mode[1] < 0 && gpio_pll_mode[1] != -ENOENT) {
758 return gpio_pll_mode[1]; 844 ret = gpio_pll_mode[1];
845 goto exit_regulators_disable;
846 }
759 847
760 of_property_read_u32(dev->of_node, "adi,pll-clkdiv", 848 of_property_read_u32(dev->of_node, "adi,pll-clkdiv",
761 &adau1701->pll_clkdiv); 849 &adau1701->pll_clkdiv);
@@ -769,7 +857,7 @@ static int adau1701_i2c_probe(struct i2c_client *client,
769 ret = devm_gpio_request_one(dev, gpio_nreset, GPIOF_OUT_INIT_LOW, 857 ret = devm_gpio_request_one(dev, gpio_nreset, GPIOF_OUT_INIT_LOW,
770 "ADAU1701 Reset"); 858 "ADAU1701 Reset");
771 if (ret < 0) 859 if (ret < 0)
772 return ret; 860 goto exit_regulators_disable;
773 } 861 }
774 862
775 if (gpio_is_valid(gpio_pll_mode[0]) && 863 if (gpio_is_valid(gpio_pll_mode[0]) &&
@@ -778,13 +866,13 @@ static int adau1701_i2c_probe(struct i2c_client *client,
778 GPIOF_OUT_INIT_LOW, 866 GPIOF_OUT_INIT_LOW,
779 "ADAU1701 PLL mode 0"); 867 "ADAU1701 PLL mode 0");
780 if (ret < 0) 868 if (ret < 0)
781 return ret; 869 goto exit_regulators_disable;
782 870
783 ret = devm_gpio_request_one(dev, gpio_pll_mode[1], 871 ret = devm_gpio_request_one(dev, gpio_pll_mode[1],
784 GPIOF_OUT_INIT_LOW, 872 GPIOF_OUT_INIT_LOW,
785 "ADAU1701 PLL mode 1"); 873 "ADAU1701 PLL mode 1");
786 if (ret < 0) 874 if (ret < 0)
787 return ret; 875 goto exit_regulators_disable;
788 } 876 }
789 877
790 adau1701->gpio_nreset = gpio_nreset; 878 adau1701->gpio_nreset = gpio_nreset;
@@ -795,11 +883,17 @@ static int adau1701_i2c_probe(struct i2c_client *client,
795 883
796 adau1701->sigmadsp = devm_sigmadsp_init_i2c(client, 884 adau1701->sigmadsp = devm_sigmadsp_init_i2c(client,
797 &adau1701_sigmadsp_ops, ADAU1701_FIRMWARE); 885 &adau1701_sigmadsp_ops, ADAU1701_FIRMWARE);
798 if (IS_ERR(adau1701->sigmadsp)) 886 if (IS_ERR(adau1701->sigmadsp)) {
799 return PTR_ERR(adau1701->sigmadsp); 887 ret = PTR_ERR(adau1701->sigmadsp);
888 goto exit_regulators_disable;
889 }
800 890
801 ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv, 891 ret = snd_soc_register_codec(&client->dev, &adau1701_codec_drv,
802 &adau1701_dai, 1); 892 &adau1701_dai, 1);
893
894exit_regulators_disable:
895
896 regulator_bulk_disable(ARRAY_SIZE(adau1701->supplies), adau1701->supplies);
803 return ret; 897 return ret;
804} 898}
805 899
diff --git a/sound/soc/codecs/adau1761.c b/sound/soc/codecs/adau1761.c
index a1baeee160f4..2f12477e539e 100644
--- a/sound/soc/codecs/adau1761.c
+++ b/sound/soc/codecs/adau1761.c
@@ -466,7 +466,6 @@ static int adau1761_set_bias_level(struct snd_soc_codec *codec,
466 break; 466 break;
467 467
468 } 468 }
469 codec->dapm.bias_level = level;
470 return 0; 469 return 0;
471} 470}
472 471
@@ -483,6 +482,7 @@ static enum adau1761_output_mode adau1761_get_lineout_mode(
483 482
484static int adau1761_setup_digmic_jackdetect(struct snd_soc_codec *codec) 483static int adau1761_setup_digmic_jackdetect(struct snd_soc_codec *codec)
485{ 484{
485 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
486 struct adau1761_platform_data *pdata = codec->dev->platform_data; 486 struct adau1761_platform_data *pdata = codec->dev->platform_data;
487 struct adau *adau = snd_soc_codec_get_drvdata(codec); 487 struct adau *adau = snd_soc_codec_get_drvdata(codec);
488 enum adau1761_digmic_jackdet_pin_mode mode; 488 enum adau1761_digmic_jackdet_pin_mode mode;
@@ -515,21 +515,18 @@ static int adau1761_setup_digmic_jackdetect(struct snd_soc_codec *codec)
515 if (ret) 515 if (ret)
516 return ret; 516 return ret;
517 case ADAU1761_DIGMIC_JACKDET_PIN_MODE_NONE: /* fallthrough */ 517 case ADAU1761_DIGMIC_JACKDET_PIN_MODE_NONE: /* fallthrough */
518 ret = snd_soc_dapm_add_routes(&codec->dapm, 518 ret = snd_soc_dapm_add_routes(dapm, adau1761_no_dmic_routes,
519 adau1761_no_dmic_routes,
520 ARRAY_SIZE(adau1761_no_dmic_routes)); 519 ARRAY_SIZE(adau1761_no_dmic_routes));
521 if (ret) 520 if (ret)
522 return ret; 521 return ret;
523 break; 522 break;
524 case ADAU1761_DIGMIC_JACKDET_PIN_MODE_DIGMIC: 523 case ADAU1761_DIGMIC_JACKDET_PIN_MODE_DIGMIC:
525 ret = snd_soc_dapm_new_controls(&codec->dapm, 524 ret = snd_soc_dapm_new_controls(dapm, adau1761_dmic_widgets,
526 adau1761_dmic_widgets,
527 ARRAY_SIZE(adau1761_dmic_widgets)); 525 ARRAY_SIZE(adau1761_dmic_widgets));
528 if (ret) 526 if (ret)
529 return ret; 527 return ret;
530 528
531 ret = snd_soc_dapm_add_routes(&codec->dapm, 529 ret = snd_soc_dapm_add_routes(dapm, adau1761_dmic_routes,
532 adau1761_dmic_routes,
533 ARRAY_SIZE(adau1761_dmic_routes)); 530 ARRAY_SIZE(adau1761_dmic_routes));
534 if (ret) 531 if (ret)
535 return ret; 532 return ret;
@@ -547,6 +544,7 @@ static int adau1761_setup_digmic_jackdetect(struct snd_soc_codec *codec)
547 544
548static int adau1761_setup_headphone_mode(struct snd_soc_codec *codec) 545static int adau1761_setup_headphone_mode(struct snd_soc_codec *codec)
549{ 546{
547 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
550 struct adau *adau = snd_soc_codec_get_drvdata(codec); 548 struct adau *adau = snd_soc_codec_get_drvdata(codec);
551 struct adau1761_platform_data *pdata = codec->dev->platform_data; 549 struct adau1761_platform_data *pdata = codec->dev->platform_data;
552 enum adau1761_output_mode mode; 550 enum adau1761_output_mode mode;
@@ -577,12 +575,12 @@ static int adau1761_setup_headphone_mode(struct snd_soc_codec *codec)
577 } 575 }
578 576
579 if (mode == ADAU1761_OUTPUT_MODE_HEADPHONE_CAPLESS) { 577 if (mode == ADAU1761_OUTPUT_MODE_HEADPHONE_CAPLESS) {
580 ret = snd_soc_dapm_new_controls(&codec->dapm, 578 ret = snd_soc_dapm_new_controls(dapm,
581 adau1761_capless_dapm_widgets, 579 adau1761_capless_dapm_widgets,
582 ARRAY_SIZE(adau1761_capless_dapm_widgets)); 580 ARRAY_SIZE(adau1761_capless_dapm_widgets));
583 if (ret) 581 if (ret)
584 return ret; 582 return ret;
585 ret = snd_soc_dapm_add_routes(&codec->dapm, 583 ret = snd_soc_dapm_add_routes(dapm,
586 adau1761_capless_dapm_routes, 584 adau1761_capless_dapm_routes,
587 ARRAY_SIZE(adau1761_capless_dapm_routes)); 585 ARRAY_SIZE(adau1761_capless_dapm_routes));
588 } else { 586 } else {
@@ -590,12 +588,12 @@ static int adau1761_setup_headphone_mode(struct snd_soc_codec *codec)
590 ARRAY_SIZE(adau1761_mono_controls)); 588 ARRAY_SIZE(adau1761_mono_controls));
591 if (ret) 589 if (ret)
592 return ret; 590 return ret;
593 ret = snd_soc_dapm_new_controls(&codec->dapm, 591 ret = snd_soc_dapm_new_controls(dapm,
594 adau1761_mono_dapm_widgets, 592 adau1761_mono_dapm_widgets,
595 ARRAY_SIZE(adau1761_mono_dapm_widgets)); 593 ARRAY_SIZE(adau1761_mono_dapm_widgets));
596 if (ret) 594 if (ret)
597 return ret; 595 return ret;
598 ret = snd_soc_dapm_add_routes(&codec->dapm, 596 ret = snd_soc_dapm_add_routes(dapm,
599 adau1761_mono_dapm_routes, 597 adau1761_mono_dapm_routes,
600 ARRAY_SIZE(adau1761_mono_dapm_routes)); 598 ARRAY_SIZE(adau1761_mono_dapm_routes));
601 } 599 }
@@ -640,6 +638,7 @@ static bool adau1761_readable_register(struct device *dev, unsigned int reg)
640 638
641static int adau1761_codec_probe(struct snd_soc_codec *codec) 639static int adau1761_codec_probe(struct snd_soc_codec *codec)
642{ 640{
641 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
643 struct adau1761_platform_data *pdata = codec->dev->platform_data; 642 struct adau1761_platform_data *pdata = codec->dev->platform_data;
644 struct adau *adau = snd_soc_codec_get_drvdata(codec); 643 struct adau *adau = snd_soc_codec_get_drvdata(codec);
645 int ret; 644 int ret;
@@ -692,14 +691,12 @@ static int adau1761_codec_probe(struct snd_soc_codec *codec)
692 return ret; 691 return ret;
693 692
694 if (adau->type == ADAU1761) { 693 if (adau->type == ADAU1761) {
695 ret = snd_soc_dapm_new_controls(&codec->dapm, 694 ret = snd_soc_dapm_new_controls(dapm, adau1761_dapm_widgets,
696 adau1761_dapm_widgets,
697 ARRAY_SIZE(adau1761_dapm_widgets)); 695 ARRAY_SIZE(adau1761_dapm_widgets));
698 if (ret) 696 if (ret)
699 return ret; 697 return ret;
700 698
701 ret = snd_soc_dapm_add_routes(&codec->dapm, 699 ret = snd_soc_dapm_add_routes(dapm, adau1761_dapm_routes,
702 adau1761_dapm_routes,
703 ARRAY_SIZE(adau1761_dapm_routes)); 700 ARRAY_SIZE(adau1761_dapm_routes));
704 if (ret) 701 if (ret)
705 return ret; 702 return ret;
diff --git a/sound/soc/codecs/adau1781.c b/sound/soc/codecs/adau1781.c
index 35581f43fa6d..fde9068550a6 100644
--- a/sound/soc/codecs/adau1781.c
+++ b/sound/soc/codecs/adau1781.c
@@ -339,7 +339,6 @@ static int adau1781_set_bias_level(struct snd_soc_codec *codec,
339 break; 339 break;
340 } 340 }
341 341
342 codec->dapm.bias_level = level;
343 return 0; 342 return 0;
344} 343}
345 344
@@ -383,6 +382,7 @@ static int adau1781_set_input_mode(struct adau *adau, unsigned int reg,
383 382
384static int adau1781_codec_probe(struct snd_soc_codec *codec) 383static int adau1781_codec_probe(struct snd_soc_codec *codec)
385{ 384{
385 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
386 struct adau1781_platform_data *pdata = dev_get_platdata(codec->dev); 386 struct adau1781_platform_data *pdata = dev_get_platdata(codec->dev);
387 struct adau *adau = snd_soc_codec_get_drvdata(codec); 387 struct adau *adau = snd_soc_codec_get_drvdata(codec);
388 int ret; 388 int ret;
@@ -403,19 +403,17 @@ static int adau1781_codec_probe(struct snd_soc_codec *codec)
403 } 403 }
404 404
405 if (pdata && pdata->use_dmic) { 405 if (pdata && pdata->use_dmic) {
406 ret = snd_soc_dapm_new_controls(&codec->dapm, 406 ret = snd_soc_dapm_new_controls(dapm,
407 adau1781_dmic_dapm_widgets, 407 adau1781_dmic_dapm_widgets,
408 ARRAY_SIZE(adau1781_dmic_dapm_widgets)); 408 ARRAY_SIZE(adau1781_dmic_dapm_widgets));
409 if (ret) 409 if (ret)
410 return ret; 410 return ret;
411 ret = snd_soc_dapm_add_routes(&codec->dapm, 411 ret = snd_soc_dapm_add_routes(dapm, adau1781_dmic_dapm_routes,
412 adau1781_dmic_dapm_routes,
413 ARRAY_SIZE(adau1781_dmic_dapm_routes)); 412 ARRAY_SIZE(adau1781_dmic_dapm_routes));
414 if (ret) 413 if (ret)
415 return ret; 414 return ret;
416 } else { 415 } else {
417 ret = snd_soc_dapm_add_routes(&codec->dapm, 416 ret = snd_soc_dapm_add_routes(dapm, adau1781_adc_dapm_routes,
418 adau1781_adc_dapm_routes,
419 ARRAY_SIZE(adau1781_adc_dapm_routes)); 417 ARRAY_SIZE(adau1781_adc_dapm_routes));
420 if (ret) 418 if (ret)
421 return ret; 419 return ret;
diff --git a/sound/soc/codecs/adau17x1.c b/sound/soc/codecs/adau17x1.c
index fa2e690e51c8..fcf05b254ecd 100644
--- a/sound/soc/codecs/adau17x1.c
+++ b/sound/soc/codecs/adau17x1.c
@@ -155,6 +155,7 @@ static int adau17x1_dsp_mux_enum_put(struct snd_kcontrol *kcontrol,
155 struct snd_ctl_elem_value *ucontrol) 155 struct snd_ctl_elem_value *ucontrol)
156{ 156{
157 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); 157 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
158 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
158 struct adau *adau = snd_soc_codec_get_drvdata(codec); 159 struct adau *adau = snd_soc_codec_get_drvdata(codec);
159 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 160 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
160 struct snd_soc_dapm_update update; 161 struct snd_soc_dapm_update update;
@@ -188,7 +189,7 @@ static int adau17x1_dsp_mux_enum_put(struct snd_kcontrol *kcontrol,
188 update.reg = reg; 189 update.reg = reg;
189 update.val = val; 190 update.val = val;
190 191
191 snd_soc_dapm_mux_update_power(&codec->dapm, kcontrol, 192 snd_soc_dapm_mux_update_power(dapm, kcontrol,
192 ucontrol->value.enumerated.item[0], e, &update); 193 ucontrol->value.enumerated.item[0], e, &update);
193 } 194 }
194 195
@@ -444,8 +445,8 @@ static int adau17x1_set_dai_pll(struct snd_soc_dai *dai, int pll_id,
444static int adau17x1_set_dai_sysclk(struct snd_soc_dai *dai, 445static int adau17x1_set_dai_sysclk(struct snd_soc_dai *dai,
445 int clk_id, unsigned int freq, int dir) 446 int clk_id, unsigned int freq, int dir)
446{ 447{
448 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(dai->codec);
447 struct adau *adau = snd_soc_codec_get_drvdata(dai->codec); 449 struct adau *adau = snd_soc_codec_get_drvdata(dai->codec);
448 struct snd_soc_dapm_context *dapm = &dai->codec->dapm;
449 450
450 switch (clk_id) { 451 switch (clk_id) {
451 case ADAU17X1_CLK_SRC_MCLK: 452 case ADAU17X1_CLK_SRC_MCLK:
@@ -804,6 +805,7 @@ EXPORT_SYMBOL_GPL(adau17x1_setup_firmware);
804 805
805int adau17x1_add_widgets(struct snd_soc_codec *codec) 806int adau17x1_add_widgets(struct snd_soc_codec *codec)
806{ 807{
808 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
807 struct adau *adau = snd_soc_codec_get_drvdata(codec); 809 struct adau *adau = snd_soc_codec_get_drvdata(codec);
808 int ret; 810 int ret;
809 811
@@ -811,14 +813,13 @@ int adau17x1_add_widgets(struct snd_soc_codec *codec)
811 ARRAY_SIZE(adau17x1_controls)); 813 ARRAY_SIZE(adau17x1_controls));
812 if (ret) 814 if (ret)
813 return ret; 815 return ret;
814 ret = snd_soc_dapm_new_controls(&codec->dapm, adau17x1_dapm_widgets, 816 ret = snd_soc_dapm_new_controls(dapm, adau17x1_dapm_widgets,
815 ARRAY_SIZE(adau17x1_dapm_widgets)); 817 ARRAY_SIZE(adau17x1_dapm_widgets));
816 if (ret) 818 if (ret)
817 return ret; 819 return ret;
818 820
819 if (adau17x1_has_dsp(adau)) { 821 if (adau17x1_has_dsp(adau)) {
820 ret = snd_soc_dapm_new_controls(&codec->dapm, 822 ret = snd_soc_dapm_new_controls(dapm, adau17x1_dsp_dapm_widgets,
821 adau17x1_dsp_dapm_widgets,
822 ARRAY_SIZE(adau17x1_dsp_dapm_widgets)); 823 ARRAY_SIZE(adau17x1_dsp_dapm_widgets));
823 if (ret) 824 if (ret)
824 return ret; 825 return ret;
@@ -840,21 +841,20 @@ EXPORT_SYMBOL_GPL(adau17x1_add_widgets);
840 841
841int adau17x1_add_routes(struct snd_soc_codec *codec) 842int adau17x1_add_routes(struct snd_soc_codec *codec)
842{ 843{
844 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
843 struct adau *adau = snd_soc_codec_get_drvdata(codec); 845 struct adau *adau = snd_soc_codec_get_drvdata(codec);
844 int ret; 846 int ret;
845 847
846 ret = snd_soc_dapm_add_routes(&codec->dapm, adau17x1_dapm_routes, 848 ret = snd_soc_dapm_add_routes(dapm, adau17x1_dapm_routes,
847 ARRAY_SIZE(adau17x1_dapm_routes)); 849 ARRAY_SIZE(adau17x1_dapm_routes));
848 if (ret) 850 if (ret)
849 return ret; 851 return ret;
850 852
851 if (adau17x1_has_dsp(adau)) { 853 if (adau17x1_has_dsp(adau)) {
852 ret = snd_soc_dapm_add_routes(&codec->dapm, 854 ret = snd_soc_dapm_add_routes(dapm, adau17x1_dsp_dapm_routes,
853 adau17x1_dsp_dapm_routes,
854 ARRAY_SIZE(adau17x1_dsp_dapm_routes)); 855 ARRAY_SIZE(adau17x1_dsp_dapm_routes));
855 } else { 856 } else {
856 ret = snd_soc_dapm_add_routes(&codec->dapm, 857 ret = snd_soc_dapm_add_routes(dapm, adau17x1_no_dsp_dapm_routes,
857 adau17x1_no_dsp_dapm_routes,
858 ARRAY_SIZE(adau17x1_no_dsp_dapm_routes)); 858 ARRAY_SIZE(adau17x1_no_dsp_dapm_routes));
859 } 859 }
860 return ret; 860 return ret;
diff --git a/sound/soc/codecs/adau1977.c b/sound/soc/codecs/adau1977.c
index 7ad8e156e2df..9bdd15f408c1 100644
--- a/sound/soc/codecs/adau1977.c
+++ b/sound/soc/codecs/adau1977.c
@@ -202,7 +202,7 @@ static const struct snd_soc_dapm_route adau1977_dapm_routes[] = {
202 ADAU1977_REG_DC_HPF_CAL, (x) - 1, 1, 0) 202 ADAU1977_REG_DC_HPF_CAL, (x) - 1, 1, 0)
203 203
204#define ADAU1977_DC_SUB_SWITCH(x) \ 204#define ADAU1977_DC_SUB_SWITCH(x) \
205 SOC_SINGLE("ADC" #x " DC Substraction Capture Switch", \ 205 SOC_SINGLE("ADC" #x " DC Subtraction Capture Switch", \
206 ADAU1977_REG_DC_HPF_CAL, (x) + 3, 1, 0) 206 ADAU1977_REG_DC_HPF_CAL, (x) + 3, 1, 0)
207 207
208static const struct snd_kcontrol_new adau1977_snd_controls[] = { 208static const struct snd_kcontrol_new adau1977_snd_controls[] = {
@@ -485,7 +485,7 @@ static int adau1977_set_bias_level(struct snd_soc_codec *codec,
485 case SND_SOC_BIAS_PREPARE: 485 case SND_SOC_BIAS_PREPARE:
486 break; 486 break;
487 case SND_SOC_BIAS_STANDBY: 487 case SND_SOC_BIAS_STANDBY:
488 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 488 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
489 ret = adau1977_power_enable(adau1977); 489 ret = adau1977_power_enable(adau1977);
490 break; 490 break;
491 case SND_SOC_BIAS_OFF: 491 case SND_SOC_BIAS_OFF:
@@ -493,12 +493,7 @@ static int adau1977_set_bias_level(struct snd_soc_codec *codec,
493 break; 493 break;
494 } 494 }
495 495
496 if (ret) 496 return ret;
497 return ret;
498
499 codec->dapm.bias_level = level;
500
501 return 0;
502} 497}
503 498
504static int adau1977_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, 499static int adau1977_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
@@ -853,12 +848,13 @@ static int adau1977_set_sysclk(struct snd_soc_codec *codec,
853 848
854static int adau1977_codec_probe(struct snd_soc_codec *codec) 849static int adau1977_codec_probe(struct snd_soc_codec *codec)
855{ 850{
851 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
856 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(codec); 852 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(codec);
857 int ret; 853 int ret;
858 854
859 switch (adau1977->type) { 855 switch (adau1977->type) {
860 case ADAU1977: 856 case ADAU1977:
861 ret = snd_soc_dapm_new_controls(&codec->dapm, 857 ret = snd_soc_dapm_new_controls(dapm,
862 adau1977_micbias_dapm_widgets, 858 adau1977_micbias_dapm_widgets,
863 ARRAY_SIZE(adau1977_micbias_dapm_widgets)); 859 ARRAY_SIZE(adau1977_micbias_dapm_widgets));
864 if (ret < 0) 860 if (ret < 0)
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c
index 4373ada95648..36d842570745 100644
--- a/sound/soc/codecs/adav80x.c
+++ b/sound/soc/codecs/adav80x.c
@@ -539,7 +539,7 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
539 unsigned int freq, int dir) 539 unsigned int freq, int dir)
540{ 540{
541 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 541 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
542 struct snd_soc_dapm_context *dapm = &codec->dapm; 542 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
543 543
544 if (dir == SND_SOC_CLOCK_IN) { 544 if (dir == SND_SOC_CLOCK_IN) {
545 switch (clk_id) { 545 switch (clk_id) {
@@ -622,6 +622,7 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
622static int adav80x_set_pll(struct snd_soc_codec *codec, int pll_id, 622static int adav80x_set_pll(struct snd_soc_codec *codec, int pll_id,
623 int source, unsigned int freq_in, unsigned int freq_out) 623 int source, unsigned int freq_in, unsigned int freq_out)
624{ 624{
625 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
625 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 626 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
626 unsigned int pll_ctrl1 = 0; 627 unsigned int pll_ctrl1 = 0;
627 unsigned int pll_ctrl2 = 0; 628 unsigned int pll_ctrl2 = 0;
@@ -687,7 +688,7 @@ static int adav80x_set_pll(struct snd_soc_codec *codec, int pll_id,
687 688
688 adav80x->pll_src = source; 689 adav80x->pll_src = source;
689 690
690 snd_soc_dapm_sync(&codec->dapm); 691 snd_soc_dapm_sync(dapm);
691 } 692 }
692 693
693 return 0; 694 return 0;
@@ -714,7 +715,6 @@ static int adav80x_set_bias_level(struct snd_soc_codec *codec,
714 break; 715 break;
715 } 716 }
716 717
717 codec->dapm.bias_level = level;
718 return 0; 718 return 0;
719} 719}
720 720
@@ -801,11 +801,12 @@ static struct snd_soc_dai_driver adav80x_dais[] = {
801 801
802static int adav80x_probe(struct snd_soc_codec *codec) 802static int adav80x_probe(struct snd_soc_codec *codec)
803{ 803{
804 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
804 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 805 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
805 806
806 /* Force PLLs on for SYSCLK output */ 807 /* Force PLLs on for SYSCLK output */
807 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL1"); 808 snd_soc_dapm_force_enable_pin(dapm, "PLL1");
808 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL2"); 809 snd_soc_dapm_force_enable_pin(dapm, "PLL2");
809 810
810 /* Power down S/PDIF receiver, since it is currently not supported */ 811 /* Power down S/PDIF receiver, since it is currently not supported */
811 regmap_write(adav80x->regmap, ADAV80X_PLL_OUTE, 0x20); 812 regmap_write(adav80x->regmap, ADAV80X_PLL_OUTE, 0x20);
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 9130d916f2f4..8670861e5bec 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -341,7 +341,6 @@ static int ak4535_set_bias_level(struct snd_soc_codec *codec,
341 snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0); 341 snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0);
342 break; 342 break;
343 } 343 }
344 codec->dapm.bias_level = level;
345 return 0; 344 return 0;
346} 345}
347 346
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 81b54a270bd8..2d0ff4595ea0 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -412,7 +412,7 @@ static int ak4641_set_bias_level(struct snd_soc_codec *codec,
412 snd_soc_update_bits(codec, AK4641_DAC, 0x20, 0x20); 412 snd_soc_update_bits(codec, AK4641_DAC, 0x20, 0x20);
413 break; 413 break;
414 case SND_SOC_BIAS_STANDBY: 414 case SND_SOC_BIAS_STANDBY:
415 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 415 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
416 if (pdata && gpio_is_valid(pdata->gpio_power)) 416 if (pdata && gpio_is_valid(pdata->gpio_power))
417 gpio_set_value(pdata->gpio_power, 1); 417 gpio_set_value(pdata->gpio_power, 1);
418 mdelay(1); 418 mdelay(1);
@@ -439,7 +439,6 @@ static int ak4641_set_bias_level(struct snd_soc_codec *codec,
439 regcache_mark_dirty(ak4641->regmap); 439 regcache_mark_dirty(ak4641->regmap);
440 break; 440 break;
441 } 441 }
442 codec->dapm.bias_level = level;
443 return 0; 442 return 0;
444} 443}
445 444
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 13585e88f597..7c0f6552c229 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -482,7 +482,6 @@ static int ak4642_set_bias_level(struct snd_soc_codec *codec,
482 snd_soc_update_bits(codec, PW_MGMT1, PMVCM, PMVCM); 482 snd_soc_update_bits(codec, PW_MGMT1, PMVCM, PMVCM);
483 break; 483 break;
484 } 484 }
485 codec->dapm.bias_level = level;
486 485
487 return 0; 486 return 0;
488} 487}
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
index 2a58b1dccd2f..0e59063aeb6f 100644
--- a/sound/soc/codecs/ak4671.c
+++ b/sound/soc/codecs/ak4671.c
@@ -577,7 +577,6 @@ static int ak4671_set_bias_level(struct snd_soc_codec *codec,
577 snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00); 577 snd_soc_write(codec, AK4671_AD_DA_POWER_MANAGEMENT, 0x00);
578 break; 578 break;
579 } 579 }
580 codec->dapm.bias_level = level;
581 return 0; 580 return 0;
582} 581}
583 582
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
index 0e357996864b..0fc24e0d518c 100644
--- a/sound/soc/codecs/alc5623.c
+++ b/sound/soc/codecs/alc5623.c
@@ -826,7 +826,6 @@ static int alc5623_set_bias_level(struct snd_soc_codec *codec,
826 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD1, 0); 826 snd_soc_write(codec, ALC5623_PWR_MANAG_ADD1, 0);
827 break; 827 break;
828 } 828 }
829 codec->dapm.bias_level = level;
830 return 0; 829 return 0;
831} 830}
832 831
@@ -894,7 +893,7 @@ static int alc5623_resume(struct snd_soc_codec *codec)
894static int alc5623_probe(struct snd_soc_codec *codec) 893static int alc5623_probe(struct snd_soc_codec *codec)
895{ 894{
896 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec); 895 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
897 struct snd_soc_dapm_context *dapm = &codec->dapm; 896 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
898 897
899 alc5623_reset(codec); 898 alc5623_reset(codec);
900 899
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index db3283abbe18..607a63b9705f 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -1000,7 +1000,6 @@ static int alc5632_set_bias_level(struct snd_soc_codec *codec,
1000 ALC5632_PWR_MANAG_ADD1_MASK, 0); 1000 ALC5632_PWR_MANAG_ADD1_MASK, 0);
1001 break; 1001 break;
1002 } 1002 }
1003 codec->dapm.bias_level = level;
1004 return 0; 1003 return 0;
1005} 1004}
1006 1005
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index eff4b4d512b7..88f6df21ad95 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -208,11 +208,12 @@ static const struct snd_soc_dapm_widget arizona_spkr =
208 208
209int arizona_init_spk(struct snd_soc_codec *codec) 209int arizona_init_spk(struct snd_soc_codec *codec)
210{ 210{
211 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
211 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 212 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
212 struct arizona *arizona = priv->arizona; 213 struct arizona *arizona = priv->arizona;
213 int ret; 214 int ret;
214 215
215 ret = snd_soc_dapm_new_controls(&codec->dapm, &arizona_spkl, 1); 216 ret = snd_soc_dapm_new_controls(dapm, &arizona_spkl, 1);
216 if (ret != 0) 217 if (ret != 0)
217 return ret; 218 return ret;
218 219
@@ -220,8 +221,7 @@ int arizona_init_spk(struct snd_soc_codec *codec)
220 case WM8997: 221 case WM8997:
221 break; 222 break;
222 default: 223 default:
223 ret = snd_soc_dapm_new_controls(&codec->dapm, 224 ret = snd_soc_dapm_new_controls(dapm, &arizona_spkr, 1);
224 &arizona_spkr, 1);
225 if (ret != 0) 225 if (ret != 0)
226 return ret; 226 return ret;
227 break; 227 break;
@@ -258,13 +258,14 @@ static const struct snd_soc_dapm_route arizona_mono_routes[] = {
258 258
259int arizona_init_mono(struct snd_soc_codec *codec) 259int arizona_init_mono(struct snd_soc_codec *codec)
260{ 260{
261 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
261 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 262 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
262 struct arizona *arizona = priv->arizona; 263 struct arizona *arizona = priv->arizona;
263 int i; 264 int i;
264 265
265 for (i = 0; i < ARIZONA_MAX_OUTPUT; ++i) { 266 for (i = 0; i < ARIZONA_MAX_OUTPUT; ++i) {
266 if (arizona->pdata.out_mono[i]) 267 if (arizona->pdata.out_mono[i])
267 snd_soc_dapm_add_routes(&codec->dapm, 268 snd_soc_dapm_add_routes(dapm,
268 &arizona_mono_routes[i], 1); 269 &arizona_mono_routes[i], 1);
269 } 270 }
270 271
@@ -274,6 +275,7 @@ EXPORT_SYMBOL_GPL(arizona_init_mono);
274 275
275int arizona_init_gpio(struct snd_soc_codec *codec) 276int arizona_init_gpio(struct snd_soc_codec *codec)
276{ 277{
278 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
277 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 279 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
278 struct arizona *arizona = priv->arizona; 280 struct arizona *arizona = priv->arizona;
279 int i; 281 int i;
@@ -281,23 +283,21 @@ int arizona_init_gpio(struct snd_soc_codec *codec)
281 switch (arizona->type) { 283 switch (arizona->type) {
282 case WM5110: 284 case WM5110:
283 case WM8280: 285 case WM8280:
284 snd_soc_dapm_disable_pin(&codec->dapm, "DRC2 Signal Activity"); 286 snd_soc_dapm_disable_pin(dapm, "DRC2 Signal Activity");
285 break; 287 break;
286 default: 288 default:
287 break; 289 break;
288 } 290 }
289 291
290 snd_soc_dapm_disable_pin(&codec->dapm, "DRC1 Signal Activity"); 292 snd_soc_dapm_disable_pin(dapm, "DRC1 Signal Activity");
291 293
292 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) { 294 for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
293 switch (arizona->pdata.gpio_defaults[i] & ARIZONA_GPN_FN_MASK) { 295 switch (arizona->pdata.gpio_defaults[i] & ARIZONA_GPN_FN_MASK) {
294 case ARIZONA_GP_FN_DRC1_SIGNAL_DETECT: 296 case ARIZONA_GP_FN_DRC1_SIGNAL_DETECT:
295 snd_soc_dapm_enable_pin(&codec->dapm, 297 snd_soc_dapm_enable_pin(dapm, "DRC1 Signal Activity");
296 "DRC1 Signal Activity");
297 break; 298 break;
298 case ARIZONA_GP_FN_DRC2_SIGNAL_DETECT: 299 case ARIZONA_GP_FN_DRC2_SIGNAL_DETECT:
299 snd_soc_dapm_enable_pin(&codec->dapm, 300 snd_soc_dapm_enable_pin(dapm, "DRC2 Signal Activity");
300 "DRC2 Signal Activity");
301 break; 301 break;
302 default: 302 default:
303 break; 303 break;
@@ -851,6 +851,134 @@ int arizona_hp_ev(struct snd_soc_dapm_widget *w,
851} 851}
852EXPORT_SYMBOL_GPL(arizona_hp_ev); 852EXPORT_SYMBOL_GPL(arizona_hp_ev);
853 853
854static int arizona_dvfs_enable(struct snd_soc_codec *codec)
855{
856 const struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
857 struct arizona *arizona = priv->arizona;
858 int ret;
859
860 ret = regulator_set_voltage(arizona->dcvdd, 1800000, 1800000);
861 if (ret) {
862 dev_err(codec->dev, "Failed to boost DCVDD: %d\n", ret);
863 return ret;
864 }
865
866 ret = regmap_update_bits(arizona->regmap,
867 ARIZONA_DYNAMIC_FREQUENCY_SCALING_1,
868 ARIZONA_SUBSYS_MAX_FREQ,
869 ARIZONA_SUBSYS_MAX_FREQ);
870 if (ret) {
871 dev_err(codec->dev, "Failed to enable subsys max: %d\n", ret);
872 regulator_set_voltage(arizona->dcvdd, 1200000, 1800000);
873 return ret;
874 }
875
876 return 0;
877}
878
879static int arizona_dvfs_disable(struct snd_soc_codec *codec)
880{
881 const struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
882 struct arizona *arizona = priv->arizona;
883 int ret;
884
885 ret = regmap_update_bits(arizona->regmap,
886 ARIZONA_DYNAMIC_FREQUENCY_SCALING_1,
887 ARIZONA_SUBSYS_MAX_FREQ, 0);
888 if (ret) {
889 dev_err(codec->dev, "Failed to disable subsys max: %d\n", ret);
890 return ret;
891 }
892
893 ret = regulator_set_voltage(arizona->dcvdd, 1200000, 1800000);
894 if (ret) {
895 dev_err(codec->dev, "Failed to unboost DCVDD: %d\n", ret);
896 return ret;
897 }
898
899 return 0;
900}
901
902int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags)
903{
904 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
905 int ret = 0;
906
907 mutex_lock(&priv->dvfs_lock);
908
909 if (!priv->dvfs_cached && !priv->dvfs_reqs) {
910 ret = arizona_dvfs_enable(codec);
911 if (ret)
912 goto err;
913 }
914
915 priv->dvfs_reqs |= flags;
916err:
917 mutex_unlock(&priv->dvfs_lock);
918 return ret;
919}
920EXPORT_SYMBOL_GPL(arizona_dvfs_up);
921
922int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags)
923{
924 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
925 unsigned int old_reqs;
926 int ret = 0;
927
928 mutex_lock(&priv->dvfs_lock);
929
930 old_reqs = priv->dvfs_reqs;
931 priv->dvfs_reqs &= ~flags;
932
933 if (!priv->dvfs_cached && old_reqs && !priv->dvfs_reqs)
934 ret = arizona_dvfs_disable(codec);
935
936 mutex_unlock(&priv->dvfs_lock);
937 return ret;
938}
939EXPORT_SYMBOL_GPL(arizona_dvfs_down);
940
941int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
942 struct snd_kcontrol *kcontrol, int event)
943{
944 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
945 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
946 int ret = 0;
947
948 mutex_lock(&priv->dvfs_lock);
949
950 switch (event) {
951 case SND_SOC_DAPM_POST_PMU:
952 if (priv->dvfs_reqs)
953 ret = arizona_dvfs_enable(codec);
954
955 priv->dvfs_cached = false;
956 break;
957 case SND_SOC_DAPM_PRE_PMD:
958 /* We must ensure DVFS is disabled before the codec goes into
959 * suspend so that we are never in an illegal state of DVFS
960 * enabled without enough DCVDD
961 */
962 priv->dvfs_cached = true;
963
964 if (priv->dvfs_reqs)
965 ret = arizona_dvfs_disable(codec);
966 break;
967 default:
968 break;
969 }
970
971 mutex_unlock(&priv->dvfs_lock);
972 return ret;
973}
974EXPORT_SYMBOL_GPL(arizona_dvfs_sysclk_ev);
975
976void arizona_init_dvfs(struct arizona_priv *priv)
977{
978 mutex_init(&priv->dvfs_lock);
979}
980EXPORT_SYMBOL_GPL(arizona_init_dvfs);
981
854static unsigned int arizona_sysclk_48k_rates[] = { 982static unsigned int arizona_sysclk_48k_rates[] = {
855 6144000, 983 6144000,
856 12288000, 984 12288000,
@@ -1266,7 +1394,7 @@ static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
1266 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 1394 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
1267 struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1]; 1395 struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1];
1268 int base = dai->driver->base; 1396 int base = dai->driver->base;
1269 int i, sr_val; 1397 int i, sr_val, ret;
1270 1398
1271 /* 1399 /*
1272 * We will need to be more flexible than this in future, 1400 * We will need to be more flexible than this in future,
@@ -1282,6 +1410,23 @@ static int arizona_hw_params_rate(struct snd_pcm_substream *substream,
1282 } 1410 }
1283 sr_val = i; 1411 sr_val = i;
1284 1412
1413 switch (priv->arizona->type) {
1414 case WM5102:
1415 case WM8997:
1416 if (arizona_sr_vals[sr_val] >= 88200)
1417 ret = arizona_dvfs_up(codec, ARIZONA_DVFS_SR1_RQ);
1418 else
1419 ret = arizona_dvfs_down(codec, ARIZONA_DVFS_SR1_RQ);
1420
1421 if (ret) {
1422 arizona_aif_err(dai, "Failed to change DVFS %d\n", ret);
1423 return ret;
1424 }
1425 break;
1426 default:
1427 break;
1428 }
1429
1285 switch (dai_priv->clk) { 1430 switch (dai_priv->clk) {
1286 case ARIZONA_CLK_SYSCLK: 1431 case ARIZONA_CLK_SYSCLK:
1287 switch (priv->arizona->type) { 1432 switch (priv->arizona->type) {
@@ -1474,6 +1619,7 @@ static int arizona_dai_set_sysclk(struct snd_soc_dai *dai,
1474 int clk_id, unsigned int freq, int dir) 1619 int clk_id, unsigned int freq, int dir)
1475{ 1620{
1476 struct snd_soc_codec *codec = dai->codec; 1621 struct snd_soc_codec *codec = dai->codec;
1622 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1477 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 1623 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
1478 struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1]; 1624 struct arizona_dai_priv *dai_priv = &priv->dai[dai->id - 1];
1479 struct snd_soc_dapm_route routes[2]; 1625 struct snd_soc_dapm_route routes[2];
@@ -1504,15 +1650,15 @@ static int arizona_dai_set_sysclk(struct snd_soc_dai *dai,
1504 1650
1505 routes[0].source = arizona_dai_clk_str(dai_priv->clk); 1651 routes[0].source = arizona_dai_clk_str(dai_priv->clk);
1506 routes[1].source = arizona_dai_clk_str(dai_priv->clk); 1652 routes[1].source = arizona_dai_clk_str(dai_priv->clk);
1507 snd_soc_dapm_del_routes(&codec->dapm, routes, ARRAY_SIZE(routes)); 1653 snd_soc_dapm_del_routes(dapm, routes, ARRAY_SIZE(routes));
1508 1654
1509 routes[0].source = arizona_dai_clk_str(clk_id); 1655 routes[0].source = arizona_dai_clk_str(clk_id);
1510 routes[1].source = arizona_dai_clk_str(clk_id); 1656 routes[1].source = arizona_dai_clk_str(clk_id);
1511 snd_soc_dapm_add_routes(&codec->dapm, routes, ARRAY_SIZE(routes)); 1657 snd_soc_dapm_add_routes(dapm, routes, ARRAY_SIZE(routes));
1512 1658
1513 dai_priv->clk = clk_id; 1659 dai_priv->clk = clk_id;
1514 1660
1515 return snd_soc_dapm_sync(&codec->dapm); 1661 return snd_soc_dapm_sync(dapm);
1516} 1662}
1517 1663
1518static int arizona_set_tristate(struct snd_soc_dai *dai, int tristate) 1664static int arizona_set_tristate(struct snd_soc_dai *dai, int tristate)
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 11ff899b0272..84e119a56515 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -60,6 +60,9 @@
60#define ARIZONA_MAX_DAI 6 60#define ARIZONA_MAX_DAI 6
61#define ARIZONA_MAX_ADSP 4 61#define ARIZONA_MAX_ADSP 4
62 62
63#define ARIZONA_DVFS_SR1_RQ 0x001
64#define ARIZONA_DVFS_ADSP1_RQ 0x100
65
63struct arizona; 66struct arizona;
64struct wm_adsp; 67struct wm_adsp;
65 68
@@ -84,6 +87,10 @@ struct arizona_priv {
84 87
85 unsigned int spk_ena:2; 88 unsigned int spk_ena:2;
86 unsigned int spk_ena_pending:1; 89 unsigned int spk_ena_pending:1;
90
91 unsigned int dvfs_reqs;
92 struct mutex dvfs_lock;
93 bool dvfs_cached;
87}; 94};
88 95
89#define ARIZONA_NUM_MIXER_INPUTS 103 96#define ARIZONA_NUM_MIXER_INPUTS 103
@@ -107,8 +114,8 @@ extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
107 arizona_mixer_tlv) 114 arizona_mixer_tlv)
108 115
109#define ARIZONA_MUX_ENUM_DECL(name, reg) \ 116#define ARIZONA_MUX_ENUM_DECL(name, reg) \
110 SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff, \ 117 SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
111 arizona_mixer_texts, arizona_mixer_values) 118 name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
112 119
113#define ARIZONA_MUX_CTL_DECL(name) \ 120#define ARIZONA_MUX_CTL_DECL(name) \
114 const struct snd_kcontrol_new name##_mux = \ 121 const struct snd_kcontrol_new name##_mux = \
@@ -245,6 +252,12 @@ struct arizona_fll {
245 char clock_ok_name[ARIZONA_FLL_NAME_LEN]; 252 char clock_ok_name[ARIZONA_FLL_NAME_LEN];
246}; 253};
247 254
255extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
256extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
257extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
258 struct snd_kcontrol *kcontrol, int event);
259extern void arizona_init_dvfs(struct arizona_priv *priv);
260
248extern int arizona_init_fll(struct arizona *arizona, int id, int base, 261extern int arizona_init_fll(struct arizona *arizona, int id, int base,
249 int lock_irq, int ok_irq, struct arizona_fll *fll); 262 int lock_irq, int ok_irq, struct arizona_fll *fll);
250extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source, 263extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index e7238b8904bc..b084ad113e96 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -63,7 +63,7 @@ static int bt_sco_remove(struct platform_device *pdev)
63 return 0; 63 return 0;
64} 64}
65 65
66static struct platform_device_id bt_sco_driver_ids[] = { 66static const struct platform_device_id bt_sco_driver_ids[] = {
67 { 67 {
68 .name = "dfbmcs320", 68 .name = "dfbmcs320",
69 }, 69 },
@@ -74,9 +74,18 @@ static struct platform_device_id bt_sco_driver_ids[] = {
74}; 74};
75MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids); 75MODULE_DEVICE_TABLE(platform, bt_sco_driver_ids);
76 76
77#if defined(CONFIG_OF)
78static const struct of_device_id bt_sco_codec_of_match[] = {
79 { .compatible = "delta,dfbmcs320", },
80 {},
81};
82MODULE_DEVICE_TABLE(of, bt_sco_codec_of_match);
83#endif
84
77static struct platform_driver bt_sco_driver = { 85static struct platform_driver bt_sco_driver = {
78 .driver = { 86 .driver = {
79 .name = "bt-sco", 87 .name = "bt-sco",
88 .of_match_table = of_match_ptr(bt_sco_codec_of_match),
80 }, 89 },
81 .probe = bt_sco_probe, 90 .probe = bt_sco_probe,
82 .remove = bt_sco_remove, 91 .remove = bt_sco_remove,
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
index d6dedd4eab29..1c895a53001d 100644
--- a/sound/soc/codecs/cq93vc.c
+++ b/sound/soc/codecs/cq93vc.c
@@ -92,7 +92,6 @@ static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
92 DAVINCI_VC_REG12_POWER_ALL_OFF); 92 DAVINCI_VC_REG12_POWER_ALL_OFF);
93 break; 93 break;
94 } 94 }
95 codec->dapm.bias_level = level;
96 95
97 return 0; 96 return 0;
98} 97}
diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c
index 60598b230341..8f40025b7e7c 100644
--- a/sound/soc/codecs/cs35l32.c
+++ b/sound/soc/codecs/cs35l32.c
@@ -13,7 +13,6 @@
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/moduleparam.h> 15#include <linux/moduleparam.h>
16#include <linux/version.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
diff --git a/sound/soc/codecs/cs4265.c b/sound/soc/codecs/cs4265.c
index cac48ddf3ba6..d7ec4756e45b 100644
--- a/sound/soc/codecs/cs4265.c
+++ b/sound/soc/codecs/cs4265.c
@@ -503,7 +503,6 @@ static int cs4265_set_bias_level(struct snd_soc_codec *codec,
503 CS4265_PWRCTL_PDN); 503 CS4265_PWRCTL_PDN);
504 break; 504 break;
505 } 505 }
506 codec->dapm.bias_level = level;
507 return 0; 506 return 0;
508} 507}
509 508
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
index 1589e7a881d8..4de52c9957ac 100644
--- a/sound/soc/codecs/cs42l52.c
+++ b/sound/soc/codecs/cs42l52.c
@@ -897,7 +897,7 @@ static int cs42l52_set_bias_level(struct snd_soc_codec *codec,
897 CS42L52_PWRCTL1_PDN_CODEC, 0); 897 CS42L52_PWRCTL1_PDN_CODEC, 0);
898 break; 898 break;
899 case SND_SOC_BIAS_STANDBY: 899 case SND_SOC_BIAS_STANDBY:
900 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 900 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
901 regcache_cache_only(cs42l52->regmap, false); 901 regcache_cache_only(cs42l52->regmap, false);
902 regcache_sync(cs42l52->regmap); 902 regcache_sync(cs42l52->regmap);
903 } 903 }
@@ -908,7 +908,6 @@ static int cs42l52_set_bias_level(struct snd_soc_codec *codec,
908 regcache_cache_only(cs42l52->regmap, true); 908 regcache_cache_only(cs42l52->regmap, true);
909 break; 909 break;
910 } 910 }
911 codec->dapm.bias_level = level;
912 911
913 return 0; 912 return 0;
914} 913}
@@ -956,7 +955,7 @@ static void cs42l52_beep_work(struct work_struct *work)
956 struct cs42l52_private *cs42l52 = 955 struct cs42l52_private *cs42l52 =
957 container_of(work, struct cs42l52_private, beep_work); 956 container_of(work, struct cs42l52_private, beep_work);
958 struct snd_soc_codec *codec = cs42l52->codec; 957 struct snd_soc_codec *codec = cs42l52->codec;
959 struct snd_soc_dapm_context *dapm = &codec->dapm; 958 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
960 int i; 959 int i;
961 int val = 0; 960 int val = 0;
962 int best = 0; 961 int best = 0;
diff --git a/sound/soc/codecs/cs42l56.c b/sound/soc/codecs/cs42l56.c
index cbc654fe48c7..1e11ba45a79f 100644
--- a/sound/soc/codecs/cs42l56.c
+++ b/sound/soc/codecs/cs42l56.c
@@ -953,7 +953,7 @@ static int cs42l56_set_bias_level(struct snd_soc_codec *codec,
953 CS42L56_PDN_ALL_MASK, 0); 953 CS42L56_PDN_ALL_MASK, 0);
954 break; 954 break;
955 case SND_SOC_BIAS_STANDBY: 955 case SND_SOC_BIAS_STANDBY:
956 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 956 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
957 regcache_cache_only(cs42l56->regmap, false); 957 regcache_cache_only(cs42l56->regmap, false);
958 regcache_sync(cs42l56->regmap); 958 regcache_sync(cs42l56->regmap);
959 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l56->supplies), 959 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l56->supplies),
@@ -978,7 +978,6 @@ static int cs42l56_set_bias_level(struct snd_soc_codec *codec,
978 cs42l56->supplies); 978 cs42l56->supplies);
979 break; 979 break;
980 } 980 }
981 codec->dapm.bias_level = level;
982 981
983 return 0; 982 return 0;
984} 983}
@@ -1026,7 +1025,7 @@ static void cs42l56_beep_work(struct work_struct *work)
1026 struct cs42l56_private *cs42l56 = 1025 struct cs42l56_private *cs42l56 =
1027 container_of(work, struct cs42l56_private, beep_work); 1026 container_of(work, struct cs42l56_private, beep_work);
1028 struct snd_soc_codec *codec = cs42l56->codec; 1027 struct snd_soc_codec *codec = cs42l56->codec;
1029 struct snd_soc_dapm_context *dapm = &codec->dapm; 1028 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1030 int i; 1029 int i;
1031 int val = 0; 1030 int val = 0;
1032 int best = 0; 1031 int best = 0;
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 8ecedba79606..b7853b9d3a60 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -1208,7 +1208,7 @@ static int cs42l73_set_bias_level(struct snd_soc_codec *codec,
1208 break; 1208 break;
1209 1209
1210 case SND_SOC_BIAS_STANDBY: 1210 case SND_SOC_BIAS_STANDBY:
1211 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1211 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1212 regcache_cache_only(cs42l73->regmap, false); 1212 regcache_cache_only(cs42l73->regmap, false);
1213 regcache_sync(cs42l73->regmap); 1213 regcache_sync(cs42l73->regmap);
1214 } 1214 }
@@ -1228,7 +1228,6 @@ static int cs42l73_set_bias_level(struct snd_soc_codec *codec,
1228 snd_soc_update_bits(codec, CS42L73_DMMCC, CS42L73_MCLKDIS, 1); 1228 snd_soc_update_bits(codec, CS42L73_DMMCC, CS42L73_MCLKDIS, 1);
1229 break; 1229 break;
1230 } 1230 }
1231 codec->dapm.bias_level = level;
1232 return 0; 1231 return 0;
1233} 1232}
1234 1233
diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c
index 670ebfe12903..e1d46862e81f 100644
--- a/sound/soc/codecs/cs42xx8.c
+++ b/sound/soc/codecs/cs42xx8.c
@@ -380,7 +380,7 @@ EXPORT_SYMBOL_GPL(cs42xx8_regmap_config);
380static int cs42xx8_codec_probe(struct snd_soc_codec *codec) 380static int cs42xx8_codec_probe(struct snd_soc_codec *codec)
381{ 381{
382 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec); 382 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
383 struct snd_soc_dapm_context *dapm = &codec->dapm; 383 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
384 384
385 switch (cs42xx8->drvdata->num_adcs) { 385 switch (cs42xx8->drvdata->num_adcs) {
386 case 3: 386 case 3:
diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c
index 0f334bc1b63c..d6f4abbbf8a7 100644
--- a/sound/soc/codecs/cx20442.c
+++ b/sound/soc/codecs/cx20442.c
@@ -333,7 +333,7 @@ static int cx20442_set_bias_level(struct snd_soc_codec *codec,
333 333
334 switch (level) { 334 switch (level) {
335 case SND_SOC_BIAS_PREPARE: 335 case SND_SOC_BIAS_PREPARE:
336 if (codec->dapm.bias_level != SND_SOC_BIAS_STANDBY) 336 if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_STANDBY)
337 break; 337 break;
338 if (IS_ERR(cx20442->por)) 338 if (IS_ERR(cx20442->por))
339 err = PTR_ERR(cx20442->por); 339 err = PTR_ERR(cx20442->por);
@@ -341,7 +341,7 @@ static int cx20442_set_bias_level(struct snd_soc_codec *codec,
341 err = regulator_enable(cx20442->por); 341 err = regulator_enable(cx20442->por);
342 break; 342 break;
343 case SND_SOC_BIAS_STANDBY: 343 case SND_SOC_BIAS_STANDBY:
344 if (codec->dapm.bias_level != SND_SOC_BIAS_PREPARE) 344 if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_PREPARE)
345 break; 345 break;
346 if (IS_ERR(cx20442->por)) 346 if (IS_ERR(cx20442->por))
347 err = PTR_ERR(cx20442->por); 347 err = PTR_ERR(cx20442->por);
@@ -351,8 +351,6 @@ static int cx20442_set_bias_level(struct snd_soc_codec *codec,
351 default: 351 default:
352 break; 352 break;
353 } 353 }
354 if (!err)
355 codec->dapm.bias_level = level;
356 354
357 return err; 355 return err;
358} 356}
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
index 9ec577f0edb4..238e48a3a4fe 100644
--- a/sound/soc/codecs/da7213.c
+++ b/sound/soc/codecs/da7213.c
@@ -1374,7 +1374,7 @@ static int da7213_set_bias_level(struct snd_soc_codec *codec,
1374 case SND_SOC_BIAS_PREPARE: 1374 case SND_SOC_BIAS_PREPARE:
1375 break; 1375 break;
1376 case SND_SOC_BIAS_STANDBY: 1376 case SND_SOC_BIAS_STANDBY:
1377 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1377 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1378 /* Enable VMID reference & master bias */ 1378 /* Enable VMID reference & master bias */
1379 snd_soc_update_bits(codec, DA7213_REFERENCES, 1379 snd_soc_update_bits(codec, DA7213_REFERENCES,
1380 DA7213_VMID_EN | DA7213_BIAS_EN, 1380 DA7213_VMID_EN | DA7213_BIAS_EN,
@@ -1387,7 +1387,6 @@ static int da7213_set_bias_level(struct snd_soc_codec *codec,
1387 DA7213_VMID_EN | DA7213_BIAS_EN, 0); 1387 DA7213_VMID_EN | DA7213_BIAS_EN, 0);
1388 break; 1388 break;
1389 } 1389 }
1390 codec->dapm.bias_level = level;
1391 return 0; 1390 return 0;
1392} 1391}
1393 1392
diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c
index 911c26c705fc..207523686bd5 100644
--- a/sound/soc/codecs/da732x.c
+++ b/sound/soc/codecs/da732x.c
@@ -1432,7 +1432,7 @@ static int da732x_set_bias_level(struct snd_soc_codec *codec,
1432 case SND_SOC_BIAS_PREPARE: 1432 case SND_SOC_BIAS_PREPARE:
1433 break; 1433 break;
1434 case SND_SOC_BIAS_STANDBY: 1434 case SND_SOC_BIAS_STANDBY:
1435 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1435 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1436 /* Init Codec */ 1436 /* Init Codec */
1437 snd_soc_write(codec, DA732X_REG_REF1, 1437 snd_soc_write(codec, DA732X_REG_REF1,
1438 DA732X_VMID_FASTCHG); 1438 DA732X_VMID_FASTCHG);
@@ -1502,8 +1502,6 @@ static int da732x_set_bias_level(struct snd_soc_codec *codec,
1502 break; 1502 break;
1503 } 1503 }
1504 1504
1505 codec->dapm.bias_level = level;
1506
1507 return 0; 1505 return 0;
1508} 1506}
1509 1507
diff --git a/sound/soc/codecs/da9055.c b/sound/soc/codecs/da9055.c
index ad19cc56702b..66bb446473b8 100644
--- a/sound/soc/codecs/da9055.c
+++ b/sound/soc/codecs/da9055.c
@@ -1364,7 +1364,7 @@ static int da9055_set_bias_level(struct snd_soc_codec *codec,
1364 case SND_SOC_BIAS_PREPARE: 1364 case SND_SOC_BIAS_PREPARE:
1365 break; 1365 break;
1366 case SND_SOC_BIAS_STANDBY: 1366 case SND_SOC_BIAS_STANDBY:
1367 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1367 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1368 /* Enable VMID reference & master bias */ 1368 /* Enable VMID reference & master bias */
1369 snd_soc_update_bits(codec, DA9055_REFERENCES, 1369 snd_soc_update_bits(codec, DA9055_REFERENCES,
1370 DA9055_VMID_EN | DA9055_BIAS_EN, 1370 DA9055_VMID_EN | DA9055_BIAS_EN,
@@ -1377,7 +1377,6 @@ static int da9055_set_bias_level(struct snd_soc_codec *codec,
1377 DA9055_VMID_EN | DA9055_BIAS_EN, 0); 1377 DA9055_VMID_EN | DA9055_BIAS_EN, 0);
1378 break; 1378 break;
1379 } 1379 }
1380 codec->dapm.bias_level = level;
1381 return 0; 1380 return 0;
1382} 1381}
1383 1382
diff --git a/sound/soc/codecs/es8328.c b/sound/soc/codecs/es8328.c
index c5f35a07e8e4..6a091016e0fc 100644
--- a/sound/soc/codecs/es8328.c
+++ b/sound/soc/codecs/es8328.c
@@ -536,7 +536,7 @@ static int es8328_set_bias_level(struct snd_soc_codec *codec,
536 break; 536 break;
537 537
538 case SND_SOC_BIAS_STANDBY: 538 case SND_SOC_BIAS_STANDBY:
539 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 539 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
540 snd_soc_update_bits(codec, ES8328_CONTROL1, 540 snd_soc_update_bits(codec, ES8328_CONTROL1,
541 ES8328_CONTROL1_VMIDSEL_MASK | 541 ES8328_CONTROL1_VMIDSEL_MASK |
542 ES8328_CONTROL1_ENREF, 542 ES8328_CONTROL1_ENREF,
@@ -566,7 +566,6 @@ static int es8328_set_bias_level(struct snd_soc_codec *codec,
566 0); 566 0);
567 break; 567 break;
568 } 568 }
569 codec->dapm.bias_level = level;
570 return 0; 569 return 0;
571} 570}
572 571
diff --git a/sound/soc/codecs/isabelle.c b/sound/soc/codecs/isabelle.c
index 3a89ce66d51d..ebd90283c960 100644
--- a/sound/soc/codecs/isabelle.c
+++ b/sound/soc/codecs/isabelle.c
@@ -909,8 +909,6 @@ static int isabelle_set_bias_level(struct snd_soc_codec *codec,
909 break; 909 break;
910 } 910 }
911 911
912 codec->dapm.bias_level = level;
913
914 return 0; 912 return 0;
915} 913}
916 914
diff --git a/sound/soc/codecs/jz4740.c b/sound/soc/codecs/jz4740.c
index 933f4476d76c..9363fdbca9cd 100644
--- a/sound/soc/codecs/jz4740.c
+++ b/sound/soc/codecs/jz4740.c
@@ -258,7 +258,7 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
258 break; 258 break;
259 case SND_SOC_BIAS_STANDBY: 259 case SND_SOC_BIAS_STANDBY:
260 /* The only way to clear the suspend flag is to reset the codec */ 260 /* The only way to clear the suspend flag is to reset the codec */
261 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 261 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
262 jz4740_codec_wakeup(regmap); 262 jz4740_codec_wakeup(regmap);
263 263
264 mask = JZ4740_CODEC_1_VREF_DISABLE | 264 mask = JZ4740_CODEC_1_VREF_DISABLE |
@@ -281,8 +281,6 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
281 break; 281 break;
282 } 282 }
283 283
284 codec->dapm.bias_level = level;
285
286 return 0; 284 return 0;
287} 285}
288 286
diff --git a/sound/soc/codecs/lm4857.c b/sound/soc/codecs/lm4857.c
index a924bb9d7886..79ad4cbdcdd4 100644
--- a/sound/soc/codecs/lm4857.c
+++ b/sound/soc/codecs/lm4857.c
@@ -89,8 +89,6 @@ static int lm4857_set_bias_level(struct snd_soc_codec *codec,
89 break; 89 break;
90 } 90 }
91 91
92 codec->dapm.bias_level = level;
93
94 return 0; 92 return 0;
95} 93}
96 94
diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c
index c4dfde9bdf1c..6600aa0a33dc 100644
--- a/sound/soc/codecs/lm49453.c
+++ b/sound/soc/codecs/lm49453.c
@@ -1271,7 +1271,7 @@ static int lm49453_set_bias_level(struct snd_soc_codec *codec,
1271 break; 1271 break;
1272 1272
1273 case SND_SOC_BIAS_STANDBY: 1273 case SND_SOC_BIAS_STANDBY:
1274 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 1274 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
1275 regcache_sync(lm49453->regmap); 1275 regcache_sync(lm49453->regmap);
1276 1276
1277 snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG, 1277 snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG,
@@ -1284,8 +1284,6 @@ static int lm49453_set_bias_level(struct snd_soc_codec *codec,
1284 break; 1284 break;
1285 } 1285 }
1286 1286
1287 codec->dapm.bias_level = level;
1288
1289 return 0; 1287 return 0;
1290} 1288}
1291 1289
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 805b3f8cd39d..d0f45348bfbb 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -1571,7 +1571,7 @@ static int max98088_set_bias_level(struct snd_soc_codec *codec,
1571 break; 1571 break;
1572 1572
1573 case SND_SOC_BIAS_STANDBY: 1573 case SND_SOC_BIAS_STANDBY:
1574 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 1574 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
1575 regcache_sync(max98088->regmap); 1575 regcache_sync(max98088->regmap);
1576 1576
1577 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN, 1577 snd_soc_update_bits(codec, M98088_REG_4C_PWR_EN_IN,
@@ -1584,7 +1584,6 @@ static int max98088_set_bias_level(struct snd_soc_codec *codec,
1584 regcache_mark_dirty(max98088->regmap); 1584 regcache_mark_dirty(max98088->regmap);
1585 break; 1585 break;
1586 } 1586 }
1587 codec->dapm.bias_level = level;
1588 return 0; 1587 return 0;
1589} 1588}
1590 1589
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 3e33ef2acf3c..c2306268cab8 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -1500,7 +1500,7 @@ static const struct snd_soc_dapm_route max98091_dapm_routes[] = {
1500static int max98090_add_widgets(struct snd_soc_codec *codec) 1500static int max98090_add_widgets(struct snd_soc_codec *codec)
1501{ 1501{
1502 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec); 1502 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
1503 struct snd_soc_dapm_context *dapm = &codec->dapm; 1503 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1504 1504
1505 snd_soc_add_codec_controls(codec, max98090_snd_controls, 1505 snd_soc_add_codec_controls(codec, max98090_snd_controls,
1506 ARRAY_SIZE(max98090_snd_controls)); 1506 ARRAY_SIZE(max98090_snd_controls));
@@ -1798,16 +1798,17 @@ static int max98090_set_bias_level(struct snd_soc_codec *codec,
1798 * away from ON. Disable the clock in that case, otherwise 1798 * away from ON. Disable the clock in that case, otherwise
1799 * enable it. 1799 * enable it.
1800 */ 1800 */
1801 if (!IS_ERR(max98090->mclk)) { 1801 if (IS_ERR(max98090->mclk))
1802 if (codec->dapm.bias_level == SND_SOC_BIAS_ON) 1802 break;
1803 clk_disable_unprepare(max98090->mclk); 1803
1804 else 1804 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON)
1805 clk_prepare_enable(max98090->mclk); 1805 clk_disable_unprepare(max98090->mclk);
1806 } 1806 else
1807 clk_prepare_enable(max98090->mclk);
1807 break; 1808 break;
1808 1809
1809 case SND_SOC_BIAS_STANDBY: 1810 case SND_SOC_BIAS_STANDBY:
1810 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1811 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1811 ret = regcache_sync(max98090->regmap); 1812 ret = regcache_sync(max98090->regmap);
1812 if (ret != 0) { 1813 if (ret != 0) {
1813 dev_err(codec->dev, 1814 dev_err(codec->dev,
@@ -1824,7 +1825,6 @@ static int max98090_set_bias_level(struct snd_soc_codec *codec,
1824 regcache_mark_dirty(max98090->regmap); 1825 regcache_mark_dirty(max98090->regmap);
1825 break; 1826 break;
1826 } 1827 }
1827 codec->dapm.bias_level = level;
1828 return 0; 1828 return 0;
1829} 1829}
1830 1830
@@ -2187,7 +2187,6 @@ static void max98090_jack_work(struct work_struct *work)
2187 struct max98090_priv, 2187 struct max98090_priv,
2188 jack_work.work); 2188 jack_work.work);
2189 struct snd_soc_codec *codec = max98090->codec; 2189 struct snd_soc_codec *codec = max98090->codec;
2190 struct snd_soc_dapm_context *dapm = &codec->dapm;
2191 int status = 0; 2190 int status = 0;
2192 int reg; 2191 int reg;
2193 2192
@@ -2266,8 +2265,6 @@ static void max98090_jack_work(struct work_struct *work)
2266 2265
2267 snd_soc_jack_report(max98090->jack, status, 2266 snd_soc_jack_report(max98090->jack, status,
2268 SND_JACK_HEADSET | SND_JACK_BTN_0); 2267 SND_JACK_HEADSET | SND_JACK_BTN_0);
2269
2270 snd_soc_dapm_sync(dapm);
2271} 2268}
2272 2269
2273static irqreturn_t max98090_interrupt(int irq, void *data) 2270static irqreturn_t max98090_interrupt(int irq, void *data)
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 8fba0c3db798..2b8b8a5f385f 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -1650,16 +1650,17 @@ static int max98095_set_bias_level(struct snd_soc_codec *codec,
1650 * away from ON. Disable the clock in that case, otherwise 1650 * away from ON. Disable the clock in that case, otherwise
1651 * enable it. 1651 * enable it.
1652 */ 1652 */
1653 if (!IS_ERR(max98095->mclk)) { 1653 if (IS_ERR(max98095->mclk))
1654 if (codec->dapm.bias_level == SND_SOC_BIAS_ON) 1654 break;
1655 clk_disable_unprepare(max98095->mclk); 1655
1656 else 1656 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON)
1657 clk_prepare_enable(max98095->mclk); 1657 clk_disable_unprepare(max98095->mclk);
1658 } 1658 else
1659 clk_prepare_enable(max98095->mclk);
1659 break; 1660 break;
1660 1661
1661 case SND_SOC_BIAS_STANDBY: 1662 case SND_SOC_BIAS_STANDBY:
1662 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1663 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1663 ret = regcache_sync(max98095->regmap); 1664 ret = regcache_sync(max98095->regmap);
1664 1665
1665 if (ret != 0) { 1666 if (ret != 0) {
@@ -1678,7 +1679,6 @@ static int max98095_set_bias_level(struct snd_soc_codec *codec,
1678 regcache_mark_dirty(max98095->regmap); 1679 regcache_mark_dirty(max98095->regmap);
1679 break; 1680 break;
1680 } 1681 }
1681 codec->dapm.bias_level = level;
1682 return 0; 1682 return 0;
1683} 1683}
1684 1684
@@ -2198,7 +2198,7 @@ static int max98095_suspend(struct snd_soc_codec *codec)
2198 if (max98095->headphone_jack || max98095->mic_jack) 2198 if (max98095->headphone_jack || max98095->mic_jack)
2199 max98095_jack_detect_disable(codec); 2199 max98095_jack_detect_disable(codec);
2200 2200
2201 max98095_set_bias_level(codec, SND_SOC_BIAS_OFF); 2201 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
2202 2202
2203 return 0; 2203 return 0;
2204} 2204}
@@ -2208,7 +2208,7 @@ static int max98095_resume(struct snd_soc_codec *codec)
2208 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 2208 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2209 struct i2c_client *client = to_i2c_client(codec->dev); 2209 struct i2c_client *client = to_i2c_client(codec->dev);
2210 2210
2211 max98095_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 2211 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
2212 2212
2213 if (max98095->headphone_jack || max98095->mic_jack) { 2213 if (max98095->headphone_jack || max98095->mic_jack) {
2214 max98095_jack_detect_enable(codec); 2214 max98095_jack_detect_enable(codec);
diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c
index 10f8e47ce2c2..481d58f1cb3f 100644
--- a/sound/soc/codecs/max9850.c
+++ b/sound/soc/codecs/max9850.c
@@ -252,7 +252,7 @@ static int max9850_set_bias_level(struct snd_soc_codec *codec,
252 case SND_SOC_BIAS_PREPARE: 252 case SND_SOC_BIAS_PREPARE:
253 break; 253 break;
254 case SND_SOC_BIAS_STANDBY: 254 case SND_SOC_BIAS_STANDBY:
255 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 255 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
256 ret = regcache_sync(max9850->regmap); 256 ret = regcache_sync(max9850->regmap);
257 if (ret) { 257 if (ret) {
258 dev_err(codec->dev, 258 dev_err(codec->dev,
@@ -264,7 +264,6 @@ static int max9850_set_bias_level(struct snd_soc_codec *codec,
264 case SND_SOC_BIAS_OFF: 264 case SND_SOC_BIAS_OFF:
265 break; 265 break;
266 } 266 }
267 codec->dapm.bias_level = level;
268 return 0; 267 return 0;
269} 268}
270 269
diff --git a/sound/soc/codecs/max98925.c b/sound/soc/codecs/max98925.c
index 9b5a17de4690..aad664225dc3 100644
--- a/sound/soc/codecs/max98925.c
+++ b/sound/soc/codecs/max98925.c
@@ -346,7 +346,7 @@ static int max98925_dai_set_fmt(struct snd_soc_dai *codec_dai,
346 } 346 }
347 347
348 regmap_update_bits(max98925->regmap, MAX98925_FORMAT, 348 regmap_update_bits(max98925->regmap, MAX98925_FORMAT,
349 M98925_DAI_BCI_MASK, invert); 349 M98925_DAI_BCI_MASK | M98925_DAI_WCI_MASK, invert);
350 return 0; 350 return 0;
351} 351}
352 352
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
index 2ffb9a0570dc..3d44fc50e4d0 100644
--- a/sound/soc/codecs/mc13783.c
+++ b/sound/soc/codecs/mc13783.c
@@ -623,14 +623,14 @@ static int mc13783_probe(struct snd_soc_codec *codec)
623 AUDIO_SSI_SEL, 0); 623 AUDIO_SSI_SEL, 0);
624 else 624 else
625 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_CODEC, 625 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_CODEC,
626 0, AUDIO_SSI_SEL); 626 AUDIO_SSI_SEL, AUDIO_SSI_SEL);
627 627
628 if (priv->dac_ssi_port == MC13783_SSI1_PORT) 628 if (priv->dac_ssi_port == MC13783_SSI1_PORT)
629 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC, 629 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC,
630 AUDIO_SSI_SEL, 0); 630 AUDIO_SSI_SEL, 0);
631 else 631 else
632 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC, 632 mc13xxx_reg_rmw(priv->mc13xxx, MC13783_AUDIO_DAC,
633 0, AUDIO_SSI_SEL); 633 AUDIO_SSI_SEL, AUDIO_SSI_SEL);
634 634
635 return 0; 635 return 0;
636} 636}
diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c
index 711f55039522..62dda2488f14 100644
--- a/sound/soc/codecs/ml26124.c
+++ b/sound/soc/codecs/ml26124.c
@@ -523,7 +523,7 @@ static int ml26124_set_bias_level(struct snd_soc_codec *codec,
523 break; 523 break;
524 case SND_SOC_BIAS_STANDBY: 524 case SND_SOC_BIAS_STANDBY:
525 /* VMID ON */ 525 /* VMID ON */
526 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 526 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
527 snd_soc_update_bits(codec, ML26124_PW_REF_PW_MNG, 527 snd_soc_update_bits(codec, ML26124_PW_REF_PW_MNG,
528 ML26124_VMID, ML26124_VMID); 528 ML26124_VMID, ML26124_VMID);
529 msleep(500); 529 msleep(500);
@@ -536,7 +536,6 @@ static int ml26124_set_bias_level(struct snd_soc_codec *codec,
536 ML26124_VMID, 0); 536 ML26124_VMID, 0);
537 break; 537 break;
538 } 538 }
539 codec->dapm.bias_level = level;
540 return 0; 539 return 0;
541} 540}
542 541
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index e12764d15431..de16429f0a43 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -242,7 +242,7 @@ static int pcm512x_overclock_pll_put(struct snd_kcontrol *kcontrol,
242 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 242 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
243 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); 243 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
244 244
245 switch (codec->dapm.bias_level) { 245 switch (snd_soc_codec_get_bias_level(codec)) {
246 case SND_SOC_BIAS_OFF: 246 case SND_SOC_BIAS_OFF:
247 case SND_SOC_BIAS_STANDBY: 247 case SND_SOC_BIAS_STANDBY:
248 break; 248 break;
@@ -270,7 +270,7 @@ static int pcm512x_overclock_dsp_put(struct snd_kcontrol *kcontrol,
270 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 270 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
271 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); 271 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
272 272
273 switch (codec->dapm.bias_level) { 273 switch (snd_soc_codec_get_bias_level(codec)) {
274 case SND_SOC_BIAS_OFF: 274 case SND_SOC_BIAS_OFF:
275 case SND_SOC_BIAS_STANDBY: 275 case SND_SOC_BIAS_STANDBY:
276 break; 276 break;
@@ -298,7 +298,7 @@ static int pcm512x_overclock_dac_put(struct snd_kcontrol *kcontrol,
298 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 298 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
299 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec); 299 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
300 300
301 switch (codec->dapm.bias_level) { 301 switch (snd_soc_codec_get_bias_level(codec)) {
302 case SND_SOC_BIAS_OFF: 302 case SND_SOC_BIAS_OFF:
303 case SND_SOC_BIAS_STANDBY: 303 case SND_SOC_BIAS_STANDBY:
304 break; 304 break;
@@ -641,8 +641,6 @@ static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
641 break; 641 break;
642 } 642 }
643 643
644 codec->dapm.bias_level = level;
645
646 return 0; 644 return 0;
647} 645}
648 646
diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c
index 0fcda35a3a93..c6cca0639e0d 100644
--- a/sound/soc/codecs/rt286.c
+++ b/sound/soc/codecs/rt286.c
@@ -301,6 +301,7 @@ static int rt286_support_power_controls[] = {
301 301
302static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic) 302static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
303{ 303{
304 struct snd_soc_dapm_context *dapm;
304 unsigned int val, buf; 305 unsigned int val, buf;
305 306
306 *hp = false; 307 *hp = false;
@@ -308,6 +309,9 @@ static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
308 309
309 if (!rt286->codec) 310 if (!rt286->codec)
310 return -EINVAL; 311 return -EINVAL;
312
313 dapm = snd_soc_codec_get_dapm(rt286->codec);
314
311 if (rt286->pdata.cbj_en) { 315 if (rt286->pdata.cbj_en) {
312 regmap_read(rt286->regmap, RT286_GET_HP_SENSE, &buf); 316 regmap_read(rt286->regmap, RT286_GET_HP_SENSE, &buf);
313 *hp = buf & 0x80000000; 317 *hp = buf & 0x80000000;
@@ -316,14 +320,11 @@ static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
316 regmap_update_bits(rt286->regmap, 320 regmap_update_bits(rt286->regmap,
317 RT286_DC_GAIN, 0x200, 0x200); 321 RT286_DC_GAIN, 0x200, 0x200);
318 322
319 snd_soc_dapm_force_enable_pin(&rt286->codec->dapm, 323 snd_soc_dapm_force_enable_pin(dapm, "HV");
320 "HV"); 324 snd_soc_dapm_force_enable_pin(dapm, "VREF");
321 snd_soc_dapm_force_enable_pin(&rt286->codec->dapm,
322 "VREF");
323 /* power LDO1 */ 325 /* power LDO1 */
324 snd_soc_dapm_force_enable_pin(&rt286->codec->dapm, 326 snd_soc_dapm_force_enable_pin(dapm, "LDO1");
325 "LDO1"); 327 snd_soc_dapm_sync(dapm);
326 snd_soc_dapm_sync(&rt286->codec->dapm);
327 328
328 regmap_write(rt286->regmap, RT286_SET_MIC1, 0x24); 329 regmap_write(rt286->regmap, RT286_SET_MIC1, 0x24);
329 msleep(50); 330 msleep(50);
@@ -360,11 +361,11 @@ static int rt286_jack_detect(struct rt286_priv *rt286, bool *hp, bool *mic)
360 *mic = buf & 0x80000000; 361 *mic = buf & 0x80000000;
361 } 362 }
362 363
363 snd_soc_dapm_disable_pin(&rt286->codec->dapm, "HV"); 364 snd_soc_dapm_disable_pin(dapm, "HV");
364 snd_soc_dapm_disable_pin(&rt286->codec->dapm, "VREF"); 365 snd_soc_dapm_disable_pin(dapm, "VREF");
365 if (!*hp) 366 if (!*hp)
366 snd_soc_dapm_disable_pin(&rt286->codec->dapm, "LDO1"); 367 snd_soc_dapm_disable_pin(dapm, "LDO1");
367 snd_soc_dapm_sync(&rt286->codec->dapm); 368 snd_soc_dapm_sync(dapm);
368 369
369 return 0; 370 return 0;
370} 371}
@@ -391,6 +392,7 @@ static void rt286_jack_detect_work(struct work_struct *work)
391 392
392int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) 393int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
393{ 394{
395 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
394 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec); 396 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec);
395 397
396 rt286->jack = jack; 398 rt286->jack = jack;
@@ -398,7 +400,7 @@ int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
398 if (jack) { 400 if (jack) {
399 /* enable IRQ */ 401 /* enable IRQ */
400 if (rt286->jack->status & SND_JACK_HEADPHONE) 402 if (rt286->jack->status & SND_JACK_HEADPHONE)
401 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO1"); 403 snd_soc_dapm_force_enable_pin(dapm, "LDO1");
402 regmap_update_bits(rt286->regmap, RT286_IRQ_CTRL, 0x2, 0x2); 404 regmap_update_bits(rt286->regmap, RT286_IRQ_CTRL, 0x2, 0x2);
403 /* Send an initial empty report */ 405 /* Send an initial empty report */
404 snd_soc_jack_report(rt286->jack, rt286->jack->status, 406 snd_soc_jack_report(rt286->jack, rt286->jack->status,
@@ -406,9 +408,9 @@ int rt286_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
406 } else { 408 } else {
407 /* disable IRQ */ 409 /* disable IRQ */
408 regmap_update_bits(rt286->regmap, RT286_IRQ_CTRL, 0x2, 0x0); 410 regmap_update_bits(rt286->regmap, RT286_IRQ_CTRL, 0x2, 0x0);
409 snd_soc_dapm_disable_pin(&codec->dapm, "LDO1"); 411 snd_soc_dapm_disable_pin(dapm, "LDO1");
410 } 412 }
411 snd_soc_dapm_sync(&codec->dapm); 413 snd_soc_dapm_sync(dapm);
412 414
413 return 0; 415 return 0;
414} 416}
@@ -985,7 +987,7 @@ static int rt286_set_bias_level(struct snd_soc_codec *codec,
985{ 987{
986 switch (level) { 988 switch (level) {
987 case SND_SOC_BIAS_PREPARE: 989 case SND_SOC_BIAS_PREPARE:
988 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 990 if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) {
989 snd_soc_write(codec, 991 snd_soc_write(codec,
990 RT286_SET_AUDIO_POWER, AC_PWRST_D0); 992 RT286_SET_AUDIO_POWER, AC_PWRST_D0);
991 snd_soc_update_bits(codec, 993 snd_soc_update_bits(codec,
@@ -1012,7 +1014,6 @@ static int rt286_set_bias_level(struct snd_soc_codec *codec,
1012 default: 1014 default:
1013 break; 1015 break;
1014 } 1016 }
1015 codec->dapm.bias_level = level;
1016 1017
1017 return 0; 1018 return 0;
1018} 1019}
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
index 2c10d77727af..058167c80d71 100644
--- a/sound/soc/codecs/rt5631.c
+++ b/sound/soc/codecs/rt5631.c
@@ -1546,7 +1546,7 @@ static int rt5631_set_bias_level(struct snd_soc_codec *codec,
1546 break; 1546 break;
1547 1547
1548 case SND_SOC_BIAS_STANDBY: 1548 case SND_SOC_BIAS_STANDBY:
1549 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1549 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1550 snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3, 1550 snd_soc_update_bits(codec, RT5631_PWR_MANAG_ADD3,
1551 RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS, 1551 RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
1552 RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS); 1552 RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
@@ -1569,7 +1569,6 @@ static int rt5631_set_bias_level(struct snd_soc_codec *codec,
1569 default: 1569 default:
1570 break; 1570 break;
1571 } 1571 }
1572 codec->dapm.bias_level = level;
1573 1572
1574 return 0; 1573 return 0;
1575} 1574}
@@ -1615,7 +1614,7 @@ static int rt5631_probe(struct snd_soc_codec *codec)
1615 RT5631_DMIC_R_CH_LATCH_RISING); 1614 RT5631_DMIC_R_CH_LATCH_RISING);
1616 } 1615 }
1617 1616
1618 codec->dapm.bias_level = SND_SOC_BIAS_STANDBY; 1617 snd_soc_codec_init_bias_level(codec, SND_SOC_BIAS_STANDBY);
1619 1618
1620 return 0; 1619 return 0;
1621} 1620}
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index 178e55d4d481..f40752a6c242 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -1870,7 +1870,7 @@ static int rt5640_set_bias_level(struct snd_soc_codec *codec,
1870{ 1870{
1871 switch (level) { 1871 switch (level) {
1872 case SND_SOC_BIAS_STANDBY: 1872 case SND_SOC_BIAS_STANDBY:
1873 if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) { 1873 if (SND_SOC_BIAS_OFF == snd_soc_codec_get_bias_level(codec)) {
1874 snd_soc_update_bits(codec, RT5640_PWR_ANLG1, 1874 snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
1875 RT5640_PWR_VREF1 | RT5640_PWR_MB | 1875 RT5640_PWR_VREF1 | RT5640_PWR_MB |
1876 RT5640_PWR_BG | RT5640_PWR_VREF2, 1876 RT5640_PWR_BG | RT5640_PWR_VREF2,
@@ -1902,7 +1902,6 @@ static int rt5640_set_bias_level(struct snd_soc_codec *codec,
1902 default: 1902 default:
1903 break; 1903 break;
1904 } 1904 }
1905 codec->dapm.bias_level = level;
1906 1905
1907 return 0; 1906 return 0;
1908} 1907}
@@ -1935,11 +1934,12 @@ EXPORT_SYMBOL_GPL(rt5640_dmic_enable);
1935 1934
1936static int rt5640_probe(struct snd_soc_codec *codec) 1935static int rt5640_probe(struct snd_soc_codec *codec)
1937{ 1936{
1937 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1938 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1938 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1939 1939
1940 rt5640->codec = codec; 1940 rt5640->codec = codec;
1941 1941
1942 rt5640_set_bias_level(codec, SND_SOC_BIAS_OFF); 1942 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
1943 1943
1944 snd_soc_update_bits(codec, RT5640_DUMMY1, 0x0301, 0x0301); 1944 snd_soc_update_bits(codec, RT5640_DUMMY1, 0x0301, 0x0301);
1945 snd_soc_update_bits(codec, RT5640_MICBIAS, 0x0030, 0x0030); 1945 snd_soc_update_bits(codec, RT5640_MICBIAS, 0x0030, 0x0030);
@@ -1951,18 +1951,18 @@ static int rt5640_probe(struct snd_soc_codec *codec)
1951 snd_soc_add_codec_controls(codec, 1951 snd_soc_add_codec_controls(codec,
1952 rt5640_specific_snd_controls, 1952 rt5640_specific_snd_controls,
1953 ARRAY_SIZE(rt5640_specific_snd_controls)); 1953 ARRAY_SIZE(rt5640_specific_snd_controls));
1954 snd_soc_dapm_new_controls(&codec->dapm, 1954 snd_soc_dapm_new_controls(dapm,
1955 rt5640_specific_dapm_widgets, 1955 rt5640_specific_dapm_widgets,
1956 ARRAY_SIZE(rt5640_specific_dapm_widgets)); 1956 ARRAY_SIZE(rt5640_specific_dapm_widgets));
1957 snd_soc_dapm_add_routes(&codec->dapm, 1957 snd_soc_dapm_add_routes(dapm,
1958 rt5640_specific_dapm_routes, 1958 rt5640_specific_dapm_routes,
1959 ARRAY_SIZE(rt5640_specific_dapm_routes)); 1959 ARRAY_SIZE(rt5640_specific_dapm_routes));
1960 break; 1960 break;
1961 case RT5640_ID_5639: 1961 case RT5640_ID_5639:
1962 snd_soc_dapm_new_controls(&codec->dapm, 1962 snd_soc_dapm_new_controls(dapm,
1963 rt5639_specific_dapm_widgets, 1963 rt5639_specific_dapm_widgets,
1964 ARRAY_SIZE(rt5639_specific_dapm_widgets)); 1964 ARRAY_SIZE(rt5639_specific_dapm_widgets));
1965 snd_soc_dapm_add_routes(&codec->dapm, 1965 snd_soc_dapm_add_routes(dapm,
1966 rt5639_specific_dapm_routes, 1966 rt5639_specific_dapm_routes,
1967 ARRAY_SIZE(rt5639_specific_dapm_routes)); 1967 ARRAY_SIZE(rt5639_specific_dapm_routes));
1968 break; 1968 break;
@@ -1991,7 +1991,7 @@ static int rt5640_suspend(struct snd_soc_codec *codec)
1991{ 1991{
1992 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1992 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1993 1993
1994 rt5640_set_bias_level(codec, SND_SOC_BIAS_OFF); 1994 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
1995 rt5640_reset(codec); 1995 rt5640_reset(codec);
1996 regcache_cache_only(rt5640->regmap, true); 1996 regcache_cache_only(rt5640->regmap, true);
1997 regcache_mark_dirty(rt5640->regmap); 1997 regcache_mark_dirty(rt5640->regmap);
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 69528ae5410c..d5f0f5680d3b 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -18,6 +18,9 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/spi/spi.h> 19#include <linux/spi/spi.h>
20#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/gpio/consumer.h>
22#include <linux/acpi.h>
23#include <linux/dmi.h>
21#include <sound/core.h> 24#include <sound/core.h>
22#include <sound/pcm.h> 25#include <sound/pcm.h>
23#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
@@ -414,9 +417,9 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg)
414} 417}
415 418
416static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); 419static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
417static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); 420static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
418static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); 421static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
419static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0); 422static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
420static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0); 423static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
421 424
422/* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */ 425/* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
@@ -431,30 +434,6 @@ static unsigned int bst_tlv[] = {
431 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0), 434 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0),
432}; 435};
433 436
434static const char * const rt5645_tdm_data_swap_select[] = {
435 "L/R", "R/L", "L/L", "R/R"
436};
437
438static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot0_1_enum,
439 RT5645_TDM_CTRL_1, 6, rt5645_tdm_data_swap_select);
440
441static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot2_3_enum,
442 RT5645_TDM_CTRL_1, 4, rt5645_tdm_data_swap_select);
443
444static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot4_5_enum,
445 RT5645_TDM_CTRL_1, 2, rt5645_tdm_data_swap_select);
446
447static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot6_7_enum,
448 RT5645_TDM_CTRL_1, 0, rt5645_tdm_data_swap_select);
449
450static const char * const rt5645_tdm_adc_data_select[] = {
451 "1/2/R", "2/1/R", "R/1/2", "R/2/1"
452};
453
454static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_sel_enum,
455 RT5645_TDM_CTRL_1, 8,
456 rt5645_tdm_adc_data_select);
457
458static const struct snd_kcontrol_new rt5645_snd_controls[] = { 437static const struct snd_kcontrol_new rt5645_snd_controls[] = {
459 /* Speaker Output Volume */ 438 /* Speaker Output Volume */
460 SOC_DOUBLE("Speaker Channel Switch", RT5645_SPK_VOL, 439 SOC_DOUBLE("Speaker Channel Switch", RT5645_SPK_VOL,
@@ -463,9 +442,9 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
463 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 39, 1, out_vol_tlv), 442 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 39, 1, out_vol_tlv),
464 443
465 /* Headphone Output Volume */ 444 /* Headphone Output Volume */
466 SOC_DOUBLE("HP Channel Switch", RT5645_HP_VOL, 445 SOC_DOUBLE("Headphone Channel Switch", RT5645_HP_VOL,
467 RT5645_VOL_L_SFT, RT5645_VOL_R_SFT, 1, 1), 446 RT5645_VOL_L_SFT, RT5645_VOL_R_SFT, 1, 1),
468 SOC_DOUBLE_TLV("HP Playback Volume", RT5645_HP_VOL, 447 SOC_DOUBLE_TLV("Headphone Playback Volume", RT5645_HP_VOL,
469 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 39, 1, out_vol_tlv), 448 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 39, 1, out_vol_tlv),
470 449
471 /* OUTPUT Control */ 450 /* OUTPUT Control */
@@ -480,9 +459,9 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
480 SOC_DOUBLE("DAC2 Playback Switch", RT5645_DAC_CTRL, 459 SOC_DOUBLE("DAC2 Playback Switch", RT5645_DAC_CTRL,
481 RT5645_M_DAC_L2_VOL_SFT, RT5645_M_DAC_R2_VOL_SFT, 1, 1), 460 RT5645_M_DAC_L2_VOL_SFT, RT5645_M_DAC_R2_VOL_SFT, 1, 1),
482 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5645_DAC1_DIG_VOL, 461 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5645_DAC1_DIG_VOL,
483 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 175, 0, dac_vol_tlv), 462 RT5645_L_VOL_SFT + 1, RT5645_R_VOL_SFT + 1, 87, 0, dac_vol_tlv),
484 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5645_DAC2_DIG_VOL, 463 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5645_DAC2_DIG_VOL,
485 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 175, 0, dac_vol_tlv), 464 RT5645_L_VOL_SFT + 1, RT5645_R_VOL_SFT + 1, 87, 0, dac_vol_tlv),
486 465
487 /* IN1/IN2 Control */ 466 /* IN1/IN2 Control */
488 SOC_SINGLE_TLV("IN1 Boost", RT5645_IN1_CTRL1, 467 SOC_SINGLE_TLV("IN1 Boost", RT5645_IN1_CTRL1,
@@ -498,11 +477,11 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
498 SOC_DOUBLE("ADC Capture Switch", RT5645_STO1_ADC_DIG_VOL, 477 SOC_DOUBLE("ADC Capture Switch", RT5645_STO1_ADC_DIG_VOL,
499 RT5645_L_MUTE_SFT, RT5645_R_MUTE_SFT, 1, 1), 478 RT5645_L_MUTE_SFT, RT5645_R_MUTE_SFT, 1, 1),
500 SOC_DOUBLE_TLV("ADC Capture Volume", RT5645_STO1_ADC_DIG_VOL, 479 SOC_DOUBLE_TLV("ADC Capture Volume", RT5645_STO1_ADC_DIG_VOL,
501 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 127, 0, adc_vol_tlv), 480 RT5645_L_VOL_SFT + 1, RT5645_R_VOL_SFT + 1, 63, 0, adc_vol_tlv),
502 SOC_DOUBLE("Mono ADC Capture Switch", RT5645_MONO_ADC_DIG_VOL, 481 SOC_DOUBLE("Mono ADC Capture Switch", RT5645_MONO_ADC_DIG_VOL,
503 RT5645_L_MUTE_SFT, RT5645_R_MUTE_SFT, 1, 1), 482 RT5645_L_MUTE_SFT, RT5645_R_MUTE_SFT, 1, 1),
504 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5645_MONO_ADC_DIG_VOL, 483 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5645_MONO_ADC_DIG_VOL,
505 RT5645_L_VOL_SFT, RT5645_R_VOL_SFT, 127, 0, adc_vol_tlv), 484 RT5645_L_VOL_SFT + 1, RT5645_R_VOL_SFT + 1, 63, 0, adc_vol_tlv),
506 485
507 /* ADC Boost Volume Control */ 486 /* ADC Boost Volume Control */
508 SOC_DOUBLE_TLV("STO1 ADC Boost Gain", RT5645_ADC_BST_VOL1, 487 SOC_DOUBLE_TLV("STO1 ADC Boost Gain", RT5645_ADC_BST_VOL1,
@@ -515,17 +494,6 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
515 /* I2S2 function select */ 494 /* I2S2 function select */
516 SOC_SINGLE("I2S2 Func Switch", RT5645_GPIO_CTRL1, RT5645_I2S2_SEL_SFT, 495 SOC_SINGLE("I2S2 Func Switch", RT5645_GPIO_CTRL1, RT5645_I2S2_SEL_SFT,
517 1, 1), 496 1, 1),
518
519 /* TDM */
520 SOC_ENUM("TDM Adc Slot0 1 Data", rt5645_tdm_adc_slot0_1_enum),
521 SOC_ENUM("TDM Adc Slot2 3 Data", rt5645_tdm_adc_slot2_3_enum),
522 SOC_ENUM("TDM Adc Slot4 5 Data", rt5645_tdm_adc_slot4_5_enum),
523 SOC_ENUM("TDM Adc Slot6 7 Data", rt5645_tdm_adc_slot6_7_enum),
524 SOC_ENUM("TDM IF1 ADC DATA Sel", rt5645_tdm_adc_sel_enum),
525 SOC_SINGLE("TDM IF1_DAC1_L Sel", RT5645_TDM_CTRL_3, 12, 7, 0),
526 SOC_SINGLE("TDM IF1_DAC1_R Sel", RT5645_TDM_CTRL_3, 8, 7, 0),
527 SOC_SINGLE("TDM IF1_DAC2_L Sel", RT5645_TDM_CTRL_3, 4, 7, 0),
528 SOC_SINGLE("TDM IF1_DAC2_R Sel", RT5645_TDM_CTRL_3, 0, 7, 0),
529}; 497};
530 498
531/** 499/**
@@ -1092,7 +1060,8 @@ static const struct snd_kcontrol_new rt5645_mono_adc_r2_mux =
1092 1060
1093/* MX-77 [9:8] */ 1061/* MX-77 [9:8] */
1094static const char * const rt5645_if1_adc_in_src[] = { 1062static const char * const rt5645_if1_adc_in_src[] = {
1095 "IF_ADC1", "IF_ADC2", "VAD_ADC" 1063 "IF_ADC1/IF_ADC2/VAD_ADC", "IF_ADC2/IF_ADC1/VAD_ADC",
1064 "VAD_ADC/IF_ADC1/IF_ADC2", "VAD_ADC/IF_ADC2/IF_ADC1"
1096}; 1065};
1097 1066
1098static SOC_ENUM_SINGLE_DECL( 1067static SOC_ENUM_SINGLE_DECL(
@@ -1102,6 +1071,140 @@ static SOC_ENUM_SINGLE_DECL(
1102static const struct snd_kcontrol_new rt5645_if1_adc_in_mux = 1071static const struct snd_kcontrol_new rt5645_if1_adc_in_mux =
1103 SOC_DAPM_ENUM("IF1 ADC IN source", rt5645_if1_adc_in_enum); 1072 SOC_DAPM_ENUM("IF1 ADC IN source", rt5645_if1_adc_in_enum);
1104 1073
1074/* MX-78 [4:0] */
1075static const char * const rt5650_if1_adc_in_src[] = {
1076 "IF_ADC1/IF_ADC2/DAC_REF/Null",
1077 "IF_ADC1/IF_ADC2/Null/DAC_REF",
1078 "IF_ADC1/DAC_REF/IF_ADC2/Null",
1079 "IF_ADC1/DAC_REF/Null/IF_ADC2",
1080 "IF_ADC1/Null/DAC_REF/IF_ADC2",
1081 "IF_ADC1/Null/IF_ADC2/DAC_REF",
1082
1083 "IF_ADC2/IF_ADC1/DAC_REF/Null",
1084 "IF_ADC2/IF_ADC1/Null/DAC_REF",
1085 "IF_ADC2/DAC_REF/IF_ADC1/Null",
1086 "IF_ADC2/DAC_REF/Null/IF_ADC1",
1087 "IF_ADC2/Null/DAC_REF/IF_ADC1",
1088 "IF_ADC2/Null/IF_ADC1/DAC_REF",
1089
1090 "DAC_REF/IF_ADC1/IF_ADC2/Null",
1091 "DAC_REF/IF_ADC1/Null/IF_ADC2",
1092 "DAC_REF/IF_ADC2/IF_ADC1/Null",
1093 "DAC_REF/IF_ADC2/Null/IF_ADC1",
1094 "DAC_REF/Null/IF_ADC1/IF_ADC2",
1095 "DAC_REF/Null/IF_ADC2/IF_ADC1",
1096
1097 "Null/IF_ADC1/IF_ADC2/DAC_REF",
1098 "Null/IF_ADC1/DAC_REF/IF_ADC2",
1099 "Null/IF_ADC2/IF_ADC1/DAC_REF",
1100 "Null/IF_ADC2/DAC_REF/IF_ADC1",
1101 "Null/DAC_REF/IF_ADC1/IF_ADC2",
1102 "Null/DAC_REF/IF_ADC2/IF_ADC1",
1103};
1104
1105static SOC_ENUM_SINGLE_DECL(
1106 rt5650_if1_adc_in_enum, RT5645_TDM_CTRL_2,
1107 0, rt5650_if1_adc_in_src);
1108
1109static const struct snd_kcontrol_new rt5650_if1_adc_in_mux =
1110 SOC_DAPM_ENUM("IF1 ADC IN source", rt5650_if1_adc_in_enum);
1111
1112/* MX-78 [15:14][13:12][11:10] */
1113static const char * const rt5645_tdm_adc_swap_select[] = {
1114 "L/R", "R/L", "L/L", "R/R"
1115};
1116
1117static SOC_ENUM_SINGLE_DECL(rt5650_tdm_adc_slot0_1_enum,
1118 RT5645_TDM_CTRL_2, 14, rt5645_tdm_adc_swap_select);
1119
1120static const struct snd_kcontrol_new rt5650_if1_adc1_in_mux =
1121 SOC_DAPM_ENUM("IF1 ADC1 IN source", rt5650_tdm_adc_slot0_1_enum);
1122
1123static SOC_ENUM_SINGLE_DECL(rt5650_tdm_adc_slot2_3_enum,
1124 RT5645_TDM_CTRL_2, 12, rt5645_tdm_adc_swap_select);
1125
1126static const struct snd_kcontrol_new rt5650_if1_adc2_in_mux =
1127 SOC_DAPM_ENUM("IF1 ADC2 IN source", rt5650_tdm_adc_slot2_3_enum);
1128
1129static SOC_ENUM_SINGLE_DECL(rt5650_tdm_adc_slot4_5_enum,
1130 RT5645_TDM_CTRL_2, 10, rt5645_tdm_adc_swap_select);
1131
1132static const struct snd_kcontrol_new rt5650_if1_adc3_in_mux =
1133 SOC_DAPM_ENUM("IF1 ADC3 IN source", rt5650_tdm_adc_slot4_5_enum);
1134
1135/* MX-77 [7:6][5:4][3:2] */
1136static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot0_1_enum,
1137 RT5645_TDM_CTRL_1, 6, rt5645_tdm_adc_swap_select);
1138
1139static const struct snd_kcontrol_new rt5645_if1_adc1_in_mux =
1140 SOC_DAPM_ENUM("IF1 ADC1 IN source", rt5645_tdm_adc_slot0_1_enum);
1141
1142static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot2_3_enum,
1143 RT5645_TDM_CTRL_1, 4, rt5645_tdm_adc_swap_select);
1144
1145static const struct snd_kcontrol_new rt5645_if1_adc2_in_mux =
1146 SOC_DAPM_ENUM("IF1 ADC2 IN source", rt5645_tdm_adc_slot2_3_enum);
1147
1148static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot4_5_enum,
1149 RT5645_TDM_CTRL_1, 2, rt5645_tdm_adc_swap_select);
1150
1151static const struct snd_kcontrol_new rt5645_if1_adc3_in_mux =
1152 SOC_DAPM_ENUM("IF1 ADC3 IN source", rt5645_tdm_adc_slot4_5_enum);
1153
1154/* MX-79 [14:12][10:8][6:4][2:0] */
1155static const char * const rt5645_tdm_dac_swap_select[] = {
1156 "Slot0", "Slot1", "Slot2", "Slot3"
1157};
1158
1159static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac0_enum,
1160 RT5645_TDM_CTRL_3, 12, rt5645_tdm_dac_swap_select);
1161
1162static const struct snd_kcontrol_new rt5645_if1_dac0_tdm_sel_mux =
1163 SOC_DAPM_ENUM("IF1 DAC0 source", rt5645_tdm_dac0_enum);
1164
1165static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac1_enum,
1166 RT5645_TDM_CTRL_3, 8, rt5645_tdm_dac_swap_select);
1167
1168static const struct snd_kcontrol_new rt5645_if1_dac1_tdm_sel_mux =
1169 SOC_DAPM_ENUM("IF1 DAC1 source", rt5645_tdm_dac1_enum);
1170
1171static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac2_enum,
1172 RT5645_TDM_CTRL_3, 4, rt5645_tdm_dac_swap_select);
1173
1174static const struct snd_kcontrol_new rt5645_if1_dac2_tdm_sel_mux =
1175 SOC_DAPM_ENUM("IF1 DAC2 source", rt5645_tdm_dac2_enum);
1176
1177static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac3_enum,
1178 RT5645_TDM_CTRL_3, 0, rt5645_tdm_dac_swap_select);
1179
1180static const struct snd_kcontrol_new rt5645_if1_dac3_tdm_sel_mux =
1181 SOC_DAPM_ENUM("IF1 DAC3 source", rt5645_tdm_dac3_enum);
1182
1183/* MX-7a [14:12][10:8][6:4][2:0] */
1184static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac0_enum,
1185 RT5650_TDM_CTRL_4, 12, rt5645_tdm_dac_swap_select);
1186
1187static const struct snd_kcontrol_new rt5650_if1_dac0_tdm_sel_mux =
1188 SOC_DAPM_ENUM("IF1 DAC0 source", rt5650_tdm_dac0_enum);
1189
1190static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac1_enum,
1191 RT5650_TDM_CTRL_4, 8, rt5645_tdm_dac_swap_select);
1192
1193static const struct snd_kcontrol_new rt5650_if1_dac1_tdm_sel_mux =
1194 SOC_DAPM_ENUM("IF1 DAC1 source", rt5650_tdm_dac1_enum);
1195
1196static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac2_enum,
1197 RT5650_TDM_CTRL_4, 4, rt5645_tdm_dac_swap_select);
1198
1199static const struct snd_kcontrol_new rt5650_if1_dac2_tdm_sel_mux =
1200 SOC_DAPM_ENUM("IF1 DAC2 source", rt5650_tdm_dac2_enum);
1201
1202static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac3_enum,
1203 RT5650_TDM_CTRL_4, 0, rt5645_tdm_dac_swap_select);
1204
1205static const struct snd_kcontrol_new rt5650_if1_dac3_tdm_sel_mux =
1206 SOC_DAPM_ENUM("IF1 DAC3 source", rt5650_tdm_dac3_enum);
1207
1105/* MX-2d [3] [2] */ 1208/* MX-2d [3] [2] */
1106static const char * const rt5650_a_dac1_src[] = { 1209static const char * const rt5650_a_dac1_src[] = {
1107 "DAC1", "Stereo DAC Mixer" 1210 "DAC1", "Stereo DAC Mixer"
@@ -1226,52 +1329,79 @@ static void hp_amp_power(struct snd_soc_codec *codec, int on)
1226 1329
1227 if (on) { 1330 if (on) {
1228 if (hp_amp_power_count <= 0) { 1331 if (hp_amp_power_count <= 0) {
1229 /* depop parameters */ 1332 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
1230 snd_soc_update_bits(codec, RT5645_DEPOP_M2, 1333 snd_soc_write(codec, RT5645_CHARGE_PUMP,
1231 RT5645_DEPOP_MASK, RT5645_DEPOP_MAN); 1334 0x0e06);
1232 snd_soc_write(codec, RT5645_DEPOP_M1, 0x000d); 1335 snd_soc_write(codec, RT5645_DEPOP_M1, 0x001d);
1233 regmap_write(rt5645->regmap, RT5645_PR_BASE + 1336 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1234 RT5645_HP_DCC_INT1, 0x9f01); 1337 0x3e, 0x7400);
1235 mdelay(150); 1338 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1236 /* headphone amp power on */ 1339 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1237 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 1340 RT5645_MAMP_INT_REG2, 0xfc00);
1238 RT5645_PWR_FV1 | RT5645_PWR_FV2 , 0); 1341 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1140);
1239 snd_soc_update_bits(codec, RT5645_PWR_VOL, 1342 } else {
1240 RT5645_PWR_HV_L | RT5645_PWR_HV_R, 1343 /* depop parameters */
1241 RT5645_PWR_HV_L | RT5645_PWR_HV_R); 1344 snd_soc_update_bits(codec, RT5645_DEPOP_M2,
1242 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 1345 RT5645_DEPOP_MASK, RT5645_DEPOP_MAN);
1243 RT5645_PWR_HP_L | RT5645_PWR_HP_R | 1346 snd_soc_write(codec, RT5645_DEPOP_M1, 0x000d);
1244 RT5645_PWR_HA, 1347 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1245 RT5645_PWR_HP_L | RT5645_PWR_HP_R | 1348 RT5645_HP_DCC_INT1, 0x9f01);
1246 RT5645_PWR_HA); 1349 mdelay(150);
1247 mdelay(5); 1350 /* headphone amp power on */
1248 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 1351 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
1249 RT5645_PWR_FV1 | RT5645_PWR_FV2, 1352 RT5645_PWR_FV1 | RT5645_PWR_FV2, 0);
1250 RT5645_PWR_FV1 | RT5645_PWR_FV2); 1353 snd_soc_update_bits(codec, RT5645_PWR_VOL,
1251 1354 RT5645_PWR_HV_L | RT5645_PWR_HV_R,
1252 snd_soc_update_bits(codec, RT5645_DEPOP_M1, 1355 RT5645_PWR_HV_L | RT5645_PWR_HV_R);
1253 RT5645_HP_CO_MASK | RT5645_HP_SG_MASK, 1356 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
1254 RT5645_HP_CO_EN | RT5645_HP_SG_EN); 1357 RT5645_PWR_HP_L | RT5645_PWR_HP_R |
1255 regmap_write(rt5645->regmap, RT5645_PR_BASE + 1358 RT5645_PWR_HA,
1256 0x14, 0x1aaa); 1359 RT5645_PWR_HP_L | RT5645_PWR_HP_R |
1257 regmap_write(rt5645->regmap, RT5645_PR_BASE + 1360 RT5645_PWR_HA);
1258 0x24, 0x0430); 1361 mdelay(5);
1362 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
1363 RT5645_PWR_FV1 | RT5645_PWR_FV2,
1364 RT5645_PWR_FV1 | RT5645_PWR_FV2);
1365
1366 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1367 RT5645_HP_CO_MASK | RT5645_HP_SG_MASK,
1368 RT5645_HP_CO_EN | RT5645_HP_SG_EN);
1369 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1370 0x14, 0x1aaa);
1371 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1372 0x24, 0x0430);
1373 }
1259 } 1374 }
1260 hp_amp_power_count++; 1375 hp_amp_power_count++;
1261 } else { 1376 } else {
1262 hp_amp_power_count--; 1377 hp_amp_power_count--;
1263 if (hp_amp_power_count <= 0) { 1378 if (hp_amp_power_count <= 0) {
1264 snd_soc_update_bits(codec, RT5645_DEPOP_M1, 1379 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
1265 RT5645_HP_SG_MASK | RT5645_HP_L_SMT_MASK | 1380 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1266 RT5645_HP_R_SMT_MASK, RT5645_HP_SG_DIS | 1381 0x3e, 0x7400);
1267 RT5645_HP_L_SMT_DIS | RT5645_HP_R_SMT_DIS); 1382 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1268 /* headphone amp power down */ 1383 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1269 snd_soc_write(codec, RT5645_DEPOP_M1, 0x0000); 1384 RT5645_MAMP_INT_REG2, 0xfc00);
1270 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 1385 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1140);
1271 RT5645_PWR_HP_L | RT5645_PWR_HP_R | 1386 msleep(100);
1272 RT5645_PWR_HA, 0); 1387 snd_soc_write(codec, RT5645_DEPOP_M1, 0x0001);
1273 snd_soc_update_bits(codec, RT5645_DEPOP_M2, 1388
1274 RT5645_DEPOP_MASK, 0); 1389 } else {
1390 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1391 RT5645_HP_SG_MASK |
1392 RT5645_HP_L_SMT_MASK |
1393 RT5645_HP_R_SMT_MASK,
1394 RT5645_HP_SG_DIS |
1395 RT5645_HP_L_SMT_DIS |
1396 RT5645_HP_R_SMT_DIS);
1397 /* headphone amp power down */
1398 snd_soc_write(codec, RT5645_DEPOP_M1, 0x0000);
1399 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
1400 RT5645_PWR_HP_L | RT5645_PWR_HP_R |
1401 RT5645_PWR_HA, 0);
1402 snd_soc_update_bits(codec, RT5645_DEPOP_M2,
1403 RT5645_DEPOP_MASK, 0);
1404 }
1275 } 1405 }
1276 } 1406 }
1277} 1407}
@@ -1286,56 +1416,52 @@ static int rt5645_hp_event(struct snd_soc_dapm_widget *w,
1286 case SND_SOC_DAPM_POST_PMU: 1416 case SND_SOC_DAPM_POST_PMU:
1287 hp_amp_power(codec, 1); 1417 hp_amp_power(codec, 1);
1288 /* headphone unmute sequence */ 1418 /* headphone unmute sequence */
1289 if (rt5645->codec_type == CODEC_TYPE_RT5650) { 1419 if (rt5645->codec_type == CODEC_TYPE_RT5645) {
1290 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1291 } else {
1292 snd_soc_update_bits(codec, RT5645_DEPOP_M3, 1420 snd_soc_update_bits(codec, RT5645_DEPOP_M3,
1293 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK | 1421 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK |
1294 RT5645_CP_FQ3_MASK, 1422 RT5645_CP_FQ3_MASK,
1295 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ1_SFT) | 1423 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ1_SFT) |
1296 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) | 1424 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) |
1297 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ3_SFT)); 1425 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ3_SFT));
1426 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1427 RT5645_MAMP_INT_REG2, 0xfc00);
1428 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1429 RT5645_SMT_TRIG_MASK, RT5645_SMT_TRIG_EN);
1430 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1431 RT5645_RSTN_MASK, RT5645_RSTN_EN);
1432 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1433 RT5645_RSTN_MASK | RT5645_HP_L_SMT_MASK |
1434 RT5645_HP_R_SMT_MASK, RT5645_RSTN_DIS |
1435 RT5645_HP_L_SMT_EN | RT5645_HP_R_SMT_EN);
1436 msleep(40);
1437 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1438 RT5645_HP_SG_MASK | RT5645_HP_L_SMT_MASK |
1439 RT5645_HP_R_SMT_MASK, RT5645_HP_SG_DIS |
1440 RT5645_HP_L_SMT_DIS | RT5645_HP_R_SMT_DIS);
1298 } 1441 }
1299 regmap_write(rt5645->regmap,
1300 RT5645_PR_BASE + RT5645_MAMP_INT_REG2, 0xfc00);
1301 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1302 RT5645_SMT_TRIG_MASK, RT5645_SMT_TRIG_EN);
1303 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1304 RT5645_RSTN_MASK, RT5645_RSTN_EN);
1305 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1306 RT5645_RSTN_MASK | RT5645_HP_L_SMT_MASK |
1307 RT5645_HP_R_SMT_MASK, RT5645_RSTN_DIS |
1308 RT5645_HP_L_SMT_EN | RT5645_HP_R_SMT_EN);
1309 msleep(40);
1310 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1311 RT5645_HP_SG_MASK | RT5645_HP_L_SMT_MASK |
1312 RT5645_HP_R_SMT_MASK, RT5645_HP_SG_DIS |
1313 RT5645_HP_L_SMT_DIS | RT5645_HP_R_SMT_DIS);
1314 break; 1442 break;
1315 1443
1316 case SND_SOC_DAPM_PRE_PMD: 1444 case SND_SOC_DAPM_PRE_PMD:
1317 /* headphone mute sequence */ 1445 /* headphone mute sequence */
1318 if (rt5645->codec_type == CODEC_TYPE_RT5650) { 1446 if (rt5645->codec_type == CODEC_TYPE_RT5645) {
1319 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1320 } else {
1321 snd_soc_update_bits(codec, RT5645_DEPOP_M3, 1447 snd_soc_update_bits(codec, RT5645_DEPOP_M3,
1322 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK | 1448 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK |
1323 RT5645_CP_FQ3_MASK, 1449 RT5645_CP_FQ3_MASK,
1324 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ1_SFT) | 1450 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ1_SFT) |
1325 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) | 1451 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) |
1326 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ3_SFT)); 1452 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ3_SFT));
1453 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1454 RT5645_MAMP_INT_REG2, 0xfc00);
1455 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1456 RT5645_HP_SG_MASK, RT5645_HP_SG_EN);
1457 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1458 RT5645_RSTP_MASK, RT5645_RSTP_EN);
1459 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1460 RT5645_RSTP_MASK | RT5645_HP_L_SMT_MASK |
1461 RT5645_HP_R_SMT_MASK, RT5645_RSTP_DIS |
1462 RT5645_HP_L_SMT_EN | RT5645_HP_R_SMT_EN);
1463 msleep(30);
1327 } 1464 }
1328 regmap_write(rt5645->regmap,
1329 RT5645_PR_BASE + RT5645_MAMP_INT_REG2, 0xfc00);
1330 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1331 RT5645_HP_SG_MASK, RT5645_HP_SG_EN);
1332 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1333 RT5645_RSTP_MASK, RT5645_RSTP_EN);
1334 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1335 RT5645_RSTP_MASK | RT5645_HP_L_SMT_MASK |
1336 RT5645_HP_R_SMT_MASK, RT5645_RSTP_DIS |
1337 RT5645_HP_L_SMT_EN | RT5645_HP_R_SMT_EN);
1338 msleep(30);
1339 hp_amp_power(codec, 0); 1465 hp_amp_power(codec, 0);
1340 break; 1466 break;
1341 1467
@@ -1570,20 +1696,50 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1570 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0), 1696 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0),
1571 1697
1572 /* IF1 2 Mux */ 1698 /* IF1 2 Mux */
1573 SND_SOC_DAPM_MUX("IF1 ADC Mux", SND_SOC_NOPM, 1699 SND_SOC_DAPM_MUX("RT5645 IF1 ADC1 Swap Mux", SND_SOC_NOPM,
1700 0, 0, &rt5645_if1_adc1_in_mux),
1701 SND_SOC_DAPM_MUX("RT5645 IF1 ADC2 Swap Mux", SND_SOC_NOPM,
1702 0, 0, &rt5645_if1_adc2_in_mux),
1703 SND_SOC_DAPM_MUX("RT5645 IF1 ADC3 Swap Mux", SND_SOC_NOPM,
1704 0, 0, &rt5645_if1_adc3_in_mux),
1705 SND_SOC_DAPM_MUX("RT5645 IF1 ADC Mux", SND_SOC_NOPM,
1574 0, 0, &rt5645_if1_adc_in_mux), 1706 0, 0, &rt5645_if1_adc_in_mux),
1707
1708 SND_SOC_DAPM_MUX("RT5650 IF1 ADC1 Swap Mux", SND_SOC_NOPM,
1709 0, 0, &rt5650_if1_adc1_in_mux),
1710 SND_SOC_DAPM_MUX("RT5650 IF1 ADC2 Swap Mux", SND_SOC_NOPM,
1711 0, 0, &rt5650_if1_adc2_in_mux),
1712 SND_SOC_DAPM_MUX("RT5650 IF1 ADC3 Swap Mux", SND_SOC_NOPM,
1713 0, 0, &rt5650_if1_adc3_in_mux),
1714 SND_SOC_DAPM_MUX("RT5650 IF1 ADC Mux", SND_SOC_NOPM,
1715 0, 0, &rt5650_if1_adc_in_mux),
1716
1575 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM, 1717 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM,
1576 0, 0, &rt5645_if2_adc_in_mux), 1718 0, 0, &rt5645_if2_adc_in_mux),
1577 1719
1578 /* Digital Interface */ 1720 /* Digital Interface */
1579 SND_SOC_DAPM_SUPPLY("I2S1", RT5645_PWR_DIG1, 1721 SND_SOC_DAPM_SUPPLY("I2S1", RT5645_PWR_DIG1,
1580 RT5645_PWR_I2S1_BIT, 0, NULL, 0), 1722 RT5645_PWR_I2S1_BIT, 0, NULL, 0),
1723 SND_SOC_DAPM_PGA("IF1 DAC0", SND_SOC_NOPM, 0, 0, NULL, 0),
1581 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0), 1724 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0),
1582 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM, 0, 0, NULL, 0), 1725 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM, 0, 0, NULL, 0),
1583 SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0), 1726 SND_SOC_DAPM_PGA("IF1 DAC3", SND_SOC_NOPM, 0, 0, NULL, 0),
1584 SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0), 1727 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 L Mux", SND_SOC_NOPM, 0, 0,
1585 SND_SOC_DAPM_PGA("IF1 DAC2 L", SND_SOC_NOPM, 0, 0, NULL, 0), 1728 &rt5645_if1_dac0_tdm_sel_mux),
1586 SND_SOC_DAPM_PGA("IF1 DAC2 R", SND_SOC_NOPM, 0, 0, NULL, 0), 1729 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 R Mux", SND_SOC_NOPM, 0, 0,
1730 &rt5645_if1_dac1_tdm_sel_mux),
1731 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 L Mux", SND_SOC_NOPM, 0, 0,
1732 &rt5645_if1_dac2_tdm_sel_mux),
1733 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0,
1734 &rt5645_if1_dac3_tdm_sel_mux),
1735 SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 L Mux", SND_SOC_NOPM, 0, 0,
1736 &rt5650_if1_dac0_tdm_sel_mux),
1737 SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 R Mux", SND_SOC_NOPM, 0, 0,
1738 &rt5650_if1_dac1_tdm_sel_mux),
1739 SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 L Mux", SND_SOC_NOPM, 0, 0,
1740 &rt5650_if1_dac2_tdm_sel_mux),
1741 SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0,
1742 &rt5650_if1_dac3_tdm_sel_mux),
1587 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 1743 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
1588 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0), 1744 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1589 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0), 1745 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -1847,42 +2003,32 @@ static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1847 { "IF_ADC2", NULL, "Mono ADC MIXR" }, 2003 { "IF_ADC2", NULL, "Mono ADC MIXR" },
1848 { "VAD_ADC", NULL, "VAD ADC Mux" }, 2004 { "VAD_ADC", NULL, "VAD ADC Mux" },
1849 2005
1850 { "IF1 ADC Mux", "IF_ADC1", "IF_ADC1" },
1851 { "IF1 ADC Mux", "IF_ADC2", "IF_ADC2" },
1852 { "IF1 ADC Mux", "VAD_ADC", "VAD_ADC" },
1853
1854 { "IF2 ADC Mux", "IF_ADC1", "IF_ADC1" }, 2006 { "IF2 ADC Mux", "IF_ADC1", "IF_ADC1" },
1855 { "IF2 ADC Mux", "IF_ADC2", "IF_ADC2" }, 2007 { "IF2 ADC Mux", "IF_ADC2", "IF_ADC2" },
1856 { "IF2 ADC Mux", "VAD_ADC", "VAD_ADC" }, 2008 { "IF2 ADC Mux", "VAD_ADC", "VAD_ADC" },
1857 2009
1858 { "IF1 ADC", NULL, "I2S1" }, 2010 { "IF1 ADC", NULL, "I2S1" },
1859 { "IF1 ADC", NULL, "IF1 ADC Mux" },
1860 { "IF2 ADC", NULL, "I2S2" }, 2011 { "IF2 ADC", NULL, "I2S2" },
1861 { "IF2 ADC", NULL, "IF2 ADC Mux" }, 2012 { "IF2 ADC", NULL, "IF2 ADC Mux" },
1862 2013
1863 { "AIF1TX", NULL, "IF1 ADC" },
1864 { "AIF1TX", NULL, "IF2 ADC" },
1865 { "AIF2TX", NULL, "IF2 ADC" }, 2014 { "AIF2TX", NULL, "IF2 ADC" },
1866 2015
2016 { "IF1 DAC0", NULL, "AIF1RX" },
1867 { "IF1 DAC1", NULL, "AIF1RX" }, 2017 { "IF1 DAC1", NULL, "AIF1RX" },
1868 { "IF1 DAC2", NULL, "AIF1RX" }, 2018 { "IF1 DAC2", NULL, "AIF1RX" },
2019 { "IF1 DAC3", NULL, "AIF1RX" },
1869 { "IF2 DAC", NULL, "AIF2RX" }, 2020 { "IF2 DAC", NULL, "AIF2RX" },
1870 2021
2022 { "IF1 DAC0", NULL, "I2S1" },
1871 { "IF1 DAC1", NULL, "I2S1" }, 2023 { "IF1 DAC1", NULL, "I2S1" },
1872 { "IF1 DAC2", NULL, "I2S1" }, 2024 { "IF1 DAC2", NULL, "I2S1" },
2025 { "IF1 DAC3", NULL, "I2S1" },
1873 { "IF2 DAC", NULL, "I2S2" }, 2026 { "IF2 DAC", NULL, "I2S2" },
1874 2027
1875 { "IF1 DAC2 L", NULL, "IF1 DAC2" },
1876 { "IF1 DAC2 R", NULL, "IF1 DAC2" },
1877 { "IF1 DAC1 L", NULL, "IF1 DAC1" },
1878 { "IF1 DAC1 R", NULL, "IF1 DAC1" },
1879 { "IF2 DAC L", NULL, "IF2 DAC" }, 2028 { "IF2 DAC L", NULL, "IF2 DAC" },
1880 { "IF2 DAC R", NULL, "IF2 DAC" }, 2029 { "IF2 DAC R", NULL, "IF2 DAC" },
1881 2030
1882 { "DAC1 L Mux", "IF1 DAC", "IF1 DAC1 L" },
1883 { "DAC1 L Mux", "IF2 DAC", "IF2 DAC L" }, 2031 { "DAC1 L Mux", "IF2 DAC", "IF2 DAC L" },
1884
1885 { "DAC1 R Mux", "IF1 DAC", "IF1 DAC1 R" },
1886 { "DAC1 R Mux", "IF2 DAC", "IF2 DAC R" }, 2032 { "DAC1 R Mux", "IF2 DAC", "IF2 DAC R" },
1887 2033
1888 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" }, 2034 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" },
@@ -1892,14 +2038,12 @@ static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1892 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" }, 2038 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" },
1893 { "DAC1 MIXR", NULL, "dac stereo1 filter" }, 2039 { "DAC1 MIXR", NULL, "dac stereo1 filter" },
1894 2040
1895 { "DAC L2 Mux", "IF1 DAC", "IF1 DAC2 L" },
1896 { "DAC L2 Mux", "IF2 DAC", "IF2 DAC L" }, 2041 { "DAC L2 Mux", "IF2 DAC", "IF2 DAC L" },
1897 { "DAC L2 Mux", "Mono ADC", "Mono ADC MIXL" }, 2042 { "DAC L2 Mux", "Mono ADC", "Mono ADC MIXL" },
1898 { "DAC L2 Mux", "VAD_ADC", "VAD_ADC" }, 2043 { "DAC L2 Mux", "VAD_ADC", "VAD_ADC" },
1899 { "DAC L2 Volume", NULL, "DAC L2 Mux" }, 2044 { "DAC L2 Volume", NULL, "DAC L2 Mux" },
1900 { "DAC L2 Volume", NULL, "dac mono left filter" }, 2045 { "DAC L2 Volume", NULL, "dac mono left filter" },
1901 2046
1902 { "DAC R2 Mux", "IF1 DAC", "IF1 DAC2 R" },
1903 { "DAC R2 Mux", "IF2 DAC", "IF2 DAC R" }, 2047 { "DAC R2 Mux", "IF2 DAC", "IF2 DAC R" },
1904 { "DAC R2 Mux", "Mono ADC", "Mono ADC MIXR" }, 2048 { "DAC R2 Mux", "Mono ADC", "Mono ADC MIXR" },
1905 { "DAC R2 Mux", "Haptic", "Haptic Generator" }, 2049 { "DAC R2 Mux", "Haptic", "Haptic Generator" },
@@ -2037,6 +2181,80 @@ static const struct snd_soc_dapm_route rt5650_specific_dapm_routes[] = {
2037 { "DAC R1", NULL, "A DAC1 R Mux" }, 2181 { "DAC R1", NULL, "A DAC1 R Mux" },
2038 { "DAC L2", NULL, "A DAC2 L Mux" }, 2182 { "DAC L2", NULL, "A DAC2 L Mux" },
2039 { "DAC R2", NULL, "A DAC2 R Mux" }, 2183 { "DAC R2", NULL, "A DAC2 R Mux" },
2184
2185 { "RT5650 IF1 ADC1 Swap Mux", "L/R", "IF_ADC1" },
2186 { "RT5650 IF1 ADC1 Swap Mux", "R/L", "IF_ADC1" },
2187 { "RT5650 IF1 ADC1 Swap Mux", "L/L", "IF_ADC1" },
2188 { "RT5650 IF1 ADC1 Swap Mux", "R/R", "IF_ADC1" },
2189
2190 { "RT5650 IF1 ADC2 Swap Mux", "L/R", "IF_ADC2" },
2191 { "RT5650 IF1 ADC2 Swap Mux", "R/L", "IF_ADC2" },
2192 { "RT5650 IF1 ADC2 Swap Mux", "L/L", "IF_ADC2" },
2193 { "RT5650 IF1 ADC2 Swap Mux", "R/R", "IF_ADC2" },
2194
2195 { "RT5650 IF1 ADC3 Swap Mux", "L/R", "VAD_ADC" },
2196 { "RT5650 IF1 ADC3 Swap Mux", "R/L", "VAD_ADC" },
2197 { "RT5650 IF1 ADC3 Swap Mux", "L/L", "VAD_ADC" },
2198 { "RT5650 IF1 ADC3 Swap Mux", "R/R", "VAD_ADC" },
2199
2200 { "IF1 ADC", NULL, "RT5650 IF1 ADC1 Swap Mux" },
2201 { "IF1 ADC", NULL, "RT5650 IF1 ADC2 Swap Mux" },
2202 { "IF1 ADC", NULL, "RT5650 IF1 ADC3 Swap Mux" },
2203
2204 { "RT5650 IF1 ADC Mux", "IF_ADC1/IF_ADC2/DAC_REF/Null", "IF1 ADC" },
2205 { "RT5650 IF1 ADC Mux", "IF_ADC1/IF_ADC2/Null/DAC_REF", "IF1 ADC" },
2206 { "RT5650 IF1 ADC Mux", "IF_ADC1/DAC_REF/IF_ADC2/Null", "IF1 ADC" },
2207 { "RT5650 IF1 ADC Mux", "IF_ADC1/DAC_REF/Null/IF_ADC2", "IF1 ADC" },
2208 { "RT5650 IF1 ADC Mux", "IF_ADC1/Null/DAC_REF/IF_ADC2", "IF1 ADC" },
2209 { "RT5650 IF1 ADC Mux", "IF_ADC1/Null/IF_ADC2/DAC_REF", "IF1 ADC" },
2210
2211 { "RT5650 IF1 ADC Mux", "IF_ADC2/IF_ADC1/DAC_REF/Null", "IF1 ADC" },
2212 { "RT5650 IF1 ADC Mux", "IF_ADC2/IF_ADC1/Null/DAC_REF", "IF1 ADC" },
2213 { "RT5650 IF1 ADC Mux", "IF_ADC2/DAC_REF/IF_ADC1/Null", "IF1 ADC" },
2214 { "RT5650 IF1 ADC Mux", "IF_ADC2/DAC_REF/Null/IF_ADC1", "IF1 ADC" },
2215 { "RT5650 IF1 ADC Mux", "IF_ADC2/Null/DAC_REF/IF_ADC1", "IF1 ADC" },
2216 { "RT5650 IF1 ADC Mux", "IF_ADC2/Null/IF_ADC1/DAC_REF", "IF1 ADC" },
2217
2218 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC1/IF_ADC2/Null", "IF1 ADC" },
2219 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC1/Null/IF_ADC2", "IF1 ADC" },
2220 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC2/IF_ADC1/Null", "IF1 ADC" },
2221 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC2/Null/IF_ADC1", "IF1 ADC" },
2222 { "RT5650 IF1 ADC Mux", "DAC_REF/Null/IF_ADC1/IF_ADC2", "IF1 ADC" },
2223 { "RT5650 IF1 ADC Mux", "DAC_REF/Null/IF_ADC2/IF_ADC1", "IF1 ADC" },
2224
2225 { "RT5650 IF1 ADC Mux", "Null/IF_ADC1/IF_ADC2/DAC_REF", "IF1 ADC" },
2226 { "RT5650 IF1 ADC Mux", "Null/IF_ADC1/DAC_REF/IF_ADC2", "IF1 ADC" },
2227 { "RT5650 IF1 ADC Mux", "Null/IF_ADC2/IF_ADC1/DAC_REF", "IF1 ADC" },
2228 { "RT5650 IF1 ADC Mux", "Null/IF_ADC2/DAC_REF/IF_ADC1", "IF1 ADC" },
2229 { "RT5650 IF1 ADC Mux", "Null/DAC_REF/IF_ADC1/IF_ADC2", "IF1 ADC" },
2230 { "RT5650 IF1 ADC Mux", "Null/DAC_REF/IF_ADC2/IF_ADC1", "IF1 ADC" },
2231 { "AIF1TX", NULL, "RT5650 IF1 ADC Mux" },
2232
2233 { "RT5650 IF1 DAC1 L Mux", "Slot0", "IF1 DAC0" },
2234 { "RT5650 IF1 DAC1 L Mux", "Slot1", "IF1 DAC1" },
2235 { "RT5650 IF1 DAC1 L Mux", "Slot2", "IF1 DAC2" },
2236 { "RT5650 IF1 DAC1 L Mux", "Slot3", "IF1 DAC3" },
2237
2238 { "RT5650 IF1 DAC1 R Mux", "Slot0", "IF1 DAC0" },
2239 { "RT5650 IF1 DAC1 R Mux", "Slot1", "IF1 DAC1" },
2240 { "RT5650 IF1 DAC1 R Mux", "Slot2", "IF1 DAC2" },
2241 { "RT5650 IF1 DAC1 R Mux", "Slot3", "IF1 DAC3" },
2242
2243 { "RT5650 IF1 DAC2 L Mux", "Slot0", "IF1 DAC0" },
2244 { "RT5650 IF1 DAC2 L Mux", "Slot1", "IF1 DAC1" },
2245 { "RT5650 IF1 DAC2 L Mux", "Slot2", "IF1 DAC2" },
2246 { "RT5650 IF1 DAC2 L Mux", "Slot3", "IF1 DAC3" },
2247
2248 { "RT5650 IF1 DAC2 R Mux", "Slot0", "IF1 DAC0" },
2249 { "RT5650 IF1 DAC2 R Mux", "Slot1", "IF1 DAC1" },
2250 { "RT5650 IF1 DAC2 R Mux", "Slot2", "IF1 DAC2" },
2251 { "RT5650 IF1 DAC2 R Mux", "Slot3", "IF1 DAC3" },
2252
2253 { "DAC1 L Mux", "IF1 DAC", "RT5650 IF1 DAC1 L Mux" },
2254 { "DAC1 R Mux", "IF1 DAC", "RT5650 IF1 DAC1 R Mux" },
2255
2256 { "DAC L2 Mux", "IF1 DAC", "RT5650 IF1 DAC2 L Mux" },
2257 { "DAC R2 Mux", "IF1 DAC", "RT5650 IF1 DAC2 R Mux" },
2040}; 2258};
2041 2259
2042static const struct snd_soc_dapm_route rt5645_specific_dapm_routes[] = { 2260static const struct snd_soc_dapm_route rt5645_specific_dapm_routes[] = {
@@ -2044,6 +2262,57 @@ static const struct snd_soc_dapm_route rt5645_specific_dapm_routes[] = {
2044 { "DAC R1", NULL, "Stereo DAC MIXR" }, 2262 { "DAC R1", NULL, "Stereo DAC MIXR" },
2045 { "DAC L2", NULL, "Mono DAC MIXL" }, 2263 { "DAC L2", NULL, "Mono DAC MIXL" },
2046 { "DAC R2", NULL, "Mono DAC MIXR" }, 2264 { "DAC R2", NULL, "Mono DAC MIXR" },
2265
2266 { "RT5645 IF1 ADC1 Swap Mux", "L/R", "IF_ADC1" },
2267 { "RT5645 IF1 ADC1 Swap Mux", "R/L", "IF_ADC1" },
2268 { "RT5645 IF1 ADC1 Swap Mux", "L/L", "IF_ADC1" },
2269 { "RT5645 IF1 ADC1 Swap Mux", "R/R", "IF_ADC1" },
2270
2271 { "RT5645 IF1 ADC2 Swap Mux", "L/R", "IF_ADC2" },
2272 { "RT5645 IF1 ADC2 Swap Mux", "R/L", "IF_ADC2" },
2273 { "RT5645 IF1 ADC2 Swap Mux", "L/L", "IF_ADC2" },
2274 { "RT5645 IF1 ADC2 Swap Mux", "R/R", "IF_ADC2" },
2275
2276 { "RT5645 IF1 ADC3 Swap Mux", "L/R", "VAD_ADC" },
2277 { "RT5645 IF1 ADC3 Swap Mux", "R/L", "VAD_ADC" },
2278 { "RT5645 IF1 ADC3 Swap Mux", "L/L", "VAD_ADC" },
2279 { "RT5645 IF1 ADC3 Swap Mux", "R/R", "VAD_ADC" },
2280
2281 { "IF1 ADC", NULL, "RT5645 IF1 ADC1 Swap Mux" },
2282 { "IF1 ADC", NULL, "RT5645 IF1 ADC2 Swap Mux" },
2283 { "IF1 ADC", NULL, "RT5645 IF1 ADC3 Swap Mux" },
2284
2285 { "RT5645 IF1 ADC Mux", "IF_ADC1/IF_ADC2/VAD_ADC", "IF1 ADC" },
2286 { "RT5645 IF1 ADC Mux", "IF_ADC2/IF_ADC1/VAD_ADC", "IF1 ADC" },
2287 { "RT5645 IF1 ADC Mux", "VAD_ADC/IF_ADC1/IF_ADC2", "IF1 ADC" },
2288 { "RT5645 IF1 ADC Mux", "VAD_ADC/IF_ADC2/IF_ADC1", "IF1 ADC" },
2289 { "AIF1TX", NULL, "RT5645 IF1 ADC Mux" },
2290
2291 { "RT5645 IF1 DAC1 L Mux", "Slot0", "IF1 DAC0" },
2292 { "RT5645 IF1 DAC1 L Mux", "Slot1", "IF1 DAC1" },
2293 { "RT5645 IF1 DAC1 L Mux", "Slot2", "IF1 DAC2" },
2294 { "RT5645 IF1 DAC1 L Mux", "Slot3", "IF1 DAC3" },
2295
2296 { "RT5645 IF1 DAC1 R Mux", "Slot0", "IF1 DAC0" },
2297 { "RT5645 IF1 DAC1 R Mux", "Slot1", "IF1 DAC1" },
2298 { "RT5645 IF1 DAC1 R Mux", "Slot2", "IF1 DAC2" },
2299 { "RT5645 IF1 DAC1 R Mux", "Slot3", "IF1 DAC3" },
2300
2301 { "RT5645 IF1 DAC2 L Mux", "Slot0", "IF1 DAC0" },
2302 { "RT5645 IF1 DAC2 L Mux", "Slot1", "IF1 DAC1" },
2303 { "RT5645 IF1 DAC2 L Mux", "Slot2", "IF1 DAC2" },
2304 { "RT5645 IF1 DAC2 L Mux", "Slot3", "IF1 DAC3" },
2305
2306 { "RT5645 IF1 DAC2 R Mux", "Slot0", "IF1 DAC0" },
2307 { "RT5645 IF1 DAC2 R Mux", "Slot1", "IF1 DAC1" },
2308 { "RT5645 IF1 DAC2 R Mux", "Slot2", "IF1 DAC2" },
2309 { "RT5645 IF1 DAC2 R Mux", "Slot3", "IF1 DAC3" },
2310
2311 { "DAC1 L Mux", "IF1 DAC", "RT5645 IF1 DAC1 L Mux" },
2312 { "DAC1 R Mux", "IF1 DAC", "RT5645 IF1 DAC1 R Mux" },
2313
2314 { "DAC L2 Mux", "IF1 DAC", "RT5645 IF1 DAC2 L Mux" },
2315 { "DAC R2 Mux", "IF1 DAC", "RT5645 IF1 DAC2 R Mux" },
2047}; 2316};
2048 2317
2049static int rt5645_hw_params(struct snd_pcm_substream *substream, 2318static int rt5645_hw_params(struct snd_pcm_substream *substream,
@@ -2101,9 +2370,8 @@ static int rt5645_hw_params(struct snd_pcm_substream *substream,
2101 2370
2102 switch (dai->id) { 2371 switch (dai->id) {
2103 case RT5645_AIF1: 2372 case RT5645_AIF1:
2104 mask_clk = RT5645_I2S_BCLK_MS1_MASK | RT5645_I2S_PD1_MASK; 2373 mask_clk = RT5645_I2S_PD1_MASK;
2105 val_clk = bclk_ms << RT5645_I2S_BCLK_MS1_SFT | 2374 val_clk = pre_div << RT5645_I2S_PD1_SFT;
2106 pre_div << RT5645_I2S_PD1_SFT;
2107 snd_soc_update_bits(codec, RT5645_I2S1_SDP, 2375 snd_soc_update_bits(codec, RT5645_I2S1_SDP,
2108 (0x3 << dl_sft), (val_len << dl_sft)); 2376 (0x3 << dl_sft), (val_len << dl_sft));
2109 snd_soc_update_bits(codec, RT5645_ADDA_CLK1, mask_clk, val_clk); 2377 snd_soc_update_bits(codec, RT5645_ADDA_CLK1, mask_clk, val_clk);
@@ -2368,6 +2636,8 @@ static int rt5645_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
2368static int rt5645_set_bias_level(struct snd_soc_codec *codec, 2636static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2369 enum snd_soc_bias_level level) 2637 enum snd_soc_bias_level level)
2370{ 2638{
2639 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2640
2371 switch (level) { 2641 switch (level) {
2372 case SND_SOC_BIAS_PREPARE: 2642 case SND_SOC_BIAS_PREPARE:
2373 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 2643 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) {
@@ -2398,8 +2668,9 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2398 2668
2399 case SND_SOC_BIAS_OFF: 2669 case SND_SOC_BIAS_OFF:
2400 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1100); 2670 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1100);
2401 snd_soc_update_bits(codec, RT5645_GEN_CTRL1, 2671 if (!rt5645->en_button_func)
2402 RT5645_DIG_GATE_CTRL, 0); 2672 snd_soc_update_bits(codec, RT5645_GEN_CTRL1,
2673 RT5645_DIG_GATE_CTRL, 0);
2403 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 2674 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
2404 RT5645_PWR_VREF1 | RT5645_PWR_MB | 2675 RT5645_PWR_VREF1 | RT5645_PWR_MB |
2405 RT5645_PWR_BG | RT5645_PWR_VREF2 | 2676 RT5645_PWR_BG | RT5645_PWR_VREF2 |
@@ -2409,72 +2680,222 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2409 default: 2680 default:
2410 break; 2681 break;
2411 } 2682 }
2412 codec->dapm.bias_level = level;
2413 2683
2414 return 0; 2684 return 0;
2415} 2685}
2416 2686
2417static int rt5645_jack_detect(struct snd_soc_codec *codec) 2687static int rt5650_calibration(struct rt5645_priv *rt5645)
2418{ 2688{
2419 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 2689 int val, i;
2420 int gpio_state, jack_type = 0; 2690 int ret = -1;
2421 unsigned int val;
2422 2691
2423 if (!gpio_is_valid(rt5645->pdata.hp_det_gpio)) { 2692 regcache_cache_bypass(rt5645->regmap, true);
2424 dev_err(codec->dev, "invalid gpio\n"); 2693 regmap_write(rt5645->regmap, RT5645_RESET, 0);
2425 return -EINVAL; 2694 regmap_write(rt5645->regmap, RT5645_GEN_CTRL3, 0x0800);
2695 regmap_write(rt5645->regmap, RT5645_PR_BASE + RT5645_CHOP_DAC_ADC,
2696 0x3600);
2697 regmap_write(rt5645->regmap, RT5645_PR_BASE + 0x25, 0x7000);
2698 regmap_write(rt5645->regmap, RT5645_I2S1_SDP, 0x8008);
2699 /* headset type */
2700 regmap_write(rt5645->regmap, RT5645_GEN_CTRL1, 0x2061);
2701 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0006);
2702 regmap_write(rt5645->regmap, RT5645_PWR_ANLG1, 0x2012);
2703 regmap_write(rt5645->regmap, RT5645_PWR_MIXER, 0x0002);
2704 regmap_write(rt5645->regmap, RT5645_PWR_VOL, 0x0020);
2705 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0);
2706 regmap_write(rt5645->regmap, RT5645_IN1_CTRL1, 0x0006);
2707 regmap_write(rt5645->regmap, RT5645_IN1_CTRL2, 0x1827);
2708 regmap_write(rt5645->regmap, RT5645_IN1_CTRL2, 0x0827);
2709 msleep(400);
2710 /* Inline command */
2711 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x0001);
2712 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD2, 0xc000);
2713 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD1, 0x0008);
2714 /* Calbration */
2715 regmap_write(rt5645->regmap, RT5645_GLB_CLK, 0x8000);
2716 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x0000);
2717 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD2, 0xc000);
2718 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD1, 0x0008);
2719 regmap_write(rt5645->regmap, RT5645_PWR_DIG2, 0x8800);
2720 regmap_write(rt5645->regmap, RT5645_PWR_ANLG1, 0xe8fa);
2721 regmap_write(rt5645->regmap, RT5645_PWR_ANLG2, 0x8c04);
2722 regmap_write(rt5645->regmap, RT5645_DEPOP_M2, 0x3100);
2723 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0e06);
2724 regmap_write(rt5645->regmap, RT5645_BASS_BACK, 0x8a13);
2725 regmap_write(rt5645->regmap, RT5645_GEN_CTRL3, 0x0820);
2726 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x000d);
2727 /* Power on and Calbration */
2728 regmap_write(rt5645->regmap, RT5645_PR_BASE + RT5645_HP_DCC_INT1,
2729 0x9f01);
2730 msleep(200);
2731 for (i = 0; i < 5; i++) {
2732 regmap_read(rt5645->regmap, RT5645_PR_BASE + 0x7a, &val);
2733 if (val != 0 && val != 0x3f3f) {
2734 ret = 0;
2735 break;
2736 }
2737 msleep(50);
2426 } 2738 }
2427 gpio_state = gpio_get_value(rt5645->pdata.hp_det_gpio); 2739 pr_debug("%s: PR-7A = 0x%x\n", __func__, val);
2740
2741 /* mute */
2742 regmap_write(rt5645->regmap, RT5645_PR_BASE + 0x3e, 0x7400);
2743 regmap_write(rt5645->regmap, RT5645_DEPOP_M3, 0x0737);
2744 regmap_write(rt5645->regmap, RT5645_PR_BASE + RT5645_MAMP_INT_REG2,
2745 0xfc00);
2746 regmap_write(rt5645->regmap, RT5645_DEPOP_M2, 0x1140);
2747 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x0000);
2748 regmap_write(rt5645->regmap, RT5645_GEN_CTRL2, 0x4020);
2749 regmap_write(rt5645->regmap, RT5645_PWR_ANLG2, 0x0006);
2750 regmap_write(rt5645->regmap, RT5645_PWR_DIG2, 0x0000);
2751 msleep(350);
2752
2753 regcache_cache_bypass(rt5645->regmap, false);
2754
2755 return ret;
2756}
2428 2757
2429 dev_dbg(codec->dev, "gpio = %d(%d)\n", rt5645->pdata.hp_det_gpio, 2758static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec,
2430 gpio_state); 2759 bool enable)
2760{
2761 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2431 2762
2432 if ((rt5645->pdata.gpio_hp_det_active_high && gpio_state) || 2763 if (enable) {
2433 (!rt5645->pdata.gpio_hp_det_active_high && !gpio_state)) { 2764 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2434 snd_soc_dapm_force_enable_pin(&codec->dapm, "micbias1"); 2765 "ADC L power");
2435 snd_soc_dapm_force_enable_pin(&codec->dapm, "micbias2"); 2766 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2436 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2"); 2767 "ADC R power");
2437 snd_soc_dapm_force_enable_pin(&codec->dapm, "Mic Det Power"); 2768 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2438 snd_soc_dapm_sync(&codec->dapm); 2769 "LDO2");
2770 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2771 "Mic Det Power");
2772 snd_soc_dapm_sync_unlocked(&codec->dapm);
2773 snd_soc_update_bits(codec,
2774 RT5645_INT_IRQ_ST, 0x8, 0x8);
2775 snd_soc_update_bits(codec,
2776 RT5650_4BTN_IL_CMD2, 0x8000, 0x8000);
2777 snd_soc_read(codec, RT5650_4BTN_IL_CMD1);
2778 pr_debug("%s read %x = %x\n", __func__, RT5650_4BTN_IL_CMD1,
2779 snd_soc_read(codec, RT5650_4BTN_IL_CMD1));
2780 } else {
2781 snd_soc_update_bits(codec, RT5650_4BTN_IL_CMD2, 0x8000, 0x0);
2782 snd_soc_update_bits(codec, RT5645_INT_IRQ_ST, 0x8, 0x0);
2783 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2784 "ADC L power");
2785 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2786 "ADC R power");
2787 if (rt5645->pdata.jd_mode == 0)
2788 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2789 "LDO2");
2790 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2791 "Mic Det Power");
2792 snd_soc_dapm_sync_unlocked(&codec->dapm);
2793 }
2794}
2439 2795
2440 snd_soc_write(codec, RT5645_IN1_CTRL1, 0x0006); 2796static int rt5645_jack_detect(struct snd_soc_codec *codec, int jack_insert)
2441 snd_soc_write(codec, RT5645_JD_CTRL3, 0x00b0); 2797{
2798 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2799 unsigned int val;
2442 2800
2443 snd_soc_update_bits(codec, RT5645_IN1_CTRL2, 2801 if (jack_insert) {
2444 RT5645_CBJ_MN_JD, 0); 2802 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0006);
2445 snd_soc_update_bits(codec, RT5645_IN1_CTRL2,
2446 RT5645_CBJ_MN_JD, RT5645_CBJ_MN_JD);
2447 2803
2448 msleep(400); 2804 if (codec->component.card->instantiated) {
2449 val = snd_soc_read(codec, RT5645_IN1_CTRL3) & 0x7; 2805 /* for jack type detect */
2806 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2");
2807 snd_soc_dapm_force_enable_pin(&codec->dapm,
2808 "Mic Det Power");
2809 snd_soc_dapm_sync(&codec->dapm);
2810 } else {
2811 /* Power up necessary bits for JD if dapm is
2812 not ready yet */
2813 regmap_update_bits(rt5645->regmap, RT5645_PWR_ANLG1,
2814 RT5645_PWR_MB | RT5645_PWR_VREF2,
2815 RT5645_PWR_MB | RT5645_PWR_VREF2);
2816 regmap_update_bits(rt5645->regmap, RT5645_PWR_MIXER,
2817 RT5645_PWR_LDO2, RT5645_PWR_LDO2);
2818 regmap_update_bits(rt5645->regmap, RT5645_PWR_VOL,
2819 RT5645_PWR_MIC_DET, RT5645_PWR_MIC_DET);
2820 }
2821
2822 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0);
2823 regmap_write(rt5645->regmap, RT5645_IN1_CTRL1, 0x0006);
2824 regmap_update_bits(rt5645->regmap,
2825 RT5645_IN1_CTRL2, 0x1000, 0x1000);
2826 msleep(100);
2827 regmap_update_bits(rt5645->regmap,
2828 RT5645_IN1_CTRL2, 0x1000, 0x0000);
2829
2830 msleep(450);
2831 regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val);
2832 val &= 0x7;
2450 dev_dbg(codec->dev, "val = %d\n", val); 2833 dev_dbg(codec->dev, "val = %d\n", val);
2451 2834
2452 if (val == 1 || val == 2) 2835 if (val == 1 || val == 2) {
2453 jack_type = SND_JACK_HEADSET; 2836 rt5645->jack_type = SND_JACK_HEADSET;
2454 else 2837 if (rt5645->en_button_func) {
2455 jack_type = SND_JACK_HEADPHONE; 2838 rt5645_enable_push_button_irq(codec, true);
2839 }
2840 } else {
2841 if (codec->component.card->instantiated) {
2842 snd_soc_dapm_disable_pin(&codec->dapm,
2843 "Mic Det Power");
2844 snd_soc_dapm_sync(&codec->dapm);
2845 } else
2846 regmap_update_bits(rt5645->regmap,
2847 RT5645_PWR_VOL, RT5645_PWR_MIC_DET, 0);
2848 rt5645->jack_type = SND_JACK_HEADPHONE;
2849 }
2456 2850
2457 snd_soc_dapm_disable_pin(&codec->dapm, "micbias1"); 2851 } else { /* jack out */
2458 snd_soc_dapm_disable_pin(&codec->dapm, "micbias2"); 2852 rt5645->jack_type = 0;
2459 if (rt5645->pdata.jd_mode == 0) 2853 if (rt5645->en_button_func)
2460 snd_soc_dapm_disable_pin(&codec->dapm, "LDO2"); 2854 rt5645_enable_push_button_irq(codec, false);
2461 snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power"); 2855 else {
2462 snd_soc_dapm_sync(&codec->dapm); 2856 if (codec->component.card->instantiated) {
2857 if (rt5645->pdata.jd_mode == 0)
2858 snd_soc_dapm_disable_pin(&codec->dapm,
2859 "LDO2");
2860 snd_soc_dapm_disable_pin(&codec->dapm,
2861 "Mic Det Power");
2862 snd_soc_dapm_sync(&codec->dapm);
2863 } else {
2864 if (rt5645->pdata.jd_mode == 0)
2865 regmap_update_bits(rt5645->regmap,
2866 RT5645_PWR_MIXER,
2867 RT5645_PWR_LDO2, 0);
2868 regmap_update_bits(rt5645->regmap,
2869 RT5645_PWR_VOL, RT5645_PWR_MIC_DET, 0);
2870 }
2871 }
2463 } 2872 }
2464 2873
2465 snd_soc_jack_report(rt5645->hp_jack, jack_type, SND_JACK_HEADPHONE); 2874 return rt5645->jack_type;
2466 snd_soc_jack_report(rt5645->mic_jack, jack_type, SND_JACK_MICROPHONE);
2467 return 0;
2468} 2875}
2469 2876
2877static int rt5645_irq_detection(struct rt5645_priv *rt5645);
2878static irqreturn_t rt5645_irq(int irq, void *data);
2879
2470int rt5645_set_jack_detect(struct snd_soc_codec *codec, 2880int rt5645_set_jack_detect(struct snd_soc_codec *codec,
2471 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack) 2881 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack,
2882 struct snd_soc_jack *btn_jack)
2472{ 2883{
2473 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 2884 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2474 2885
2475 rt5645->hp_jack = hp_jack; 2886 rt5645->hp_jack = hp_jack;
2476 rt5645->mic_jack = mic_jack; 2887 rt5645->mic_jack = mic_jack;
2477 rt5645_jack_detect(codec); 2888 rt5645->btn_jack = btn_jack;
2889 if (rt5645->btn_jack && rt5645->codec_type == CODEC_TYPE_RT5650) {
2890 rt5645->en_button_func = true;
2891 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2892 RT5645_GP1_PIN_IRQ, RT5645_GP1_PIN_IRQ);
2893 regmap_update_bits(rt5645->regmap, RT5645_DEPOP_M1,
2894 RT5645_HP_CB_MASK, RT5645_HP_CB_PU);
2895 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1,
2896 RT5645_DIG_GATE_CTRL, RT5645_DIG_GATE_CTRL);
2897 }
2898 rt5645_irq(0, rt5645);
2478 2899
2479 return 0; 2900 return 0;
2480} 2901}
@@ -2485,7 +2906,7 @@ static void rt5645_jack_detect_work(struct work_struct *work)
2485 struct rt5645_priv *rt5645 = 2906 struct rt5645_priv *rt5645 =
2486 container_of(work, struct rt5645_priv, jack_detect_work.work); 2907 container_of(work, struct rt5645_priv, jack_detect_work.work);
2487 2908
2488 rt5645_jack_detect(rt5645->codec); 2909 rt5645_irq_detection(rt5645);
2489} 2910}
2490 2911
2491static irqreturn_t rt5645_irq(int irq, void *data) 2912static irqreturn_t rt5645_irq(int irq, void *data)
@@ -2498,6 +2919,126 @@ static irqreturn_t rt5645_irq(int irq, void *data)
2498 return IRQ_HANDLED; 2919 return IRQ_HANDLED;
2499} 2920}
2500 2921
2922static int rt5645_button_detect(struct snd_soc_codec *codec)
2923{
2924 int btn_type, val;
2925
2926 val = snd_soc_read(codec, RT5650_4BTN_IL_CMD1);
2927 pr_debug("val=0x%x\n", val);
2928 btn_type = val & 0xfff0;
2929 snd_soc_write(codec, RT5650_4BTN_IL_CMD1, val);
2930
2931 return btn_type;
2932}
2933
2934static int rt5645_irq_detection(struct rt5645_priv *rt5645)
2935{
2936 int val, btn_type, gpio_state = 0, report = 0;
2937
2938 switch (rt5645->pdata.jd_mode) {
2939 case 0: /* Not using rt5645 JD */
2940 if (gpio_is_valid(rt5645->pdata.hp_det_gpio)) {
2941 gpio_state = gpio_get_value(rt5645->pdata.hp_det_gpio);
2942 dev_dbg(rt5645->codec->dev, "gpio = %d(%d)\n",
2943 rt5645->pdata.hp_det_gpio, gpio_state);
2944 }
2945 if ((rt5645->pdata.gpio_hp_det_active_high && gpio_state) ||
2946 (!rt5645->pdata.gpio_hp_det_active_high &&
2947 !gpio_state)) {
2948 report = rt5645_jack_detect(rt5645->codec, 1);
2949 } else {
2950 report = rt5645_jack_detect(rt5645->codec, 0);
2951 }
2952 snd_soc_jack_report(rt5645->hp_jack,
2953 report, SND_JACK_HEADPHONE);
2954 snd_soc_jack_report(rt5645->mic_jack,
2955 report, SND_JACK_MICROPHONE);
2956 return report;
2957 case 1: /* 2 port */
2958 val = snd_soc_read(rt5645->codec, RT5645_A_JD_CTRL1) & 0x0070;
2959 break;
2960 default: /* 1 port */
2961 val = snd_soc_read(rt5645->codec, RT5645_A_JD_CTRL1) & 0x0020;
2962 break;
2963
2964 }
2965
2966 switch (val) {
2967 /* jack in */
2968 case 0x30: /* 2 port */
2969 case 0x0: /* 1 port or 2 port */
2970 if (rt5645->jack_type == 0) {
2971 report = rt5645_jack_detect(rt5645->codec, 1);
2972 /* for push button and jack out */
2973 break;
2974 }
2975 btn_type = 0;
2976 if (snd_soc_read(rt5645->codec, RT5645_INT_IRQ_ST) & 0x4) {
2977 /* button pressed */
2978 report = SND_JACK_HEADSET;
2979 btn_type = rt5645_button_detect(rt5645->codec);
2980 /* rt5650 can report three kinds of button behavior,
2981 one click, double click and hold. However,
2982 currently we will report button pressed/released
2983 event. So all the three button behaviors are
2984 treated as button pressed. */
2985 switch (btn_type) {
2986 case 0x8000:
2987 case 0x4000:
2988 case 0x2000:
2989 report |= SND_JACK_BTN_0;
2990 break;
2991 case 0x1000:
2992 case 0x0800:
2993 case 0x0400:
2994 report |= SND_JACK_BTN_1;
2995 break;
2996 case 0x0200:
2997 case 0x0100:
2998 case 0x0080:
2999 report |= SND_JACK_BTN_2;
3000 break;
3001 case 0x0040:
3002 case 0x0020:
3003 case 0x0010:
3004 report |= SND_JACK_BTN_3;
3005 break;
3006 case 0x0000: /* unpressed */
3007 break;
3008 default:
3009 dev_err(rt5645->codec->dev,
3010 "Unexpected button code 0x%04x\n",
3011 btn_type);
3012 break;
3013 }
3014 }
3015 if (btn_type == 0)/* button release */
3016 report = rt5645->jack_type;
3017
3018 break;
3019 /* jack out */
3020 case 0x70: /* 2 port */
3021 case 0x10: /* 2 port */
3022 case 0x20: /* 1 port */
3023 report = 0;
3024 snd_soc_update_bits(rt5645->codec,
3025 RT5645_INT_IRQ_ST, 0x1, 0x0);
3026 rt5645_jack_detect(rt5645->codec, 0);
3027 break;
3028 default:
3029 break;
3030 }
3031
3032 snd_soc_jack_report(rt5645->hp_jack, report, SND_JACK_HEADPHONE);
3033 snd_soc_jack_report(rt5645->mic_jack, report, SND_JACK_MICROPHONE);
3034 if (rt5645->en_button_func)
3035 snd_soc_jack_report(rt5645->btn_jack,
3036 report, SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3037 SND_JACK_BTN_2 | SND_JACK_BTN_3);
3038
3039 return report;
3040}
3041
2501static int rt5645_probe(struct snd_soc_codec *codec) 3042static int rt5645_probe(struct snd_soc_codec *codec)
2502{ 3043{
2503 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 3044 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
@@ -2520,12 +3061,10 @@ static int rt5645_probe(struct snd_soc_codec *codec)
2520 break; 3061 break;
2521 } 3062 }
2522 3063
2523 rt5645_set_bias_level(codec, SND_SOC_BIAS_OFF); 3064 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
2524
2525 snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200);
2526 3065
2527 /* for JD function */ 3066 /* for JD function */
2528 if (rt5645->pdata.en_jd_func) { 3067 if (rt5645->pdata.jd_mode) {
2529 snd_soc_dapm_force_enable_pin(&codec->dapm, "JD Power"); 3068 snd_soc_dapm_force_enable_pin(&codec->dapm, "JD Power");
2530 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2"); 3069 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2");
2531 snd_soc_dapm_sync(&codec->dapm); 3070 snd_soc_dapm_sync(&codec->dapm);
@@ -2656,6 +3195,41 @@ static const struct i2c_device_id rt5645_i2c_id[] = {
2656}; 3195};
2657MODULE_DEVICE_TABLE(i2c, rt5645_i2c_id); 3196MODULE_DEVICE_TABLE(i2c, rt5645_i2c_id);
2658 3197
3198#ifdef CONFIG_ACPI
3199static struct acpi_device_id rt5645_acpi_match[] = {
3200 { "10EC5645", 0 },
3201 { "10EC5650", 0 },
3202 {},
3203};
3204MODULE_DEVICE_TABLE(acpi, rt5645_acpi_match);
3205#endif
3206
3207static struct rt5645_platform_data *rt5645_pdata;
3208
3209static struct rt5645_platform_data strago_platform_data = {
3210 .dmic1_data_pin = RT5645_DMIC1_DISABLE,
3211 .dmic2_data_pin = RT5645_DMIC_DATA_IN2P,
3212 .jd_mode = 3,
3213};
3214
3215static int strago_quirk_cb(const struct dmi_system_id *id)
3216{
3217 rt5645_pdata = &strago_platform_data;
3218
3219 return 1;
3220}
3221
3222static struct dmi_system_id dmi_platform_intel_braswell[] = {
3223 {
3224 .ident = "Intel Strago",
3225 .callback = strago_quirk_cb,
3226 .matches = {
3227 DMI_MATCH(DMI_PRODUCT_NAME, "Strago"),
3228 },
3229 },
3230 { }
3231};
3232
2659static int rt5645_i2c_probe(struct i2c_client *i2c, 3233static int rt5645_i2c_probe(struct i2c_client *i2c,
2660 const struct i2c_device_id *id) 3234 const struct i2c_device_id *id)
2661{ 3235{
@@ -2663,6 +3237,7 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2663 struct rt5645_priv *rt5645; 3237 struct rt5645_priv *rt5645;
2664 int ret; 3238 int ret;
2665 unsigned int val; 3239 unsigned int val;
3240 struct gpio_desc *gpiod;
2666 3241
2667 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), 3242 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv),
2668 GFP_KERNEL); 3243 GFP_KERNEL);
@@ -2672,8 +3247,23 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2672 rt5645->i2c = i2c; 3247 rt5645->i2c = i2c;
2673 i2c_set_clientdata(i2c, rt5645); 3248 i2c_set_clientdata(i2c, rt5645);
2674 3249
2675 if (pdata) 3250 if (pdata) {
2676 rt5645->pdata = *pdata; 3251 rt5645->pdata = *pdata;
3252 } else {
3253 if (dmi_check_system(dmi_platform_intel_braswell)) {
3254 rt5645->pdata = *rt5645_pdata;
3255 gpiod = devm_gpiod_get_index(&i2c->dev, "rt5645", 0);
3256
3257 if (IS_ERR(gpiod) || gpiod_direction_input(gpiod)) {
3258 rt5645->pdata.hp_det_gpio = -1;
3259 dev_err(&i2c->dev, "failed to initialize gpiod\n");
3260 } else {
3261 rt5645->pdata.hp_det_gpio = desc_to_gpio(gpiod);
3262 rt5645->pdata.gpio_hp_det_active_high
3263 = !gpiod_is_active_low(gpiod);
3264 }
3265 }
3266 }
2677 3267
2678 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap); 3268 rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap);
2679 if (IS_ERR(rt5645->regmap)) { 3269 if (IS_ERR(rt5645->regmap)) {
@@ -2699,6 +3289,13 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2699 return -ENODEV; 3289 return -ENODEV;
2700 } 3290 }
2701 3291
3292 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
3293 ret = rt5650_calibration(rt5645);
3294
3295 if (ret < 0)
3296 pr_err("calibration failed!\n");
3297 }
3298
2702 regmap_write(rt5645->regmap, RT5645_RESET, 0); 3299 regmap_write(rt5645->regmap, RT5645_RESET, 0);
2703 3300
2704 ret = regmap_register_patch(rt5645->regmap, init_list, 3301 ret = regmap_register_patch(rt5645->regmap, init_list,
@@ -2718,84 +3315,76 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2718 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL, 3315 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL,
2719 RT5645_IN_DF2, RT5645_IN_DF2); 3316 RT5645_IN_DF2, RT5645_IN_DF2);
2720 3317
2721 if (rt5645->pdata.dmic_en) { 3318 if (rt5645->pdata.dmic1_data_pin || rt5645->pdata.dmic2_data_pin) {
2722 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 3319 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2723 RT5645_GP2_PIN_MASK, RT5645_GP2_PIN_DMIC1_SCL); 3320 RT5645_GP2_PIN_MASK, RT5645_GP2_PIN_DMIC1_SCL);
3321 }
3322 switch (rt5645->pdata.dmic1_data_pin) {
3323 case RT5645_DMIC_DATA_IN2N:
3324 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
3325 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_IN2N);
3326 break;
2724 3327
2725 switch (rt5645->pdata.dmic1_data_pin) { 3328 case RT5645_DMIC_DATA_GPIO5:
2726 case RT5645_DMIC_DATA_IN2N: 3329 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2727 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 3330 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_GPIO5);
2728 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_IN2N); 3331 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2729 break; 3332 RT5645_GP5_PIN_MASK, RT5645_GP5_PIN_DMIC1_SDA);
2730 3333 break;
2731 case RT5645_DMIC_DATA_GPIO5:
2732 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2733 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_GPIO5);
2734 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2735 RT5645_GP5_PIN_MASK, RT5645_GP5_PIN_DMIC1_SDA);
2736 break;
2737
2738 case RT5645_DMIC_DATA_GPIO11:
2739 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2740 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_GPIO11);
2741 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2742 RT5645_GP11_PIN_MASK,
2743 RT5645_GP11_PIN_DMIC1_SDA);
2744 break;
2745 3334
2746 default: 3335 case RT5645_DMIC_DATA_GPIO11:
2747 break; 3336 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2748 } 3337 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_GPIO11);
3338 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
3339 RT5645_GP11_PIN_MASK,
3340 RT5645_GP11_PIN_DMIC1_SDA);
3341 break;
2749 3342
2750 switch (rt5645->pdata.dmic2_data_pin) { 3343 default:
2751 case RT5645_DMIC_DATA_IN2P: 3344 break;
2752 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 3345 }
2753 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_IN2P);
2754 break;
2755 3346
2756 case RT5645_DMIC_DATA_GPIO6: 3347 switch (rt5645->pdata.dmic2_data_pin) {
2757 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 3348 case RT5645_DMIC_DATA_IN2P:
2758 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_GPIO6); 3349 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2759 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 3350 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_IN2P);
2760 RT5645_GP6_PIN_MASK, RT5645_GP6_PIN_DMIC2_SDA); 3351 break;
2761 break;
2762 3352
2763 case RT5645_DMIC_DATA_GPIO10: 3353 case RT5645_DMIC_DATA_GPIO6:
2764 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 3354 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2765 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_GPIO10); 3355 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_GPIO6);
2766 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 3356 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2767 RT5645_GP10_PIN_MASK, 3357 RT5645_GP6_PIN_MASK, RT5645_GP6_PIN_DMIC2_SDA);
2768 RT5645_GP10_PIN_DMIC2_SDA); 3358 break;
2769 break;
2770 3359
2771 case RT5645_DMIC_DATA_GPIO12: 3360 case RT5645_DMIC_DATA_GPIO10:
2772 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 3361 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2773 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_2_DP_GPIO12); 3362 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_GPIO10);
2774 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 3363 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
2775 RT5645_GP12_PIN_MASK, 3364 RT5645_GP10_PIN_MASK,
2776 RT5645_GP12_PIN_DMIC2_SDA); 3365 RT5645_GP10_PIN_DMIC2_SDA);
2777 break; 3366 break;
2778 3367
2779 default: 3368 case RT5645_DMIC_DATA_GPIO12:
2780 break; 3369 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
2781 } 3370 RT5645_DMIC_2_DP_MASK, RT5645_DMIC_2_DP_GPIO12);
3371 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
3372 RT5645_GP12_PIN_MASK,
3373 RT5645_GP12_PIN_DMIC2_SDA);
3374 break;
2782 3375
3376 default:
3377 break;
2783 } 3378 }
2784 3379
2785 if (rt5645->pdata.en_jd_func) { 3380 if (rt5645->pdata.jd_mode) {
2786 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, 3381 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3,
2787 RT5645_IRQ_CLK_GATE_CTRL | RT5645_MICINDET_MANU, 3382 RT5645_IRQ_CLK_GATE_CTRL,
2788 RT5645_IRQ_CLK_GATE_CTRL | RT5645_MICINDET_MANU); 3383 RT5645_IRQ_CLK_GATE_CTRL);
2789 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, 3384 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1,
2790 RT5645_CBJ_BST1_EN, RT5645_CBJ_BST1_EN); 3385 RT5645_CBJ_BST1_EN, RT5645_CBJ_BST1_EN);
2791 regmap_update_bits(rt5645->regmap, RT5645_JD_CTRL3,
2792 RT5645_JD_CBJ_EN | RT5645_JD_CBJ_POL,
2793 RT5645_JD_CBJ_EN | RT5645_JD_CBJ_POL);
2794 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, 3386 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS,
2795 RT5645_IRQ_CLK_INT, RT5645_IRQ_CLK_INT); 3387 RT5645_IRQ_CLK_INT, RT5645_IRQ_CLK_INT);
2796 }
2797
2798 if (rt5645->pdata.jd_mode) {
2799 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, 3388 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
2800 RT5645_IRQ_JD_1_1_EN, RT5645_IRQ_JD_1_1_EN); 3389 RT5645_IRQ_JD_1_1_EN, RT5645_IRQ_JD_1_1_EN);
2801 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, 3390 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3,
@@ -2827,6 +3416,8 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2827 } 3416 }
2828 } 3417 }
2829 3418
3419 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work);
3420
2830 if (rt5645->i2c->irq) { 3421 if (rt5645->i2c->irq) {
2831 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, 3422 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq,
2832 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING 3423 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
@@ -2845,8 +3436,6 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2845 dev_err(&i2c->dev, "Fail gpio_direction hp_det_gpio\n"); 3436 dev_err(&i2c->dev, "Fail gpio_direction hp_det_gpio\n");
2846 } 3437 }
2847 3438
2848 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work);
2849
2850 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645, 3439 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645,
2851 rt5645_dai, ARRAY_SIZE(rt5645_dai)); 3440 rt5645_dai, ARRAY_SIZE(rt5645_dai));
2852} 3441}
@@ -2872,6 +3461,7 @@ static struct i2c_driver rt5645_i2c_driver = {
2872 .driver = { 3461 .driver = {
2873 .name = "rt5645", 3462 .name = "rt5645",
2874 .owner = THIS_MODULE, 3463 .owner = THIS_MODULE,
3464 .acpi_match_table = ACPI_PTR(rt5645_acpi_match),
2875 }, 3465 },
2876 .probe = rt5645_i2c_probe, 3466 .probe = rt5645_i2c_probe,
2877 .remove = rt5645_i2c_remove, 3467 .remove = rt5645_i2c_remove,
diff --git a/sound/soc/codecs/rt5645.h b/sound/soc/codecs/rt5645.h
index db78e9462876..9ec4e899795d 100644
--- a/sound/soc/codecs/rt5645.h
+++ b/sound/soc/codecs/rt5645.h
@@ -105,6 +105,7 @@
105#define RT5645_TDM_CTRL_1 0x77 105#define RT5645_TDM_CTRL_1 0x77
106#define RT5645_TDM_CTRL_2 0x78 106#define RT5645_TDM_CTRL_2 0x78
107#define RT5645_TDM_CTRL_3 0x79 107#define RT5645_TDM_CTRL_3 0x79
108#define RT5650_TDM_CTRL_4 0x7a
108 109
109/* Function - Analog */ 110/* Function - Analog */
110#define RT5645_GLB_CLK 0x80 111#define RT5645_GLB_CLK 0x80
@@ -942,10 +943,6 @@
942#define RT5645_I2S2_SDI_I2S2 (0x1 << 6) 943#define RT5645_I2S2_SDI_I2S2 (0x1 << 6)
943 944
944/* ADC/DAC Clock Control 1 (0x73) */ 945/* ADC/DAC Clock Control 1 (0x73) */
945#define RT5645_I2S_BCLK_MS1_MASK (0x1 << 15)
946#define RT5645_I2S_BCLK_MS1_SFT 15
947#define RT5645_I2S_BCLK_MS1_32 (0x0 << 15)
948#define RT5645_I2S_BCLK_MS1_64 (0x1 << 15)
949#define RT5645_I2S_PD1_MASK (0x7 << 12) 946#define RT5645_I2S_PD1_MASK (0x7 << 12)
950#define RT5645_I2S_PD1_SFT 12 947#define RT5645_I2S_PD1_SFT 12
951#define RT5645_I2S_PD1_1 (0x0 << 12) 948#define RT5645_I2S_PD1_1 (0x0 << 12)
@@ -1067,13 +1064,14 @@
1067#define RT5645_SCLK_SRC_SFT 14 1064#define RT5645_SCLK_SRC_SFT 14
1068#define RT5645_SCLK_SRC_MCLK (0x0 << 14) 1065#define RT5645_SCLK_SRC_MCLK (0x0 << 14)
1069#define RT5645_SCLK_SRC_PLL1 (0x1 << 14) 1066#define RT5645_SCLK_SRC_PLL1 (0x1 << 14)
1070#define RT5645_SCLK_SRC_RCCLK (0x2 << 14) /* 15MHz */ 1067#define RT5645_SCLK_SRC_RCCLK (0x2 << 14)
1071#define RT5645_PLL1_SRC_MASK (0x3 << 12) 1068#define RT5645_PLL1_SRC_MASK (0x7 << 11)
1072#define RT5645_PLL1_SRC_SFT 12 1069#define RT5645_PLL1_SRC_SFT 11
1073#define RT5645_PLL1_SRC_MCLK (0x0 << 12) 1070#define RT5645_PLL1_SRC_MCLK (0x0 << 11)
1074#define RT5645_PLL1_SRC_BCLK1 (0x1 << 12) 1071#define RT5645_PLL1_SRC_BCLK1 (0x1 << 11)
1075#define RT5645_PLL1_SRC_BCLK2 (0x2 << 12) 1072#define RT5645_PLL1_SRC_BCLK2 (0x2 << 11)
1076#define RT5645_PLL1_SRC_BCLK3 (0x3 << 12) 1073#define RT5645_PLL1_SRC_BCLK3 (0x3 << 11)
1074#define RT5645_PLL1_SRC_RCCLK (0x4 << 11)
1077#define RT5645_PLL1_PD_MASK (0x1 << 3) 1075#define RT5645_PLL1_PD_MASK (0x1 << 3)
1078#define RT5645_PLL1_PD_SFT 3 1076#define RT5645_PLL1_PD_SFT 3
1079#define RT5645_PLL1_PD_1 (0x0 << 3) 1077#define RT5645_PLL1_PD_1 (0x0 << 3)
@@ -2147,6 +2145,7 @@ enum {
2147}; 2145};
2148 2146
2149enum { 2147enum {
2148 RT5645_DMIC1_DISABLE,
2150 RT5645_DMIC_DATA_IN2P, 2149 RT5645_DMIC_DATA_IN2P,
2151 RT5645_DMIC_DATA_GPIO6, 2150 RT5645_DMIC_DATA_GPIO6,
2152 RT5645_DMIC_DATA_GPIO10, 2151 RT5645_DMIC_DATA_GPIO10,
@@ -2154,6 +2153,7 @@ enum {
2154}; 2153};
2155 2154
2156enum { 2155enum {
2156 RT5645_DMIC2_DISABLE,
2157 RT5645_DMIC_DATA_IN2N, 2157 RT5645_DMIC_DATA_IN2N,
2158 RT5645_DMIC_DATA_GPIO5, 2158 RT5645_DMIC_DATA_GPIO5,
2159 RT5645_DMIC_DATA_GPIO11, 2159 RT5645_DMIC_DATA_GPIO11,
@@ -2184,6 +2184,7 @@ struct rt5645_priv {
2184 struct i2c_client *i2c; 2184 struct i2c_client *i2c;
2185 struct snd_soc_jack *hp_jack; 2185 struct snd_soc_jack *hp_jack;
2186 struct snd_soc_jack *mic_jack; 2186 struct snd_soc_jack *mic_jack;
2187 struct snd_soc_jack *btn_jack;
2187 struct delayed_work jack_detect_work; 2188 struct delayed_work jack_detect_work;
2188 2189
2189 int codec_type; 2190 int codec_type;
@@ -2196,9 +2197,12 @@ struct rt5645_priv {
2196 int pll_src; 2197 int pll_src;
2197 int pll_in; 2198 int pll_in;
2198 int pll_out; 2199 int pll_out;
2200
2201 int jack_type;
2202 bool en_button_func;
2199}; 2203};
2200 2204
2201int rt5645_set_jack_detect(struct snd_soc_codec *codec, 2205int rt5645_set_jack_detect(struct snd_soc_codec *codec,
2202 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack); 2206 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack,
2203 2207 struct snd_soc_jack *btn_jack);
2204#endif /* __RT5645_H__ */ 2208#endif /* __RT5645_H__ */
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 9f4c7be6d798..a3506e193abc 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -1571,7 +1571,7 @@ static int rt5651_set_bias_level(struct snd_soc_codec *codec,
1571{ 1571{
1572 switch (level) { 1572 switch (level) {
1573 case SND_SOC_BIAS_PREPARE: 1573 case SND_SOC_BIAS_PREPARE:
1574 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 1574 if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) {
1575 snd_soc_update_bits(codec, RT5651_PWR_ANLG1, 1575 snd_soc_update_bits(codec, RT5651_PWR_ANLG1,
1576 RT5651_PWR_VREF1 | RT5651_PWR_MB | 1576 RT5651_PWR_VREF1 | RT5651_PWR_MB |
1577 RT5651_PWR_BG | RT5651_PWR_VREF2, 1577 RT5651_PWR_BG | RT5651_PWR_VREF2,
@@ -1604,7 +1604,6 @@ static int rt5651_set_bias_level(struct snd_soc_codec *codec,
1604 default: 1604 default:
1605 break; 1605 break;
1606 } 1606 }
1607 codec->dapm.bias_level = level;
1608 1607
1609 return 0; 1608 return 0;
1610} 1609}
@@ -1625,7 +1624,7 @@ static int rt5651_probe(struct snd_soc_codec *codec)
1625 RT5651_PWR_FV1 | RT5651_PWR_FV2, 1624 RT5651_PWR_FV1 | RT5651_PWR_FV2,
1626 RT5651_PWR_FV1 | RT5651_PWR_FV2); 1625 RT5651_PWR_FV1 | RT5651_PWR_FV2);
1627 1626
1628 rt5651_set_bias_level(codec, SND_SOC_BIAS_OFF); 1627 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
1629 1628
1630 return 0; 1629 return 0;
1631} 1630}
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index cc7f84a150a7..840dd6d0003a 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -416,12 +416,12 @@ static bool rt5670_readable_register(struct device *dev, unsigned int reg)
416static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert) 416static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert)
417{ 417{
418 int val; 418 int val;
419 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
419 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 420 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
420 421
421 if (jack_insert) { 422 if (jack_insert) {
422 snd_soc_dapm_force_enable_pin(&codec->dapm, 423 snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power");
423 "Mic Det Power"); 424 snd_soc_dapm_sync(dapm);
424 snd_soc_dapm_sync(&codec->dapm);
425 snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x0); 425 snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x0);
426 snd_soc_update_bits(codec, RT5670_CJ_CTRL2, 426 snd_soc_update_bits(codec, RT5670_CJ_CTRL2,
427 RT5670_CBJ_DET_MODE | RT5670_CBJ_MN_JD, 427 RT5670_CBJ_DET_MODE | RT5670_CBJ_MN_JD,
@@ -447,15 +447,15 @@ static int rt5670_headset_detect(struct snd_soc_codec *codec, int jack_insert)
447 } else { 447 } else {
448 snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4); 448 snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4);
449 rt5670->jack_type = SND_JACK_HEADPHONE; 449 rt5670->jack_type = SND_JACK_HEADPHONE;
450 snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power"); 450 snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
451 snd_soc_dapm_sync(&codec->dapm); 451 snd_soc_dapm_sync(dapm);
452 } 452 }
453 } else { 453 } else {
454 snd_soc_update_bits(codec, RT5670_INT_IRQ_ST, 0x8, 0x0); 454 snd_soc_update_bits(codec, RT5670_INT_IRQ_ST, 0x8, 0x0);
455 snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4); 455 snd_soc_update_bits(codec, RT5670_GEN_CTRL3, 0x4, 0x4);
456 rt5670->jack_type = 0; 456 rt5670->jack_type = 0;
457 snd_soc_dapm_disable_pin(&codec->dapm, "Mic Det Power"); 457 snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
458 snd_soc_dapm_sync(&codec->dapm); 458 snd_soc_dapm_sync(dapm);
459 } 459 }
460 460
461 return rt5670->jack_type; 461 return rt5670->jack_type;
@@ -2603,7 +2603,7 @@ static int rt5670_set_bias_level(struct snd_soc_codec *codec,
2603 2603
2604 switch (level) { 2604 switch (level) {
2605 case SND_SOC_BIAS_PREPARE: 2605 case SND_SOC_BIAS_PREPARE:
2606 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 2606 if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) {
2607 snd_soc_update_bits(codec, RT5670_PWR_ANLG1, 2607 snd_soc_update_bits(codec, RT5670_PWR_ANLG1,
2608 RT5670_PWR_VREF1 | RT5670_PWR_MB | 2608 RT5670_PWR_VREF1 | RT5670_PWR_MB |
2609 RT5670_PWR_BG | RT5670_PWR_VREF2, 2609 RT5670_PWR_BG | RT5670_PWR_VREF2,
@@ -2647,30 +2647,30 @@ static int rt5670_set_bias_level(struct snd_soc_codec *codec,
2647 default: 2647 default:
2648 break; 2648 break;
2649 } 2649 }
2650 codec->dapm.bias_level = level;
2651 2650
2652 return 0; 2651 return 0;
2653} 2652}
2654 2653
2655static int rt5670_probe(struct snd_soc_codec *codec) 2654static int rt5670_probe(struct snd_soc_codec *codec)
2656{ 2655{
2656 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2657 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 2657 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
2658 2658
2659 switch (snd_soc_read(codec, RT5670_RESET) & RT5670_ID_MASK) { 2659 switch (snd_soc_read(codec, RT5670_RESET) & RT5670_ID_MASK) {
2660 case RT5670_ID_5670: 2660 case RT5670_ID_5670:
2661 case RT5670_ID_5671: 2661 case RT5670_ID_5671:
2662 snd_soc_dapm_new_controls(&codec->dapm, 2662 snd_soc_dapm_new_controls(dapm,
2663 rt5670_specific_dapm_widgets, 2663 rt5670_specific_dapm_widgets,
2664 ARRAY_SIZE(rt5670_specific_dapm_widgets)); 2664 ARRAY_SIZE(rt5670_specific_dapm_widgets));
2665 snd_soc_dapm_add_routes(&codec->dapm, 2665 snd_soc_dapm_add_routes(dapm,
2666 rt5670_specific_dapm_routes, 2666 rt5670_specific_dapm_routes,
2667 ARRAY_SIZE(rt5670_specific_dapm_routes)); 2667 ARRAY_SIZE(rt5670_specific_dapm_routes));
2668 break; 2668 break;
2669 case RT5670_ID_5672: 2669 case RT5670_ID_5672:
2670 snd_soc_dapm_new_controls(&codec->dapm, 2670 snd_soc_dapm_new_controls(dapm,
2671 rt5672_specific_dapm_widgets, 2671 rt5672_specific_dapm_widgets,
2672 ARRAY_SIZE(rt5672_specific_dapm_widgets)); 2672 ARRAY_SIZE(rt5672_specific_dapm_widgets));
2673 snd_soc_dapm_add_routes(&codec->dapm, 2673 snd_soc_dapm_add_routes(dapm,
2674 rt5672_specific_dapm_routes, 2674 rt5672_specific_dapm_routes,
2675 ARRAY_SIZE(rt5672_specific_dapm_routes)); 2675 ARRAY_SIZE(rt5672_specific_dapm_routes));
2676 break; 2676 break;
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index af182586712d..fe5581675983 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -62,6 +62,9 @@ static const struct reg_default init_list[] = {
62 {RT5677_PR_BASE + 0x1e, 0x0000}, 62 {RT5677_PR_BASE + 0x1e, 0x0000},
63 {RT5677_PR_BASE + 0x12, 0x0eaa}, 63 {RT5677_PR_BASE + 0x12, 0x0eaa},
64 {RT5677_PR_BASE + 0x14, 0x018a}, 64 {RT5677_PR_BASE + 0x14, 0x018a},
65 {RT5677_PR_BASE + 0x15, 0x0490},
66 {RT5677_PR_BASE + 0x38, 0x0f71},
67 {RT5677_PR_BASE + 0x39, 0x0f71},
65}; 68};
66#define RT5677_INIT_REG_LEN ARRAY_SIZE(init_list) 69#define RT5677_INIT_REG_LEN ARRAY_SIZE(init_list)
67 70
@@ -817,7 +820,7 @@ static int rt5677_dsp_vad_put(struct snd_kcontrol *kcontrol,
817 820
818 rt5677->dsp_vad_en = !!ucontrol->value.integer.value[0]; 821 rt5677->dsp_vad_en = !!ucontrol->value.integer.value[0];
819 822
820 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 823 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
821 rt5677_set_dsp_vad(codec, rt5677->dsp_vad_en); 824 rt5677_set_dsp_vad(codec, rt5677->dsp_vad_en);
822 825
823 return 0; 826 return 0;
@@ -914,7 +917,7 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
914{ 917{
915 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 918 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
916 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 919 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
917 int idx = rl6231_calc_dmic_clk(rt5677->sysclk); 920 int idx = rl6231_calc_dmic_clk(rt5677->lrck[RT5677_AIF1] << 8);
918 921
919 if (idx < 0) 922 if (idx < 0)
920 dev_err(codec->dev, "Failed to set DMIC clock\n"); 923 dev_err(codec->dev, "Failed to set DMIC clock\n");
@@ -2476,7 +2479,7 @@ static int rt5677_vref_event(struct snd_soc_dapm_widget *w,
2476 2479
2477 switch (event) { 2480 switch (event) {
2478 case SND_SOC_DAPM_POST_PMU: 2481 case SND_SOC_DAPM_POST_PMU:
2479 if (codec->dapm.bias_level != SND_SOC_BIAS_ON && 2482 if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_ON &&
2480 !rt5677->is_vref_slow) { 2483 !rt5677->is_vref_slow) {
2481 mdelay(20); 2484 mdelay(20);
2482 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, 2485 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
@@ -4350,7 +4353,7 @@ static int rt5677_set_bias_level(struct snd_soc_codec *codec,
4350 break; 4353 break;
4351 4354
4352 case SND_SOC_BIAS_PREPARE: 4355 case SND_SOC_BIAS_PREPARE:
4353 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) { 4356 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) {
4354 rt5677_set_dsp_vad(codec, false); 4357 rt5677_set_dsp_vad(codec, false);
4355 4358
4356 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, 4359 regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
@@ -4392,7 +4395,6 @@ static int rt5677_set_bias_level(struct snd_soc_codec *codec,
4392 default: 4395 default:
4393 break; 4396 break;
4394 } 4397 }
4395 codec->dapm.bias_level = level;
4396 4398
4397 return 0; 4399 return 0;
4398} 4400}
@@ -4603,22 +4605,23 @@ static void rt5677_free_gpio(struct i2c_client *i2c)
4603 4605
4604static int rt5677_probe(struct snd_soc_codec *codec) 4606static int rt5677_probe(struct snd_soc_codec *codec)
4605{ 4607{
4608 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
4606 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4609 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
4607 int i; 4610 int i;
4608 4611
4609 rt5677->codec = codec; 4612 rt5677->codec = codec;
4610 4613
4611 if (rt5677->pdata.dmic2_clk_pin == RT5677_DMIC_CLK2) { 4614 if (rt5677->pdata.dmic2_clk_pin == RT5677_DMIC_CLK2) {
4612 snd_soc_dapm_add_routes(&codec->dapm, 4615 snd_soc_dapm_add_routes(dapm,
4613 rt5677_dmic2_clk_2, 4616 rt5677_dmic2_clk_2,
4614 ARRAY_SIZE(rt5677_dmic2_clk_2)); 4617 ARRAY_SIZE(rt5677_dmic2_clk_2));
4615 } else { /*use dmic1 clock by default*/ 4618 } else { /*use dmic1 clock by default*/
4616 snd_soc_dapm_add_routes(&codec->dapm, 4619 snd_soc_dapm_add_routes(dapm,
4617 rt5677_dmic2_clk_1, 4620 rt5677_dmic2_clk_1,
4618 ARRAY_SIZE(rt5677_dmic2_clk_1)); 4621 ARRAY_SIZE(rt5677_dmic2_clk_1));
4619 } 4622 }
4620 4623
4621 rt5677_set_bias_level(codec, SND_SOC_BIAS_OFF); 4624 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
4622 4625
4623 regmap_write(rt5677->regmap, RT5677_DIG_MISC, 0x0020); 4626 regmap_write(rt5677->regmap, RT5677_DIG_MISC, 0x0020);
4624 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x0c00); 4627 regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x0c00);
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 3593a1496056..661ed4d22007 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -948,7 +948,7 @@ static int sgtl5000_set_bias_level(struct snd_soc_codec *codec,
948 case SND_SOC_BIAS_PREPARE: 948 case SND_SOC_BIAS_PREPARE:
949 break; 949 break;
950 case SND_SOC_BIAS_STANDBY: 950 case SND_SOC_BIAS_STANDBY:
951 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 951 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
952 ret = regulator_bulk_enable( 952 ret = regulator_bulk_enable(
953 ARRAY_SIZE(sgtl5000->supplies), 953 ARRAY_SIZE(sgtl5000->supplies),
954 sgtl5000->supplies); 954 sgtl5000->supplies);
@@ -979,7 +979,6 @@ static int sgtl5000_set_bias_level(struct snd_soc_codec *codec,
979 break; 979 break;
980 } 980 }
981 981
982 codec->dapm.bias_level = level;
983 return 0; 982 return 0;
984} 983}
985 984
diff --git a/sound/soc/codecs/sirf-audio-codec.c b/sound/soc/codecs/sirf-audio-codec.c
index 0a8e43c98a07..29cb44256044 100644
--- a/sound/soc/codecs/sirf-audio-codec.c
+++ b/sound/soc/codecs/sirf-audio-codec.c
@@ -395,7 +395,7 @@ struct snd_soc_dai_driver sirf_audio_codec_dai = {
395 395
396static int sirf_audio_codec_probe(struct snd_soc_codec *codec) 396static int sirf_audio_codec_probe(struct snd_soc_codec *codec)
397{ 397{
398 struct snd_soc_dapm_context *dapm = &codec->dapm; 398 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
399 399
400 pm_runtime_enable(codec->dev); 400 pm_runtime_enable(codec->dev);
401 401
diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c
index 7947c0ebb1ed..3a7de0159f24 100644
--- a/sound/soc/codecs/sn95031.c
+++ b/sound/soc/codecs/sn95031.c
@@ -194,7 +194,7 @@ static int sn95031_set_vaud_bias(struct snd_soc_codec *codec,
194 break; 194 break;
195 195
196 case SND_SOC_BIAS_PREPARE: 196 case SND_SOC_BIAS_PREPARE:
197 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) { 197 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) {
198 pr_debug("vaud_bias powering up pll\n"); 198 pr_debug("vaud_bias powering up pll\n");
199 /* power up the pll */ 199 /* power up the pll */
200 snd_soc_write(codec, SN95031_AUDPLLCTRL, BIT(5)); 200 snd_soc_write(codec, SN95031_AUDPLLCTRL, BIT(5));
@@ -205,17 +205,22 @@ static int sn95031_set_vaud_bias(struct snd_soc_codec *codec,
205 break; 205 break;
206 206
207 case SND_SOC_BIAS_STANDBY: 207 case SND_SOC_BIAS_STANDBY:
208 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 208 switch (snd_soc_codec_get_bias_level(codec)) {
209 case SND_SOC_BIAS_OFF:
209 pr_debug("vaud_bias power up rail\n"); 210 pr_debug("vaud_bias power up rail\n");
210 /* power up the rail */ 211 /* power up the rail */
211 snd_soc_write(codec, SN95031_VAUD, 212 snd_soc_write(codec, SN95031_VAUD,
212 BIT(2)|BIT(1)|BIT(0)); 213 BIT(2)|BIT(1)|BIT(0));
213 msleep(1); 214 msleep(1);
214 } else if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) { 215 break;
216 case SND_SOC_BIAS_PREPARE:
215 /* turn off pcm */ 217 /* turn off pcm */
216 pr_debug("vaud_bias power dn pcm\n"); 218 pr_debug("vaud_bias power dn pcm\n");
217 snd_soc_update_bits(codec, SN95031_PCM2C2, BIT(0), 0); 219 snd_soc_update_bits(codec, SN95031_PCM2C2, BIT(0), 0);
218 snd_soc_write(codec, SN95031_AUDPLLCTRL, 0); 220 snd_soc_write(codec, SN95031_AUDPLLCTRL, 0);
221 break;
222 default:
223 break;
219 } 224 }
220 break; 225 break;
221 226
@@ -226,7 +231,6 @@ static int sn95031_set_vaud_bias(struct snd_soc_codec *codec,
226 break; 231 break;
227 } 232 }
228 233
229 codec->dapm.bias_level = level;
230 return 0; 234 return 0;
231} 235}
232 236
diff --git a/sound/soc/codecs/ssm2518.c b/sound/soc/codecs/ssm2518.c
index 67ea55adb307..13c6ab0f7af0 100644
--- a/sound/soc/codecs/ssm2518.c
+++ b/sound/soc/codecs/ssm2518.c
@@ -518,12 +518,7 @@ static int ssm2518_set_bias_level(struct snd_soc_codec *codec,
518 break; 518 break;
519 } 519 }
520 520
521 if (ret) 521 return ret;
522 return ret;
523
524 codec->dapm.bias_level = level;
525
526 return 0;
527} 522}
528 523
529static int ssm2518_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, 524static int ssm2518_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index 314eaece1b7d..296a140b8c35 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -473,7 +473,6 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
473 break; 473 break;
474 474
475 } 475 }
476 codec->dapm.bias_level = level;
477 return 0; 476 return 0;
478} 477}
479 478
diff --git a/sound/soc/codecs/ssm4567.c b/sound/soc/codecs/ssm4567.c
index a984485108cd..643bcff4a919 100644
--- a/sound/soc/codecs/ssm4567.c
+++ b/sound/soc/codecs/ssm4567.c
@@ -361,12 +361,7 @@ static int ssm4567_set_bias_level(struct snd_soc_codec *codec,
361 break; 361 break;
362 } 362 }
363 363
364 if (ret) 364 return ret;
365 return ret;
366
367 codec->dapm.bias_level = level;
368
369 return 0;
370} 365}
371 366
372static const struct snd_soc_dai_ops ssm4567_dai_ops = { 367static const struct snd_soc_dai_ops ssm4567_dai_ops = {
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 007a0e3bc273..ffe6187dce85 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -819,7 +819,7 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec,
819 break; 819 break;
820 820
821 case SND_SOC_BIAS_STANDBY: 821 case SND_SOC_BIAS_STANDBY:
822 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 822 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
823 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), 823 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies),
824 sta32x->supplies); 824 sta32x->supplies);
825 if (ret != 0) { 825 if (ret != 0) {
@@ -854,7 +854,6 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec,
854 sta32x->supplies); 854 sta32x->supplies);
855 break; 855 break;
856 } 856 }
857 codec->dapm.bias_level = level;
858 return 0; 857 return 0;
859} 858}
860 859
@@ -970,7 +969,7 @@ static int sta32x_probe(struct snd_soc_codec *codec)
970 if (sta32x->pdata->needs_esd_watchdog) 969 if (sta32x->pdata->needs_esd_watchdog)
971 INIT_DELAYED_WORK(&sta32x->watchdog_work, sta32x_watchdog); 970 INIT_DELAYED_WORK(&sta32x->watchdog_work, sta32x_watchdog);
972 971
973 sta32x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 972 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
974 /* Bias level configuration will have done an extra enable */ 973 /* Bias level configuration will have done an extra enable */
975 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); 974 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
976 975
diff --git a/sound/soc/codecs/sta350.c b/sound/soc/codecs/sta350.c
index 669e3228241e..025f6639330e 100644
--- a/sound/soc/codecs/sta350.c
+++ b/sound/soc/codecs/sta350.c
@@ -853,7 +853,7 @@ static int sta350_set_bias_level(struct snd_soc_codec *codec,
853 break; 853 break;
854 854
855 case SND_SOC_BIAS_STANDBY: 855 case SND_SOC_BIAS_STANDBY:
856 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 856 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
857 ret = regulator_bulk_enable( 857 ret = regulator_bulk_enable(
858 ARRAY_SIZE(sta350->supplies), 858 ARRAY_SIZE(sta350->supplies),
859 sta350->supplies); 859 sta350->supplies);
@@ -890,7 +890,6 @@ static int sta350_set_bias_level(struct snd_soc_codec *codec,
890 sta350->supplies); 890 sta350->supplies);
891 break; 891 break;
892 } 892 }
893 codec->dapm.bias_level = level;
894 return 0; 893 return 0;
895} 894}
896 895
@@ -1037,7 +1036,7 @@ static int sta350_probe(struct snd_soc_codec *codec)
1037 sta350->coef_shadow[60] = 0x400000; 1036 sta350->coef_shadow[60] = 0x400000;
1038 sta350->coef_shadow[61] = 0x400000; 1037 sta350->coef_shadow[61] = 0x400000;
1039 1038
1040 sta350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1039 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1041 /* Bias level configuration will have done an extra enable */ 1040 /* Bias level configuration will have done an extra enable */
1042 regulator_bulk_disable(ARRAY_SIZE(sta350->supplies), sta350->supplies); 1041 regulator_bulk_disable(ARRAY_SIZE(sta350->supplies), sta350->supplies);
1043 1042
diff --git a/sound/soc/codecs/sta529.c b/sound/soc/codecs/sta529.c
index b0f436d10125..4f70378b2cfb 100644
--- a/sound/soc/codecs/sta529.c
+++ b/sound/soc/codecs/sta529.c
@@ -165,7 +165,7 @@ static int sta529_set_bias_level(struct snd_soc_codec *codec, enum
165 FFX_CLK_ENB); 165 FFX_CLK_ENB);
166 break; 166 break;
167 case SND_SOC_BIAS_STANDBY: 167 case SND_SOC_BIAS_STANDBY:
168 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 168 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
169 regcache_sync(sta529->regmap); 169 regcache_sync(sta529->regmap);
170 snd_soc_update_bits(codec, STA529_FFXCFG0, 170 snd_soc_update_bits(codec, STA529_FFXCFG0,
171 POWER_CNTLMSAK, POWER_STDBY); 171 POWER_CNTLMSAK, POWER_STDBY);
@@ -179,12 +179,6 @@ static int sta529_set_bias_level(struct snd_soc_codec *codec, enum
179 break; 179 break;
180 } 180 }
181 181
182 /*
183 * store the label for powers down audio subsystem for suspend.This is
184 * used by soc core layer
185 */
186 codec->dapm.bias_level = level;
187
188 return 0; 182 return 0;
189 183
190} 184}
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index 6464caf72b21..ed4cca7f6779 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -236,7 +236,6 @@ static int stac9766_set_bias_level(struct snd_soc_codec *codec,
236 stac9766_ac97_write(codec, AC97_POWERDOWN, 0xffff); 236 stac9766_ac97_write(codec, AC97_POWERDOWN, 0xffff);
237 break; 237 break;
238 } 238 }
239 codec->dapm.bias_level = level;
240 return 0; 239 return 0;
241} 240}
242 241
@@ -321,7 +320,7 @@ static struct snd_soc_dai_driver stac9766_dai[] = {
321 .channels_max = 2, 320 .channels_max = 2,
322 .rates = SNDRV_PCM_RATE_32000 | \ 321 .rates = SNDRV_PCM_RATE_32000 | \
323 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, 322 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
324 .formats = SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE, 323 .formats = SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
325 }, 324 },
326 /* alsa ops */ 325 /* alsa ops */
327 .ops = &stac9766_dai_ops_digital, 326 .ops = &stac9766_dai_ops_digital,
diff --git a/sound/soc/codecs/tfa9879.c b/sound/soc/codecs/tfa9879.c
index 16f1b71edb55..aab0af681e8c 100644
--- a/sound/soc/codecs/tfa9879.c
+++ b/sound/soc/codecs/tfa9879.c
@@ -280,8 +280,8 @@ static int tfa9879_i2c_probe(struct i2c_client *i2c,
280 int i; 280 int i;
281 281
282 tfa9879 = devm_kzalloc(&i2c->dev, sizeof(*tfa9879), GFP_KERNEL); 282 tfa9879 = devm_kzalloc(&i2c->dev, sizeof(*tfa9879), GFP_KERNEL);
283 if (IS_ERR(tfa9879)) 283 if (!tfa9879)
284 return PTR_ERR(tfa9879); 284 return -ENOMEM;
285 285
286 i2c_set_clientdata(i2c, tfa9879); 286 i2c_set_clientdata(i2c, tfa9879);
287 287
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index cc17e7e5126e..cd8c02b6e4de 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -506,7 +506,6 @@ static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec,
506 snd_soc_write(codec, TLV320AIC23_PWR, 0x1ff); 506 snd_soc_write(codec, TLV320AIC23_PWR, 0x1ff);
507 break; 507 break;
508 } 508 }
509 codec->dapm.bias_level = level;
510 return 0; 509 return 0;
511} 510}
512 511
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index c86dd9aae157..c4c960f592a1 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -646,7 +646,7 @@ static int aic31xx_add_controls(struct snd_soc_codec *codec)
646 646
647static int aic31xx_add_widgets(struct snd_soc_codec *codec) 647static int aic31xx_add_widgets(struct snd_soc_codec *codec)
648{ 648{
649 struct snd_soc_dapm_context *dapm = &codec->dapm; 649 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
650 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); 650 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
651 int ret = 0; 651 int ret = 0;
652 652
@@ -1027,17 +1027,17 @@ static int aic31xx_set_bias_level(struct snd_soc_codec *codec,
1027 enum snd_soc_bias_level level) 1027 enum snd_soc_bias_level level)
1028{ 1028{
1029 dev_dbg(codec->dev, "## %s: %d -> %d\n", __func__, 1029 dev_dbg(codec->dev, "## %s: %d -> %d\n", __func__,
1030 codec->dapm.bias_level, level); 1030 snd_soc_codec_get_bias_level(codec), level);
1031 1031
1032 switch (level) { 1032 switch (level) {
1033 case SND_SOC_BIAS_ON: 1033 case SND_SOC_BIAS_ON:
1034 break; 1034 break;
1035 case SND_SOC_BIAS_PREPARE: 1035 case SND_SOC_BIAS_PREPARE:
1036 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) 1036 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY)
1037 aic31xx_clk_on(codec); 1037 aic31xx_clk_on(codec);
1038 break; 1038 break;
1039 case SND_SOC_BIAS_STANDBY: 1039 case SND_SOC_BIAS_STANDBY:
1040 switch (codec->dapm.bias_level) { 1040 switch (snd_soc_codec_get_bias_level(codec)) {
1041 case SND_SOC_BIAS_OFF: 1041 case SND_SOC_BIAS_OFF:
1042 aic31xx_power_on(codec); 1042 aic31xx_power_on(codec);
1043 break; 1043 break;
@@ -1049,11 +1049,10 @@ static int aic31xx_set_bias_level(struct snd_soc_codec *codec,
1049 } 1049 }
1050 break; 1050 break;
1051 case SND_SOC_BIAS_OFF: 1051 case SND_SOC_BIAS_OFF:
1052 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) 1052 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY)
1053 aic31xx_power_off(codec); 1053 aic31xx_power_off(codec);
1054 break; 1054 break;
1055 } 1055 }
1056 codec->dapm.bias_level = level;
1057 1056
1058 return 0; 1057 return 0;
1059} 1058}
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index 015467ed606b..ad6cb90e5f9b 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -564,7 +564,6 @@ static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
564 case SND_SOC_BIAS_OFF: 564 case SND_SOC_BIAS_OFF:
565 break; 565 break;
566 } 566 }
567 codec->dapm.bias_level = level;
568 return 0; 567 return 0;
569} 568}
570 569
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 51c4713ac6e3..a7cf19b53fb2 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -147,6 +147,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
147 struct snd_ctl_elem_value *ucontrol) 147 struct snd_ctl_elem_value *ucontrol)
148{ 148{
149 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); 149 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
150 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
150 struct soc_mixer_control *mc = 151 struct soc_mixer_control *mc =
151 (struct soc_mixer_control *)kcontrol->private_value; 152 (struct soc_mixer_control *)kcontrol->private_value;
152 unsigned int reg = mc->reg; 153 unsigned int reg = mc->reg;
@@ -179,7 +180,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
179 update.mask = mask; 180 update.mask = mask;
180 update.val = val; 181 update.val = val;
181 182
182 snd_soc_dapm_mixer_update_power(&codec->dapm, kcontrol, connect, 183 snd_soc_dapm_mixer_update_power(dapm, kcontrol, connect,
183 &update); 184 &update);
184 } 185 }
185 186
@@ -979,7 +980,7 @@ static const struct snd_soc_dapm_route intercon_3007[] = {
979static int aic3x_add_widgets(struct snd_soc_codec *codec) 980static int aic3x_add_widgets(struct snd_soc_codec *codec)
980{ 981{
981 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 982 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
982 struct snd_soc_dapm_context *dapm = &codec->dapm; 983 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
983 984
984 switch (aic3x->model) { 985 switch (aic3x->model) {
985 case AIC3X_MODEL_3X: 986 case AIC3X_MODEL_3X:
@@ -1384,7 +1385,7 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1384 case SND_SOC_BIAS_ON: 1385 case SND_SOC_BIAS_ON:
1385 break; 1386 break;
1386 case SND_SOC_BIAS_PREPARE: 1387 case SND_SOC_BIAS_PREPARE:
1387 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY && 1388 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY &&
1388 aic3x->master) { 1389 aic3x->master) {
1389 /* enable pll */ 1390 /* enable pll */
1390 snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, 1391 snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
@@ -1394,7 +1395,7 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1394 case SND_SOC_BIAS_STANDBY: 1395 case SND_SOC_BIAS_STANDBY:
1395 if (!aic3x->power) 1396 if (!aic3x->power)
1396 aic3x_set_power(codec, 1); 1397 aic3x_set_power(codec, 1);
1397 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE && 1398 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE &&
1398 aic3x->master) { 1399 aic3x->master) {
1399 /* disable pll */ 1400 /* disable pll */
1400 snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, 1401 snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
@@ -1406,7 +1407,6 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1406 aic3x_set_power(codec, 0); 1407 aic3x_set_power(codec, 0);
1407 break; 1408 break;
1408 } 1409 }
1409 codec->dapm.bias_level = level;
1410 1410
1411 return 0; 1411 return 0;
1412} 1412}
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 4e3e607dec13..d67a311f0e75 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -633,7 +633,7 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
633 case SND_SOC_BIAS_PREPARE: 633 case SND_SOC_BIAS_PREPARE:
634 break; 634 break;
635 case SND_SOC_BIAS_STANDBY: 635 case SND_SOC_BIAS_STANDBY:
636 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 636 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
637 /* Coming from OFF, switch on the codec */ 637 /* Coming from OFF, switch on the codec */
638 ret = dac33_hard_power(codec, 1); 638 ret = dac33_hard_power(codec, 1);
639 if (ret != 0) 639 if (ret != 0)
@@ -644,14 +644,13 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
644 break; 644 break;
645 case SND_SOC_BIAS_OFF: 645 case SND_SOC_BIAS_OFF:
646 /* Do not power off, when the codec is already off */ 646 /* Do not power off, when the codec is already off */
647 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 647 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
648 return 0; 648 return 0;
649 ret = dac33_hard_power(codec, 0); 649 ret = dac33_hard_power(codec, 0);
650 if (ret != 0) 650 if (ret != 0)
651 return ret; 651 return ret;
652 break; 652 break;
653 } 653 }
654 codec->dapm.bias_level = level;
655 654
656 return 0; 655 return 0;
657} 656}
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index d04693e9cf9f..90f5f04eca2d 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -1588,14 +1588,13 @@ static int twl4030_set_bias_level(struct snd_soc_codec *codec,
1588 case SND_SOC_BIAS_PREPARE: 1588 case SND_SOC_BIAS_PREPARE:
1589 break; 1589 break;
1590 case SND_SOC_BIAS_STANDBY: 1590 case SND_SOC_BIAS_STANDBY:
1591 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 1591 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
1592 twl4030_codec_enable(codec, 1); 1592 twl4030_codec_enable(codec, 1);
1593 break; 1593 break;
1594 case SND_SOC_BIAS_OFF: 1594 case SND_SOC_BIAS_OFF:
1595 twl4030_codec_enable(codec, 0); 1595 twl4030_codec_enable(codec, 0);
1596 break; 1596 break;
1597 } 1597 }
1598 codec->dapm.bias_level = level;
1599 1598
1600 return 0; 1599 return 0;
1601} 1600}
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index aeec27b6f1af..9db7408f6e05 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -533,7 +533,7 @@ static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol,
533 533
534int twl6040_get_dl1_gain(struct snd_soc_codec *codec) 534int twl6040_get_dl1_gain(struct snd_soc_codec *codec)
535{ 535{
536 struct snd_soc_dapm_context *dapm = &codec->dapm; 536 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
537 537
538 if (snd_soc_dapm_get_pin_status(dapm, "EP")) 538 if (snd_soc_dapm_get_pin_status(dapm, "EP"))
539 return -1; /* -1dB */ 539 return -1; /* -1dB */
@@ -853,8 +853,6 @@ static int twl6040_set_bias_level(struct snd_soc_codec *codec,
853 break; 853 break;
854 } 854 }
855 855
856 codec->dapm.bias_level = level;
857
858 return 0; 856 return 0;
859} 857}
860 858
@@ -1130,7 +1128,7 @@ static int twl6040_probe(struct snd_soc_codec *codec)
1130 return ret; 1128 return ret;
1131 } 1129 }
1132 1130
1133 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1131 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1134 twl6040_init_chip(codec); 1132 twl6040_init_chip(codec);
1135 1133
1136 return 0; 1134 return 0;
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index f883308c00de..913edf283239 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -350,7 +350,6 @@ static int uda134x_set_bias_level(struct snd_soc_codec *codec,
350 pd->power(0); 350 pd->power(0);
351 break; 351 break;
352 } 352 }
353 codec->dapm.bias_level = level;
354 return 0; 353 return 0;
355} 354}
356 355
@@ -478,6 +477,7 @@ static struct snd_soc_dai_driver uda134x_dai = {
478 477
479static int uda134x_soc_probe(struct snd_soc_codec *codec) 478static int uda134x_soc_probe(struct snd_soc_codec *codec)
480{ 479{
480 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
481 struct uda134x_priv *uda134x; 481 struct uda134x_priv *uda134x;
482 struct uda134x_platform_data *pd = codec->component.card->dev->platform_data; 482 struct uda134x_platform_data *pd = codec->component.card->dev->platform_data;
483 const struct snd_soc_dapm_widget *widgets; 483 const struct snd_soc_dapm_widget *widgets;
@@ -526,7 +526,7 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
526 num_widgets = ARRAY_SIZE(uda1340_dapm_widgets); 526 num_widgets = ARRAY_SIZE(uda1340_dapm_widgets);
527 } 527 }
528 528
529 ret = snd_soc_dapm_new_controls(&codec->dapm, widgets, num_widgets); 529 ret = snd_soc_dapm_new_controls(dapm, widgets, num_widgets);
530 if (ret) { 530 if (ret) {
531 printk(KERN_ERR "%s failed to register dapm controls: %d", 531 printk(KERN_ERR "%s failed to register dapm controls: %d",
532 __func__, ret); 532 __func__, ret);
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index dc7778b6dd7f..6e159f59d219 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -437,7 +437,7 @@ static int uda1380_set_dai_fmt_both(struct snd_soc_dai *codec_dai,
437 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) 437 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
438 return -EINVAL; 438 return -EINVAL;
439 439
440 uda1380_write(codec, UDA1380_IFACE, iface); 440 uda1380_write_reg_cache(codec, UDA1380_IFACE, iface);
441 441
442 return 0; 442 return 0;
443} 443}
@@ -590,9 +590,6 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
590 int reg; 590 int reg;
591 struct uda1380_platform_data *pdata = codec->dev->platform_data; 591 struct uda1380_platform_data *pdata = codec->dev->platform_data;
592 592
593 if (codec->dapm.bias_level == level)
594 return 0;
595
596 switch (level) { 593 switch (level) {
597 case SND_SOC_BIAS_ON: 594 case SND_SOC_BIAS_ON:
598 case SND_SOC_BIAS_PREPARE: 595 case SND_SOC_BIAS_PREPARE:
@@ -600,7 +597,7 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
600 uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm); 597 uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm);
601 break; 598 break;
602 case SND_SOC_BIAS_STANDBY: 599 case SND_SOC_BIAS_STANDBY:
603 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 600 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
604 if (gpio_is_valid(pdata->gpio_power)) { 601 if (gpio_is_valid(pdata->gpio_power)) {
605 gpio_set_value(pdata->gpio_power, 1); 602 gpio_set_value(pdata->gpio_power, 1);
606 mdelay(1); 603 mdelay(1);
@@ -623,7 +620,6 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
623 for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM; reg++) 620 for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM; reg++)
624 set_bit(reg - 0x10, &uda1380_cache_dirty); 621 set_bit(reg - 0x10, &uda1380_cache_dirty);
625 } 622 }
626 codec->dapm.bias_level = level;
627 return 0; 623 return 0;
628} 624}
629 625
diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c
index f37989ec7cba..6560a66b3f35 100644
--- a/sound/soc/codecs/wm0010.c
+++ b/sound/soc/codecs/wm0010.c
@@ -751,13 +751,13 @@ static int wm0010_set_bias_level(struct snd_soc_codec *codec,
751 751
752 switch (level) { 752 switch (level) {
753 case SND_SOC_BIAS_ON: 753 case SND_SOC_BIAS_ON:
754 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) 754 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE)
755 wm0010_boot(codec); 755 wm0010_boot(codec);
756 break; 756 break;
757 case SND_SOC_BIAS_PREPARE: 757 case SND_SOC_BIAS_PREPARE:
758 break; 758 break;
759 case SND_SOC_BIAS_STANDBY: 759 case SND_SOC_BIAS_STANDBY:
760 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) { 760 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE) {
761 mutex_lock(&wm0010->lock); 761 mutex_lock(&wm0010->lock);
762 wm0010_halt(codec); 762 wm0010_halt(codec);
763 mutex_unlock(&wm0010->lock); 763 mutex_unlock(&wm0010->lock);
@@ -767,8 +767,6 @@ static int wm0010_set_bias_level(struct snd_soc_codec *codec,
767 break; 767 break;
768 } 768 }
769 769
770 codec->dapm.bias_level = level;
771
772 return 0; 770 return 0;
773} 771}
774 772
diff --git a/sound/soc/codecs/wm1250-ev1.c b/sound/soc/codecs/wm1250-ev1.c
index 8011f75fb6cb..048f00568260 100644
--- a/sound/soc/codecs/wm1250-ev1.c
+++ b/sound/soc/codecs/wm1250-ev1.c
@@ -61,8 +61,6 @@ static int wm1250_ev1_set_bias_level(struct snd_soc_codec *codec,
61 break; 61 break;
62 } 62 }
63 63
64 codec->dapm.bias_level = level;
65
66 return 0; 64 return 0;
67} 65}
68 66
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index 96740379b711..98495dd61239 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -2101,7 +2101,7 @@ static void wm5100_micd_irq(struct wm5100_priv *wm5100)
2101int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) 2101int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
2102{ 2102{
2103 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); 2103 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
2104 struct snd_soc_dapm_context *dapm = &codec->dapm; 2104 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2105 2105
2106 if (jack) { 2106 if (jack) {
2107 wm5100->jack = jack; 2107 wm5100->jack = jack;
@@ -2336,6 +2336,7 @@ static void wm5100_free_gpio(struct i2c_client *i2c)
2336 2336
2337static int wm5100_probe(struct snd_soc_codec *codec) 2337static int wm5100_probe(struct snd_soc_codec *codec)
2338{ 2338{
2339 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2339 struct i2c_client *i2c = to_i2c_client(codec->dev); 2340 struct i2c_client *i2c = to_i2c_client(codec->dev);
2340 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); 2341 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
2341 int ret, i; 2342 int ret, i;
@@ -2353,8 +2354,7 @@ static int wm5100_probe(struct snd_soc_codec *codec)
2353 /* TODO: check if we're symmetric */ 2354 /* TODO: check if we're symmetric */
2354 2355
2355 if (i2c->irq) 2356 if (i2c->irq)
2356 snd_soc_dapm_new_controls(&codec->dapm, 2357 snd_soc_dapm_new_controls(dapm, wm5100_dapm_widgets_noirq,
2357 wm5100_dapm_widgets_noirq,
2358 ARRAY_SIZE(wm5100_dapm_widgets_noirq)); 2358 ARRAY_SIZE(wm5100_dapm_widgets_noirq));
2359 2359
2360 if (wm5100->pdata.hp_pol) { 2360 if (wm5100->pdata.hp_pol) {
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index 0c6d1bc0526e..d8959e31853d 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -42,7 +42,7 @@ struct wm5102_priv {
42static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0); 42static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0);
43static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 43static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
44static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); 44static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
45static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0); 45static DECLARE_TLV_DB_SCALE(noise_tlv, -13200, 600, 0);
46static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0); 46static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
47 47
48static const struct wm_adsp_region wm5102_dsp1_regions[] = { 48static const struct wm_adsp_region wm5102_dsp1_regions[] = {
@@ -605,12 +605,56 @@ static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w,
605 regmap_write_async(regmap, patch[i].reg, 605 regmap_write_async(regmap, patch[i].reg,
606 patch[i].def); 606 patch[i].def);
607 break; 607 break;
608 case SND_SOC_DAPM_PRE_PMD:
609 break;
610 default:
611 return 0;
612 }
613
614 return arizona_dvfs_sysclk_ev(w, kcontrol, event);
615}
616
617static int wm5102_adsp_power_ev(struct snd_soc_dapm_widget *w,
618 struct snd_kcontrol *kcontrol, int event)
619{
620 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
621 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
622 unsigned int v;
623 int ret;
624
625 switch (event) {
626 case SND_SOC_DAPM_PRE_PMU:
627 ret = regmap_read(arizona->regmap, ARIZONA_SYSTEM_CLOCK_1, &v);
628 if (ret != 0) {
629 dev_err(codec->dev,
630 "Failed to read SYSCLK state: %d\n", ret);
631 return -EIO;
632 }
633
634 v = (v & ARIZONA_SYSCLK_FREQ_MASK) >> ARIZONA_SYSCLK_FREQ_SHIFT;
635
636 if (v >= 3) {
637 ret = arizona_dvfs_up(codec, ARIZONA_DVFS_ADSP1_RQ);
638 if (ret) {
639 dev_err(codec->dev,
640 "Failed to raise DVFS: %d\n", ret);
641 return ret;
642 }
643 }
644 break;
645
646 case SND_SOC_DAPM_POST_PMD:
647 ret = arizona_dvfs_down(codec, ARIZONA_DVFS_ADSP1_RQ);
648 if (ret)
649 dev_warn(codec->dev,
650 "Failed to lower DVFS: %d\n", ret);
651 break;
608 652
609 default: 653 default:
610 break; 654 break;
611 } 655 }
612 656
613 return 0; 657 return wm_adsp2_early_event(w, kcontrol, event);
614} 658}
615 659
616static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol, 660static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol,
@@ -1036,7 +1080,8 @@ static const struct snd_kcontrol_new wm5102_aec_loopback_mux =
1036 1080
1037static const struct snd_soc_dapm_widget wm5102_dapm_widgets[] = { 1081static const struct snd_soc_dapm_widget wm5102_dapm_widgets[] = {
1038SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT, 1082SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT,
1039 0, wm5102_sysclk_ev, SND_SOC_DAPM_POST_PMU), 1083 0, wm5102_sysclk_ev,
1084 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1040SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1, 1085SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
1041 ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0), 1086 ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
1042SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK, 1087SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
@@ -1367,7 +1412,7 @@ ARIZONA_MUX_WIDGETS(ISRC2DEC2, "ISRC2DEC2"),
1367ARIZONA_MUX_WIDGETS(ISRC2INT1, "ISRC2INT1"), 1412ARIZONA_MUX_WIDGETS(ISRC2INT1, "ISRC2INT1"),
1368ARIZONA_MUX_WIDGETS(ISRC2INT2, "ISRC2INT2"), 1413ARIZONA_MUX_WIDGETS(ISRC2INT2, "ISRC2INT2"),
1369 1414
1370WM_ADSP2("DSP1", 0), 1415WM_ADSP2_E("DSP1", 0, wm5102_adsp_power_ev),
1371 1416
1372SND_SOC_DAPM_OUTPUT("HPOUT1L"), 1417SND_SOC_DAPM_OUTPUT("HPOUT1L"),
1373SND_SOC_DAPM_OUTPUT("HPOUT1R"), 1418SND_SOC_DAPM_OUTPUT("HPOUT1R"),
@@ -1827,6 +1872,7 @@ static struct snd_soc_dai_driver wm5102_dai[] = {
1827 1872
1828static int wm5102_codec_probe(struct snd_soc_codec *codec) 1873static int wm5102_codec_probe(struct snd_soc_codec *codec)
1829{ 1874{
1875 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1830 struct wm5102_priv *priv = snd_soc_codec_get_drvdata(codec); 1876 struct wm5102_priv *priv = snd_soc_codec_get_drvdata(codec);
1831 int ret; 1877 int ret;
1832 1878
@@ -1837,9 +1883,9 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
1837 arizona_init_spk(codec); 1883 arizona_init_spk(codec);
1838 arizona_init_gpio(codec); 1884 arizona_init_gpio(codec);
1839 1885
1840 snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS"); 1886 snd_soc_dapm_disable_pin(dapm, "HAPTICS");
1841 1887
1842 priv->core.arizona->dapm = &codec->dapm; 1888 priv->core.arizona->dapm = dapm;
1843 1889
1844 return 0; 1890 return 0;
1845} 1891}
@@ -1909,6 +1955,8 @@ static int wm5102_probe(struct platform_device *pdev)
1909 wm5102->core.arizona = arizona; 1955 wm5102->core.arizona = arizona;
1910 wm5102->core.num_inputs = 6; 1956 wm5102->core.num_inputs = 6;
1911 1957
1958 arizona_init_dvfs(&wm5102->core);
1959
1912 wm5102->core.adsp[0].part = "wm5102"; 1960 wm5102->core.adsp[0].part = "wm5102";
1913 wm5102->core.adsp[0].num = 1; 1961 wm5102->core.adsp[0].num = 1;
1914 wm5102->core.adsp[0].type = WMFW_ADSP2; 1962 wm5102->core.adsp[0].type = WMFW_ADSP2;
@@ -1918,7 +1966,7 @@ static int wm5102_probe(struct platform_device *pdev)
1918 wm5102->core.adsp[0].mem = wm5102_dsp1_regions; 1966 wm5102->core.adsp[0].mem = wm5102_dsp1_regions;
1919 wm5102->core.adsp[0].num_mems = ARRAY_SIZE(wm5102_dsp1_regions); 1967 wm5102->core.adsp[0].num_mems = ARRAY_SIZE(wm5102_dsp1_regions);
1920 1968
1921 ret = wm_adsp2_init(&wm5102->core.adsp[0], true); 1969 ret = wm_adsp2_init(&wm5102->core.adsp[0]);
1922 if (ret != 0) 1970 if (ret != 0)
1923 return ret; 1971 return ret;
1924 1972
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index fbaeddb3e903..14a7739d6c09 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -167,7 +167,7 @@ static int wm5110_sysclk_ev(struct snd_soc_dapm_widget *w,
167static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0); 167static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0);
168static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 168static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
169static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); 169static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
170static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0); 170static DECLARE_TLV_DB_SCALE(noise_tlv, -13200, 600, 0);
171static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0); 171static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
172 172
173#define WM5110_NG_SRC(name, base) \ 173#define WM5110_NG_SRC(name, base) \
@@ -1598,10 +1598,11 @@ static struct snd_soc_dai_driver wm5110_dai[] = {
1598 1598
1599static int wm5110_codec_probe(struct snd_soc_codec *codec) 1599static int wm5110_codec_probe(struct snd_soc_codec *codec)
1600{ 1600{
1601 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1601 struct wm5110_priv *priv = snd_soc_codec_get_drvdata(codec); 1602 struct wm5110_priv *priv = snd_soc_codec_get_drvdata(codec);
1602 int ret; 1603 int ret;
1603 1604
1604 priv->core.arizona->dapm = &codec->dapm; 1605 priv->core.arizona->dapm = dapm;
1605 1606
1606 arizona_init_spk(codec); 1607 arizona_init_spk(codec);
1607 arizona_init_gpio(codec); 1608 arizona_init_gpio(codec);
@@ -1611,9 +1612,7 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
1611 if (ret != 0) 1612 if (ret != 0)
1612 return ret; 1613 return ret;
1613 1614
1614 snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS"); 1615 snd_soc_dapm_disable_pin(dapm, "HAPTICS");
1615
1616 priv->core.arizona->dapm = &codec->dapm;
1617 1616
1618 return 0; 1617 return 0;
1619} 1618}
@@ -1697,7 +1696,7 @@ static int wm5110_probe(struct platform_device *pdev)
1697 wm5110->core.adsp[i].num_mems 1696 wm5110->core.adsp[i].num_mems
1698 = ARRAY_SIZE(wm5110_dsp1_regions); 1697 = ARRAY_SIZE(wm5110_dsp1_regions);
1699 1698
1700 ret = wm_adsp2_init(&wm5110->core.adsp[i], false); 1699 ret = wm_adsp2_init(&wm5110->core.adsp[i]);
1701 if (ret != 0) 1700 if (ret != 0)
1702 return ret; 1701 return ret;
1703 } 1702 }
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index c65e5a75fc1a..41c62c1e62db 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -1102,7 +1102,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1102 break; 1102 break;
1103 1103
1104 case SND_SOC_BIAS_STANDBY: 1104 case SND_SOC_BIAS_STANDBY:
1105 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1105 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1106 ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), 1106 ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies),
1107 priv->supplies); 1107 priv->supplies);
1108 if (ret != 0) 1108 if (ret != 0)
@@ -1235,7 +1235,6 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1235 priv->supplies); 1235 priv->supplies);
1236 break; 1236 break;
1237 } 1237 }
1238 codec->dapm.bias_level = level;
1239 return 0; 1238 return 0;
1240} 1239}
1241 1240
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index b0d84e552fca..d7555085e7f4 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -1145,7 +1145,7 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1145 break; 1145 break;
1146 1146
1147 case SND_SOC_BIAS_STANDBY: 1147 case SND_SOC_BIAS_STANDBY:
1148 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1148 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1149 ret = regulator_bulk_enable(ARRAY_SIZE(power), 1149 ret = regulator_bulk_enable(ARRAY_SIZE(power),
1150 &power[0]); 1150 &power[0]);
1151 if (ret != 0) { 1151 if (ret != 0) {
@@ -1232,7 +1232,6 @@ static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1232 break; 1232 break;
1233 } 1233 }
1234 1234
1235 codec->dapm.bias_level = level;
1236 return 0; 1235 return 0;
1237} 1236}
1238 1237
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 8736ad094b24..dac5beb4d023 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -519,7 +519,7 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
519 case SND_SOC_BIAS_STANDBY: 519 case SND_SOC_BIAS_STANDBY:
520 power1 |= WM8510_POWER1_BIASEN | WM8510_POWER1_BUFIOEN; 520 power1 |= WM8510_POWER1_BIASEN | WM8510_POWER1_BUFIOEN;
521 521
522 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 522 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
523 regcache_sync(wm8510->regmap); 523 regcache_sync(wm8510->regmap);
524 524
525 /* Initial cap charge at VMID 5k */ 525 /* Initial cap charge at VMID 5k */
@@ -538,7 +538,6 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
538 break; 538 break;
539 } 539 }
540 540
541 codec->dapm.bias_level = level;
542 return 0; 541 return 0;
543} 542}
544 543
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index b1cc94f5fc4b..8c5b9df3e542 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -308,7 +308,7 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec,
308 break; 308 break;
309 309
310 case SND_SOC_BIAS_STANDBY: 310 case SND_SOC_BIAS_STANDBY:
311 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 311 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
312 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies), 312 ret = regulator_bulk_enable(ARRAY_SIZE(wm8523->supplies),
313 wm8523->supplies); 313 wm8523->supplies);
314 if (ret != 0) { 314 if (ret != 0) {
@@ -344,7 +344,6 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec,
344 wm8523->supplies); 344 wm8523->supplies);
345 break; 345 break;
346 } 346 }
347 codec->dapm.bias_level = level;
348 return 0; 347 return 0;
349} 348}
350 349
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 0a887c5ec83a..759a7928ac3e 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -795,7 +795,7 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
795 break; 795 break;
796 796
797 case SND_SOC_BIAS_STANDBY: 797 case SND_SOC_BIAS_STANDBY:
798 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 798 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
799 /* Power up and get individual control of the DACs */ 799 /* Power up and get individual control of the DACs */
800 snd_soc_update_bits(codec, WM8580_PWRDN1, 800 snd_soc_update_bits(codec, WM8580_PWRDN1,
801 WM8580_PWRDN1_PWDN | 801 WM8580_PWRDN1_PWDN |
@@ -812,7 +812,6 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
812 WM8580_PWRDN1_PWDN, WM8580_PWRDN1_PWDN); 812 WM8580_PWRDN1_PWDN, WM8580_PWRDN1_PWDN);
813 break; 813 break;
814 } 814 }
815 codec->dapm.bias_level = level;
816 return 0; 815 return 0;
817} 816}
818 817
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c
index 121e46d53779..cc8251f09f8a 100644
--- a/sound/soc/codecs/wm8711.c
+++ b/sound/soc/codecs/wm8711.c
@@ -310,7 +310,7 @@ static int wm8711_set_bias_level(struct snd_soc_codec *codec,
310 case SND_SOC_BIAS_PREPARE: 310 case SND_SOC_BIAS_PREPARE:
311 break; 311 break;
312 case SND_SOC_BIAS_STANDBY: 312 case SND_SOC_BIAS_STANDBY:
313 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 313 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
314 regcache_sync(wm8711->regmap); 314 regcache_sync(wm8711->regmap);
315 315
316 snd_soc_write(codec, WM8711_PWR, reg | 0x0040); 316 snd_soc_write(codec, WM8711_PWR, reg | 0x0040);
@@ -320,7 +320,6 @@ static int wm8711_set_bias_level(struct snd_soc_codec *codec,
320 snd_soc_write(codec, WM8711_PWR, 0xffff); 320 snd_soc_write(codec, WM8711_PWR, 0xffff);
321 break; 321 break;
322 } 322 }
323 codec->dapm.bias_level = level;
324 return 0; 323 return 0;
325} 324}
326 325
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index 55c7fb4fc786..f1a173e6ec33 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -170,7 +170,7 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec,
170 case SND_SOC_BIAS_ON: 170 case SND_SOC_BIAS_ON:
171 case SND_SOC_BIAS_PREPARE: 171 case SND_SOC_BIAS_PREPARE:
172 case SND_SOC_BIAS_STANDBY: 172 case SND_SOC_BIAS_STANDBY:
173 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 173 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
174 /* Power everything up... */ 174 /* Power everything up... */
175 reg = snd_soc_read(codec, WM8728_DACCTL); 175 reg = snd_soc_read(codec, WM8728_DACCTL);
176 snd_soc_write(codec, WM8728_DACCTL, reg & ~0x4); 176 snd_soc_write(codec, WM8728_DACCTL, reg & ~0x4);
@@ -185,7 +185,6 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec,
185 snd_soc_write(codec, WM8728_DACCTL, reg | 0x4); 185 snd_soc_write(codec, WM8728_DACCTL, reg | 0x4);
186 break; 186 break;
187 } 187 }
188 codec->dapm.bias_level = level;
189 return 0; 188 return 0;
190} 189}
191 190
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 2245b6a32f3d..915ea11ad4b6 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -387,6 +387,7 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
387 int clk_id, unsigned int freq, int dir) 387 int clk_id, unsigned int freq, int dir)
388{ 388{
389 struct snd_soc_codec *codec = codec_dai->codec; 389 struct snd_soc_codec *codec = codec_dai->codec;
390 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
390 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 391 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
391 392
392 switch (clk_id) { 393 switch (clk_id) {
@@ -421,7 +422,7 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
421 422
422 wm8731->sysclk = freq; 423 wm8731->sysclk = freq;
423 424
424 snd_soc_dapm_sync(&codec->dapm); 425 snd_soc_dapm_sync(dapm);
425 426
426 return 0; 427 return 0;
427} 428}
@@ -501,7 +502,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
501 case SND_SOC_BIAS_PREPARE: 502 case SND_SOC_BIAS_PREPARE:
502 break; 503 break;
503 case SND_SOC_BIAS_STANDBY: 504 case SND_SOC_BIAS_STANDBY:
504 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 505 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
505 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 506 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
506 wm8731->supplies); 507 wm8731->supplies);
507 if (ret != 0) 508 if (ret != 0)
@@ -523,7 +524,6 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
523 regcache_mark_dirty(wm8731->regmap); 524 regcache_mark_dirty(wm8731->regmap);
524 break; 525 break;
525 } 526 }
526 codec->dapm.bias_level = level;
527 return 0; 527 return 0;
528} 528}
529 529
@@ -599,7 +599,7 @@ static int wm8731_probe(struct snd_soc_codec *codec)
599 goto err_regulator_enable; 599 goto err_regulator_enable;
600 } 600 }
601 601
602 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 602 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
603 603
604 /* Latch the update bits */ 604 /* Latch the update bits */
605 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0); 605 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0);
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
index ada9ac1ba2c6..6ad606fd8b69 100644
--- a/sound/soc/codecs/wm8737.c
+++ b/sound/soc/codecs/wm8737.c
@@ -469,7 +469,7 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
469 break; 469 break;
470 470
471 case SND_SOC_BIAS_STANDBY: 471 case SND_SOC_BIAS_STANDBY:
472 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 472 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
473 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 473 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies),
474 wm8737->supplies); 474 wm8737->supplies);
475 if (ret != 0) { 475 if (ret != 0) {
@@ -483,7 +483,8 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
483 483
484 /* Fast VMID ramp at 2*2.5k */ 484 /* Fast VMID ramp at 2*2.5k */
485 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 485 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
486 WM8737_VMIDSEL_MASK, 0x4); 486 WM8737_VMIDSEL_MASK,
487 2 << WM8737_VMIDSEL_SHIFT);
487 488
488 /* Bring VMID up */ 489 /* Bring VMID up */
489 snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT, 490 snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT,
@@ -497,7 +498,8 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
497 498
498 /* VMID at 2*300k */ 499 /* VMID at 2*300k */
499 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 500 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL,
500 WM8737_VMIDSEL_MASK, 2); 501 WM8737_VMIDSEL_MASK,
502 1 << WM8737_VMIDSEL_SHIFT);
501 503
502 break; 504 break;
503 505
@@ -510,7 +512,6 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec,
510 break; 512 break;
511 } 513 }
512 514
513 codec->dapm.bias_level = level;
514 return 0; 515 return 0;
515} 516}
516 517
@@ -560,7 +561,7 @@ static int wm8737_probe(struct snd_soc_codec *codec)
560 snd_soc_update_bits(codec, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU, 561 snd_soc_update_bits(codec, WM8737_RIGHT_PGA_VOLUME, WM8737_RVU,
561 WM8737_RVU); 562 WM8737_RVU);
562 563
563 wm8737_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 564 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
564 565
565 /* Bias level configuration will have done an extra enable */ 566 /* Bias level configuration will have done an extra enable */
566 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies); 567 regulator_bulk_disable(ARRAY_SIZE(wm8737->supplies), wm8737->supplies);
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index eb0a1644ba11..56d89b0865fa 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -634,7 +634,7 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
634 case SND_SOC_BIAS_PREPARE: 634 case SND_SOC_BIAS_PREPARE:
635 break; 635 break;
636 case SND_SOC_BIAS_STANDBY: 636 case SND_SOC_BIAS_STANDBY:
637 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 637 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
638 snd_soc_cache_sync(codec); 638 snd_soc_cache_sync(codec);
639 639
640 /* Set VMID to 5k */ 640 /* Set VMID to 5k */
@@ -651,7 +651,6 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
651 snd_soc_write(codec, WM8750_PWR1, 0x0001); 651 snd_soc_write(codec, WM8750_PWR1, 0x0001);
652 break; 652 break;
653 } 653 }
654 codec->dapm.bias_level = level;
655 return 0; 654 return 0;
656} 655}
657 656
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index c50a5959345f..feb2997a377a 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -1352,7 +1352,7 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec,
1352 flush_delayed_work(&wm8753->charge_work); 1352 flush_delayed_work(&wm8753->charge_work);
1353 break; 1353 break;
1354 case SND_SOC_BIAS_STANDBY: 1354 case SND_SOC_BIAS_STANDBY:
1355 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1355 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1356 /* set vmid to 5k for quick power up */ 1356 /* set vmid to 5k for quick power up */
1357 snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x01c1); 1357 snd_soc_write(codec, WM8753_PWR1, pwr_reg | 0x01c1);
1358 schedule_delayed_work(&wm8753->charge_work, 1358 schedule_delayed_work(&wm8753->charge_work,
@@ -1367,7 +1367,6 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec,
1367 snd_soc_write(codec, WM8753_PWR1, 0x0001); 1367 snd_soc_write(codec, WM8753_PWR1, 0x0001);
1368 break; 1368 break;
1369 } 1369 }
1370 codec->dapm.bias_level = level;
1371 return 0; 1370 return 0;
1372} 1371}
1373 1372
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c
index 53e977da2f86..66c1f151071d 100644
--- a/sound/soc/codecs/wm8770.c
+++ b/sound/soc/codecs/wm8770.c
@@ -510,7 +510,7 @@ static int wm8770_set_bias_level(struct snd_soc_codec *codec,
510 case SND_SOC_BIAS_PREPARE: 510 case SND_SOC_BIAS_PREPARE:
511 break; 511 break;
512 case SND_SOC_BIAS_STANDBY: 512 case SND_SOC_BIAS_STANDBY:
513 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 513 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
514 ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies), 514 ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies),
515 wm8770->supplies); 515 wm8770->supplies);
516 if (ret) { 516 if (ret) {
@@ -534,7 +534,6 @@ static int wm8770_set_bias_level(struct snd_soc_codec *codec,
534 break; 534 break;
535 } 535 }
536 536
537 codec->dapm.bias_level = level;
538 return 0; 537 return 0;
539} 538}
540 539
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index c13050b77931..ece9b4456767 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -344,7 +344,7 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
344 case SND_SOC_BIAS_PREPARE: 344 case SND_SOC_BIAS_PREPARE:
345 break; 345 break;
346 case SND_SOC_BIAS_STANDBY: 346 case SND_SOC_BIAS_STANDBY:
347 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 347 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
348 regcache_sync(wm8776->regmap); 348 regcache_sync(wm8776->regmap);
349 349
350 /* Disable the global powerdown; DAPM does the rest */ 350 /* Disable the global powerdown; DAPM does the rest */
@@ -357,7 +357,6 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
357 break; 357 break;
358 } 358 }
359 359
360 codec->dapm.bias_level = level;
361 return 0; 360 return 0;
362} 361}
363 362
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index 1e403f67cf16..c195c2e8af07 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -162,7 +162,7 @@ static int txsrc_put(struct snd_kcontrol *kcontrol,
162 struct snd_ctl_elem_value *ucontrol) 162 struct snd_ctl_elem_value *ucontrol)
163{ 163{
164 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); 164 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
165 struct snd_soc_dapm_context *dapm = &codec->dapm; 165 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
166 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 166 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
167 unsigned int val = ucontrol->value.enumerated.item[0] << e->shift_l; 167 unsigned int val = ucontrol->value.enumerated.item[0] << e->shift_l;
168 unsigned int mask = 1 << e->shift_l; 168 unsigned int mask = 1 << e->shift_l;
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 2eb986c19b88..f3759ec5a863 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -998,8 +998,8 @@ static int wm8900_digital_mute(struct snd_soc_dai *codec_dai, int mute)
998 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 998 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
999 999
1000#define WM8900_PCM_FORMATS \ 1000#define WM8900_PCM_FORMATS \
1001 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ 1001 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1002 SNDRV_PCM_FORMAT_S24_LE) 1002 SNDRV_PCM_FMTBIT_S24_LE)
1003 1003
1004static const struct snd_soc_dai_ops wm8900_dai_ops = { 1004static const struct snd_soc_dai_ops wm8900_dai_ops = {
1005 .hw_params = wm8900_hw_params, 1005 .hw_params = wm8900_hw_params,
@@ -1049,7 +1049,7 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec,
1049 1049
1050 case SND_SOC_BIAS_STANDBY: 1050 case SND_SOC_BIAS_STANDBY:
1051 /* Charge capacitors if initial power up */ 1051 /* Charge capacitors if initial power up */
1052 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1052 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1053 /* STARTUP_BIAS_ENA on */ 1053 /* STARTUP_BIAS_ENA on */
1054 snd_soc_write(codec, WM8900_REG_POWER1, 1054 snd_soc_write(codec, WM8900_REG_POWER1,
1055 WM8900_REG_POWER1_STARTUP_BIAS_ENA); 1055 WM8900_REG_POWER1_STARTUP_BIAS_ENA);
@@ -1117,7 +1117,6 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec,
1117 WM8900_REG_POWER2_SYSCLK_ENA); 1117 WM8900_REG_POWER2_SYSCLK_ENA);
1118 break; 1118 break;
1119 } 1119 }
1120 codec->dapm.bias_level = level;
1121 return 0; 1120 return 0;
1122} 1121}
1123 1122
@@ -1138,7 +1137,7 @@ static int wm8900_suspend(struct snd_soc_codec *codec)
1138 wm8900->fll_out = fll_out; 1137 wm8900->fll_out = fll_out;
1139 wm8900->fll_in = fll_in; 1138 wm8900->fll_in = fll_in;
1140 1139
1141 wm8900_set_bias_level(codec, SND_SOC_BIAS_OFF); 1140 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
1142 1141
1143 return 0; 1142 return 0;
1144} 1143}
@@ -1156,7 +1155,7 @@ static int wm8900_resume(struct snd_soc_codec *codec)
1156 return ret; 1155 return ret;
1157 } 1156 }
1158 1157
1159 wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1158 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1160 1159
1161 /* Restart the FLL? */ 1160 /* Restart the FLL? */
1162 if (wm8900->fll_out) { 1161 if (wm8900->fll_out) {
@@ -1189,7 +1188,7 @@ static int wm8900_probe(struct snd_soc_codec *codec)
1189 wm8900_reset(codec); 1188 wm8900_reset(codec);
1190 1189
1191 /* Turn the chip on */ 1190 /* Turn the chip on */
1192 wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1191 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1193 1192
1194 /* Latch the volume update bits */ 1193 /* Latch the volume update bits */
1195 snd_soc_update_bits(codec, WM8900_REG_LINVOL, 0x100, 0x100); 1194 snd_soc_update_bits(codec, WM8900_REG_LINVOL, 0x100, 0x100);
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index 04b04f8e147c..b5322c1544fb 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -1105,7 +1105,7 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
1105 break; 1105 break;
1106 1106
1107 case SND_SOC_BIAS_STANDBY: 1107 case SND_SOC_BIAS_STANDBY:
1108 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1108 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1109 snd_soc_update_bits(codec, WM8903_BIAS_CONTROL_0, 1109 snd_soc_update_bits(codec, WM8903_BIAS_CONTROL_0,
1110 WM8903_POBCTRL | WM8903_ISEL_MASK | 1110 WM8903_POBCTRL | WM8903_ISEL_MASK |
1111 WM8903_STARTUP_BIAS_ENA | 1111 WM8903_STARTUP_BIAS_ENA |
@@ -1200,8 +1200,6 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec,
1200 break; 1200 break;
1201 } 1201 }
1202 1202
1203 codec->dapm.bias_level = level;
1204
1205 return 0; 1203 return 0;
1206} 1204}
1207 1205
diff --git a/sound/soc/codecs/wm8903.h b/sound/soc/codecs/wm8903.h
index db949311c0f2..0bb4a647755d 100644
--- a/sound/soc/codecs/wm8903.h
+++ b/sound/soc/codecs/wm8903.h
@@ -172,7 +172,7 @@ extern int wm8903_mic_detect(struct snd_soc_codec *codec,
172#define WM8903_VMID_BUF_ENA_WIDTH 1 /* VMID_BUF_ENA */ 172#define WM8903_VMID_BUF_ENA_WIDTH 1 /* VMID_BUF_ENA */
173 173
174#define WM8903_VMID_RES_50K 2 174#define WM8903_VMID_RES_50K 2
175#define WM8903_VMID_RES_250K 3 175#define WM8903_VMID_RES_250K 4
176#define WM8903_VMID_RES_5K 6 176#define WM8903_VMID_RES_5K 6
177 177
178/* 178/*
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 215e93c1ddf0..265a4a58a2d1 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -1168,7 +1168,7 @@ static const struct snd_soc_dapm_route wm8912_intercon[] = {
1168static int wm8904_add_widgets(struct snd_soc_codec *codec) 1168static int wm8904_add_widgets(struct snd_soc_codec *codec)
1169{ 1169{
1170 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); 1170 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
1171 struct snd_soc_dapm_context *dapm = &codec->dapm; 1171 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1172 1172
1173 snd_soc_dapm_new_controls(dapm, wm8904_core_dapm_widgets, 1173 snd_soc_dapm_new_controls(dapm, wm8904_core_dapm_widgets,
1174 ARRAY_SIZE(wm8904_core_dapm_widgets)); 1174 ARRAY_SIZE(wm8904_core_dapm_widgets));
@@ -1852,7 +1852,7 @@ static int wm8904_set_bias_level(struct snd_soc_codec *codec,
1852 break; 1852 break;
1853 1853
1854 case SND_SOC_BIAS_STANDBY: 1854 case SND_SOC_BIAS_STANDBY:
1855 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1855 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1856 ret = regulator_bulk_enable(ARRAY_SIZE(wm8904->supplies), 1856 ret = regulator_bulk_enable(ARRAY_SIZE(wm8904->supplies),
1857 wm8904->supplies); 1857 wm8904->supplies);
1858 if (ret != 0) { 1858 if (ret != 0) {
@@ -1907,7 +1907,6 @@ static int wm8904_set_bias_level(struct snd_soc_codec *codec,
1907 clk_disable_unprepare(wm8904->mclk); 1907 clk_disable_unprepare(wm8904->mclk);
1908 break; 1908 break;
1909 } 1909 }
1910 codec->dapm.bias_level = level;
1911 return 0; 1910 return 0;
1912} 1911}
1913 1912
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index e4142b4309eb..98ef0ba5c2a4 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -492,7 +492,7 @@ static int wm8940_set_bias_level(struct snd_soc_codec *codec,
492 ret = snd_soc_write(codec, WM8940_POWER1, pwr_reg | 0x1); 492 ret = snd_soc_write(codec, WM8940_POWER1, pwr_reg | 0x1);
493 break; 493 break;
494 case SND_SOC_BIAS_STANDBY: 494 case SND_SOC_BIAS_STANDBY:
495 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 495 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
496 ret = regcache_sync(wm8940->regmap); 496 ret = regcache_sync(wm8940->regmap);
497 if (ret < 0) { 497 if (ret < 0) {
498 dev_err(codec->dev, "Failed to sync cache: %d\n", ret); 498 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
@@ -510,8 +510,6 @@ static int wm8940_set_bias_level(struct snd_soc_codec *codec,
510 break; 510 break;
511 } 511 }
512 512
513 codec->dapm.bias_level = level;
514
515 return ret; 513 return ret;
516} 514}
517 515
@@ -707,7 +705,7 @@ static int wm8940_probe(struct snd_soc_codec *codec)
707 return ret; 705 return ret;
708 } 706 }
709 707
710 wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 708 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
711 709
712 ret = snd_soc_write(codec, WM8940_POWER1, 0x180); 710 ret = snd_soc_write(codec, WM8940_POWER1, 0x180);
713 if (ret < 0) 711 if (ret < 0)
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index 00bec915d652..2d591c24704b 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -298,7 +298,7 @@ static int wm8955_configure_clocking(struct snd_soc_codec *codec)
298 snd_soc_update_bits(codec, WM8955_PLL_CONTROL_2, 298 snd_soc_update_bits(codec, WM8955_PLL_CONTROL_2,
299 WM8955_K_17_9_MASK, 299 WM8955_K_17_9_MASK,
300 (pll.k >> 9) & WM8955_K_17_9_MASK); 300 (pll.k >> 9) & WM8955_K_17_9_MASK);
301 snd_soc_update_bits(codec, WM8955_PLL_CONTROL_2, 301 snd_soc_update_bits(codec, WM8955_PLL_CONTROL_3,
302 WM8955_K_8_0_MASK, 302 WM8955_K_8_0_MASK,
303 pll.k & WM8955_K_8_0_MASK); 303 pll.k & WM8955_K_8_0_MASK);
304 if (pll.k) 304 if (pll.k)
@@ -785,7 +785,7 @@ static int wm8955_set_bias_level(struct snd_soc_codec *codec,
785 break; 785 break;
786 786
787 case SND_SOC_BIAS_STANDBY: 787 case SND_SOC_BIAS_STANDBY:
788 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 788 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
789 ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies), 789 ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies),
790 wm8955->supplies); 790 wm8955->supplies);
791 if (ret != 0) { 791 if (ret != 0) {
@@ -838,7 +838,6 @@ static int wm8955_set_bias_level(struct snd_soc_codec *codec,
838 wm8955->supplies); 838 wm8955->supplies);
839 break; 839 break;
840 } 840 }
841 codec->dapm.bias_level = level;
842 return 0; 841 return 0;
843} 842}
844 843
@@ -929,7 +928,7 @@ static int wm8955_probe(struct snd_soc_codec *codec)
929 WM8955_DMEN, WM8955_DMEN); 928 WM8955_DMEN, WM8955_DMEN);
930 } 929 }
931 930
932 wm8955_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 931 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
933 932
934 /* Bias level configuration will have done an extra enable */ 933 /* Bias level configuration will have done an extra enable */
935 regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies), wm8955->supplies); 934 regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies), wm8955->supplies);
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 3035d9856415..af095b64f880 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -395,7 +395,7 @@ static const struct snd_soc_dapm_route audio_paths[] = {
395 { "Right Input Mixer", "Boost Switch", "Right Boost Mixer", }, 395 { "Right Input Mixer", "Boost Switch", "Right Boost Mixer", },
396 { "Right Input Mixer", NULL, "RINPUT1", }, /* Really Boost Switch */ 396 { "Right Input Mixer", NULL, "RINPUT1", }, /* Really Boost Switch */
397 { "Right Input Mixer", NULL, "RINPUT2" }, 397 { "Right Input Mixer", NULL, "RINPUT2" },
398 { "Right Input Mixer", NULL, "LINPUT3" }, 398 { "Right Input Mixer", NULL, "RINPUT3" },
399 399
400 { "Left ADC", NULL, "Left Input Mixer" }, 400 { "Left ADC", NULL, "Left Input Mixer" },
401 { "Right ADC", NULL, "Right Input Mixer" }, 401 { "Right ADC", NULL, "Right Input Mixer" },
@@ -445,7 +445,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
445{ 445{
446 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 446 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
447 struct wm8960_data *pdata = &wm8960->pdata; 447 struct wm8960_data *pdata = &wm8960->pdata;
448 struct snd_soc_dapm_context *dapm = &codec->dapm; 448 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
449 struct snd_soc_dapm_widget *w; 449 struct snd_soc_dapm_widget *w;
450 450
451 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets, 451 snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,
@@ -476,7 +476,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec)
476 * and save the result. 476 * and save the result.
477 */ 477 */
478 list_for_each_entry(w, &codec->component.card->widgets, list) { 478 list_for_each_entry(w, &codec->component.card->widgets, list) {
479 if (w->dapm != &codec->dapm) 479 if (w->dapm != dapm)
480 continue; 480 continue;
481 if (strcmp(w->name, "LOUT1 PGA") == 0) 481 if (strcmp(w->name, "LOUT1 PGA") == 0)
482 wm8960->lout1 = w; 482 wm8960->lout1 = w;
@@ -627,7 +627,7 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
627 break; 627 break;
628 628
629 case SND_SOC_BIAS_PREPARE: 629 case SND_SOC_BIAS_PREPARE:
630 switch (codec->dapm.bias_level) { 630 switch (snd_soc_codec_get_bias_level(codec)) {
631 case SND_SOC_BIAS_STANDBY: 631 case SND_SOC_BIAS_STANDBY:
632 if (!IS_ERR(wm8960->mclk)) { 632 if (!IS_ERR(wm8960->mclk)) {
633 ret = clk_prepare_enable(wm8960->mclk); 633 ret = clk_prepare_enable(wm8960->mclk);
@@ -655,7 +655,7 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
655 break; 655 break;
656 656
657 case SND_SOC_BIAS_STANDBY: 657 case SND_SOC_BIAS_STANDBY:
658 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 658 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
659 regcache_sync(wm8960->regmap); 659 regcache_sync(wm8960->regmap);
660 660
661 /* Enable anti-pop features */ 661 /* Enable anti-pop features */
@@ -691,8 +691,6 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
691 break; 691 break;
692 } 692 }
693 693
694 codec->dapm.bias_level = level;
695
696 return 0; 694 return 0;
697} 695}
698 696
@@ -707,7 +705,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
707 break; 705 break;
708 706
709 case SND_SOC_BIAS_PREPARE: 707 case SND_SOC_BIAS_PREPARE:
710 switch (codec->dapm.bias_level) { 708 switch (snd_soc_codec_get_bias_level(codec)) {
711 case SND_SOC_BIAS_STANDBY: 709 case SND_SOC_BIAS_STANDBY:
712 /* Enable anti pop mode */ 710 /* Enable anti pop mode */
713 snd_soc_update_bits(codec, WM8960_APOP1, 711 snd_soc_update_bits(codec, WM8960_APOP1,
@@ -778,7 +776,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
778 break; 776 break;
779 777
780 case SND_SOC_BIAS_STANDBY: 778 case SND_SOC_BIAS_STANDBY:
781 switch (codec->dapm.bias_level) { 779 switch (snd_soc_codec_get_bias_level(codec)) {
782 case SND_SOC_BIAS_PREPARE: 780 case SND_SOC_BIAS_PREPARE:
783 /* Disable HP discharge */ 781 /* Disable HP discharge */
784 snd_soc_update_bits(codec, WM8960_APOP2, 782 snd_soc_update_bits(codec, WM8960_APOP2,
@@ -802,8 +800,6 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
802 break; 800 break;
803 } 801 }
804 802
805 codec->dapm.bias_level = level;
806
807 return 0; 803 return 0;
808} 804}
809 805
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index 95e2c1bfc809..a057662632ff 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -758,7 +758,7 @@ static int wm8961_set_bias_level(struct snd_soc_codec *codec,
758 break; 758 break;
759 759
760 case SND_SOC_BIAS_PREPARE: 760 case SND_SOC_BIAS_PREPARE:
761 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) { 761 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) {
762 /* Enable bias generation */ 762 /* Enable bias generation */
763 reg = snd_soc_read(codec, WM8961_ANTI_POP); 763 reg = snd_soc_read(codec, WM8961_ANTI_POP);
764 reg |= WM8961_BUFIOEN | WM8961_BUFDCOPEN; 764 reg |= WM8961_BUFIOEN | WM8961_BUFDCOPEN;
@@ -773,7 +773,7 @@ static int wm8961_set_bias_level(struct snd_soc_codec *codec,
773 break; 773 break;
774 774
775 case SND_SOC_BIAS_STANDBY: 775 case SND_SOC_BIAS_STANDBY:
776 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) { 776 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE) {
777 /* VREF off */ 777 /* VREF off */
778 reg = snd_soc_read(codec, WM8961_PWR_MGMT_1); 778 reg = snd_soc_read(codec, WM8961_PWR_MGMT_1);
779 reg &= ~WM8961_VREF; 779 reg &= ~WM8961_VREF;
@@ -795,8 +795,6 @@ static int wm8961_set_bias_level(struct snd_soc_codec *codec,
795 break; 795 break;
796 } 796 }
797 797
798 codec->dapm.bias_level = level;
799
800 return 0; 798 return 0;
801} 799}
802 800
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 118b0034ba23..c5748fd4f296 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -2361,7 +2361,7 @@ static int wm8962_add_widgets(struct snd_soc_codec *codec)
2361{ 2361{
2362 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 2362 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
2363 struct wm8962_pdata *pdata = &wm8962->pdata; 2363 struct wm8962_pdata *pdata = &wm8962->pdata;
2364 struct snd_soc_dapm_context *dapm = &codec->dapm; 2364 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2365 2365
2366 snd_soc_add_codec_controls(codec, wm8962_snd_controls, 2366 snd_soc_add_codec_controls(codec, wm8962_snd_controls,
2367 ARRAY_SIZE(wm8962_snd_controls)); 2367 ARRAY_SIZE(wm8962_snd_controls));
@@ -2446,13 +2446,13 @@ static void wm8962_configure_bclk(struct snd_soc_codec *codec)
2446 * So we here provisionally enable it and then disable it afterward 2446 * So we here provisionally enable it and then disable it afterward
2447 * if current bias_level hasn't reached SND_SOC_BIAS_ON. 2447 * if current bias_level hasn't reached SND_SOC_BIAS_ON.
2448 */ 2448 */
2449 if (codec->dapm.bias_level != SND_SOC_BIAS_ON) 2449 if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_ON)
2450 snd_soc_update_bits(codec, WM8962_CLOCKING2, 2450 snd_soc_update_bits(codec, WM8962_CLOCKING2,
2451 WM8962_SYSCLK_ENA_MASK, WM8962_SYSCLK_ENA); 2451 WM8962_SYSCLK_ENA_MASK, WM8962_SYSCLK_ENA);
2452 2452
2453 dspclk = snd_soc_read(codec, WM8962_CLOCKING1); 2453 dspclk = snd_soc_read(codec, WM8962_CLOCKING1);
2454 2454
2455 if (codec->dapm.bias_level != SND_SOC_BIAS_ON) 2455 if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_ON)
2456 snd_soc_update_bits(codec, WM8962_CLOCKING2, 2456 snd_soc_update_bits(codec, WM8962_CLOCKING2,
2457 WM8962_SYSCLK_ENA_MASK, 0); 2457 WM8962_SYSCLK_ENA_MASK, 0);
2458 2458
@@ -2510,9 +2510,6 @@ static void wm8962_configure_bclk(struct snd_soc_codec *codec)
2510static int wm8962_set_bias_level(struct snd_soc_codec *codec, 2510static int wm8962_set_bias_level(struct snd_soc_codec *codec,
2511 enum snd_soc_bias_level level) 2511 enum snd_soc_bias_level level)
2512{ 2512{
2513 if (level == codec->dapm.bias_level)
2514 return 0;
2515
2516 switch (level) { 2513 switch (level) {
2517 case SND_SOC_BIAS_ON: 2514 case SND_SOC_BIAS_ON:
2518 break; 2515 break;
@@ -2530,7 +2527,7 @@ static int wm8962_set_bias_level(struct snd_soc_codec *codec,
2530 snd_soc_update_bits(codec, WM8962_PWR_MGMT_1, 2527 snd_soc_update_bits(codec, WM8962_PWR_MGMT_1,
2531 WM8962_VMID_SEL_MASK, 0x100); 2528 WM8962_VMID_SEL_MASK, 0x100);
2532 2529
2533 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) 2530 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
2534 msleep(100); 2531 msleep(100);
2535 break; 2532 break;
2536 2533
@@ -2538,7 +2535,6 @@ static int wm8962_set_bias_level(struct snd_soc_codec *codec,
2538 break; 2535 break;
2539 } 2536 }
2540 2537
2541 codec->dapm.bias_level = level;
2542 return 0; 2538 return 0;
2543} 2539}
2544 2540
@@ -2614,7 +2610,7 @@ static int wm8962_hw_params(struct snd_pcm_substream *substream,
2614 dev_dbg(codec->dev, "hw_params set BCLK %dHz LRCLK %dHz\n", 2610 dev_dbg(codec->dev, "hw_params set BCLK %dHz LRCLK %dHz\n",
2615 wm8962->bclk, wm8962->lrclk); 2611 wm8962->bclk, wm8962->lrclk);
2616 2612
2617 if (codec->dapm.bias_level == SND_SOC_BIAS_ON) 2613 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON)
2618 wm8962_configure_bclk(codec); 2614 wm8962_configure_bclk(codec);
2619 2615
2620 return 0; 2616 return 0;
@@ -3118,7 +3114,7 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3118int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) 3114int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
3119{ 3115{
3120 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3116 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3121 struct snd_soc_dapm_context *dapm = &codec->dapm; 3117 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3122 int irq_mask, enable; 3118 int irq_mask, enable;
3123 3119
3124 wm8962->jack = jack; 3120 wm8962->jack = jack;
@@ -3164,7 +3160,7 @@ static void wm8962_beep_work(struct work_struct *work)
3164 struct wm8962_priv *wm8962 = 3160 struct wm8962_priv *wm8962 =
3165 container_of(work, struct wm8962_priv, beep_work); 3161 container_of(work, struct wm8962_priv, beep_work);
3166 struct snd_soc_codec *codec = wm8962->codec; 3162 struct snd_soc_codec *codec = wm8962->codec;
3167 struct snd_soc_dapm_context *dapm = &codec->dapm; 3163 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3168 int i; 3164 int i;
3169 int reg = 0; 3165 int reg = 0;
3170 int best = 0; 3166 int best = 0;
@@ -3415,6 +3411,7 @@ static void wm8962_free_gpio(struct snd_soc_codec *codec)
3415 3411
3416static int wm8962_probe(struct snd_soc_codec *codec) 3412static int wm8962_probe(struct snd_soc_codec *codec)
3417{ 3413{
3414 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3418 int ret; 3415 int ret;
3419 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3416 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3420 int i; 3417 int i;
@@ -3462,7 +3459,7 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3462 } 3459 }
3463 if (!dmicclk || !dmicdat) { 3460 if (!dmicclk || !dmicdat) {
3464 dev_dbg(codec->dev, "DMIC not in use, disabling\n"); 3461 dev_dbg(codec->dev, "DMIC not in use, disabling\n");
3465 snd_soc_dapm_nc_pin(&codec->dapm, "DMICDAT"); 3462 snd_soc_dapm_nc_pin(dapm, "DMICDAT");
3466 } 3463 }
3467 if (dmicclk != dmicdat) 3464 if (dmicclk != dmicdat)
3468 dev_warn(codec->dev, "DMIC GPIOs partially configured\n"); 3465 dev_warn(codec->dev, "DMIC GPIOs partially configured\n");
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index f9cbabdc6238..b51184c4e816 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -577,7 +577,7 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
577 flush_delayed_work(&wm8971->charge_work); 577 flush_delayed_work(&wm8971->charge_work);
578 break; 578 break;
579 case SND_SOC_BIAS_STANDBY: 579 case SND_SOC_BIAS_STANDBY:
580 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 580 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
581 snd_soc_cache_sync(codec); 581 snd_soc_cache_sync(codec);
582 /* charge output caps - set vmid to 5k for quick power up */ 582 /* charge output caps - set vmid to 5k for quick power up */
583 snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x01c0); 583 snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x01c0);
@@ -594,7 +594,6 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
594 snd_soc_write(codec, WM8971_PWR1, 0x0001); 594 snd_soc_write(codec, WM8971_PWR1, 0x0001);
595 break; 595 break;
596 } 596 }
597 codec->dapm.bias_level = level;
598 return 0; 597 return 0;
599} 598}
600 599
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index ff0e4646b934..33b16a7ba82e 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -514,7 +514,7 @@ static int wm8974_set_bias_level(struct snd_soc_codec *codec,
514 case SND_SOC_BIAS_STANDBY: 514 case SND_SOC_BIAS_STANDBY:
515 power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN; 515 power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN;
516 516
517 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 517 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
518 regcache_sync(dev_get_regmap(codec->dev, NULL)); 518 regcache_sync(dev_get_regmap(codec->dev, NULL));
519 519
520 /* Initial cap charge at VMID 5k */ 520 /* Initial cap charge at VMID 5k */
@@ -533,7 +533,6 @@ static int wm8974_set_bias_level(struct snd_soc_codec *codec,
533 break; 533 break;
534 } 534 }
535 535
536 codec->dapm.bias_level = level;
537 return 0; 536 return 0;
538} 537}
539 538
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index cf7032911721..cfc8cdf49970 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -868,7 +868,7 @@ static int wm8978_set_bias_level(struct snd_soc_codec *codec,
868 /* bit 3: enable bias, bit 2: enable I/O tie off buffer */ 868 /* bit 3: enable bias, bit 2: enable I/O tie off buffer */
869 power1 |= 0xc; 869 power1 |= 0xc;
870 870
871 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 871 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
872 /* Initial cap charge at VMID 5k */ 872 /* Initial cap charge at VMID 5k */
873 snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1, 873 snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1,
874 power1 | 0x3); 874 power1 | 0x3);
@@ -888,7 +888,6 @@ static int wm8978_set_bias_level(struct snd_soc_codec *codec,
888 888
889 dev_dbg(codec->dev, "%s: %d, %x\n", __func__, level, power1); 889 dev_dbg(codec->dev, "%s: %d, %x\n", __func__, level, power1);
890 890
891 codec->dapm.bias_level = level;
892 return 0; 891 return 0;
893} 892}
894 893
@@ -928,7 +927,7 @@ static int wm8978_suspend(struct snd_soc_codec *codec)
928{ 927{
929 struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); 928 struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
930 929
931 wm8978_set_bias_level(codec, SND_SOC_BIAS_OFF); 930 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
932 /* Also switch PLL off */ 931 /* Also switch PLL off */
933 snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1, 0); 932 snd_soc_write(codec, WM8978_POWER_MANAGEMENT_1, 0);
934 933
@@ -944,7 +943,7 @@ static int wm8978_resume(struct snd_soc_codec *codec)
944 /* Sync reg_cache with the hardware */ 943 /* Sync reg_cache with the hardware */
945 regcache_sync(wm8978->regmap); 944 regcache_sync(wm8978->regmap);
946 945
947 wm8978_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 946 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
948 947
949 if (wm8978->f_pllout) 948 if (wm8978->f_pllout)
950 /* Switch PLL on */ 949 /* Switch PLL on */
diff --git a/sound/soc/codecs/wm8983.c b/sound/soc/codecs/wm8983.c
index 5d1cf08a72b8..2fdd2c6cc09d 100644
--- a/sound/soc/codecs/wm8983.c
+++ b/sound/soc/codecs/wm8983.c
@@ -915,7 +915,7 @@ static int wm8983_set_bias_level(struct snd_soc_codec *codec,
915 1 << WM8983_VMIDSEL_SHIFT); 915 1 << WM8983_VMIDSEL_SHIFT);
916 break; 916 break;
917 case SND_SOC_BIAS_STANDBY: 917 case SND_SOC_BIAS_STANDBY:
918 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 918 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
919 ret = regcache_sync(wm8983->regmap); 919 ret = regcache_sync(wm8983->regmap);
920 if (ret < 0) { 920 if (ret < 0) {
921 dev_err(codec->dev, "Failed to sync cache: %d\n", ret); 921 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
@@ -963,7 +963,6 @@ static int wm8983_set_bias_level(struct snd_soc_codec *codec,
963 break; 963 break;
964 } 964 }
965 965
966 codec->dapm.bias_level = level;
967 return 0; 966 return 0;
968} 967}
969 968
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index 0b3b54c9971d..8a85f5004d41 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -897,7 +897,7 @@ static int wm8985_set_bias_level(struct snd_soc_codec *codec,
897 1 << WM8985_VMIDSEL_SHIFT); 897 1 << WM8985_VMIDSEL_SHIFT);
898 break; 898 break;
899 case SND_SOC_BIAS_STANDBY: 899 case SND_SOC_BIAS_STANDBY:
900 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 900 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
901 ret = regulator_bulk_enable(ARRAY_SIZE(wm8985->supplies), 901 ret = regulator_bulk_enable(ARRAY_SIZE(wm8985->supplies),
902 wm8985->supplies); 902 wm8985->supplies);
903 if (ret) { 903 if (ret) {
@@ -957,7 +957,6 @@ static int wm8985_set_bias_level(struct snd_soc_codec *codec,
957 break; 957 break;
958 } 958 }
959 959
960 codec->dapm.bias_level = level;
961 return 0; 960 return 0;
962} 961}
963 962
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index 24968aa8618a..f13a995af277 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -738,7 +738,7 @@ static int wm8988_set_bias_level(struct snd_soc_codec *codec,
738 break; 738 break;
739 739
740 case SND_SOC_BIAS_STANDBY: 740 case SND_SOC_BIAS_STANDBY:
741 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 741 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
742 regcache_sync(wm8988->regmap); 742 regcache_sync(wm8988->regmap);
743 743
744 /* VREF, VMID=2x5k */ 744 /* VREF, VMID=2x5k */
@@ -756,7 +756,6 @@ static int wm8988_set_bias_level(struct snd_soc_codec *codec,
756 snd_soc_write(codec, WM8988_PWR1, 0x0000); 756 snd_soc_write(codec, WM8988_PWR1, 0x0000);
757 break; 757 break;
758 } 758 }
759 codec->dapm.bias_level = level;
760 return 0; 759 return 0;
761} 760}
762 761
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index c93bffcb3cfb..1993fd2a6f15 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -1124,7 +1124,7 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
1124 break; 1124 break;
1125 1125
1126 case SND_SOC_BIAS_STANDBY: 1126 case SND_SOC_BIAS_STANDBY:
1127 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1127 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1128 ret = regcache_sync(wm8990->regmap); 1128 ret = regcache_sync(wm8990->regmap);
1129 if (ret < 0) { 1129 if (ret < 0) {
1130 dev_err(codec->dev, "Failed to sync cache: %d\n", ret); 1130 dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
@@ -1227,7 +1227,6 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
1227 break; 1227 break;
1228 } 1228 }
1229 1229
1230 codec->dapm.bias_level = level;
1231 return 0; 1230 return 0;
1232} 1231}
1233 1232
@@ -1281,7 +1280,7 @@ static int wm8990_probe(struct snd_soc_codec *codec)
1281 wm8990_reset(codec); 1280 wm8990_reset(codec);
1282 1281
1283 /* charge output caps */ 1282 /* charge output caps */
1284 wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1283 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1285 1284
1286 snd_soc_update_bits(codec, WM8990_AUDIO_INTERFACE_4, 1285 snd_soc_update_bits(codec, WM8990_AUDIO_INTERFACE_4,
1287 WM8990_ALRCGPIO1, WM8990_ALRCGPIO1); 1286 WM8990_ALRCGPIO1, WM8990_ALRCGPIO1);
diff --git a/sound/soc/codecs/wm8991.c b/sound/soc/codecs/wm8991.c
index 49df0dc607e6..44a677720828 100644
--- a/sound/soc/codecs/wm8991.c
+++ b/sound/soc/codecs/wm8991.c
@@ -1131,7 +1131,7 @@ static int wm8991_set_bias_level(struct snd_soc_codec *codec,
1131 break; 1131 break;
1132 1132
1133 case SND_SOC_BIAS_STANDBY: 1133 case SND_SOC_BIAS_STANDBY:
1134 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1134 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1135 regcache_sync(wm8991->regmap); 1135 regcache_sync(wm8991->regmap);
1136 /* Enable all output discharge bits */ 1136 /* Enable all output discharge bits */
1137 snd_soc_write(codec, WM8991_ANTIPOP1, WM8991_DIS_LLINE | 1137 snd_soc_write(codec, WM8991_ANTIPOP1, WM8991_DIS_LLINE |
@@ -1224,7 +1224,6 @@ static int wm8991_set_bias_level(struct snd_soc_codec *codec,
1224 break; 1224 break;
1225 } 1225 }
1226 1226
1227 codec->dapm.bias_level = level;
1228 return 0; 1227 return 0;
1229} 1228}
1230 1229
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 2e70a270eb28..8a8db8605dc2 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -992,7 +992,7 @@ static int wm8993_set_bias_level(struct snd_soc_codec *codec,
992 break; 992 break;
993 993
994 case SND_SOC_BIAS_STANDBY: 994 case SND_SOC_BIAS_STANDBY:
995 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 995 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
996 ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), 996 ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies),
997 wm8993->supplies); 997 wm8993->supplies);
998 if (ret != 0) 998 if (ret != 0)
@@ -1065,8 +1065,6 @@ static int wm8993_set_bias_level(struct snd_soc_codec *codec,
1065 break; 1065 break;
1066 } 1066 }
1067 1067
1068 codec->dapm.bias_level = level;
1069
1070 return 0; 1068 return 0;
1071} 1069}
1072 1070
@@ -1485,7 +1483,7 @@ static struct snd_soc_dai_driver wm8993_dai = {
1485static int wm8993_probe(struct snd_soc_codec *codec) 1483static int wm8993_probe(struct snd_soc_codec *codec)
1486{ 1484{
1487 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1485 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1488 struct snd_soc_dapm_context *dapm = &codec->dapm; 1486 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1489 1487
1490 wm8993->hubs_data.hp_startup_mode = 1; 1488 wm8993->hubs_data.hp_startup_mode = 1;
1491 wm8993->hubs_data.dcs_codes_l = -2; 1489 wm8993->hubs_data.dcs_codes_l = -2;
@@ -1539,7 +1537,7 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1539 * VMID as an output and can disable it. 1537 * VMID as an output and can disable it.
1540 */ 1538 */
1541 if (wm8993->pdata.lineout1_diff && wm8993->pdata.lineout2_diff) 1539 if (wm8993->pdata.lineout1_diff && wm8993->pdata.lineout2_diff)
1542 codec->dapm.idle_bias_off = 1; 1540 dapm->idle_bias_off = 1;
1543 1541
1544 return 0; 1542 return 0;
1545 1543
@@ -1563,7 +1561,7 @@ static int wm8993_suspend(struct snd_soc_codec *codec)
1563 wm8993->fll_fout = fll_fout; 1561 wm8993->fll_fout = fll_fout;
1564 wm8993->fll_fref = fll_fref; 1562 wm8993->fll_fref = fll_fref;
1565 1563
1566 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); 1564 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
1567 1565
1568 return 0; 1566 return 0;
1569} 1567}
@@ -1573,7 +1571,7 @@ static int wm8993_resume(struct snd_soc_codec *codec)
1573 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); 1571 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1574 int ret; 1572 int ret;
1575 1573
1576 wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1574 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1577 1575
1578 /* Restart the FLL? */ 1576 /* Restart the FLL? */
1579 if (wm8993->fll_fout) { 1577 if (wm8993->fll_fout) {
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 4fbc7689339a..7c3ee6f91a4a 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -212,6 +212,7 @@ static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
212 212
213static int configure_clock(struct snd_soc_codec *codec) 213static int configure_clock(struct snd_soc_codec *codec)
214{ 214{
215 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
215 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 216 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
216 int change, new; 217 int change, new;
217 218
@@ -239,7 +240,7 @@ static int configure_clock(struct snd_soc_codec *codec)
239 change = snd_soc_update_bits(codec, WM8994_CLOCKING_1, 240 change = snd_soc_update_bits(codec, WM8994_CLOCKING_1,
240 WM8994_SYSCLK_SRC, new); 241 WM8994_SYSCLK_SRC, new);
241 if (change) 242 if (change)
242 snd_soc_dapm_sync(&codec->dapm); 243 snd_soc_dapm_sync(dapm);
243 244
244 wm8958_micd_set_rate(codec); 245 wm8958_micd_set_rate(codec);
245 246
@@ -2492,12 +2493,12 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2492 break; 2493 break;
2493 } 2494 }
2494 2495
2495 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) 2496 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY)
2496 active_reference(codec); 2497 active_reference(codec);
2497 break; 2498 break;
2498 2499
2499 case SND_SOC_BIAS_STANDBY: 2500 case SND_SOC_BIAS_STANDBY:
2500 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 2501 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
2501 switch (control->type) { 2502 switch (control->type) {
2502 case WM8958: 2503 case WM8958:
2503 if (control->revision == 0) { 2504 if (control->revision == 0) {
@@ -2521,7 +2522,7 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2521 WM8994_LINEOUT2_DISCH); 2522 WM8994_LINEOUT2_DISCH);
2522 } 2523 }
2523 2524
2524 if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE) 2525 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_PREPARE)
2525 active_dereference(codec); 2526 active_dereference(codec);
2526 2527
2527 /* MICBIAS into bypass mode on newer devices */ 2528 /* MICBIAS into bypass mode on newer devices */
@@ -2541,20 +2542,18 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2541 break; 2542 break;
2542 2543
2543 case SND_SOC_BIAS_OFF: 2544 case SND_SOC_BIAS_OFF:
2544 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) 2545 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY)
2545 wm8994->cur_fw = NULL; 2546 wm8994->cur_fw = NULL;
2546 break; 2547 break;
2547 } 2548 }
2548 2549
2549 codec->dapm.bias_level = level;
2550
2551 return 0; 2550 return 0;
2552} 2551}
2553 2552
2554int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode) 2553int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
2555{ 2554{
2556 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 2555 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2557 struct snd_soc_dapm_context *dapm = &codec->dapm; 2556 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2558 2557
2559 switch (mode) { 2558 switch (mode) {
2560 case WM8994_VMID_NORMAL: 2559 case WM8994_VMID_NORMAL:
@@ -2754,7 +2753,7 @@ static struct {
2754}; 2753};
2755 2754
2756static int fs_ratios[] = { 2755static int fs_ratios[] = {
2757 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536 2756 64, 128, 192, 256, 384, 512, 768, 1024, 1408, 1536
2758}; 2757};
2759 2758
2760static int bclk_divs[] = { 2759static int bclk_divs[] = {
@@ -3163,7 +3162,7 @@ static int wm8994_codec_suspend(struct snd_soc_codec *codec)
3163 i + 1, ret); 3162 i + 1, ret);
3164 } 3163 }
3165 3164
3166 wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF); 3165 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
3167 3166
3168 return 0; 3167 return 0;
3169} 3168}
@@ -3356,6 +3355,7 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3356int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, 3355int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3357 int micbias) 3356 int micbias)
3358{ 3357{
3358 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3359 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 3359 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3360 struct wm8994_micdet *micdet; 3360 struct wm8994_micdet *micdet;
3361 struct wm8994 *control = wm8994->wm8994; 3361 struct wm8994 *control = wm8994->wm8994;
@@ -3370,20 +3370,16 @@ int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3370 case 1: 3370 case 1:
3371 micdet = &wm8994->micdet[0]; 3371 micdet = &wm8994->micdet[0];
3372 if (jack) 3372 if (jack)
3373 ret = snd_soc_dapm_force_enable_pin(&codec->dapm, 3373 ret = snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
3374 "MICBIAS1");
3375 else 3374 else
3376 ret = snd_soc_dapm_disable_pin(&codec->dapm, 3375 ret = snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
3377 "MICBIAS1");
3378 break; 3376 break;
3379 case 2: 3377 case 2:
3380 micdet = &wm8994->micdet[1]; 3378 micdet = &wm8994->micdet[1];
3381 if (jack) 3379 if (jack)
3382 ret = snd_soc_dapm_force_enable_pin(&codec->dapm, 3380 ret = snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
3383 "MICBIAS1");
3384 else 3381 else
3385 ret = snd_soc_dapm_disable_pin(&codec->dapm, 3382 ret = snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
3386 "MICBIAS1");
3387 break; 3383 break;
3388 default: 3384 default:
3389 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias); 3385 dev_warn(codec->dev, "Invalid MICBIAS %d\n", micbias);
@@ -3415,7 +3411,7 @@ int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3415 WM8994_MIC2_DET_DB_MASK | WM8994_MIC2_SHRT_DB_MASK, 3411 WM8994_MIC2_DET_DB_MASK | WM8994_MIC2_SHRT_DB_MASK,
3416 WM8994_MIC1_DET_DB | WM8994_MIC1_SHRT_DB); 3412 WM8994_MIC1_DET_DB | WM8994_MIC1_SHRT_DB);
3417 3413
3418 snd_soc_dapm_sync(&codec->dapm); 3414 snd_soc_dapm_sync(dapm);
3419 3415
3420 return 0; 3416 return 0;
3421} 3417}
@@ -3505,6 +3501,7 @@ static irqreturn_t wm8994_mic_irq(int irq, void *data)
3505/* Should be called with accdet_lock held */ 3501/* Should be called with accdet_lock held */
3506static void wm1811_micd_stop(struct snd_soc_codec *codec) 3502static void wm1811_micd_stop(struct snd_soc_codec *codec)
3507{ 3503{
3504 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3508 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 3505 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3509 3506
3510 if (!wm8994->jackdet) 3507 if (!wm8994->jackdet)
@@ -3515,8 +3512,7 @@ static void wm1811_micd_stop(struct snd_soc_codec *codec)
3515 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK); 3512 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
3516 3513
3517 if (wm8994->wm8994->pdata.jd_ext_cap) 3514 if (wm8994->wm8994->pdata.jd_ext_cap)
3518 snd_soc_dapm_disable_pin(&codec->dapm, 3515 snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
3519 "MICBIAS2");
3520} 3516}
3521 3517
3522static void wm8958_button_det(struct snd_soc_codec *codec, u16 status) 3518static void wm8958_button_det(struct snd_soc_codec *codec, u16 status)
@@ -3625,14 +3621,14 @@ static void wm1811_mic_work(struct work_struct *work)
3625 mic_work.work); 3621 mic_work.work);
3626 struct wm8994 *control = wm8994->wm8994; 3622 struct wm8994 *control = wm8994->wm8994;
3627 struct snd_soc_codec *codec = wm8994->hubs.codec; 3623 struct snd_soc_codec *codec = wm8994->hubs.codec;
3624 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3628 3625
3629 pm_runtime_get_sync(codec->dev); 3626 pm_runtime_get_sync(codec->dev);
3630 3627
3631 /* If required for an external cap force MICBIAS on */ 3628 /* If required for an external cap force MICBIAS on */
3632 if (control->pdata.jd_ext_cap) { 3629 if (control->pdata.jd_ext_cap) {
3633 snd_soc_dapm_force_enable_pin(&codec->dapm, 3630 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS2");
3634 "MICBIAS2"); 3631 snd_soc_dapm_sync(dapm);
3635 snd_soc_dapm_sync(&codec->dapm);
3636 } 3632 }
3637 3633
3638 mutex_lock(&wm8994->accdet_lock); 3634 mutex_lock(&wm8994->accdet_lock);
@@ -3664,6 +3660,7 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3664 struct wm8994_priv *wm8994 = data; 3660 struct wm8994_priv *wm8994 = data;
3665 struct wm8994 *control = wm8994->wm8994; 3661 struct wm8994 *control = wm8994->wm8994;
3666 struct snd_soc_codec *codec = wm8994->hubs.codec; 3662 struct snd_soc_codec *codec = wm8994->hubs.codec;
3663 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3667 int reg, delay; 3664 int reg, delay;
3668 bool present; 3665 bool present;
3669 3666
@@ -3724,7 +3721,7 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
3724 3721
3725 /* Turn off MICBIAS if it was on for an external cap */ 3722 /* Turn off MICBIAS if it was on for an external cap */
3726 if (control->pdata.jd_ext_cap && !present) 3723 if (control->pdata.jd_ext_cap && !present)
3727 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2"); 3724 snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
3728 3725
3729 if (present) 3726 if (present)
3730 snd_soc_jack_report(wm8994->micdet[0].jack, 3727 snd_soc_jack_report(wm8994->micdet[0].jack,
@@ -3770,6 +3767,7 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3770 wm1811_micdet_cb det_cb, void *det_cb_data, 3767 wm1811_micdet_cb det_cb, void *det_cb_data,
3771 wm1811_mic_id_cb id_cb, void *id_cb_data) 3768 wm1811_mic_id_cb id_cb, void *id_cb_data)
3772{ 3769{
3770 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3773 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 3771 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3774 struct wm8994 *control = wm8994->wm8994; 3772 struct wm8994 *control = wm8994->wm8994;
3775 u16 micd_lvl_sel; 3773 u16 micd_lvl_sel;
@@ -3783,8 +3781,8 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3783 } 3781 }
3784 3782
3785 if (jack) { 3783 if (jack) {
3786 snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS"); 3784 snd_soc_dapm_force_enable_pin(dapm, "CLK_SYS");
3787 snd_soc_dapm_sync(&codec->dapm); 3785 snd_soc_dapm_sync(dapm);
3788 3786
3789 wm8994->micdet[0].jack = jack; 3787 wm8994->micdet[0].jack = jack;
3790 3788
@@ -3819,7 +3817,7 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3819 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2, 3817 snd_soc_update_bits(codec, WM8958_MIC_DETECT_2,
3820 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel); 3818 WM8958_MICD_LVL_SEL_MASK, micd_lvl_sel);
3821 3819
3822 WARN_ON(codec->dapm.bias_level > SND_SOC_BIAS_STANDBY); 3820 WARN_ON(snd_soc_codec_get_bias_level(codec) > SND_SOC_BIAS_STANDBY);
3823 3821
3824 /* 3822 /*
3825 * If we can use jack detection start off with that, 3823 * If we can use jack detection start off with that,
@@ -3846,8 +3844,8 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
3846 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, 3844 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
3847 WM8958_MICD_ENA, 0); 3845 WM8958_MICD_ENA, 0);
3848 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE); 3846 wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
3849 snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS"); 3847 snd_soc_dapm_disable_pin(dapm, "CLK_SYS");
3850 snd_soc_dapm_sync(&codec->dapm); 3848 snd_soc_dapm_sync(dapm);
3851 } 3849 }
3852 3850
3853 return 0; 3851 return 0;
@@ -3985,9 +3983,9 @@ static irqreturn_t wm8994_temp_shut(int irq, void *data)
3985 3983
3986static int wm8994_codec_probe(struct snd_soc_codec *codec) 3984static int wm8994_codec_probe(struct snd_soc_codec *codec)
3987{ 3985{
3986 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3988 struct wm8994 *control = dev_get_drvdata(codec->dev->parent); 3987 struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
3989 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 3988 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
3990 struct snd_soc_dapm_context *dapm = &codec->dapm;
3991 unsigned int reg; 3989 unsigned int reg;
3992 int ret, i; 3990 int ret, i;
3993 3991
@@ -4018,7 +4016,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
4018 wm8994->micdet_irq = control->pdata.micdet_irq; 4016 wm8994->micdet_irq = control->pdata.micdet_irq;
4019 4017
4020 /* By default use idle_bias_off, will override for WM8994 */ 4018 /* By default use idle_bias_off, will override for WM8994 */
4021 codec->dapm.idle_bias_off = 1; 4019 dapm->idle_bias_off = 1;
4022 4020
4023 /* Set revision-specific configuration */ 4021 /* Set revision-specific configuration */
4024 switch (control->type) { 4022 switch (control->type) {
@@ -4026,7 +4024,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
4026 /* Single ended line outputs should have VMID on. */ 4024 /* Single ended line outputs should have VMID on. */
4027 if (!control->pdata.lineout1_diff || 4025 if (!control->pdata.lineout1_diff ||
4028 !control->pdata.lineout2_diff) 4026 !control->pdata.lineout2_diff)
4029 codec->dapm.idle_bias_off = 0; 4027 dapm->idle_bias_off = 0;
4030 4028
4031 switch (control->revision) { 4029 switch (control->revision) {
4032 case 2: 4030 case 2:
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c
index 66103c2b012e..687c4dd7ec99 100644
--- a/sound/soc/codecs/wm8995.c
+++ b/sound/soc/codecs/wm8995.c
@@ -721,6 +721,7 @@ static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
721 721
722static int configure_clock(struct snd_soc_codec *codec) 722static int configure_clock(struct snd_soc_codec *codec)
723{ 723{
724 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
724 struct wm8995_priv *wm8995; 725 struct wm8995_priv *wm8995;
725 int change, new; 726 int change, new;
726 727
@@ -751,7 +752,7 @@ static int configure_clock(struct snd_soc_codec *codec)
751 if (!change) 752 if (!change)
752 return 0; 753 return 0;
753 754
754 snd_soc_dapm_sync(&codec->dapm); 755 snd_soc_dapm_sync(dapm);
755 756
756 return 0; 757 return 0;
757} 758}
@@ -1965,7 +1966,7 @@ static int wm8995_set_bias_level(struct snd_soc_codec *codec,
1965 case SND_SOC_BIAS_PREPARE: 1966 case SND_SOC_BIAS_PREPARE:
1966 break; 1967 break;
1967 case SND_SOC_BIAS_STANDBY: 1968 case SND_SOC_BIAS_STANDBY:
1968 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1969 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1969 ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies), 1970 ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
1970 wm8995->supplies); 1971 wm8995->supplies);
1971 if (ret) 1972 if (ret)
@@ -1990,7 +1991,6 @@ static int wm8995_set_bias_level(struct snd_soc_codec *codec,
1990 break; 1991 break;
1991 } 1992 }
1992 1993
1993 codec->dapm.bias_level = level;
1994 return 0; 1994 return 0;
1995} 1995}
1996 1996
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index 308748a022c5..370459fcf21c 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -1590,7 +1590,7 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
1590 break; 1590 break;
1591 1591
1592 case SND_SOC_BIAS_STANDBY: 1592 case SND_SOC_BIAS_STANDBY:
1593 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1593 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
1594 ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies), 1594 ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies),
1595 wm8996->supplies); 1595 wm8996->supplies);
1596 if (ret != 0) { 1596 if (ret != 0) {
@@ -1628,8 +1628,6 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
1628 break; 1628 break;
1629 } 1629 }
1630 1630
1631 codec->dapm.bias_level = level;
1632
1633 return 0; 1631 return 0;
1634} 1632}
1635 1633
@@ -2247,7 +2245,7 @@ int wm8996_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2247 wm8996_polarity_fn polarity_cb) 2245 wm8996_polarity_fn polarity_cb)
2248{ 2246{
2249 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); 2247 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2250 struct snd_soc_dapm_context *dapm = &codec->dapm; 2248 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2251 2249
2252 wm8996->jack = jack; 2250 wm8996->jack = jack;
2253 wm8996->detecting = true; 2251 wm8996->detecting = true;
@@ -2292,6 +2290,7 @@ EXPORT_SYMBOL_GPL(wm8996_detect);
2292 2290
2293static void wm8996_hpdet_irq(struct snd_soc_codec *codec) 2291static void wm8996_hpdet_irq(struct snd_soc_codec *codec)
2294{ 2292{
2293 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2295 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); 2294 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2296 int val, reg, report; 2295 int val, reg, report;
2297 2296
@@ -2345,12 +2344,14 @@ out:
2345 snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, 2344 snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA,
2346 WM8996_MICD_ENA); 2345 WM8996_MICD_ENA);
2347 2346
2348 snd_soc_dapm_disable_pin(&codec->dapm, "Bandgap"); 2347 snd_soc_dapm_disable_pin(dapm, "Bandgap");
2349 snd_soc_dapm_sync(&codec->dapm); 2348 snd_soc_dapm_sync(dapm);
2350} 2349}
2351 2350
2352static void wm8996_hpdet_start(struct snd_soc_codec *codec) 2351static void wm8996_hpdet_start(struct snd_soc_codec *codec)
2353{ 2352{
2353 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2354
2354 /* Unclamp the output, we can't measure while we're shorting it */ 2355 /* Unclamp the output, we can't measure while we're shorting it */
2355 snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1, 2356 snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1,
2356 WM8996_HPOUT1L_RMV_SHORT | 2357 WM8996_HPOUT1L_RMV_SHORT |
@@ -2359,8 +2360,8 @@ static void wm8996_hpdet_start(struct snd_soc_codec *codec)
2359 WM8996_HPOUT1R_RMV_SHORT); 2360 WM8996_HPOUT1R_RMV_SHORT);
2360 2361
2361 /* We need bandgap for HPDET */ 2362 /* We need bandgap for HPDET */
2362 snd_soc_dapm_force_enable_pin(&codec->dapm, "Bandgap"); 2363 snd_soc_dapm_force_enable_pin(dapm, "Bandgap");
2363 snd_soc_dapm_sync(&codec->dapm); 2364 snd_soc_dapm_sync(dapm);
2364 2365
2365 /* Go into headphone detect left mode */ 2366 /* Go into headphone detect left mode */
2366 snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, 0); 2367 snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, 0);
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index a4d11770630c..4134dc7e1243 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -40,7 +40,7 @@ struct wm8997_priv {
40static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0); 40static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0);
41static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 41static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
42static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); 42static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0);
43static DECLARE_TLV_DB_SCALE(noise_tlv, 0, 600, 0); 43static DECLARE_TLV_DB_SCALE(noise_tlv, -13200, 600, 0);
44static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0); 44static DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0);
45 45
46static const struct reg_default wm8997_sysclk_reva_patch[] = { 46static const struct reg_default wm8997_sysclk_reva_patch[] = {
@@ -106,11 +106,13 @@ static int wm8997_sysclk_ev(struct snd_soc_dapm_widget *w,
106 regmap_write_async(regmap, patch[i].reg, 106 regmap_write_async(regmap, patch[i].reg,
107 patch[i].def); 107 patch[i].def);
108 break; 108 break;
109 default: 109 case SND_SOC_DAPM_PRE_PMD:
110 break; 110 break;
111 default:
112 return 0;
111 } 113 }
112 114
113 return 0; 115 return arizona_dvfs_sysclk_ev(w, kcontrol, event);
114} 116}
115 117
116static const char *wm8997_osr_text[] = { 118static const char *wm8997_osr_text[] = {
@@ -409,7 +411,8 @@ static const struct snd_kcontrol_new wm8997_aec_loopback_mux =
409 411
410static const struct snd_soc_dapm_widget wm8997_dapm_widgets[] = { 412static const struct snd_soc_dapm_widget wm8997_dapm_widgets[] = {
411SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT, 413SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT,
412 0, wm8997_sysclk_ev, SND_SOC_DAPM_POST_PMU), 414 0, wm8997_sysclk_ev,
415 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
413SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1, 416SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
414 ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0), 417 ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
415SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK, 418SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
@@ -1055,13 +1058,14 @@ static struct snd_soc_dai_driver wm8997_dai[] = {
1055 1058
1056static int wm8997_codec_probe(struct snd_soc_codec *codec) 1059static int wm8997_codec_probe(struct snd_soc_codec *codec)
1057{ 1060{
1061 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1058 struct wm8997_priv *priv = snd_soc_codec_get_drvdata(codec); 1062 struct wm8997_priv *priv = snd_soc_codec_get_drvdata(codec);
1059 1063
1060 arizona_init_spk(codec); 1064 arizona_init_spk(codec);
1061 1065
1062 snd_soc_dapm_disable_pin(&codec->dapm, "HAPTICS"); 1066 snd_soc_dapm_disable_pin(dapm, "HAPTICS");
1063 1067
1064 priv->core.arizona->dapm = &codec->dapm; 1068 priv->core.arizona->dapm = dapm;
1065 1069
1066 return 0; 1070 return 0;
1067} 1071}
@@ -1126,6 +1130,8 @@ static int wm8997_probe(struct platform_device *pdev)
1126 wm8997->core.arizona = arizona; 1130 wm8997->core.arizona = arizona;
1127 wm8997->core.num_inputs = 4; 1131 wm8997->core.num_inputs = 4;
1128 1132
1133 arizona_init_dvfs(&wm8997->core);
1134
1129 for (i = 0; i < ARRAY_SIZE(wm8997->fll); i++) 1135 for (i = 0; i < ARRAY_SIZE(wm8997->fll); i++)
1130 wm8997->fll[i].vco_mult = 1; 1136 wm8997->fll[i].vco_mult = 1;
1131 1137
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index 13a3f335ea5b..8a8b1c0f9142 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -838,7 +838,7 @@ static int wm9081_set_bias_level(struct snd_soc_codec *codec,
838 838
839 case SND_SOC_BIAS_STANDBY: 839 case SND_SOC_BIAS_STANDBY:
840 /* Initial cold start */ 840 /* Initial cold start */
841 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 841 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
842 regcache_cache_only(wm9081->regmap, false); 842 regcache_cache_only(wm9081->regmap, false);
843 regcache_sync(wm9081->regmap); 843 regcache_sync(wm9081->regmap);
844 844
@@ -898,8 +898,6 @@ static int wm9081_set_bias_level(struct snd_soc_codec *codec,
898 break; 898 break;
899 } 899 }
900 900
901 codec->dapm.bias_level = level;
902
903 return 0; 901 return 0;
904} 902}
905 903
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index 60d243c904f5..13d23fc797db 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -425,7 +425,7 @@ static const struct snd_soc_dapm_route audio_map_in2_diff[] = {
425static int wm9090_add_controls(struct snd_soc_codec *codec) 425static int wm9090_add_controls(struct snd_soc_codec *codec)
426{ 426{
427 struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec); 427 struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec);
428 struct snd_soc_dapm_context *dapm = &codec->dapm; 428 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
429 int i; 429 int i;
430 430
431 snd_soc_dapm_new_controls(dapm, wm9090_dapm_widgets, 431 snd_soc_dapm_new_controls(dapm, wm9090_dapm_widgets,
@@ -496,7 +496,7 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,
496 break; 496 break;
497 497
498 case SND_SOC_BIAS_STANDBY: 498 case SND_SOC_BIAS_STANDBY:
499 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 499 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
500 /* Restore the register cache */ 500 /* Restore the register cache */
501 regcache_sync(wm9090->regmap); 501 regcache_sync(wm9090->regmap);
502 } 502 }
@@ -515,8 +515,6 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,
515 break; 515 break;
516 } 516 }
517 517
518 codec->dapm.bias_level = level;
519
520 return 0; 518 return 0;
521} 519}
522 520
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 98c9525bd751..1fda104dfc45 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -610,7 +610,6 @@ static int wm9712_set_bias_level(struct snd_soc_codec *codec,
610 ac97_write(codec, AC97_POWERDOWN, 0xffff); 610 ac97_write(codec, AC97_POWERDOWN, 0xffff);
611 break; 611 break;
612 } 612 }
613 codec->dapm.bias_level = level;
614 return 0; 613 return 0;
615} 614}
616 615
@@ -646,7 +645,7 @@ static int wm9712_soc_resume(struct snd_soc_codec *codec)
646 if (ret < 0) 645 if (ret < 0)
647 return ret; 646 return ret;
648 647
649 wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 648 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
650 649
651 if (ret == 0) { 650 if (ret == 0) {
652 /* Sync reg_cache with the hardware after cold reset */ 651 /* Sync reg_cache with the hardware after cold reset */
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index 79552953e1bd..89cd2d6f57c0 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -1054,8 +1054,8 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream,
1054 SNDRV_PCM_RATE_48000) 1054 SNDRV_PCM_RATE_48000)
1055 1055
1056#define WM9713_PCM_FORMATS \ 1056#define WM9713_PCM_FORMATS \
1057 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ 1057 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1058 SNDRV_PCM_FORMAT_S24_LE) 1058 SNDRV_PCM_FMTBIT_S24_LE)
1059 1059
1060static const struct snd_soc_dai_ops wm9713_dai_ops_hifi = { 1060static const struct snd_soc_dai_ops wm9713_dai_ops_hifi = {
1061 .prepare = ac97_hifi_prepare, 1061 .prepare = ac97_hifi_prepare,
@@ -1171,7 +1171,6 @@ static int wm9713_set_bias_level(struct snd_soc_codec *codec,
1171 ac97_write(codec, AC97_POWERDOWN, 0xffff); 1171 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1172 break; 1172 break;
1173 } 1173 }
1174 codec->dapm.bias_level = level;
1175 return 0; 1174 return 0;
1176} 1175}
1177 1176
@@ -1201,7 +1200,7 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1201 if (ret < 0) 1200 if (ret < 0)
1202 return ret; 1201 return ret;
1203 1202
1204 wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1203 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
1205 1204
1206 /* do we need to re-start the PLL ? */ 1205 /* do we need to re-start the PLL ? */
1207 if (wm9713->pll_in) 1206 if (wm9713->pll_in)
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index d01c2095452f..b62ffd0c133e 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -121,6 +121,11 @@
121#define ADSP2_WDMA_CONFIG_2 0x31 121#define ADSP2_WDMA_CONFIG_2 0x31
122#define ADSP2_RDMA_CONFIG_1 0x34 122#define ADSP2_RDMA_CONFIG_1 0x34
123 123
124#define ADSP2_SCRATCH0 0x40
125#define ADSP2_SCRATCH1 0x41
126#define ADSP2_SCRATCH2 0x42
127#define ADSP2_SCRATCH3 0x43
128
124/* 129/*
125 * ADSP2 Control 130 * ADSP2 Control
126 */ 131 */
@@ -229,16 +234,18 @@ struct wm_coeff_ctl_ops {
229 234
230struct wm_coeff_ctl { 235struct wm_coeff_ctl {
231 const char *name; 236 const char *name;
232 struct wm_adsp_alg_region region; 237 const char *fw_name;
238 struct wm_adsp_alg_region alg_region;
233 struct wm_coeff_ctl_ops ops; 239 struct wm_coeff_ctl_ops ops;
234 struct wm_adsp *adsp; 240 struct wm_adsp *dsp;
235 void *private;
236 unsigned int enabled:1; 241 unsigned int enabled:1;
237 struct list_head list; 242 struct list_head list;
238 void *cache; 243 void *cache;
244 unsigned int offset;
239 size_t len; 245 size_t len;
240 unsigned int set:1; 246 unsigned int set:1;
241 struct snd_kcontrol *kcontrol; 247 struct snd_kcontrol *kcontrol;
248 unsigned int flags;
242}; 249};
243 250
244static int wm_adsp_fw_get(struct snd_kcontrol *kcontrol, 251static int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
@@ -246,9 +253,9 @@ static int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
246{ 253{
247 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 254 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
248 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 255 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
249 struct wm_adsp *adsp = snd_soc_codec_get_drvdata(codec); 256 struct wm_adsp *dsp = snd_soc_codec_get_drvdata(codec);
250 257
251 ucontrol->value.integer.value[0] = adsp[e->shift_l].fw; 258 ucontrol->value.integer.value[0] = dsp[e->shift_l].fw;
252 259
253 return 0; 260 return 0;
254} 261}
@@ -258,18 +265,18 @@ static int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
258{ 265{
259 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 266 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
260 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 267 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
261 struct wm_adsp *adsp = snd_soc_codec_get_drvdata(codec); 268 struct wm_adsp *dsp = snd_soc_codec_get_drvdata(codec);
262 269
263 if (ucontrol->value.integer.value[0] == adsp[e->shift_l].fw) 270 if (ucontrol->value.integer.value[0] == dsp[e->shift_l].fw)
264 return 0; 271 return 0;
265 272
266 if (ucontrol->value.integer.value[0] >= WM_ADSP_NUM_FW) 273 if (ucontrol->value.integer.value[0] >= WM_ADSP_NUM_FW)
267 return -EINVAL; 274 return -EINVAL;
268 275
269 if (adsp[e->shift_l].running) 276 if (dsp[e->shift_l].running)
270 return -EBUSY; 277 return -EBUSY;
271 278
272 adsp[e->shift_l].fw = ucontrol->value.integer.value[0]; 279 dsp[e->shift_l].fw = ucontrol->value.integer.value[0];
273 280
274 return 0; 281 return 0;
275} 282}
@@ -340,28 +347,47 @@ static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp,
340 return NULL; 347 return NULL;
341} 348}
342 349
343static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *region, 350static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *mem,
344 unsigned int offset) 351 unsigned int offset)
345{ 352{
346 if (WARN_ON(!region)) 353 if (WARN_ON(!mem))
347 return offset; 354 return offset;
348 switch (region->type) { 355 switch (mem->type) {
349 case WMFW_ADSP1_PM: 356 case WMFW_ADSP1_PM:
350 return region->base + (offset * 3); 357 return mem->base + (offset * 3);
351 case WMFW_ADSP1_DM: 358 case WMFW_ADSP1_DM:
352 return region->base + (offset * 2); 359 return mem->base + (offset * 2);
353 case WMFW_ADSP2_XM: 360 case WMFW_ADSP2_XM:
354 return region->base + (offset * 2); 361 return mem->base + (offset * 2);
355 case WMFW_ADSP2_YM: 362 case WMFW_ADSP2_YM:
356 return region->base + (offset * 2); 363 return mem->base + (offset * 2);
357 case WMFW_ADSP1_ZM: 364 case WMFW_ADSP1_ZM:
358 return region->base + (offset * 2); 365 return mem->base + (offset * 2);
359 default: 366 default:
360 WARN(1, "Unknown memory region type"); 367 WARN(1, "Unknown memory region type");
361 return offset; 368 return offset;
362 } 369 }
363} 370}
364 371
372static void wm_adsp2_show_fw_status(struct wm_adsp *dsp)
373{
374 u16 scratch[4];
375 int ret;
376
377 ret = regmap_raw_read(dsp->regmap, dsp->base + ADSP2_SCRATCH0,
378 scratch, sizeof(scratch));
379 if (ret) {
380 adsp_err(dsp, "Failed to read SCRATCH regs: %d\n", ret);
381 return;
382 }
383
384 adsp_dbg(dsp, "FW SCRATCH 0:0x%x 1:0x%x 2:0x%x 3:0x%x\n",
385 be16_to_cpu(scratch[0]),
386 be16_to_cpu(scratch[1]),
387 be16_to_cpu(scratch[2]),
388 be16_to_cpu(scratch[3]));
389}
390
365static int wm_coeff_info(struct snd_kcontrol *kcontrol, 391static int wm_coeff_info(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_info *uinfo) 392 struct snd_ctl_elem_info *uinfo)
367{ 393{
@@ -372,40 +398,39 @@ static int wm_coeff_info(struct snd_kcontrol *kcontrol,
372 return 0; 398 return 0;
373} 399}
374 400
375static int wm_coeff_write_control(struct snd_kcontrol *kcontrol, 401static int wm_coeff_write_control(struct wm_coeff_ctl *ctl,
376 const void *buf, size_t len) 402 const void *buf, size_t len)
377{ 403{
378 struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value; 404 struct wm_adsp_alg_region *alg_region = &ctl->alg_region;
379 struct wm_adsp_alg_region *region = &ctl->region;
380 const struct wm_adsp_region *mem; 405 const struct wm_adsp_region *mem;
381 struct wm_adsp *adsp = ctl->adsp; 406 struct wm_adsp *dsp = ctl->dsp;
382 void *scratch; 407 void *scratch;
383 int ret; 408 int ret;
384 unsigned int reg; 409 unsigned int reg;
385 410
386 mem = wm_adsp_find_region(adsp, region->type); 411 mem = wm_adsp_find_region(dsp, alg_region->type);
387 if (!mem) { 412 if (!mem) {
388 adsp_err(adsp, "No base for region %x\n", 413 adsp_err(dsp, "No base for region %x\n",
389 region->type); 414 alg_region->type);
390 return -EINVAL; 415 return -EINVAL;
391 } 416 }
392 417
393 reg = ctl->region.base; 418 reg = ctl->alg_region.base + ctl->offset;
394 reg = wm_adsp_region_to_reg(mem, reg); 419 reg = wm_adsp_region_to_reg(mem, reg);
395 420
396 scratch = kmemdup(buf, ctl->len, GFP_KERNEL | GFP_DMA); 421 scratch = kmemdup(buf, ctl->len, GFP_KERNEL | GFP_DMA);
397 if (!scratch) 422 if (!scratch)
398 return -ENOMEM; 423 return -ENOMEM;
399 424
400 ret = regmap_raw_write(adsp->regmap, reg, scratch, 425 ret = regmap_raw_write(dsp->regmap, reg, scratch,
401 ctl->len); 426 ctl->len);
402 if (ret) { 427 if (ret) {
403 adsp_err(adsp, "Failed to write %zu bytes to %x: %d\n", 428 adsp_err(dsp, "Failed to write %zu bytes to %x: %d\n",
404 ctl->len, reg, ret); 429 ctl->len, reg, ret);
405 kfree(scratch); 430 kfree(scratch);
406 return ret; 431 return ret;
407 } 432 }
408 adsp_dbg(adsp, "Wrote %zu bytes to %x\n", ctl->len, reg); 433 adsp_dbg(dsp, "Wrote %zu bytes to %x\n", ctl->len, reg);
409 434
410 kfree(scratch); 435 kfree(scratch);
411 436
@@ -424,42 +449,41 @@ static int wm_coeff_put(struct snd_kcontrol *kcontrol,
424 if (!ctl->enabled) 449 if (!ctl->enabled)
425 return 0; 450 return 0;
426 451
427 return wm_coeff_write_control(kcontrol, p, ctl->len); 452 return wm_coeff_write_control(ctl, p, ctl->len);
428} 453}
429 454
430static int wm_coeff_read_control(struct snd_kcontrol *kcontrol, 455static int wm_coeff_read_control(struct wm_coeff_ctl *ctl,
431 void *buf, size_t len) 456 void *buf, size_t len)
432{ 457{
433 struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value; 458 struct wm_adsp_alg_region *alg_region = &ctl->alg_region;
434 struct wm_adsp_alg_region *region = &ctl->region;
435 const struct wm_adsp_region *mem; 459 const struct wm_adsp_region *mem;
436 struct wm_adsp *adsp = ctl->adsp; 460 struct wm_adsp *dsp = ctl->dsp;
437 void *scratch; 461 void *scratch;
438 int ret; 462 int ret;
439 unsigned int reg; 463 unsigned int reg;
440 464
441 mem = wm_adsp_find_region(adsp, region->type); 465 mem = wm_adsp_find_region(dsp, alg_region->type);
442 if (!mem) { 466 if (!mem) {
443 adsp_err(adsp, "No base for region %x\n", 467 adsp_err(dsp, "No base for region %x\n",
444 region->type); 468 alg_region->type);
445 return -EINVAL; 469 return -EINVAL;
446 } 470 }
447 471
448 reg = ctl->region.base; 472 reg = ctl->alg_region.base + ctl->offset;
449 reg = wm_adsp_region_to_reg(mem, reg); 473 reg = wm_adsp_region_to_reg(mem, reg);
450 474
451 scratch = kmalloc(ctl->len, GFP_KERNEL | GFP_DMA); 475 scratch = kmalloc(ctl->len, GFP_KERNEL | GFP_DMA);
452 if (!scratch) 476 if (!scratch)
453 return -ENOMEM; 477 return -ENOMEM;
454 478
455 ret = regmap_raw_read(adsp->regmap, reg, scratch, ctl->len); 479 ret = regmap_raw_read(dsp->regmap, reg, scratch, ctl->len);
456 if (ret) { 480 if (ret) {
457 adsp_err(adsp, "Failed to read %zu bytes from %x: %d\n", 481 adsp_err(dsp, "Failed to read %zu bytes from %x: %d\n",
458 ctl->len, reg, ret); 482 ctl->len, reg, ret);
459 kfree(scratch); 483 kfree(scratch);
460 return ret; 484 return ret;
461 } 485 }
462 adsp_dbg(adsp, "Read %zu bytes from %x\n", ctl->len, reg); 486 adsp_dbg(dsp, "Read %zu bytes from %x\n", ctl->len, reg);
463 487
464 memcpy(buf, scratch, ctl->len); 488 memcpy(buf, scratch, ctl->len);
465 kfree(scratch); 489 kfree(scratch);
@@ -473,17 +497,25 @@ static int wm_coeff_get(struct snd_kcontrol *kcontrol,
473 struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value; 497 struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value;
474 char *p = ucontrol->value.bytes.data; 498 char *p = ucontrol->value.bytes.data;
475 499
500 if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) {
501 if (ctl->enabled)
502 return wm_coeff_read_control(ctl, p, ctl->len);
503 else
504 return -EPERM;
505 }
506
476 memcpy(p, ctl->cache, ctl->len); 507 memcpy(p, ctl->cache, ctl->len);
508
477 return 0; 509 return 0;
478} 510}
479 511
480struct wmfw_ctl_work { 512struct wmfw_ctl_work {
481 struct wm_adsp *adsp; 513 struct wm_adsp *dsp;
482 struct wm_coeff_ctl *ctl; 514 struct wm_coeff_ctl *ctl;
483 struct work_struct work; 515 struct work_struct work;
484}; 516};
485 517
486static int wmfw_add_ctl(struct wm_adsp *adsp, struct wm_coeff_ctl *ctl) 518static int wmfw_add_ctl(struct wm_adsp *dsp, struct wm_coeff_ctl *ctl)
487{ 519{
488 struct snd_kcontrol_new *kcontrol; 520 struct snd_kcontrol_new *kcontrol;
489 int ret; 521 int ret;
@@ -502,17 +534,25 @@ static int wmfw_add_ctl(struct wm_adsp *adsp, struct wm_coeff_ctl *ctl)
502 kcontrol->put = wm_coeff_put; 534 kcontrol->put = wm_coeff_put;
503 kcontrol->private_value = (unsigned long)ctl; 535 kcontrol->private_value = (unsigned long)ctl;
504 536
505 ret = snd_soc_add_card_controls(adsp->card, 537 if (ctl->flags) {
538 if (ctl->flags & WMFW_CTL_FLAG_WRITEABLE)
539 kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
540 if (ctl->flags & WMFW_CTL_FLAG_READABLE)
541 kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_READ;
542 if (ctl->flags & WMFW_CTL_FLAG_VOLATILE)
543 kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_VOLATILE;
544 }
545
546 ret = snd_soc_add_card_controls(dsp->card,
506 kcontrol, 1); 547 kcontrol, 1);
507 if (ret < 0) 548 if (ret < 0)
508 goto err_kcontrol; 549 goto err_kcontrol;
509 550
510 kfree(kcontrol); 551 kfree(kcontrol);
511 552
512 ctl->kcontrol = snd_soc_card_get_kcontrol(adsp->card, 553 ctl->kcontrol = snd_soc_card_get_kcontrol(dsp->card,
513 ctl->name); 554 ctl->name);
514 555
515 list_add(&ctl->list, &adsp->ctl_list);
516 return 0; 556 return 0;
517 557
518err_kcontrol: 558err_kcontrol:
@@ -520,6 +560,358 @@ err_kcontrol:
520 return ret; 560 return ret;
521} 561}
522 562
563static int wm_coeff_init_control_caches(struct wm_adsp *dsp)
564{
565 struct wm_coeff_ctl *ctl;
566 int ret;
567
568 list_for_each_entry(ctl, &dsp->ctl_list, list) {
569 if (!ctl->enabled || ctl->set)
570 continue;
571 if (ctl->flags & WMFW_CTL_FLAG_VOLATILE)
572 continue;
573
574 ret = wm_coeff_read_control(ctl,
575 ctl->cache,
576 ctl->len);
577 if (ret < 0)
578 return ret;
579 }
580
581 return 0;
582}
583
584static int wm_coeff_sync_controls(struct wm_adsp *dsp)
585{
586 struct wm_coeff_ctl *ctl;
587 int ret;
588
589 list_for_each_entry(ctl, &dsp->ctl_list, list) {
590 if (!ctl->enabled)
591 continue;
592 if (ctl->set && !(ctl->flags & WMFW_CTL_FLAG_VOLATILE)) {
593 ret = wm_coeff_write_control(ctl,
594 ctl->cache,
595 ctl->len);
596 if (ret < 0)
597 return ret;
598 }
599 }
600
601 return 0;
602}
603
604static void wm_adsp_ctl_work(struct work_struct *work)
605{
606 struct wmfw_ctl_work *ctl_work = container_of(work,
607 struct wmfw_ctl_work,
608 work);
609
610 wmfw_add_ctl(ctl_work->dsp, ctl_work->ctl);
611 kfree(ctl_work);
612}
613
614static int wm_adsp_create_control(struct wm_adsp *dsp,
615 const struct wm_adsp_alg_region *alg_region,
616 unsigned int offset, unsigned int len,
617 const char *subname, unsigned int subname_len,
618 unsigned int flags)
619{
620 struct wm_coeff_ctl *ctl;
621 struct wmfw_ctl_work *ctl_work;
622 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
623 char *region_name;
624 int ret;
625
626 if (flags & WMFW_CTL_FLAG_SYS)
627 return 0;
628
629 switch (alg_region->type) {
630 case WMFW_ADSP1_PM:
631 region_name = "PM";
632 break;
633 case WMFW_ADSP1_DM:
634 region_name = "DM";
635 break;
636 case WMFW_ADSP2_XM:
637 region_name = "XM";
638 break;
639 case WMFW_ADSP2_YM:
640 region_name = "YM";
641 break;
642 case WMFW_ADSP1_ZM:
643 region_name = "ZM";
644 break;
645 default:
646 adsp_err(dsp, "Unknown region type: %d\n", alg_region->type);
647 return -EINVAL;
648 }
649
650 switch (dsp->fw_ver) {
651 case 0:
652 case 1:
653 snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x",
654 dsp->num, region_name, alg_region->alg);
655 break;
656 default:
657 ret = snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
658 "DSP%d%c %.12s %x", dsp->num, *region_name,
659 wm_adsp_fw_text[dsp->fw], alg_region->alg);
660
661 /* Truncate the subname from the start if it is too long */
662 if (subname) {
663 int avail = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret - 2;
664 int skip = 0;
665
666 if (subname_len > avail)
667 skip = subname_len - avail;
668
669 snprintf(name + ret,
670 SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret, " %.*s",
671 subname_len - skip, subname + skip);
672 }
673 break;
674 }
675
676 list_for_each_entry(ctl, &dsp->ctl_list,
677 list) {
678 if (!strcmp(ctl->name, name)) {
679 if (!ctl->enabled)
680 ctl->enabled = 1;
681 return 0;
682 }
683 }
684
685 ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
686 if (!ctl)
687 return -ENOMEM;
688 ctl->fw_name = wm_adsp_fw_text[dsp->fw];
689 ctl->alg_region = *alg_region;
690 ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL);
691 if (!ctl->name) {
692 ret = -ENOMEM;
693 goto err_ctl;
694 }
695 ctl->enabled = 1;
696 ctl->set = 0;
697 ctl->ops.xget = wm_coeff_get;
698 ctl->ops.xput = wm_coeff_put;
699 ctl->dsp = dsp;
700
701 ctl->flags = flags;
702 ctl->offset = offset;
703 if (len > 512) {
704 adsp_warn(dsp, "Truncating control %s from %d\n",
705 ctl->name, len);
706 len = 512;
707 }
708 ctl->len = len;
709 ctl->cache = kzalloc(ctl->len, GFP_KERNEL);
710 if (!ctl->cache) {
711 ret = -ENOMEM;
712 goto err_ctl_name;
713 }
714
715 list_add(&ctl->list, &dsp->ctl_list);
716
717 ctl_work = kzalloc(sizeof(*ctl_work), GFP_KERNEL);
718 if (!ctl_work) {
719 ret = -ENOMEM;
720 goto err_ctl_cache;
721 }
722
723 ctl_work->dsp = dsp;
724 ctl_work->ctl = ctl;
725 INIT_WORK(&ctl_work->work, wm_adsp_ctl_work);
726 schedule_work(&ctl_work->work);
727
728 return 0;
729
730err_ctl_cache:
731 kfree(ctl->cache);
732err_ctl_name:
733 kfree(ctl->name);
734err_ctl:
735 kfree(ctl);
736
737 return ret;
738}
739
740struct wm_coeff_parsed_alg {
741 int id;
742 const u8 *name;
743 int name_len;
744 int ncoeff;
745};
746
747struct wm_coeff_parsed_coeff {
748 int offset;
749 int mem_type;
750 const u8 *name;
751 int name_len;
752 int ctl_type;
753 int flags;
754 int len;
755};
756
757static int wm_coeff_parse_string(int bytes, const u8 **pos, const u8 **str)
758{
759 int length;
760
761 switch (bytes) {
762 case 1:
763 length = **pos;
764 break;
765 case 2:
766 length = le16_to_cpu(*((__le16 *)*pos));
767 break;
768 default:
769 return 0;
770 }
771
772 if (str)
773 *str = *pos + bytes;
774
775 *pos += ((length + bytes) + 3) & ~0x03;
776
777 return length;
778}
779
780static int wm_coeff_parse_int(int bytes, const u8 **pos)
781{
782 int val = 0;
783
784 switch (bytes) {
785 case 2:
786 val = le16_to_cpu(*((__le16 *)*pos));
787 break;
788 case 4:
789 val = le32_to_cpu(*((__le32 *)*pos));
790 break;
791 default:
792 break;
793 }
794
795 *pos += bytes;
796
797 return val;
798}
799
800static inline void wm_coeff_parse_alg(struct wm_adsp *dsp, const u8 **data,
801 struct wm_coeff_parsed_alg *blk)
802{
803 const struct wmfw_adsp_alg_data *raw;
804
805 switch (dsp->fw_ver) {
806 case 0:
807 case 1:
808 raw = (const struct wmfw_adsp_alg_data *)*data;
809 *data = raw->data;
810
811 blk->id = le32_to_cpu(raw->id);
812 blk->name = raw->name;
813 blk->name_len = strlen(raw->name);
814 blk->ncoeff = le32_to_cpu(raw->ncoeff);
815 break;
816 default:
817 blk->id = wm_coeff_parse_int(sizeof(raw->id), data);
818 blk->name_len = wm_coeff_parse_string(sizeof(u8), data,
819 &blk->name);
820 wm_coeff_parse_string(sizeof(u16), data, NULL);
821 blk->ncoeff = wm_coeff_parse_int(sizeof(raw->ncoeff), data);
822 break;
823 }
824
825 adsp_dbg(dsp, "Algorithm ID: %#x\n", blk->id);
826 adsp_dbg(dsp, "Algorithm name: %.*s\n", blk->name_len, blk->name);
827 adsp_dbg(dsp, "# of coefficient descriptors: %#x\n", blk->ncoeff);
828}
829
830static inline void wm_coeff_parse_coeff(struct wm_adsp *dsp, const u8 **data,
831 struct wm_coeff_parsed_coeff *blk)
832{
833 const struct wmfw_adsp_coeff_data *raw;
834 const u8 *tmp;
835 int length;
836
837 switch (dsp->fw_ver) {
838 case 0:
839 case 1:
840 raw = (const struct wmfw_adsp_coeff_data *)*data;
841 *data = *data + sizeof(raw->hdr) + le32_to_cpu(raw->hdr.size);
842
843 blk->offset = le16_to_cpu(raw->hdr.offset);
844 blk->mem_type = le16_to_cpu(raw->hdr.type);
845 blk->name = raw->name;
846 blk->name_len = strlen(raw->name);
847 blk->ctl_type = le16_to_cpu(raw->ctl_type);
848 blk->flags = le16_to_cpu(raw->flags);
849 blk->len = le32_to_cpu(raw->len);
850 break;
851 default:
852 tmp = *data;
853 blk->offset = wm_coeff_parse_int(sizeof(raw->hdr.offset), &tmp);
854 blk->mem_type = wm_coeff_parse_int(sizeof(raw->hdr.type), &tmp);
855 length = wm_coeff_parse_int(sizeof(raw->hdr.size), &tmp);
856 blk->name_len = wm_coeff_parse_string(sizeof(u8), &tmp,
857 &blk->name);
858 wm_coeff_parse_string(sizeof(u8), &tmp, NULL);
859 wm_coeff_parse_string(sizeof(u16), &tmp, NULL);
860 blk->ctl_type = wm_coeff_parse_int(sizeof(raw->ctl_type), &tmp);
861 blk->flags = wm_coeff_parse_int(sizeof(raw->flags), &tmp);
862 blk->len = wm_coeff_parse_int(sizeof(raw->len), &tmp);
863
864 *data = *data + sizeof(raw->hdr) + length;
865 break;
866 }
867
868 adsp_dbg(dsp, "\tCoefficient type: %#x\n", blk->mem_type);
869 adsp_dbg(dsp, "\tCoefficient offset: %#x\n", blk->offset);
870 adsp_dbg(dsp, "\tCoefficient name: %.*s\n", blk->name_len, blk->name);
871 adsp_dbg(dsp, "\tCoefficient flags: %#x\n", blk->flags);
872 adsp_dbg(dsp, "\tALSA control type: %#x\n", blk->ctl_type);
873 adsp_dbg(dsp, "\tALSA control len: %#x\n", blk->len);
874}
875
876static int wm_adsp_parse_coeff(struct wm_adsp *dsp,
877 const struct wmfw_region *region)
878{
879 struct wm_adsp_alg_region alg_region = {};
880 struct wm_coeff_parsed_alg alg_blk;
881 struct wm_coeff_parsed_coeff coeff_blk;
882 const u8 *data = region->data;
883 int i, ret;
884
885 wm_coeff_parse_alg(dsp, &data, &alg_blk);
886 for (i = 0; i < alg_blk.ncoeff; i++) {
887 wm_coeff_parse_coeff(dsp, &data, &coeff_blk);
888
889 switch (coeff_blk.ctl_type) {
890 case SNDRV_CTL_ELEM_TYPE_BYTES:
891 break;
892 default:
893 adsp_err(dsp, "Unknown control type: %d\n",
894 coeff_blk.ctl_type);
895 return -EINVAL;
896 }
897
898 alg_region.type = coeff_blk.mem_type;
899 alg_region.alg = alg_blk.id;
900
901 ret = wm_adsp_create_control(dsp, &alg_region,
902 coeff_blk.offset,
903 coeff_blk.len,
904 coeff_blk.name,
905 coeff_blk.name_len,
906 coeff_blk.flags);
907 if (ret < 0)
908 adsp_err(dsp, "Failed to create control: %.*s, %d\n",
909 coeff_blk.name_len, coeff_blk.name, ret);
910 }
911
912 return 0;
913}
914
523static int wm_adsp_load(struct wm_adsp *dsp) 915static int wm_adsp_load(struct wm_adsp *dsp)
524{ 916{
525 LIST_HEAD(buf_list); 917 LIST_HEAD(buf_list);
@@ -568,12 +960,22 @@ static int wm_adsp_load(struct wm_adsp *dsp)
568 goto out_fw; 960 goto out_fw;
569 } 961 }
570 962
571 if (header->ver != 0) { 963 switch (header->ver) {
964 case 0:
965 adsp_warn(dsp, "%s: Depreciated file format %d\n",
966 file, header->ver);
967 break;
968 case 1:
969 case 2:
970 break;
971 default:
572 adsp_err(dsp, "%s: unknown file format %d\n", 972 adsp_err(dsp, "%s: unknown file format %d\n",
573 file, header->ver); 973 file, header->ver);
574 goto out_fw; 974 goto out_fw;
575 } 975 }
976
576 adsp_info(dsp, "Firmware version: %d\n", header->ver); 977 adsp_info(dsp, "Firmware version: %d\n", header->ver);
978 dsp->fw_ver = header->ver;
577 979
578 if (header->core != dsp->type) { 980 if (header->core != dsp->type) {
579 adsp_err(dsp, "%s: invalid core %d != %d\n", 981 adsp_err(dsp, "%s: invalid core %d != %d\n",
@@ -638,6 +1040,12 @@ static int wm_adsp_load(struct wm_adsp *dsp)
638 text = kzalloc(le32_to_cpu(region->len) + 1, 1040 text = kzalloc(le32_to_cpu(region->len) + 1,
639 GFP_KERNEL); 1041 GFP_KERNEL);
640 break; 1042 break;
1043 case WMFW_ALGORITHM_DATA:
1044 region_name = "Algorithm";
1045 ret = wm_adsp_parse_coeff(dsp, region);
1046 if (ret != 0)
1047 goto out_fw;
1048 break;
641 case WMFW_INFO_TEXT: 1049 case WMFW_INFO_TEXT:
642 region_name = "Information"; 1050 region_name = "Information";
643 text = kzalloc(le32_to_cpu(region->len) + 1, 1051 text = kzalloc(le32_to_cpu(region->len) + 1,
@@ -730,444 +1138,316 @@ out:
730 return ret; 1138 return ret;
731} 1139}
732 1140
733static int wm_coeff_init_control_caches(struct wm_adsp *adsp) 1141static void wm_adsp_ctl_fixup_base(struct wm_adsp *dsp,
1142 const struct wm_adsp_alg_region *alg_region)
734{ 1143{
735 struct wm_coeff_ctl *ctl; 1144 struct wm_coeff_ctl *ctl;
736 int ret;
737 1145
738 list_for_each_entry(ctl, &adsp->ctl_list, list) { 1146 list_for_each_entry(ctl, &dsp->ctl_list, list) {
739 if (!ctl->enabled || ctl->set) 1147 if (ctl->fw_name == wm_adsp_fw_text[dsp->fw] &&
740 continue; 1148 alg_region->alg == ctl->alg_region.alg &&
741 ret = wm_coeff_read_control(ctl->kcontrol, 1149 alg_region->type == ctl->alg_region.type) {
742 ctl->cache, 1150 ctl->alg_region.base = alg_region->base;
743 ctl->len); 1151 }
744 if (ret < 0)
745 return ret;
746 } 1152 }
747
748 return 0;
749} 1153}
750 1154
751static int wm_coeff_sync_controls(struct wm_adsp *adsp) 1155static void *wm_adsp_read_algs(struct wm_adsp *dsp, size_t n_algs,
1156 unsigned int pos, unsigned int len)
752{ 1157{
753 struct wm_coeff_ctl *ctl; 1158 void *alg;
754 int ret; 1159 int ret;
1160 __be32 val;
755 1161
756 list_for_each_entry(ctl, &adsp->ctl_list, list) { 1162 if (n_algs == 0) {
757 if (!ctl->enabled) 1163 adsp_err(dsp, "No algorithms\n");
758 continue; 1164 return ERR_PTR(-EINVAL);
759 if (ctl->set) {
760 ret = wm_coeff_write_control(ctl->kcontrol,
761 ctl->cache,
762 ctl->len);
763 if (ret < 0)
764 return ret;
765 }
766 } 1165 }
767 1166
768 return 0; 1167 if (n_algs > 1024) {
769} 1168 adsp_err(dsp, "Algorithm count %zx excessive\n", n_algs);
770 1169 return ERR_PTR(-EINVAL);
771static void wm_adsp_ctl_work(struct work_struct *work) 1170 }
772{
773 struct wmfw_ctl_work *ctl_work = container_of(work,
774 struct wmfw_ctl_work,
775 work);
776
777 wmfw_add_ctl(ctl_work->adsp, ctl_work->ctl);
778 kfree(ctl_work);
779}
780
781static int wm_adsp_create_control(struct wm_adsp *dsp,
782 const struct wm_adsp_alg_region *region)
783
784{
785 struct wm_coeff_ctl *ctl;
786 struct wmfw_ctl_work *ctl_work;
787 char *name;
788 char *region_name;
789 int ret;
790
791 name = kmalloc(PAGE_SIZE, GFP_KERNEL);
792 if (!name)
793 return -ENOMEM;
794 1171
795 switch (region->type) { 1172 /* Read the terminator first to validate the length */
796 case WMFW_ADSP1_PM: 1173 ret = regmap_raw_read(dsp->regmap, pos + len, &val, sizeof(val));
797 region_name = "PM"; 1174 if (ret != 0) {
798 break; 1175 adsp_err(dsp, "Failed to read algorithm list end: %d\n",
799 case WMFW_ADSP1_DM: 1176 ret);
800 region_name = "DM"; 1177 return ERR_PTR(ret);
801 break;
802 case WMFW_ADSP2_XM:
803 region_name = "XM";
804 break;
805 case WMFW_ADSP2_YM:
806 region_name = "YM";
807 break;
808 case WMFW_ADSP1_ZM:
809 region_name = "ZM";
810 break;
811 default:
812 ret = -EINVAL;
813 goto err_name;
814 } 1178 }
815 1179
816 snprintf(name, PAGE_SIZE, "DSP%d %s %x", 1180 if (be32_to_cpu(val) != 0xbedead)
817 dsp->num, region_name, region->alg); 1181 adsp_warn(dsp, "Algorithm list end %x 0x%x != 0xbeadead\n",
1182 pos + len, be32_to_cpu(val));
818 1183
819 list_for_each_entry(ctl, &dsp->ctl_list, 1184 alg = kzalloc(len * 2, GFP_KERNEL | GFP_DMA);
820 list) { 1185 if (!alg)
821 if (!strcmp(ctl->name, name)) { 1186 return ERR_PTR(-ENOMEM);
822 if (!ctl->enabled)
823 ctl->enabled = 1;
824 goto found;
825 }
826 }
827 1187
828 ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); 1188 ret = regmap_raw_read(dsp->regmap, pos, alg, len * 2);
829 if (!ctl) { 1189 if (ret != 0) {
830 ret = -ENOMEM; 1190 adsp_err(dsp, "Failed to read algorithm list: %d\n",
831 goto err_name; 1191 ret);
832 } 1192 kfree(alg);
833 ctl->region = *region; 1193 return ERR_PTR(ret);
834 ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL);
835 if (!ctl->name) {
836 ret = -ENOMEM;
837 goto err_ctl;
838 } 1194 }
839 ctl->enabled = 1;
840 ctl->set = 0;
841 ctl->ops.xget = wm_coeff_get;
842 ctl->ops.xput = wm_coeff_put;
843 ctl->adsp = dsp;
844 1195
845 ctl->len = region->len; 1196 return alg;
846 ctl->cache = kzalloc(ctl->len, GFP_KERNEL); 1197}
847 if (!ctl->cache) {
848 ret = -ENOMEM;
849 goto err_ctl_name;
850 }
851 1198
852 ctl_work = kzalloc(sizeof(*ctl_work), GFP_KERNEL); 1199static struct wm_adsp_alg_region *wm_adsp_create_region(struct wm_adsp *dsp,
853 if (!ctl_work) { 1200 int type, __be32 id,
854 ret = -ENOMEM; 1201 __be32 base)
855 goto err_ctl_cache; 1202{
856 } 1203 struct wm_adsp_alg_region *alg_region;
857 1204
858 ctl_work->adsp = dsp; 1205 alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL);
859 ctl_work->ctl = ctl; 1206 if (!alg_region)
860 INIT_WORK(&ctl_work->work, wm_adsp_ctl_work); 1207 return ERR_PTR(-ENOMEM);
861 schedule_work(&ctl_work->work);
862 1208
863found: 1209 alg_region->type = type;
864 kfree(name); 1210 alg_region->alg = be32_to_cpu(id);
1211 alg_region->base = be32_to_cpu(base);
865 1212
866 return 0; 1213 list_add_tail(&alg_region->list, &dsp->alg_regions);
867 1214
868err_ctl_cache: 1215 if (dsp->fw_ver > 0)
869 kfree(ctl->cache); 1216 wm_adsp_ctl_fixup_base(dsp, alg_region);
870err_ctl_name: 1217
871 kfree(ctl->name); 1218 return alg_region;
872err_ctl:
873 kfree(ctl);
874err_name:
875 kfree(name);
876 return ret;
877} 1219}
878 1220
879static int wm_adsp_setup_algs(struct wm_adsp *dsp) 1221static int wm_adsp1_setup_algs(struct wm_adsp *dsp)
880{ 1222{
881 struct regmap *regmap = dsp->regmap;
882 struct wmfw_adsp1_id_hdr adsp1_id; 1223 struct wmfw_adsp1_id_hdr adsp1_id;
883 struct wmfw_adsp2_id_hdr adsp2_id;
884 struct wmfw_adsp1_alg_hdr *adsp1_alg; 1224 struct wmfw_adsp1_alg_hdr *adsp1_alg;
885 struct wmfw_adsp2_alg_hdr *adsp2_alg; 1225 struct wm_adsp_alg_region *alg_region;
886 void *alg, *buf;
887 struct wm_adsp_alg_region *region;
888 const struct wm_adsp_region *mem; 1226 const struct wm_adsp_region *mem;
889 unsigned int pos, term; 1227 unsigned int pos, len;
890 size_t algs, buf_size; 1228 size_t n_algs;
891 __be32 val;
892 int i, ret; 1229 int i, ret;
893 1230
894 switch (dsp->type) { 1231 mem = wm_adsp_find_region(dsp, WMFW_ADSP1_DM);
895 case WMFW_ADSP1:
896 mem = wm_adsp_find_region(dsp, WMFW_ADSP1_DM);
897 break;
898 case WMFW_ADSP2:
899 mem = wm_adsp_find_region(dsp, WMFW_ADSP2_XM);
900 break;
901 default:
902 mem = NULL;
903 break;
904 }
905
906 if (WARN_ON(!mem)) 1232 if (WARN_ON(!mem))
907 return -EINVAL; 1233 return -EINVAL;
908 1234
909 switch (dsp->type) { 1235 ret = regmap_raw_read(dsp->regmap, mem->base, &adsp1_id,
910 case WMFW_ADSP1: 1236 sizeof(adsp1_id));
911 ret = regmap_raw_read(regmap, mem->base, &adsp1_id,
912 sizeof(adsp1_id));
913 if (ret != 0) {
914 adsp_err(dsp, "Failed to read algorithm info: %d\n",
915 ret);
916 return ret;
917 }
918
919 buf = &adsp1_id;
920 buf_size = sizeof(adsp1_id);
921
922 algs = be32_to_cpu(adsp1_id.algs);
923 dsp->fw_id = be32_to_cpu(adsp1_id.fw.id);
924 adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n",
925 dsp->fw_id,
926 (be32_to_cpu(adsp1_id.fw.ver) & 0xff0000) >> 16,
927 (be32_to_cpu(adsp1_id.fw.ver) & 0xff00) >> 8,
928 be32_to_cpu(adsp1_id.fw.ver) & 0xff,
929 algs);
930
931 region = kzalloc(sizeof(*region), GFP_KERNEL);
932 if (!region)
933 return -ENOMEM;
934 region->type = WMFW_ADSP1_ZM;
935 region->alg = be32_to_cpu(adsp1_id.fw.id);
936 region->base = be32_to_cpu(adsp1_id.zm);
937 list_add_tail(&region->list, &dsp->alg_regions);
938
939 region = kzalloc(sizeof(*region), GFP_KERNEL);
940 if (!region)
941 return -ENOMEM;
942 region->type = WMFW_ADSP1_DM;
943 region->alg = be32_to_cpu(adsp1_id.fw.id);
944 region->base = be32_to_cpu(adsp1_id.dm);
945 list_add_tail(&region->list, &dsp->alg_regions);
946
947 pos = sizeof(adsp1_id) / 2;
948 term = pos + ((sizeof(*adsp1_alg) * algs) / 2);
949 break;
950
951 case WMFW_ADSP2:
952 ret = regmap_raw_read(regmap, mem->base, &adsp2_id,
953 sizeof(adsp2_id));
954 if (ret != 0) {
955 adsp_err(dsp, "Failed to read algorithm info: %d\n",
956 ret);
957 return ret;
958 }
959
960 buf = &adsp2_id;
961 buf_size = sizeof(adsp2_id);
962
963 algs = be32_to_cpu(adsp2_id.algs);
964 dsp->fw_id = be32_to_cpu(adsp2_id.fw.id);
965 adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n",
966 dsp->fw_id,
967 (be32_to_cpu(adsp2_id.fw.ver) & 0xff0000) >> 16,
968 (be32_to_cpu(adsp2_id.fw.ver) & 0xff00) >> 8,
969 be32_to_cpu(adsp2_id.fw.ver) & 0xff,
970 algs);
971
972 region = kzalloc(sizeof(*region), GFP_KERNEL);
973 if (!region)
974 return -ENOMEM;
975 region->type = WMFW_ADSP2_XM;
976 region->alg = be32_to_cpu(adsp2_id.fw.id);
977 region->base = be32_to_cpu(adsp2_id.xm);
978 list_add_tail(&region->list, &dsp->alg_regions);
979
980 region = kzalloc(sizeof(*region), GFP_KERNEL);
981 if (!region)
982 return -ENOMEM;
983 region->type = WMFW_ADSP2_YM;
984 region->alg = be32_to_cpu(adsp2_id.fw.id);
985 region->base = be32_to_cpu(adsp2_id.ym);
986 list_add_tail(&region->list, &dsp->alg_regions);
987
988 region = kzalloc(sizeof(*region), GFP_KERNEL);
989 if (!region)
990 return -ENOMEM;
991 region->type = WMFW_ADSP2_ZM;
992 region->alg = be32_to_cpu(adsp2_id.fw.id);
993 region->base = be32_to_cpu(adsp2_id.zm);
994 list_add_tail(&region->list, &dsp->alg_regions);
995
996 pos = sizeof(adsp2_id) / 2;
997 term = pos + ((sizeof(*adsp2_alg) * algs) / 2);
998 break;
999
1000 default:
1001 WARN(1, "Unknown DSP type");
1002 return -EINVAL;
1003 }
1004
1005 if (algs == 0) {
1006 adsp_err(dsp, "No algorithms\n");
1007 return -EINVAL;
1008 }
1009
1010 if (algs > 1024) {
1011 adsp_err(dsp, "Algorithm count %zx excessive\n", algs);
1012 print_hex_dump_bytes(dev_name(dsp->dev), DUMP_PREFIX_OFFSET,
1013 buf, buf_size);
1014 return -EINVAL;
1015 }
1016
1017 /* Read the terminator first to validate the length */
1018 ret = regmap_raw_read(regmap, mem->base + term, &val, sizeof(val));
1019 if (ret != 0) { 1237 if (ret != 0) {
1020 adsp_err(dsp, "Failed to read algorithm list end: %d\n", 1238 adsp_err(dsp, "Failed to read algorithm info: %d\n",
1021 ret); 1239 ret);
1022 return ret; 1240 return ret;
1023 } 1241 }
1024 1242
1025 if (be32_to_cpu(val) != 0xbedead) 1243 n_algs = be32_to_cpu(adsp1_id.n_algs);
1026 adsp_warn(dsp, "Algorithm list end %x 0x%x != 0xbeadead\n", 1244 dsp->fw_id = be32_to_cpu(adsp1_id.fw.id);
1027 term, be32_to_cpu(val)); 1245 adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n",
1028 1246 dsp->fw_id,
1029 alg = kzalloc((term - pos) * 2, GFP_KERNEL | GFP_DMA); 1247 (be32_to_cpu(adsp1_id.fw.ver) & 0xff0000) >> 16,
1030 if (!alg) 1248 (be32_to_cpu(adsp1_id.fw.ver) & 0xff00) >> 8,
1031 return -ENOMEM; 1249 be32_to_cpu(adsp1_id.fw.ver) & 0xff,
1032 1250 n_algs);
1033 ret = regmap_raw_read(regmap, mem->base + pos, alg, (term - pos) * 2); 1251
1034 if (ret != 0) { 1252 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM,
1035 adsp_err(dsp, "Failed to read algorithm list: %d\n", 1253 adsp1_id.fw.id, adsp1_id.zm);
1036 ret); 1254 if (IS_ERR(alg_region))
1037 goto out; 1255 return PTR_ERR(alg_region);
1038 } 1256
1039 1257 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM,
1040 adsp1_alg = alg; 1258 adsp1_id.fw.id, adsp1_id.dm);
1041 adsp2_alg = alg; 1259 if (IS_ERR(alg_region))
1042 1260 return PTR_ERR(alg_region);
1043 for (i = 0; i < algs; i++) { 1261
1044 switch (dsp->type) { 1262 pos = sizeof(adsp1_id) / 2;
1045 case WMFW_ADSP1: 1263 len = (sizeof(*adsp1_alg) * n_algs) / 2;
1046 adsp_info(dsp, "%d: ID %x v%d.%d.%d DM@%x ZM@%x\n", 1264
1047 i, be32_to_cpu(adsp1_alg[i].alg.id), 1265 adsp1_alg = wm_adsp_read_algs(dsp, n_algs, mem->base + pos, len);
1048 (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff0000) >> 16, 1266 if (IS_ERR(adsp1_alg))
1049 (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff00) >> 8, 1267 return PTR_ERR(adsp1_alg);
1050 be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff, 1268
1051 be32_to_cpu(adsp1_alg[i].dm), 1269 for (i = 0; i < n_algs; i++) {
1052 be32_to_cpu(adsp1_alg[i].zm)); 1270 adsp_info(dsp, "%d: ID %x v%d.%d.%d DM@%x ZM@%x\n",
1053 1271 i, be32_to_cpu(adsp1_alg[i].alg.id),
1054 region = kzalloc(sizeof(*region), GFP_KERNEL); 1272 (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff0000) >> 16,
1055 if (!region) { 1273 (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff00) >> 8,
1056 ret = -ENOMEM; 1274 be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff,
1057 goto out; 1275 be32_to_cpu(adsp1_alg[i].dm),
1058 } 1276 be32_to_cpu(adsp1_alg[i].zm));
1059 region->type = WMFW_ADSP1_DM; 1277
1060 region->alg = be32_to_cpu(adsp1_alg[i].alg.id); 1278 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM,
1061 region->base = be32_to_cpu(adsp1_alg[i].dm); 1279 adsp1_alg[i].alg.id,
1062 region->len = 0; 1280 adsp1_alg[i].dm);
1063 list_add_tail(&region->list, &dsp->alg_regions); 1281 if (IS_ERR(alg_region)) {
1064 if (i + 1 < algs) { 1282 ret = PTR_ERR(alg_region);
1065 region->len = be32_to_cpu(adsp1_alg[i + 1].dm); 1283 goto out;
1066 region->len -= be32_to_cpu(adsp1_alg[i].dm); 1284 }
1067 region->len *= 4; 1285 if (dsp->fw_ver == 0) {
1068 wm_adsp_create_control(dsp, region); 1286 if (i + 1 < n_algs) {
1287 len = be32_to_cpu(adsp1_alg[i + 1].dm);
1288 len -= be32_to_cpu(adsp1_alg[i].dm);
1289 len *= 4;
1290 wm_adsp_create_control(dsp, alg_region, 0,
1291 len, NULL, 0, 0);
1069 } else { 1292 } else {
1070 adsp_warn(dsp, "Missing length info for region DM with ID %x\n", 1293 adsp_warn(dsp, "Missing length info for region DM with ID %x\n",
1071 be32_to_cpu(adsp1_alg[i].alg.id)); 1294 be32_to_cpu(adsp1_alg[i].alg.id));
1072 } 1295 }
1296 }
1073 1297
1074 region = kzalloc(sizeof(*region), GFP_KERNEL); 1298 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM,
1075 if (!region) { 1299 adsp1_alg[i].alg.id,
1076 ret = -ENOMEM; 1300 adsp1_alg[i].zm);
1077 goto out; 1301 if (IS_ERR(alg_region)) {
1078 } 1302 ret = PTR_ERR(alg_region);
1079 region->type = WMFW_ADSP1_ZM; 1303 goto out;
1080 region->alg = be32_to_cpu(adsp1_alg[i].alg.id); 1304 }
1081 region->base = be32_to_cpu(adsp1_alg[i].zm); 1305 if (dsp->fw_ver == 0) {
1082 region->len = 0; 1306 if (i + 1 < n_algs) {
1083 list_add_tail(&region->list, &dsp->alg_regions); 1307 len = be32_to_cpu(adsp1_alg[i + 1].zm);
1084 if (i + 1 < algs) { 1308 len -= be32_to_cpu(adsp1_alg[i].zm);
1085 region->len = be32_to_cpu(adsp1_alg[i + 1].zm); 1309 len *= 4;
1086 region->len -= be32_to_cpu(adsp1_alg[i].zm); 1310 wm_adsp_create_control(dsp, alg_region, 0,
1087 region->len *= 4; 1311 len, NULL, 0, 0);
1088 wm_adsp_create_control(dsp, region);
1089 } else { 1312 } else {
1090 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", 1313 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n",
1091 be32_to_cpu(adsp1_alg[i].alg.id)); 1314 be32_to_cpu(adsp1_alg[i].alg.id));
1092 } 1315 }
1093 break; 1316 }
1317 }
1094 1318
1095 case WMFW_ADSP2: 1319out:
1096 adsp_info(dsp, 1320 kfree(adsp1_alg);
1097 "%d: ID %x v%d.%d.%d XM@%x YM@%x ZM@%x\n", 1321 return ret;
1098 i, be32_to_cpu(adsp2_alg[i].alg.id), 1322}
1099 (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff0000) >> 16, 1323
1100 (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff00) >> 8, 1324static int wm_adsp2_setup_algs(struct wm_adsp *dsp)
1101 be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff, 1325{
1102 be32_to_cpu(adsp2_alg[i].xm), 1326 struct wmfw_adsp2_id_hdr adsp2_id;
1103 be32_to_cpu(adsp2_alg[i].ym), 1327 struct wmfw_adsp2_alg_hdr *adsp2_alg;
1104 be32_to_cpu(adsp2_alg[i].zm)); 1328 struct wm_adsp_alg_region *alg_region;
1105 1329 const struct wm_adsp_region *mem;
1106 region = kzalloc(sizeof(*region), GFP_KERNEL); 1330 unsigned int pos, len;
1107 if (!region) { 1331 size_t n_algs;
1108 ret = -ENOMEM; 1332 int i, ret;
1109 goto out; 1333
1110 } 1334 mem = wm_adsp_find_region(dsp, WMFW_ADSP2_XM);
1111 region->type = WMFW_ADSP2_XM; 1335 if (WARN_ON(!mem))
1112 region->alg = be32_to_cpu(adsp2_alg[i].alg.id); 1336 return -EINVAL;
1113 region->base = be32_to_cpu(adsp2_alg[i].xm); 1337
1114 region->len = 0; 1338 ret = regmap_raw_read(dsp->regmap, mem->base, &adsp2_id,
1115 list_add_tail(&region->list, &dsp->alg_regions); 1339 sizeof(adsp2_id));
1116 if (i + 1 < algs) { 1340 if (ret != 0) {
1117 region->len = be32_to_cpu(adsp2_alg[i + 1].xm); 1341 adsp_err(dsp, "Failed to read algorithm info: %d\n",
1118 region->len -= be32_to_cpu(adsp2_alg[i].xm); 1342 ret);
1119 region->len *= 4; 1343 return ret;
1120 wm_adsp_create_control(dsp, region); 1344 }
1345
1346 n_algs = be32_to_cpu(adsp2_id.n_algs);
1347 dsp->fw_id = be32_to_cpu(adsp2_id.fw.id);
1348 adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n",
1349 dsp->fw_id,
1350 (be32_to_cpu(adsp2_id.fw.ver) & 0xff0000) >> 16,
1351 (be32_to_cpu(adsp2_id.fw.ver) & 0xff00) >> 8,
1352 be32_to_cpu(adsp2_id.fw.ver) & 0xff,
1353 n_algs);
1354
1355 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM,
1356 adsp2_id.fw.id, adsp2_id.xm);
1357 if (IS_ERR(alg_region))
1358 return PTR_ERR(alg_region);
1359
1360 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM,
1361 adsp2_id.fw.id, adsp2_id.ym);
1362 if (IS_ERR(alg_region))
1363 return PTR_ERR(alg_region);
1364
1365 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM,
1366 adsp2_id.fw.id, adsp2_id.zm);
1367 if (IS_ERR(alg_region))
1368 return PTR_ERR(alg_region);
1369
1370 pos = sizeof(adsp2_id) / 2;
1371 len = (sizeof(*adsp2_alg) * n_algs) / 2;
1372
1373 adsp2_alg = wm_adsp_read_algs(dsp, n_algs, mem->base + pos, len);
1374 if (IS_ERR(adsp2_alg))
1375 return PTR_ERR(adsp2_alg);
1376
1377 for (i = 0; i < n_algs; i++) {
1378 adsp_info(dsp,
1379 "%d: ID %x v%d.%d.%d XM@%x YM@%x ZM@%x\n",
1380 i, be32_to_cpu(adsp2_alg[i].alg.id),
1381 (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff0000) >> 16,
1382 (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff00) >> 8,
1383 be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff,
1384 be32_to_cpu(adsp2_alg[i].xm),
1385 be32_to_cpu(adsp2_alg[i].ym),
1386 be32_to_cpu(adsp2_alg[i].zm));
1387
1388 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM,
1389 adsp2_alg[i].alg.id,
1390 adsp2_alg[i].xm);
1391 if (IS_ERR(alg_region)) {
1392 ret = PTR_ERR(alg_region);
1393 goto out;
1394 }
1395 if (dsp->fw_ver == 0) {
1396 if (i + 1 < n_algs) {
1397 len = be32_to_cpu(adsp2_alg[i + 1].xm);
1398 len -= be32_to_cpu(adsp2_alg[i].xm);
1399 len *= 4;
1400 wm_adsp_create_control(dsp, alg_region, 0,
1401 len, NULL, 0, 0);
1121 } else { 1402 } else {
1122 adsp_warn(dsp, "Missing length info for region XM with ID %x\n", 1403 adsp_warn(dsp, "Missing length info for region XM with ID %x\n",
1123 be32_to_cpu(adsp2_alg[i].alg.id)); 1404 be32_to_cpu(adsp2_alg[i].alg.id));
1124 } 1405 }
1406 }
1125 1407
1126 region = kzalloc(sizeof(*region), GFP_KERNEL); 1408 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM,
1127 if (!region) { 1409 adsp2_alg[i].alg.id,
1128 ret = -ENOMEM; 1410 adsp2_alg[i].ym);
1129 goto out; 1411 if (IS_ERR(alg_region)) {
1130 } 1412 ret = PTR_ERR(alg_region);
1131 region->type = WMFW_ADSP2_YM; 1413 goto out;
1132 region->alg = be32_to_cpu(adsp2_alg[i].alg.id); 1414 }
1133 region->base = be32_to_cpu(adsp2_alg[i].ym); 1415 if (dsp->fw_ver == 0) {
1134 region->len = 0; 1416 if (i + 1 < n_algs) {
1135 list_add_tail(&region->list, &dsp->alg_regions); 1417 len = be32_to_cpu(adsp2_alg[i + 1].ym);
1136 if (i + 1 < algs) { 1418 len -= be32_to_cpu(adsp2_alg[i].ym);
1137 region->len = be32_to_cpu(adsp2_alg[i + 1].ym); 1419 len *= 4;
1138 region->len -= be32_to_cpu(adsp2_alg[i].ym); 1420 wm_adsp_create_control(dsp, alg_region, 0,
1139 region->len *= 4; 1421 len, NULL, 0, 0);
1140 wm_adsp_create_control(dsp, region);
1141 } else { 1422 } else {
1142 adsp_warn(dsp, "Missing length info for region YM with ID %x\n", 1423 adsp_warn(dsp, "Missing length info for region YM with ID %x\n",
1143 be32_to_cpu(adsp2_alg[i].alg.id)); 1424 be32_to_cpu(adsp2_alg[i].alg.id));
1144 } 1425 }
1426 }
1145 1427
1146 region = kzalloc(sizeof(*region), GFP_KERNEL); 1428 alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM,
1147 if (!region) { 1429 adsp2_alg[i].alg.id,
1148 ret = -ENOMEM; 1430 adsp2_alg[i].zm);
1149 goto out; 1431 if (IS_ERR(alg_region)) {
1150 } 1432 ret = PTR_ERR(alg_region);
1151 region->type = WMFW_ADSP2_ZM; 1433 goto out;
1152 region->alg = be32_to_cpu(adsp2_alg[i].alg.id); 1434 }
1153 region->base = be32_to_cpu(adsp2_alg[i].zm); 1435 if (dsp->fw_ver == 0) {
1154 region->len = 0; 1436 if (i + 1 < n_algs) {
1155 list_add_tail(&region->list, &dsp->alg_regions); 1437 len = be32_to_cpu(adsp2_alg[i + 1].zm);
1156 if (i + 1 < algs) { 1438 len -= be32_to_cpu(adsp2_alg[i].zm);
1157 region->len = be32_to_cpu(adsp2_alg[i + 1].zm); 1439 len *= 4;
1158 region->len -= be32_to_cpu(adsp2_alg[i].zm); 1440 wm_adsp_create_control(dsp, alg_region, 0,
1159 region->len *= 4; 1441 len, NULL, 0, 0);
1160 wm_adsp_create_control(dsp, region);
1161 } else { 1442 } else {
1162 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", 1443 adsp_warn(dsp, "Missing length info for region ZM with ID %x\n",
1163 be32_to_cpu(adsp2_alg[i].alg.id)); 1444 be32_to_cpu(adsp2_alg[i].alg.id));
1164 } 1445 }
1165 break;
1166 } 1446 }
1167 } 1447 }
1168 1448
1169out: 1449out:
1170 kfree(alg); 1450 kfree(adsp2_alg);
1171 return ret; 1451 return ret;
1172} 1452}
1173 1453
@@ -1354,9 +1634,9 @@ out:
1354 return ret; 1634 return ret;
1355} 1635}
1356 1636
1357int wm_adsp1_init(struct wm_adsp *adsp) 1637int wm_adsp1_init(struct wm_adsp *dsp)
1358{ 1638{
1359 INIT_LIST_HEAD(&adsp->alg_regions); 1639 INIT_LIST_HEAD(&dsp->alg_regions);
1360 1640
1361 return 0; 1641 return 0;
1362} 1642}
@@ -1410,7 +1690,7 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
1410 if (ret != 0) 1690 if (ret != 0)
1411 goto err; 1691 goto err;
1412 1692
1413 ret = wm_adsp_setup_algs(dsp); 1693 ret = wm_adsp1_setup_algs(dsp);
1414 if (ret != 0) 1694 if (ret != 0)
1415 goto err; 1695 goto err;
1416 1696
@@ -1531,35 +1811,6 @@ static void wm_adsp2_boot_work(struct work_struct *work)
1531 return; 1811 return;
1532 } 1812 }
1533 1813
1534 if (dsp->dvfs) {
1535 ret = regmap_read(dsp->regmap,
1536 dsp->base + ADSP2_CLOCKING, &val);
1537 if (ret != 0) {
1538 adsp_err(dsp, "Failed to read clocking: %d\n", ret);
1539 return;
1540 }
1541
1542 if ((val & ADSP2_CLK_SEL_MASK) >= 3) {
1543 ret = regulator_enable(dsp->dvfs);
1544 if (ret != 0) {
1545 adsp_err(dsp,
1546 "Failed to enable supply: %d\n",
1547 ret);
1548 return;
1549 }
1550
1551 ret = regulator_set_voltage(dsp->dvfs,
1552 1800000,
1553 1800000);
1554 if (ret != 0) {
1555 adsp_err(dsp,
1556 "Failed to raise supply: %d\n",
1557 ret);
1558 return;
1559 }
1560 }
1561 }
1562
1563 ret = wm_adsp2_ena(dsp); 1814 ret = wm_adsp2_ena(dsp);
1564 if (ret != 0) 1815 if (ret != 0)
1565 return; 1816 return;
@@ -1568,7 +1819,7 @@ static void wm_adsp2_boot_work(struct work_struct *work)
1568 if (ret != 0) 1819 if (ret != 0)
1569 goto err; 1820 goto err;
1570 1821
1571 ret = wm_adsp_setup_algs(dsp); 1822 ret = wm_adsp2_setup_algs(dsp);
1572 if (ret != 0) 1823 if (ret != 0)
1573 goto err; 1824 goto err;
1574 1825
@@ -1642,6 +1893,9 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
1642 break; 1893 break;
1643 1894
1644 case SND_SOC_DAPM_PRE_PMD: 1895 case SND_SOC_DAPM_PRE_PMD:
1896 /* Log firmware state, it can be useful for analysis */
1897 wm_adsp2_show_fw_status(dsp);
1898
1645 dsp->running = false; 1899 dsp->running = false;
1646 1900
1647 regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, 1901 regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL,
@@ -1653,21 +1907,6 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
1653 regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_2, 0); 1907 regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_2, 0);
1654 regmap_write(dsp->regmap, dsp->base + ADSP2_RDMA_CONFIG_1, 0); 1908 regmap_write(dsp->regmap, dsp->base + ADSP2_RDMA_CONFIG_1, 0);
1655 1909
1656 if (dsp->dvfs) {
1657 ret = regulator_set_voltage(dsp->dvfs, 1200000,
1658 1800000);
1659 if (ret != 0)
1660 adsp_warn(dsp,
1661 "Failed to lower supply: %d\n",
1662 ret);
1663
1664 ret = regulator_disable(dsp->dvfs);
1665 if (ret != 0)
1666 adsp_err(dsp,
1667 "Failed to enable supply: %d\n",
1668 ret);
1669 }
1670
1671 list_for_each_entry(ctl, &dsp->ctl_list, list) 1910 list_for_each_entry(ctl, &dsp->ctl_list, list)
1672 ctl->enabled = 0; 1911 ctl->enabled = 0;
1673 1912
@@ -1694,7 +1933,7 @@ err:
1694} 1933}
1695EXPORT_SYMBOL_GPL(wm_adsp2_event); 1934EXPORT_SYMBOL_GPL(wm_adsp2_event);
1696 1935
1697int wm_adsp2_init(struct wm_adsp *adsp, bool dvfs) 1936int wm_adsp2_init(struct wm_adsp *dsp)
1698{ 1937{
1699 int ret; 1938 int ret;
1700 1939
@@ -1702,43 +1941,16 @@ int wm_adsp2_init(struct wm_adsp *adsp, bool dvfs)
1702 * Disable the DSP memory by default when in reset for a small 1941 * Disable the DSP memory by default when in reset for a small
1703 * power saving. 1942 * power saving.
1704 */ 1943 */
1705 ret = regmap_update_bits(adsp->regmap, adsp->base + ADSP2_CONTROL, 1944 ret = regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL,
1706 ADSP2_MEM_ENA, 0); 1945 ADSP2_MEM_ENA, 0);
1707 if (ret != 0) { 1946 if (ret != 0) {
1708 adsp_err(adsp, "Failed to clear memory retention: %d\n", ret); 1947 adsp_err(dsp, "Failed to clear memory retention: %d\n", ret);
1709 return ret; 1948 return ret;
1710 } 1949 }
1711 1950
1712 INIT_LIST_HEAD(&adsp->alg_regions); 1951 INIT_LIST_HEAD(&dsp->alg_regions);
1713 INIT_LIST_HEAD(&adsp->ctl_list); 1952 INIT_LIST_HEAD(&dsp->ctl_list);
1714 INIT_WORK(&adsp->boot_work, wm_adsp2_boot_work); 1953 INIT_WORK(&dsp->boot_work, wm_adsp2_boot_work);
1715
1716 if (dvfs) {
1717 adsp->dvfs = devm_regulator_get(adsp->dev, "DCVDD");
1718 if (IS_ERR(adsp->dvfs)) {
1719 ret = PTR_ERR(adsp->dvfs);
1720 adsp_err(adsp, "Failed to get DCVDD: %d\n", ret);
1721 return ret;
1722 }
1723
1724 ret = regulator_enable(adsp->dvfs);
1725 if (ret != 0) {
1726 adsp_err(adsp, "Failed to enable DCVDD: %d\n", ret);
1727 return ret;
1728 }
1729
1730 ret = regulator_set_voltage(adsp->dvfs, 1200000, 1800000);
1731 if (ret != 0) {
1732 adsp_err(adsp, "Failed to initialise DVFS: %d\n", ret);
1733 return ret;
1734 }
1735
1736 ret = regulator_disable(adsp->dvfs);
1737 if (ret != 0) {
1738 adsp_err(adsp, "Failed to disable DCVDD: %d\n", ret);
1739 return ret;
1740 }
1741 }
1742 1954
1743 return 0; 1955 return 0;
1744} 1956}
diff --git a/sound/soc/codecs/wm_adsp.h b/sound/soc/codecs/wm_adsp.h
index a4f6b64deb61..0e5f07c35d50 100644
--- a/sound/soc/codecs/wm_adsp.h
+++ b/sound/soc/codecs/wm_adsp.h
@@ -18,8 +18,6 @@
18 18
19#include "wmfw.h" 19#include "wmfw.h"
20 20
21struct regulator;
22
23struct wm_adsp_region { 21struct wm_adsp_region {
24 int type; 22 int type;
25 unsigned int base; 23 unsigned int base;
@@ -30,7 +28,6 @@ struct wm_adsp_alg_region {
30 unsigned int alg; 28 unsigned int alg;
31 int type; 29 int type;
32 unsigned int base; 30 unsigned int base;
33 size_t len;
34}; 31};
35 32
36struct wm_adsp { 33struct wm_adsp {
@@ -54,10 +51,9 @@ struct wm_adsp {
54 int num_mems; 51 int num_mems;
55 52
56 int fw; 53 int fw;
54 int fw_ver;
57 bool running; 55 bool running;
58 56
59 struct regulator *dvfs;
60
61 struct list_head ctl_list; 57 struct list_head ctl_list;
62 58
63 struct work_struct boot_work; 59 struct work_struct boot_work;
@@ -67,19 +63,22 @@ struct wm_adsp {
67 SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \ 63 SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \
68 wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD) 64 wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
69 65
70#define WM_ADSP2(wname, num) \ 66#define WM_ADSP2_E(wname, num, event_fn) \
71{ .id = snd_soc_dapm_dai_link, .name = wname " Preloader", \ 67{ .id = snd_soc_dapm_dai_link, .name = wname " Preloader", \
72 .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp2_early_event, \ 68 .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \
73 .event_flags = SND_SOC_DAPM_PRE_PMU }, \ 69 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD }, \
74{ .id = snd_soc_dapm_out_drv, .name = wname, \ 70{ .id = snd_soc_dapm_out_drv, .name = wname, \
75 .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp2_event, \ 71 .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp2_event, \
76 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD } 72 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD }
77 73
74#define WM_ADSP2(wname, num) \
75 WM_ADSP2_E(wname, num, wm_adsp2_early_event)
76
78extern const struct snd_kcontrol_new wm_adsp1_fw_controls[]; 77extern const struct snd_kcontrol_new wm_adsp1_fw_controls[];
79extern const struct snd_kcontrol_new wm_adsp2_fw_controls[]; 78extern const struct snd_kcontrol_new wm_adsp2_fw_controls[];
80 79
81int wm_adsp1_init(struct wm_adsp *adsp); 80int wm_adsp1_init(struct wm_adsp *dsp);
82int wm_adsp2_init(struct wm_adsp *adsp, bool dvfs); 81int wm_adsp2_init(struct wm_adsp *dsp);
83int wm_adsp1_event(struct snd_soc_dapm_widget *w, 82int wm_adsp1_event(struct snd_soc_dapm_widget *w,
84 struct snd_kcontrol *kcontrol, int event); 83 struct snd_kcontrol *kcontrol, int event);
85int wm_adsp2_early_event(struct snd_soc_dapm_widget *w, 84int wm_adsp2_early_event(struct snd_soc_dapm_widget *w,
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 8366e19657a7..fd86bd105460 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -1116,7 +1116,7 @@ static const struct snd_soc_dapm_route lineout2_se_routes[] = {
1116 1116
1117int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec) 1117int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec)
1118{ 1118{
1119 struct snd_soc_dapm_context *dapm = &codec->dapm; 1119 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1120 1120
1121 /* Latch volume update bits & default ZC on */ 1121 /* Latch volume update bits & default ZC on */
1122 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 1122 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME,
@@ -1160,7 +1160,7 @@ int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec,
1160 int lineout1_diff, int lineout2_diff) 1160 int lineout1_diff, int lineout2_diff)
1161{ 1161{
1162 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 1162 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
1163 struct snd_soc_dapm_context *dapm = &codec->dapm; 1163 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1164 1164
1165 hubs->codec = codec; 1165 hubs->codec = codec;
1166 1166
diff --git a/sound/soc/codecs/wmfw.h b/sound/soc/codecs/wmfw.h
index ef163360a745..7613d60d62ea 100644
--- a/sound/soc/codecs/wmfw.h
+++ b/sound/soc/codecs/wmfw.h
@@ -15,6 +15,17 @@
15 15
16#include <linux/types.h> 16#include <linux/types.h>
17 17
18#define WMFW_MAX_ALG_NAME 256
19#define WMFW_MAX_ALG_DESCR_NAME 256
20
21#define WMFW_MAX_COEFF_NAME 256
22#define WMFW_MAX_COEFF_DESCR_NAME 256
23
24#define WMFW_CTL_FLAG_SYS 0x8000
25#define WMFW_CTL_FLAG_VOLATILE 0x0004
26#define WMFW_CTL_FLAG_WRITEABLE 0x0002
27#define WMFW_CTL_FLAG_READABLE 0x0001
28
18struct wmfw_header { 29struct wmfw_header {
19 char magic[4]; 30 char magic[4];
20 __le32 len; 31 __le32 len;
@@ -61,7 +72,7 @@ struct wmfw_adsp1_id_hdr {
61 struct wmfw_id_hdr fw; 72 struct wmfw_id_hdr fw;
62 __be32 zm; 73 __be32 zm;
63 __be32 dm; 74 __be32 dm;
64 __be32 algs; 75 __be32 n_algs;
65} __packed; 76} __packed;
66 77
67struct wmfw_adsp2_id_hdr { 78struct wmfw_adsp2_id_hdr {
@@ -69,7 +80,7 @@ struct wmfw_adsp2_id_hdr {
69 __be32 zm; 80 __be32 zm;
70 __be32 xm; 81 __be32 xm;
71 __be32 ym; 82 __be32 ym;
72 __be32 algs; 83 __be32 n_algs;
73} __packed; 84} __packed;
74 85
75struct wmfw_alg_hdr { 86struct wmfw_alg_hdr {
@@ -90,6 +101,28 @@ struct wmfw_adsp2_alg_hdr {
90 __be32 ym; 101 __be32 ym;
91} __packed; 102} __packed;
92 103
104struct wmfw_adsp_alg_data {
105 __le32 id;
106 u8 name[WMFW_MAX_ALG_NAME];
107 u8 descr[WMFW_MAX_ALG_DESCR_NAME];
108 __le32 ncoeff;
109 u8 data[];
110} __packed;
111
112struct wmfw_adsp_coeff_data {
113 struct {
114 __le16 offset;
115 __le16 type;
116 __le32 size;
117 } hdr;
118 u8 name[WMFW_MAX_COEFF_NAME];
119 u8 descr[WMFW_MAX_COEFF_DESCR_NAME];
120 __le16 ctl_type;
121 __le16 flags;
122 __le32 len;
123 u8 data[];
124} __packed;
125
93struct wmfw_coeff_hdr { 126struct wmfw_coeff_hdr {
94 u8 magic[4]; 127 u8 magic[4];
95 __le32 len; 128 __le32 len;
@@ -117,9 +150,10 @@ struct wmfw_coeff_item {
117#define WMFW_ADSP1 1 150#define WMFW_ADSP1 1
118#define WMFW_ADSP2 2 151#define WMFW_ADSP2 2
119 152
120#define WMFW_ABSOLUTE 0xf0 153#define WMFW_ABSOLUTE 0xf0
121#define WMFW_NAME_TEXT 0xfe 154#define WMFW_ALGORITHM_DATA 0xf2
122#define WMFW_INFO_TEXT 0xff 155#define WMFW_NAME_TEXT 0xfe
156#define WMFW_INFO_TEXT 0xff
123 157
124#define WMFW_ADSP1_PM 2 158#define WMFW_ADSP1_PM 2
125#define WMFW_ADSP1_DM 3 159#define WMFW_ADSP1_DM 3
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index bb4b78eada58..d79349434a9a 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -107,6 +107,7 @@ struct davinci_mcasp {
107#endif 107#endif
108 108
109 struct davinci_mcasp_ruledata ruledata[2]; 109 struct davinci_mcasp_ruledata ruledata[2];
110 struct snd_pcm_hw_constraint_list chconstr[2];
110}; 111};
111 112
112static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset, 113static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset,
@@ -915,15 +916,12 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
915 * the machine driver, we need to calculate the ratio. 916 * the machine driver, we need to calculate the ratio.
916 */ 917 */
917 if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { 918 if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) {
918 int channels = params_channels(params); 919 int slots = mcasp->tdm_slots;
919 int rate = params_rate(params); 920 int rate = params_rate(params);
920 int sbits = params_width(params); 921 int sbits = params_width(params);
921 int ppm, div; 922 int ppm, div;
922 923
923 if (channels > mcasp->tdm_slots) 924 div = davinci_mcasp_calc_clk_div(mcasp, rate*sbits*slots,
924 channels = mcasp->tdm_slots;
925
926 div = davinci_mcasp_calc_clk_div(mcasp, rate*sbits*channels,
927 &ppm); 925 &ppm);
928 if (ppm) 926 if (ppm)
929 dev_info(mcasp->dev, "Sample-rate is off by %d PPM\n", 927 dev_info(mcasp->dev, "Sample-rate is off by %d PPM\n",
@@ -1024,31 +1022,36 @@ static int davinci_mcasp_hw_rule_rate(struct snd_pcm_hw_params *params,
1024 struct snd_interval *ri = 1022 struct snd_interval *ri =
1025 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 1023 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1026 int sbits = params_width(params); 1024 int sbits = params_width(params);
1027 int channels = params_channels(params); 1025 int slots = rd->mcasp->tdm_slots;
1028 unsigned int list[ARRAY_SIZE(davinci_mcasp_dai_rates)]; 1026 struct snd_interval range;
1029 int i, count = 0; 1027 int i;
1030 1028
1031 if (channels > rd->mcasp->tdm_slots) 1029 snd_interval_any(&range);
1032 channels = rd->mcasp->tdm_slots; 1030 range.empty = 1;
1033 1031
1034 for (i = 0; i < ARRAY_SIZE(davinci_mcasp_dai_rates); i++) { 1032 for (i = 0; i < ARRAY_SIZE(davinci_mcasp_dai_rates); i++) {
1035 if (ri->min <= davinci_mcasp_dai_rates[i] && 1033 if (snd_interval_test(ri, davinci_mcasp_dai_rates[i])) {
1036 ri->max >= davinci_mcasp_dai_rates[i]) { 1034 uint bclk_freq = sbits*slots*
1037 uint bclk_freq = sbits*channels*
1038 davinci_mcasp_dai_rates[i]; 1035 davinci_mcasp_dai_rates[i];
1039 int ppm; 1036 int ppm;
1040 1037
1041 davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm); 1038 davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm);
1042 if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) 1039 if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) {
1043 list[count++] = davinci_mcasp_dai_rates[i]; 1040 if (range.empty) {
1041 range.min = davinci_mcasp_dai_rates[i];
1042 range.empty = 0;
1043 }
1044 range.max = davinci_mcasp_dai_rates[i];
1045 }
1044 } 1046 }
1045 } 1047 }
1048
1046 dev_dbg(rd->mcasp->dev, 1049 dev_dbg(rd->mcasp->dev,
1047 "%d frequencies (%d-%d) for %d sbits and %d channels\n", 1050 "Frequencies %d-%d -> %d-%d for %d sbits and %d tdm slots\n",
1048 count, ri->min, ri->max, sbits, channels); 1051 ri->min, ri->max, range.min, range.max, sbits, slots);
1049 1052
1050 return snd_interval_list(hw_param_interval(params, rule->var), 1053 return snd_interval_refine(hw_param_interval(params, rule->var),
1051 count, list, 0); 1054 &range);
1052} 1055}
1053 1056
1054static int davinci_mcasp_hw_rule_format(struct snd_pcm_hw_params *params, 1057static int davinci_mcasp_hw_rule_format(struct snd_pcm_hw_params *params,
@@ -1058,17 +1061,14 @@ static int davinci_mcasp_hw_rule_format(struct snd_pcm_hw_params *params,
1058 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 1061 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1059 struct snd_mask nfmt; 1062 struct snd_mask nfmt;
1060 int rate = params_rate(params); 1063 int rate = params_rate(params);
1061 int channels = params_channels(params); 1064 int slots = rd->mcasp->tdm_slots;
1062 int i, count = 0; 1065 int i, count = 0;
1063 1066
1064 snd_mask_none(&nfmt); 1067 snd_mask_none(&nfmt);
1065 1068
1066 if (channels > rd->mcasp->tdm_slots)
1067 channels = rd->mcasp->tdm_slots;
1068
1069 for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) { 1069 for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) {
1070 if (snd_mask_test(fmt, i)) { 1070 if (snd_mask_test(fmt, i)) {
1071 uint bclk_freq = snd_pcm_format_width(i)*channels*rate; 1071 uint bclk_freq = snd_pcm_format_width(i)*slots*rate;
1072 int ppm; 1072 int ppm;
1073 1073
1074 davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm); 1074 davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm);
@@ -1079,51 +1079,12 @@ static int davinci_mcasp_hw_rule_format(struct snd_pcm_hw_params *params,
1079 } 1079 }
1080 } 1080 }
1081 dev_dbg(rd->mcasp->dev, 1081 dev_dbg(rd->mcasp->dev,
1082 "%d possible sample format for %d Hz and %d channels\n", 1082 "%d possible sample format for %d Hz and %d tdm slots\n",
1083 count, rate, channels); 1083 count, rate, slots);
1084 1084
1085 return snd_mask_refine(fmt, &nfmt); 1085 return snd_mask_refine(fmt, &nfmt);
1086} 1086}
1087 1087
1088static int davinci_mcasp_hw_rule_channels(struct snd_pcm_hw_params *params,
1089 struct snd_pcm_hw_rule *rule)
1090{
1091 struct davinci_mcasp_ruledata *rd = rule->private;
1092 struct snd_interval *ci =
1093 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
1094 int sbits = params_width(params);
1095 int rate = params_rate(params);
1096 int max_chan_per_wire = rd->mcasp->tdm_slots < ci->max ?
1097 rd->mcasp->tdm_slots : ci->max;
1098 unsigned int list[ci->max - ci->min + 1];
1099 int c1, c, count = 0;
1100
1101 for (c1 = ci->min; c1 <= max_chan_per_wire; c1++) {
1102 uint bclk_freq = c1*sbits*rate;
1103 int ppm;
1104
1105 davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm);
1106 if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) {
1107 /* If we can use all tdm_slots, we can put any
1108 amount of channels to remaining wires as
1109 long as they fit in. */
1110 if (c1 == rd->mcasp->tdm_slots) {
1111 for (c = c1; c <= rd->serializers*c1 &&
1112 c <= ci->max; c++)
1113 list[count++] = c;
1114 } else {
1115 list[count++] = c1;
1116 }
1117 }
1118 }
1119 dev_dbg(rd->mcasp->dev,
1120 "%d possible channel counts (%d-%d) for %d Hz and %d sbits\n",
1121 count, ci->min, ci->max, rate, sbits);
1122
1123 return snd_interval_list(hw_param_interval(params, rule->var),
1124 count, list, 0);
1125}
1126
1127static int davinci_mcasp_startup(struct snd_pcm_substream *substream, 1088static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
1128 struct snd_soc_dai *cpu_dai) 1089 struct snd_soc_dai *cpu_dai)
1129{ 1090{
@@ -1167,6 +1128,11 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
1167 SNDRV_PCM_HW_PARAM_CHANNELS, 1128 SNDRV_PCM_HW_PARAM_CHANNELS,
1168 2, max_channels); 1129 2, max_channels);
1169 1130
1131 if (mcasp->chconstr[substream->stream].count)
1132 snd_pcm_hw_constraint_list(substream->runtime,
1133 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1134 &mcasp->chconstr[substream->stream]);
1135
1170 /* 1136 /*
1171 * If we rely on implicit BCLK divider setting we should 1137 * If we rely on implicit BCLK divider setting we should
1172 * set constraints based on what we can provide. 1138 * set constraints based on what we can provide.
@@ -1180,24 +1146,14 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
1180 SNDRV_PCM_HW_PARAM_RATE, 1146 SNDRV_PCM_HW_PARAM_RATE,
1181 davinci_mcasp_hw_rule_rate, 1147 davinci_mcasp_hw_rule_rate,
1182 ruledata, 1148 ruledata,
1183 SNDRV_PCM_HW_PARAM_FORMAT, 1149 SNDRV_PCM_HW_PARAM_FORMAT, -1);
1184 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
1185 if (ret) 1150 if (ret)
1186 return ret; 1151 return ret;
1187 ret = snd_pcm_hw_rule_add(substream->runtime, 0, 1152 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
1188 SNDRV_PCM_HW_PARAM_FORMAT, 1153 SNDRV_PCM_HW_PARAM_FORMAT,
1189 davinci_mcasp_hw_rule_format, 1154 davinci_mcasp_hw_rule_format,
1190 ruledata, 1155 ruledata,
1191 SNDRV_PCM_HW_PARAM_RATE, 1156 SNDRV_PCM_HW_PARAM_RATE, -1);
1192 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
1193 if (ret)
1194 return ret;
1195 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
1196 SNDRV_PCM_HW_PARAM_CHANNELS,
1197 davinci_mcasp_hw_rule_channels,
1198 ruledata,
1199 SNDRV_PCM_HW_PARAM_RATE,
1200 SNDRV_PCM_HW_PARAM_FORMAT, -1);
1201 if (ret) 1157 if (ret)
1202 return ret; 1158 return ret;
1203 } 1159 }
@@ -1247,7 +1203,7 @@ static int davinci_mcasp_suspend(struct snd_soc_dai *dai)
1247 u32 reg; 1203 u32 reg;
1248 int i; 1204 int i;
1249 1205
1250 context->pm_state = pm_runtime_enabled(mcasp->dev); 1206 context->pm_state = pm_runtime_active(mcasp->dev);
1251 if (!context->pm_state) 1207 if (!context->pm_state)
1252 pm_runtime_get_sync(mcasp->dev); 1208 pm_runtime_get_sync(mcasp->dev);
1253 1209
@@ -1556,6 +1512,59 @@ nodata:
1556 return pdata; 1512 return pdata;
1557} 1513}
1558 1514
1515/* All serializers must have equal number of channels */
1516static int davinci_mcasp_ch_constraint(struct davinci_mcasp *mcasp,
1517 struct snd_pcm_hw_constraint_list *cl,
1518 int serializers)
1519{
1520 unsigned int *list;
1521 int i, count = 0;
1522
1523 if (serializers <= 1)
1524 return 0;
1525
1526 list = devm_kzalloc(mcasp->dev, sizeof(unsigned int) *
1527 (mcasp->tdm_slots + serializers - 2),
1528 GFP_KERNEL);
1529 if (!list)
1530 return -ENOMEM;
1531
1532 for (i = 2; i <= mcasp->tdm_slots; i++)
1533 list[count++] = i;
1534
1535 for (i = 2; i <= serializers; i++)
1536 list[count++] = i*mcasp->tdm_slots;
1537
1538 cl->count = count;
1539 cl->list = list;
1540
1541 return 0;
1542}
1543
1544
1545static int davinci_mcasp_init_ch_constraints(struct davinci_mcasp *mcasp)
1546{
1547 int rx_serializers = 0, tx_serializers = 0, ret, i;
1548
1549 for (i = 0; i < mcasp->num_serializer; i++)
1550 if (mcasp->serial_dir[i] == TX_MODE)
1551 tx_serializers++;
1552 else if (mcasp->serial_dir[i] == RX_MODE)
1553 rx_serializers++;
1554
1555 ret = davinci_mcasp_ch_constraint(mcasp, &mcasp->chconstr[
1556 SNDRV_PCM_STREAM_PLAYBACK],
1557 tx_serializers);
1558 if (ret)
1559 return ret;
1560
1561 ret = davinci_mcasp_ch_constraint(mcasp, &mcasp->chconstr[
1562 SNDRV_PCM_STREAM_CAPTURE],
1563 rx_serializers);
1564
1565 return ret;
1566}
1567
1559static int davinci_mcasp_probe(struct platform_device *pdev) 1568static int davinci_mcasp_probe(struct platform_device *pdev)
1560{ 1569{
1561 struct snd_dmaengine_dai_dma_data *dma_data; 1570 struct snd_dmaengine_dai_dma_data *dma_data;
@@ -1739,6 +1748,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1739 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE; 1748 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
1740 } 1749 }
1741 1750
1751 ret = davinci_mcasp_init_ch_constraints(mcasp);
1752 if (ret)
1753 goto err;
1754
1742 dev_set_drvdata(&pdev->dev, mcasp); 1755 dev_set_drvdata(&pdev->dev, mcasp);
1743 1756
1744 mcasp_reparent_fck(pdev); 1757 mcasp_reparent_fck(pdev);
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 93d7e56c6066..ccadefceeff2 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -445,7 +445,7 @@ static int fsl_dma_open(struct snd_pcm_substream *substream)
445 return ret; 445 return ret;
446 } 446 }
447 447
448 dma->assigned = 1; 448 dma->assigned = true;
449 449
450 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); 450 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
451 snd_soc_set_runtime_hwparams(substream, &fsl_dma_hardware); 451 snd_soc_set_runtime_hwparams(substream, &fsl_dma_hardware);
@@ -814,7 +814,7 @@ static int fsl_dma_close(struct snd_pcm_substream *substream)
814 substream->runtime->private_data = NULL; 814 substream->runtime->private_data = NULL;
815 } 815 }
816 816
817 dma->assigned = 0; 817 dma->assigned = false;
818 818
819 return 0; 819 return 0;
820} 820}
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index ec79c3d5e65e..5c73bea7b11e 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Freescale ALSA SoC Digital Audio Interface (SAI) driver. 2 * Freescale ALSA SoC Digital Audio Interface (SAI) driver.
3 * 3 *
4 * Copyright 2012-2013 Freescale Semiconductor, Inc. 4 * Copyright 2012-2015 Freescale Semiconductor, Inc.
5 * 5 *
6 * This program is free software, you can redistribute it and/or modify it 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 7 * under the terms of the GNU General Public License as published by the
@@ -27,6 +27,17 @@
27#define FSL_SAI_FLAGS (FSL_SAI_CSR_SEIE |\ 27#define FSL_SAI_FLAGS (FSL_SAI_CSR_SEIE |\
28 FSL_SAI_CSR_FEIE) 28 FSL_SAI_CSR_FEIE)
29 29
30static u32 fsl_sai_rates[] = {
31 8000, 11025, 12000, 16000, 22050,
32 24000, 32000, 44100, 48000, 64000,
33 88200, 96000, 176400, 192000
34};
35
36static struct snd_pcm_hw_constraint_list fsl_sai_rate_constraints = {
37 .count = ARRAY_SIZE(fsl_sai_rates),
38 .list = fsl_sai_rates,
39};
40
30static irqreturn_t fsl_sai_isr(int irq, void *devid) 41static irqreturn_t fsl_sai_isr(int irq, void *devid)
31{ 42{
32 struct fsl_sai *sai = (struct fsl_sai *)devid; 43 struct fsl_sai *sai = (struct fsl_sai *)devid;
@@ -251,12 +262,14 @@ static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai,
251 val_cr4 |= FSL_SAI_CR4_FSD_MSTR; 262 val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
252 break; 263 break;
253 case SND_SOC_DAIFMT_CBM_CFM: 264 case SND_SOC_DAIFMT_CBM_CFM:
265 sai->is_slave_mode = true;
254 break; 266 break;
255 case SND_SOC_DAIFMT_CBS_CFM: 267 case SND_SOC_DAIFMT_CBS_CFM:
256 val_cr2 |= FSL_SAI_CR2_BCD_MSTR; 268 val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
257 break; 269 break;
258 case SND_SOC_DAIFMT_CBM_CFS: 270 case SND_SOC_DAIFMT_CBM_CFS:
259 val_cr4 |= FSL_SAI_CR4_FSD_MSTR; 271 val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
272 sai->is_slave_mode = true;
260 break; 273 break;
261 default: 274 default:
262 return -EINVAL; 275 return -EINVAL;
@@ -288,6 +301,79 @@ static int fsl_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
288 return ret; 301 return ret;
289} 302}
290 303
304static int fsl_sai_set_bclk(struct snd_soc_dai *dai, bool tx, u32 freq)
305{
306 struct fsl_sai *sai = snd_soc_dai_get_drvdata(dai);
307 unsigned long clk_rate;
308 u32 savediv = 0, ratio, savesub = freq;
309 u32 id;
310 int ret = 0;
311
312 /* Don't apply to slave mode */
313 if (sai->is_slave_mode)
314 return 0;
315
316 for (id = 0; id < FSL_SAI_MCLK_MAX; id++) {
317 clk_rate = clk_get_rate(sai->mclk_clk[id]);
318 if (!clk_rate)
319 continue;
320
321 ratio = clk_rate / freq;
322
323 ret = clk_rate - ratio * freq;
324
325 /*
326 * Drop the source that can not be
327 * divided into the required rate.
328 */
329 if (ret != 0 && clk_rate / ret < 1000)
330 continue;
331
332 dev_dbg(dai->dev,
333 "ratio %d for freq %dHz based on clock %ldHz\n",
334 ratio, freq, clk_rate);
335
336 if (ratio % 2 == 0 && ratio >= 2 && ratio <= 512)
337 ratio /= 2;
338 else
339 continue;
340
341 if (ret < savesub) {
342 savediv = ratio;
343 sai->mclk_id[tx] = id;
344 savesub = ret;
345 }
346
347 if (ret == 0)
348 break;
349 }
350
351 if (savediv == 0) {
352 dev_err(dai->dev, "failed to derive required %cx rate: %d\n",
353 tx ? 'T' : 'R', freq);
354 return -EINVAL;
355 }
356
357 if ((tx && sai->synchronous[TX]) || (!tx && !sai->synchronous[RX])) {
358 regmap_update_bits(sai->regmap, FSL_SAI_RCR2,
359 FSL_SAI_CR2_MSEL_MASK,
360 FSL_SAI_CR2_MSEL(sai->mclk_id[tx]));
361 regmap_update_bits(sai->regmap, FSL_SAI_RCR2,
362 FSL_SAI_CR2_DIV_MASK, savediv - 1);
363 } else {
364 regmap_update_bits(sai->regmap, FSL_SAI_TCR2,
365 FSL_SAI_CR2_MSEL_MASK,
366 FSL_SAI_CR2_MSEL(sai->mclk_id[tx]));
367 regmap_update_bits(sai->regmap, FSL_SAI_TCR2,
368 FSL_SAI_CR2_DIV_MASK, savediv - 1);
369 }
370
371 dev_dbg(dai->dev, "best fit: clock id=%d, div=%d, deviation =%d\n",
372 sai->mclk_id[tx], savediv, savesub);
373
374 return 0;
375}
376
291static int fsl_sai_hw_params(struct snd_pcm_substream *substream, 377static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
292 struct snd_pcm_hw_params *params, 378 struct snd_pcm_hw_params *params,
293 struct snd_soc_dai *cpu_dai) 379 struct snd_soc_dai *cpu_dai)
@@ -297,6 +383,24 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
297 unsigned int channels = params_channels(params); 383 unsigned int channels = params_channels(params);
298 u32 word_width = snd_pcm_format_width(params_format(params)); 384 u32 word_width = snd_pcm_format_width(params_format(params));
299 u32 val_cr4 = 0, val_cr5 = 0; 385 u32 val_cr4 = 0, val_cr5 = 0;
386 int ret;
387
388 if (!sai->is_slave_mode) {
389 ret = fsl_sai_set_bclk(cpu_dai, tx,
390 2 * word_width * params_rate(params));
391 if (ret)
392 return ret;
393
394 /* Do not enable the clock if it is already enabled */
395 if (!(sai->mclk_streams & BIT(substream->stream))) {
396 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[tx]]);
397 if (ret)
398 return ret;
399
400 sai->mclk_streams |= BIT(substream->stream);
401 }
402
403 }
300 404
301 if (!sai->is_dsp_mode) 405 if (!sai->is_dsp_mode)
302 val_cr4 |= FSL_SAI_CR4_SYWD(word_width); 406 val_cr4 |= FSL_SAI_CR4_SYWD(word_width);
@@ -322,6 +426,22 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
322 return 0; 426 return 0;
323} 427}
324 428
429static int fsl_sai_hw_free(struct snd_pcm_substream *substream,
430 struct snd_soc_dai *cpu_dai)
431{
432 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
433 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
434
435 if (!sai->is_slave_mode &&
436 sai->mclk_streams & BIT(substream->stream)) {
437 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[tx]]);
438 sai->mclk_streams &= ~BIT(substream->stream);
439 }
440
441 return 0;
442}
443
444
325static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd, 445static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
326 struct snd_soc_dai *cpu_dai) 446 struct snd_soc_dai *cpu_dai)
327{ 447{
@@ -410,7 +530,10 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
410 regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx), FSL_SAI_CR3_TRCE, 530 regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx), FSL_SAI_CR3_TRCE,
411 FSL_SAI_CR3_TRCE); 531 FSL_SAI_CR3_TRCE);
412 532
413 return 0; 533 ret = snd_pcm_hw_constraint_list(substream->runtime, 0,
534 SNDRV_PCM_HW_PARAM_RATE, &fsl_sai_rate_constraints);
535
536 return ret;
414} 537}
415 538
416static void fsl_sai_shutdown(struct snd_pcm_substream *substream, 539static void fsl_sai_shutdown(struct snd_pcm_substream *substream,
@@ -428,6 +551,7 @@ static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = {
428 .set_sysclk = fsl_sai_set_dai_sysclk, 551 .set_sysclk = fsl_sai_set_dai_sysclk,
429 .set_fmt = fsl_sai_set_dai_fmt, 552 .set_fmt = fsl_sai_set_dai_fmt,
430 .hw_params = fsl_sai_hw_params, 553 .hw_params = fsl_sai_hw_params,
554 .hw_free = fsl_sai_hw_free,
431 .trigger = fsl_sai_trigger, 555 .trigger = fsl_sai_trigger,
432 .startup = fsl_sai_startup, 556 .startup = fsl_sai_startup,
433 .shutdown = fsl_sai_shutdown, 557 .shutdown = fsl_sai_shutdown,
@@ -463,14 +587,18 @@ static struct snd_soc_dai_driver fsl_sai_dai = {
463 .stream_name = "CPU-Playback", 587 .stream_name = "CPU-Playback",
464 .channels_min = 1, 588 .channels_min = 1,
465 .channels_max = 2, 589 .channels_max = 2,
466 .rates = SNDRV_PCM_RATE_8000_96000, 590 .rate_min = 8000,
591 .rate_max = 192000,
592 .rates = SNDRV_PCM_RATE_KNOT,
467 .formats = FSL_SAI_FORMATS, 593 .formats = FSL_SAI_FORMATS,
468 }, 594 },
469 .capture = { 595 .capture = {
470 .stream_name = "CPU-Capture", 596 .stream_name = "CPU-Capture",
471 .channels_min = 1, 597 .channels_min = 1,
472 .channels_max = 2, 598 .channels_max = 2,
473 .rates = SNDRV_PCM_RATE_8000_96000, 599 .rate_min = 8000,
600 .rate_max = 192000,
601 .rates = SNDRV_PCM_RATE_KNOT,
474 .formats = FSL_SAI_FORMATS, 602 .formats = FSL_SAI_FORMATS,
475 }, 603 },
476 .ops = &fsl_sai_pcm_dai_ops, 604 .ops = &fsl_sai_pcm_dai_ops,
@@ -600,8 +728,9 @@ static int fsl_sai_probe(struct platform_device *pdev)
600 sai->bus_clk = NULL; 728 sai->bus_clk = NULL;
601 } 729 }
602 730
603 for (i = 0; i < FSL_SAI_MCLK_MAX; i++) { 731 sai->mclk_clk[0] = sai->bus_clk;
604 sprintf(tmp, "mclk%d", i + 1); 732 for (i = 1; i < FSL_SAI_MCLK_MAX; i++) {
733 sprintf(tmp, "mclk%d", i);
605 sai->mclk_clk[i] = devm_clk_get(&pdev->dev, tmp); 734 sai->mclk_clk[i] = devm_clk_get(&pdev->dev, tmp);
606 if (IS_ERR(sai->mclk_clk[i])) { 735 if (IS_ERR(sai->mclk_clk[i])) {
607 dev_err(&pdev->dev, "failed to get mclk%d clock: %ld\n", 736 dev_err(&pdev->dev, "failed to get mclk%d clock: %ld\n",
@@ -664,8 +793,7 @@ static int fsl_sai_probe(struct platform_device *pdev)
664 if (sai->sai_on_imx) 793 if (sai->sai_on_imx)
665 return imx_pcm_dma_init(pdev); 794 return imx_pcm_dma_init(pdev);
666 else 795 else
667 return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 796 return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
668 SND_DMAENGINE_PCM_FLAG_NO_RESIDUE);
669} 797}
670 798
671static const struct of_device_id fsl_sai_ids[] = { 799static const struct of_device_id fsl_sai_ids[] = {
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
index 34667209b607..066280953c85 100644
--- a/sound/soc/fsl/fsl_sai.h
+++ b/sound/soc/fsl/fsl_sai.h
@@ -72,13 +72,15 @@
72 72
73/* SAI Transmit and Recieve Configuration 2 Register */ 73/* SAI Transmit and Recieve Configuration 2 Register */
74#define FSL_SAI_CR2_SYNC BIT(30) 74#define FSL_SAI_CR2_SYNC BIT(30)
75#define FSL_SAI_CR2_MSEL_MASK (0xff << 26) 75#define FSL_SAI_CR2_MSEL_MASK (0x3 << 26)
76#define FSL_SAI_CR2_MSEL_BUS 0 76#define FSL_SAI_CR2_MSEL_BUS 0
77#define FSL_SAI_CR2_MSEL_MCLK1 BIT(26) 77#define FSL_SAI_CR2_MSEL_MCLK1 BIT(26)
78#define FSL_SAI_CR2_MSEL_MCLK2 BIT(27) 78#define FSL_SAI_CR2_MSEL_MCLK2 BIT(27)
79#define FSL_SAI_CR2_MSEL_MCLK3 (BIT(26) | BIT(27)) 79#define FSL_SAI_CR2_MSEL_MCLK3 (BIT(26) | BIT(27))
80#define FSL_SAI_CR2_MSEL(ID) ((ID) << 26)
80#define FSL_SAI_CR2_BCP BIT(25) 81#define FSL_SAI_CR2_BCP BIT(25)
81#define FSL_SAI_CR2_BCD_MSTR BIT(24) 82#define FSL_SAI_CR2_BCD_MSTR BIT(24)
83#define FSL_SAI_CR2_DIV_MASK 0xff
82 84
83/* SAI Transmit and Recieve Configuration 3 Register */ 85/* SAI Transmit and Recieve Configuration 3 Register */
84#define FSL_SAI_CR3_TRCE BIT(16) 86#define FSL_SAI_CR3_TRCE BIT(16)
@@ -120,7 +122,7 @@
120#define FSL_SAI_CLK_MAST2 2 122#define FSL_SAI_CLK_MAST2 2
121#define FSL_SAI_CLK_MAST3 3 123#define FSL_SAI_CLK_MAST3 3
122 124
123#define FSL_SAI_MCLK_MAX 3 125#define FSL_SAI_MCLK_MAX 4
124 126
125/* SAI data transfer numbers per DMA request */ 127/* SAI data transfer numbers per DMA request */
126#define FSL_SAI_MAXBURST_TX 6 128#define FSL_SAI_MAXBURST_TX 6
@@ -132,11 +134,14 @@ struct fsl_sai {
132 struct clk *bus_clk; 134 struct clk *bus_clk;
133 struct clk *mclk_clk[FSL_SAI_MCLK_MAX]; 135 struct clk *mclk_clk[FSL_SAI_MCLK_MAX];
134 136
137 bool is_slave_mode;
135 bool is_lsb_first; 138 bool is_lsb_first;
136 bool is_dsp_mode; 139 bool is_dsp_mode;
137 bool sai_on_imx; 140 bool sai_on_imx;
138 bool synchronous[2]; 141 bool synchronous[2];
139 142
143 unsigned int mclk_id[2];
144 unsigned int mclk_streams;
140 struct snd_dmaengine_dai_dma_data dma_params_rx; 145 struct snd_dmaengine_dai_dma_data dma_params_rx;
141 struct snd_dmaengine_dai_dma_data dma_params_tx; 146 struct snd_dmaengine_dai_dma_data dma_params_tx;
142}; 147};
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index e8bb8eef1d16..c7647e066cfd 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -1292,13 +1292,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1292 void __iomem *iomem; 1292 void __iomem *iomem;
1293 char name[64]; 1293 char name[64];
1294 1294
1295 /* SSIs that are not connected on the board should have a
1296 * status = "disabled"
1297 * property in their device tree nodes.
1298 */
1299 if (!of_device_is_available(np))
1300 return -ENODEV;
1301
1302 of_id = of_match_device(fsl_ssi_ids, &pdev->dev); 1295 of_id = of_match_device(fsl_ssi_ids, &pdev->dev);
1303 if (!of_id || !of_id->data) 1296 if (!of_id || !of_id->data)
1304 return -EINVAL; 1297 return -EINVAL;
@@ -1357,7 +1350,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1357 } 1350 }
1358 1351
1359 ssi_private->irq = platform_get_irq(pdev, 0); 1352 ssi_private->irq = platform_get_irq(pdev, 0);
1360 if (!ssi_private->irq) { 1353 if (ssi_private->irq < 0) {
1361 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name); 1354 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
1362 return ssi_private->irq; 1355 return ssi_private->irq;
1363 } 1356 }
diff --git a/sound/soc/fsl/imx-audmux.c b/sound/soc/fsl/imx-audmux.c
index d9050d946ae7..fc57da341d61 100644
--- a/sound/soc/fsl/imx-audmux.c
+++ b/sound/soc/fsl/imx-audmux.c
@@ -184,7 +184,7 @@ static enum imx_audmux_type {
184 IMX31_AUDMUX, 184 IMX31_AUDMUX,
185} audmux_type; 185} audmux_type;
186 186
187static struct platform_device_id imx_audmux_ids[] = { 187static const struct platform_device_id imx_audmux_ids[] = {
188 { 188 {
189 .name = "imx21-audmux", 189 .name = "imx21-audmux",
190 .driver_data = IMX21_AUDMUX, 190 .driver_data = IMX21_AUDMUX,
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c
index 9e6493d4e7ff..bb0459018b45 100644
--- a/sound/soc/fsl/imx-mc13783.c
+++ b/sound/soc/fsl/imx-mc13783.c
@@ -45,11 +45,7 @@ static int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream,
45 if (ret) 45 if (ret)
46 return ret; 46 return ret;
47 47
48 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 16); 48 return snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 16);
49 if (ret)
50 return ret;
51
52 return 0;
53} 49}
54 50
55static struct snd_soc_ops imx_mc13783_hifi_ops = { 51static struct snd_soc_ops imx_mc13783_hifi_ops = {
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
index cd9aee9871a3..3853ec2ddbc7 100644
--- a/sound/soc/intel/Makefile
+++ b/sound/soc/intel/Makefile
@@ -4,7 +4,7 @@ obj-$(CONFIG_SND_SOC_INTEL_SST) += common/
4# Platform Support 4# Platform Support
5obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/ 5obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/
6obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/ 6obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/
7obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += atom/ 7obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += atom/
8 8
9# Machine support 9# Machine support
10obj-$(CONFIG_SND_SOC_INTEL_SST) += boards/ 10obj-$(CONFIG_SND_SOC_INTEL_SST) += boards/
diff --git a/sound/soc/intel/baytrail/sst-baytrail-ipc.c b/sound/soc/intel/baytrail/sst-baytrail-ipc.c
index 1efb33b36303..a839dbfa5218 100644
--- a/sound/soc/intel/baytrail/sst-baytrail-ipc.c
+++ b/sound/soc/intel/baytrail/sst-baytrail-ipc.c
@@ -759,7 +759,6 @@ fw_err:
759dsp_new_err: 759dsp_new_err:
760 sst_ipc_fini(ipc); 760 sst_ipc_fini(ipc);
761ipc_init_err: 761ipc_init_err:
762 kfree(byt);
763 762
764 return err; 763 return err;
765} 764}
diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c
index 20a28b22e30f..26e01f36b704 100644
--- a/sound/soc/intel/boards/cht_bsw_rt5645.c
+++ b/sound/soc/intel/boards/cht_bsw_rt5645.c
@@ -185,7 +185,7 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
185 return ret; 185 return ret;
186 } 186 }
187 187
188 rt5645_set_jack_detect(codec, &ctx->hp_jack, &ctx->mic_jack); 188 rt5645_set_jack_detect(codec, &ctx->hp_jack, &ctx->mic_jack, NULL);
189 189
190 return ret; 190 return ret;
191} 191}
diff --git a/sound/soc/intel/haswell/sst-haswell-ipc.c b/sound/soc/intel/haswell/sst-haswell-ipc.c
index 344a1e9bbce5..324eceb07b25 100644
--- a/sound/soc/intel/haswell/sst-haswell-ipc.c
+++ b/sound/soc/intel/haswell/sst-haswell-ipc.c
@@ -2201,7 +2201,6 @@ dma_err:
2201dsp_new_err: 2201dsp_new_err:
2202 sst_ipc_fini(ipc); 2202 sst_ipc_fini(ipc);
2203ipc_init_err: 2203ipc_init_err:
2204 kfree(hsw);
2205 return ret; 2204 return ret;
2206} 2205}
2207EXPORT_SYMBOL_GPL(sst_hsw_dsp_init); 2206EXPORT_SYMBOL_GPL(sst_hsw_dsp_init);
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index 6698d058de29..dc790abaa331 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -194,7 +194,7 @@ static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream,
194 int cmd, struct snd_soc_dai *dai) 194 int cmd, struct snd_soc_dai *dai)
195{ 195{
196 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); 196 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
197 int ret; 197 int ret = -EINVAL;
198 198
199 switch (cmd) { 199 switch (cmd) {
200 case SNDRV_PCM_TRIGGER_START: 200 case SNDRV_PCM_TRIGGER_START:
diff --git a/sound/soc/samsung/s3c24xx-i2s.c b/sound/soc/samsung/s3c24xx-i2s.c
index 326d3c3804e3..5bf723689692 100644
--- a/sound/soc/samsung/s3c24xx-i2s.c
+++ b/sound/soc/samsung/s3c24xx-i2s.c
@@ -461,8 +461,8 @@ static int s3c24xx_iis_dev_probe(struct platform_device *pdev)
461 return -ENOENT; 461 return -ENOENT;
462 } 462 }
463 s3c24xx_i2s.regs = devm_ioremap_resource(&pdev->dev, res); 463 s3c24xx_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
464 if (s3c24xx_i2s.regs == NULL) 464 if (IS_ERR(s3c24xx_i2s.regs))
465 return -ENXIO; 465 return PTR_ERR(s3c24xx_i2s.regs);
466 466
467 s3c24xx_i2s_pcm_stereo_out.dma_addr = res->start + S3C2410_IISFIFO; 467 s3c24xx_i2s_pcm_stereo_out.dma_addr = res->start + S3C2410_IISFIFO;
468 s3c24xx_i2s_pcm_stereo_in.dma_addr = res->start + S3C2410_IISFIFO; 468 s3c24xx_i2s_pcm_stereo_in.dma_addr = res->start + S3C2410_IISFIFO;
diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c
index ac3756f6af60..144308f15fb3 100644
--- a/sound/soc/sh/rcar/dma.c
+++ b/sound/soc/sh/rcar/dma.c
@@ -156,6 +156,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
156 (void *)id); 156 (void *)id);
157 } 157 }
158 if (IS_ERR_OR_NULL(dmaen->chan)) { 158 if (IS_ERR_OR_NULL(dmaen->chan)) {
159 dmaen->chan = NULL;
159 dev_err(dev, "can't get dma channel\n"); 160 dev_err(dev, "can't get dma channel\n");
160 goto rsnd_dma_channel_err; 161 goto rsnd_dma_channel_err;
161 } 162 }
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 23732523f87c..95f83bec1d14 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -92,30 +92,21 @@ static int format_register_str(struct snd_soc_codec *codec,
92 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 92 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
93 int regsize = codec->driver->reg_word_size * 2; 93 int regsize = codec->driver->reg_word_size * 2;
94 int ret; 94 int ret;
95 char tmpbuf[len + 1];
96 char regbuf[regsize + 1];
97
98 /* since tmpbuf is allocated on the stack, warn the callers if they
99 * try to abuse this function */
100 WARN_ON(len > 63);
101 95
102 /* +2 for ': ' and + 1 for '\n' */ 96 /* +2 for ': ' and + 1 for '\n' */
103 if (wordsize + regsize + 2 + 1 != len) 97 if (wordsize + regsize + 2 + 1 != len)
104 return -EINVAL; 98 return -EINVAL;
105 99
106 ret = snd_soc_read(codec, reg); 100 sprintf(buf, "%.*x: ", wordsize, reg);
107 if (ret < 0) { 101 buf += wordsize + 2;
108 memset(regbuf, 'X', regsize);
109 regbuf[regsize] = '\0';
110 } else {
111 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
112 }
113
114 /* prepare the buffer */
115 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
116 /* copy it back to the caller without the '\0' */
117 memcpy(buf, tmpbuf, len);
118 102
103 ret = snd_soc_read(codec, reg);
104 if (ret < 0)
105 memset(buf, 'X', regsize);
106 else
107 sprintf(buf, "%.*x", regsize, ret);
108 buf[regsize] = '\n';
109 /* no NUL-termination needed */
119 return 0; 110 return 0;
120} 111}
121 112
@@ -750,23 +741,10 @@ static void soc_resume_deferred(struct work_struct *work)
750 } 741 }
751 742
752 list_for_each_entry(codec, &card->codec_dev_list, card_list) { 743 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
753 /* If the CODEC was idle over suspend then it will have been
754 * left with bias OFF or STANDBY and suspended so we must now
755 * resume. Otherwise the suspend was suppressed.
756 */
757 if (codec->suspended) { 744 if (codec->suspended) {
758 switch (codec->dapm.bias_level) { 745 if (codec->driver->resume)
759 case SND_SOC_BIAS_STANDBY: 746 codec->driver->resume(codec);
760 case SND_SOC_BIAS_OFF: 747 codec->suspended = 0;
761 if (codec->driver->resume)
762 codec->driver->resume(codec);
763 codec->suspended = 0;
764 break;
765 default:
766 dev_dbg(codec->dev,
767 "ASoC: CODEC was on over suspend\n");
768 break;
769 }
770 } 748 }
771 } 749 }
772 750
@@ -904,12 +882,17 @@ static struct snd_soc_dai *snd_soc_find_dai(
904{ 882{
905 struct snd_soc_component *component; 883 struct snd_soc_component *component;
906 struct snd_soc_dai *dai; 884 struct snd_soc_dai *dai;
885 struct device_node *component_of_node;
907 886
908 lockdep_assert_held(&client_mutex); 887 lockdep_assert_held(&client_mutex);
909 888
910 /* Find CPU DAI from registered DAIs*/ 889 /* Find CPU DAI from registered DAIs*/
911 list_for_each_entry(component, &component_list, list) { 890 list_for_each_entry(component, &component_list, list) {
912 if (dlc->of_node && component->dev->of_node != dlc->of_node) 891 component_of_node = component->dev->of_node;
892 if (!component_of_node && component->dev->parent)
893 component_of_node = component->dev->parent->of_node;
894
895 if (dlc->of_node && component_of_node != dlc->of_node)
913 continue; 896 continue;
914 if (dlc->name && strcmp(component->name, dlc->name)) 897 if (dlc->name && strcmp(component->name, dlc->name))
915 continue; 898 continue;
@@ -2599,7 +2582,8 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
2599 * the same naming style even though those DAIs are not 2582 * the same naming style even though those DAIs are not
2600 * component-less anymore. 2583 * component-less anymore.
2601 */ 2584 */
2602 if (count == 1 && legacy_dai_naming) { 2585 if (count == 1 && legacy_dai_naming &&
2586 (dai_drv[i].id == 0 || dai_drv[i].name == NULL)) {
2603 dai->name = fmt_single_name(dev, &dai->id); 2587 dai->name = fmt_single_name(dev, &dai->id);
2604 } else { 2588 } else {
2605 dai->name = fmt_multiple_name(dev, &dai_drv[i]); 2589 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
@@ -3488,11 +3472,16 @@ static int snd_soc_get_dai_name(struct of_phandle_args *args,
3488 const char **dai_name) 3472 const char **dai_name)
3489{ 3473{
3490 struct snd_soc_component *pos; 3474 struct snd_soc_component *pos;
3475 struct device_node *component_of_node;
3491 int ret = -EPROBE_DEFER; 3476 int ret = -EPROBE_DEFER;
3492 3477
3493 mutex_lock(&client_mutex); 3478 mutex_lock(&client_mutex);
3494 list_for_each_entry(pos, &component_list, list) { 3479 list_for_each_entry(pos, &component_list, list) {
3495 if (pos->dev->of_node != args->np) 3480 component_of_node = pos->dev->of_node;
3481 if (!component_of_node && pos->dev->parent)
3482 component_of_node = pos->dev->parent->of_node;
3483
3484 if (component_of_node != args->np)
3496 continue; 3485 continue;
3497 3486
3498 if (pos->driver->of_xlate_dai_name) { 3487 if (pos->driver->of_xlate_dai_name) {
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index defe0f0082b5..aa327c92480c 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -52,10 +52,15 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
52 const char *control, 52 const char *control,
53 int (*connected)(struct snd_soc_dapm_widget *source, 53 int (*connected)(struct snd_soc_dapm_widget *source,
54 struct snd_soc_dapm_widget *sink)); 54 struct snd_soc_dapm_widget *sink));
55static struct snd_soc_dapm_widget * 55
56struct snd_soc_dapm_widget *
56snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, 57snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
57 const struct snd_soc_dapm_widget *widget); 58 const struct snd_soc_dapm_widget *widget);
58 59
60struct snd_soc_dapm_widget *
61snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
62 const struct snd_soc_dapm_widget *widget);
63
59/* dapm power sequences - make this per codec in the future */ 64/* dapm power sequences - make this per codec in the future */
60static int dapm_up_seq[] = { 65static int dapm_up_seq[] = {
61 [snd_soc_dapm_pre] = 0, 66 [snd_soc_dapm_pre] = 0,
@@ -70,6 +75,7 @@ static int dapm_up_seq[] = {
70 [snd_soc_dapm_aif_out] = 4, 75 [snd_soc_dapm_aif_out] = 4,
71 [snd_soc_dapm_mic] = 5, 76 [snd_soc_dapm_mic] = 5,
72 [snd_soc_dapm_mux] = 6, 77 [snd_soc_dapm_mux] = 6,
78 [snd_soc_dapm_demux] = 6,
73 [snd_soc_dapm_dac] = 7, 79 [snd_soc_dapm_dac] = 7,
74 [snd_soc_dapm_switch] = 8, 80 [snd_soc_dapm_switch] = 8,
75 [snd_soc_dapm_mixer] = 8, 81 [snd_soc_dapm_mixer] = 8,
@@ -100,6 +106,7 @@ static int dapm_down_seq[] = {
100 [snd_soc_dapm_mic] = 7, 106 [snd_soc_dapm_mic] = 7,
101 [snd_soc_dapm_micbias] = 8, 107 [snd_soc_dapm_micbias] = 8,
102 [snd_soc_dapm_mux] = 9, 108 [snd_soc_dapm_mux] = 9,
109 [snd_soc_dapm_demux] = 9,
103 [snd_soc_dapm_aif_in] = 10, 110 [snd_soc_dapm_aif_in] = 10,
104 [snd_soc_dapm_aif_out] = 10, 111 [snd_soc_dapm_aif_out] = 10,
105 [snd_soc_dapm_dai_in] = 10, 112 [snd_soc_dapm_dai_in] = 10,
@@ -308,14 +315,13 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
308{ 315{
309 struct dapm_kcontrol_data *data; 316 struct dapm_kcontrol_data *data;
310 struct soc_mixer_control *mc; 317 struct soc_mixer_control *mc;
318 struct soc_enum *e;
319 const char *name;
320 int ret;
311 321
312 data = kzalloc(sizeof(*data), GFP_KERNEL); 322 data = kzalloc(sizeof(*data), GFP_KERNEL);
313 if (!data) { 323 if (!data)
314 dev_err(widget->dapm->dev,
315 "ASoC: can't allocate kcontrol data for %s\n",
316 widget->name);
317 return -ENOMEM; 324 return -ENOMEM;
318 }
319 325
320 INIT_LIST_HEAD(&data->paths); 326 INIT_LIST_HEAD(&data->paths);
321 327
@@ -328,6 +334,13 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
328 if (mc->autodisable) { 334 if (mc->autodisable) {
329 struct snd_soc_dapm_widget template; 335 struct snd_soc_dapm_widget template;
330 336
337 name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name,
338 "Autodisable");
339 if (!name) {
340 ret = -ENOMEM;
341 goto err_data;
342 }
343
331 memset(&template, 0, sizeof(template)); 344 memset(&template, 0, sizeof(template));
332 template.reg = mc->reg; 345 template.reg = mc->reg;
333 template.mask = (1 << fls(mc->max)) - 1; 346 template.mask = (1 << fls(mc->max)) - 1;
@@ -338,18 +351,55 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
338 template.off_val = 0; 351 template.off_val = 0;
339 template.on_val = template.off_val; 352 template.on_val = template.off_val;
340 template.id = snd_soc_dapm_kcontrol; 353 template.id = snd_soc_dapm_kcontrol;
341 template.name = kcontrol->id.name; 354 template.name = name;
342 355
343 data->value = template.on_val; 356 data->value = template.on_val;
344 357
345 data->widget = snd_soc_dapm_new_control(widget->dapm, 358 data->widget =
359 snd_soc_dapm_new_control_unlocked(widget->dapm,
346 &template); 360 &template);
347 if (!data->widget) { 361 if (!data->widget) {
348 kfree(data); 362 ret = -ENOMEM;
349 return -ENOMEM; 363 goto err_name;
350 } 364 }
351 } 365 }
352 break; 366 break;
367 case snd_soc_dapm_demux:
368 case snd_soc_dapm_mux:
369 e = (struct soc_enum *)kcontrol->private_value;
370
371 if (e->autodisable) {
372 struct snd_soc_dapm_widget template;
373
374 name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name,
375 "Autodisable");
376 if (!name) {
377 ret = -ENOMEM;
378 goto err_data;
379 }
380
381 memset(&template, 0, sizeof(template));
382 template.reg = e->reg;
383 template.mask = e->mask << e->shift_l;
384 template.shift = e->shift_l;
385 template.off_val = snd_soc_enum_item_to_val(e, 0);
386 template.on_val = template.off_val;
387 template.id = snd_soc_dapm_kcontrol;
388 template.name = name;
389
390 data->value = template.on_val;
391
392 data->widget = snd_soc_dapm_new_control(widget->dapm,
393 &template);
394 if (!data->widget) {
395 ret = -ENOMEM;
396 goto err_name;
397 }
398
399 snd_soc_dapm_add_path(widget->dapm, data->widget,
400 widget, NULL, NULL);
401 }
402 break;
353 default: 403 default:
354 break; 404 break;
355 } 405 }
@@ -357,11 +407,19 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
357 kcontrol->private_data = data; 407 kcontrol->private_data = data;
358 408
359 return 0; 409 return 0;
410
411err_name:
412 kfree(name);
413err_data:
414 kfree(data);
415 return ret;
360} 416}
361 417
362static void dapm_kcontrol_free(struct snd_kcontrol *kctl) 418static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
363{ 419{
364 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl); 420 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
421 if (data->widget)
422 kfree(data->widget->name);
365 kfree(data->wlist); 423 kfree(data->wlist);
366 kfree(data); 424 kfree(data);
367} 425}
@@ -405,11 +463,6 @@ static void dapm_kcontrol_add_path(const struct snd_kcontrol *kcontrol,
405 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); 463 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
406 464
407 list_add_tail(&path->list_kcontrol, &data->paths); 465 list_add_tail(&path->list_kcontrol, &data->paths);
408
409 if (data->widget) {
410 snd_soc_dapm_add_path(data->widget->dapm, data->widget,
411 path->source, NULL, NULL);
412 }
413} 466}
414 467
415static bool dapm_kcontrol_is_powered(const struct snd_kcontrol *kcontrol) 468static bool dapm_kcontrol_is_powered(const struct snd_kcontrol *kcontrol)
@@ -525,6 +578,67 @@ static void soc_dapm_async_complete(struct snd_soc_dapm_context *dapm)
525 snd_soc_component_async_complete(dapm->component); 578 snd_soc_component_async_complete(dapm->component);
526} 579}
527 580
581static struct snd_soc_dapm_widget *
582dapm_wcache_lookup(struct snd_soc_dapm_wcache *wcache, const char *name)
583{
584 struct snd_soc_dapm_widget *w = wcache->widget;
585 struct list_head *wlist;
586 const int depth = 2;
587 int i = 0;
588
589 if (w) {
590 wlist = &w->dapm->card->widgets;
591
592 list_for_each_entry_from(w, wlist, list) {
593 if (!strcmp(name, w->name))
594 return w;
595
596 if (++i == depth)
597 break;
598 }
599 }
600
601 return NULL;
602}
603
604static inline void dapm_wcache_update(struct snd_soc_dapm_wcache *wcache,
605 struct snd_soc_dapm_widget *w)
606{
607 wcache->widget = w;
608}
609
610/**
611 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
612 * @dapm: The DAPM context for which to set the level
613 * @level: The level to set
614 *
615 * Forces the DAPM bias level to a specific state. It will call the bias level
616 * callback of DAPM context with the specified level. This will even happen if
617 * the context is already at the same level. Furthermore it will not go through
618 * the normal bias level sequencing, meaning any intermediate states between the
619 * current and the target state will not be entered.
620 *
621 * Note that the change in bias level is only temporary and the next time
622 * snd_soc_dapm_sync() is called the state will be set to the level as
623 * determined by the DAPM core. The function is mainly intended to be used to
624 * used during probe or resume from suspend to power up the device so
625 * initialization can be done, before the DAPM core takes over.
626 */
627int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm,
628 enum snd_soc_bias_level level)
629{
630 int ret = 0;
631
632 if (dapm->set_bias_level)
633 ret = dapm->set_bias_level(dapm, level);
634
635 if (ret == 0)
636 dapm->bias_level = level;
637
638 return ret;
639}
640EXPORT_SYMBOL_GPL(snd_soc_dapm_force_bias_level);
641
528/** 642/**
529 * snd_soc_dapm_set_bias_level - set the bias level for the system 643 * snd_soc_dapm_set_bias_level - set the bias level for the system
530 * @dapm: DAPM context 644 * @dapm: DAPM context
@@ -547,10 +661,8 @@ static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
547 if (ret != 0) 661 if (ret != 0)
548 goto out; 662 goto out;
549 663
550 if (dapm->set_bias_level) 664 if (!card || dapm != &card->dapm)
551 ret = dapm->set_bias_level(dapm, level); 665 ret = snd_soc_dapm_force_bias_level(dapm, level);
552 else if (!card || dapm != &card->dapm)
553 dapm->bias_level = level;
554 666
555 if (ret != 0) 667 if (ret != 0)
556 goto out; 668 goto out;
@@ -565,9 +677,10 @@ out:
565 677
566/* connect mux widget to its interconnecting audio paths */ 678/* connect mux widget to its interconnecting audio paths */
567static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, 679static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
568 struct snd_soc_dapm_path *path, const char *control_name) 680 struct snd_soc_dapm_path *path, const char *control_name,
681 struct snd_soc_dapm_widget *w)
569{ 682{
570 const struct snd_kcontrol_new *kcontrol = &path->sink->kcontrol_news[0]; 683 const struct snd_kcontrol_new *kcontrol = &w->kcontrol_news[0];
571 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 684 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
572 unsigned int val, item; 685 unsigned int val, item;
573 int i; 686 int i;
@@ -707,6 +820,7 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
707 wname_in_long_name = false; 820 wname_in_long_name = false;
708 kcname_in_long_name = true; 821 kcname_in_long_name = true;
709 break; 822 break;
823 case snd_soc_dapm_demux:
710 case snd_soc_dapm_mux: 824 case snd_soc_dapm_mux:
711 wname_in_long_name = true; 825 wname_in_long_name = true;
712 kcname_in_long_name = false; 826 kcname_in_long_name = false;
@@ -777,6 +891,7 @@ static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
777{ 891{
778 int i, ret; 892 int i, ret;
779 struct snd_soc_dapm_path *path; 893 struct snd_soc_dapm_path *path;
894 struct dapm_kcontrol_data *data;
780 895
781 /* add kcontrol */ 896 /* add kcontrol */
782 for (i = 0; i < w->num_kcontrols; i++) { 897 for (i = 0; i < w->num_kcontrols; i++) {
@@ -786,16 +901,20 @@ static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
786 if (path->name != (char *)w->kcontrol_news[i].name) 901 if (path->name != (char *)w->kcontrol_news[i].name)
787 continue; 902 continue;
788 903
789 if (w->kcontrols[i]) { 904 if (!w->kcontrols[i]) {
790 dapm_kcontrol_add_path(w->kcontrols[i], path); 905 ret = dapm_create_or_share_mixmux_kcontrol(w, i);
791 continue; 906 if (ret < 0)
907 return ret;
792 } 908 }
793 909
794 ret = dapm_create_or_share_mixmux_kcontrol(w, i);
795 if (ret < 0)
796 return ret;
797
798 dapm_kcontrol_add_path(w->kcontrols[i], path); 910 dapm_kcontrol_add_path(w->kcontrols[i], path);
911
912 data = snd_kcontrol_chip(w->kcontrols[i]);
913 if (data->widget)
914 snd_soc_dapm_add_path(data->widget->dapm,
915 data->widget,
916 path->source,
917 NULL, NULL);
799 } 918 }
800 } 919 }
801 920
@@ -807,17 +926,32 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
807{ 926{
808 struct snd_soc_dapm_context *dapm = w->dapm; 927 struct snd_soc_dapm_context *dapm = w->dapm;
809 struct snd_soc_dapm_path *path; 928 struct snd_soc_dapm_path *path;
929 struct list_head *paths;
930 const char *type;
810 int ret; 931 int ret;
811 932
933 switch (w->id) {
934 case snd_soc_dapm_mux:
935 paths = &w->sources;
936 type = "mux";
937 break;
938 case snd_soc_dapm_demux:
939 paths = &w->sinks;
940 type = "demux";
941 break;
942 default:
943 return -EINVAL;
944 }
945
812 if (w->num_kcontrols != 1) { 946 if (w->num_kcontrols != 1) {
813 dev_err(dapm->dev, 947 dev_err(dapm->dev,
814 "ASoC: mux %s has incorrect number of controls\n", 948 "ASoC: %s %s has incorrect number of controls\n", type,
815 w->name); 949 w->name);
816 return -EINVAL; 950 return -EINVAL;
817 } 951 }
818 952
819 if (list_empty(&w->sources)) { 953 if (list_empty(paths)) {
820 dev_err(dapm->dev, "ASoC: mux %s has no paths\n", w->name); 954 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name);
821 return -EINVAL; 955 return -EINVAL;
822 } 956 }
823 957
@@ -825,9 +959,16 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
825 if (ret < 0) 959 if (ret < 0)
826 return ret; 960 return ret;
827 961
828 list_for_each_entry(path, &w->sources, list_sink) { 962 if (w->id == snd_soc_dapm_mux) {
829 if (path->name) 963 list_for_each_entry(path, &w->sources, list_sink) {
830 dapm_kcontrol_add_path(w->kcontrols[0], path); 964 if (path->name)
965 dapm_kcontrol_add_path(w->kcontrols[0], path);
966 }
967 } else {
968 list_for_each_entry(path, &w->sinks, list_source) {
969 if (path->name)
970 dapm_kcontrol_add_path(w->kcontrols[0], path);
971 }
831 } 972 }
832 973
833 return 0; 974 return 0;
@@ -2335,6 +2476,50 @@ static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w)
2335 } 2476 }
2336} 2477}
2337 2478
2479static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context *dapm,
2480 struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink,
2481 const char *control)
2482{
2483 bool dynamic_source = false;
2484 bool dynamic_sink = false;
2485
2486 if (!control)
2487 return 0;
2488
2489 switch (source->id) {
2490 case snd_soc_dapm_demux:
2491 dynamic_source = true;
2492 break;
2493 default:
2494 break;
2495 }
2496
2497 switch (sink->id) {
2498 case snd_soc_dapm_mux:
2499 case snd_soc_dapm_switch:
2500 case snd_soc_dapm_mixer:
2501 case snd_soc_dapm_mixer_named_ctl:
2502 dynamic_sink = true;
2503 break;
2504 default:
2505 break;
2506 }
2507
2508 if (dynamic_source && dynamic_sink) {
2509 dev_err(dapm->dev,
2510 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n",
2511 source->name, control, sink->name);
2512 return -EINVAL;
2513 } else if (!dynamic_source && !dynamic_sink) {
2514 dev_err(dapm->dev,
2515 "Control not supported for path %s -> [%s] -> %s\n",
2516 source->name, control, sink->name);
2517 return -EINVAL;
2518 }
2519
2520 return 0;
2521}
2522
2338static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, 2523static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2339 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink, 2524 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink,
2340 const char *control, 2525 const char *control,
@@ -2365,6 +2550,10 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2365 return -EINVAL; 2550 return -EINVAL;
2366 } 2551 }
2367 2552
2553 ret = snd_soc_dapm_check_dynamic_path(dapm, wsource, wsink, control);
2554 if (ret)
2555 return ret;
2556
2368 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); 2557 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
2369 if (!path) 2558 if (!path)
2370 return -ENOMEM; 2559 return -ENOMEM;
@@ -2384,10 +2573,19 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2384 if (control == NULL) { 2573 if (control == NULL) {
2385 path->connect = 1; 2574 path->connect = 1;
2386 } else { 2575 } else {
2387 /* connect dynamic paths */ 2576 switch (wsource->id) {
2577 case snd_soc_dapm_demux:
2578 ret = dapm_connect_mux(dapm, path, control, wsource);
2579 if (ret)
2580 goto err;
2581 break;
2582 default:
2583 break;
2584 }
2585
2388 switch (wsink->id) { 2586 switch (wsink->id) {
2389 case snd_soc_dapm_mux: 2587 case snd_soc_dapm_mux:
2390 ret = dapm_connect_mux(dapm, path, control); 2588 ret = dapm_connect_mux(dapm, path, control, wsink);
2391 if (ret != 0) 2589 if (ret != 0)
2392 goto err; 2590 goto err;
2393 break; 2591 break;
@@ -2399,11 +2597,7 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2399 goto err; 2597 goto err;
2400 break; 2598 break;
2401 default: 2599 default:
2402 dev_err(dapm->dev, 2600 break;
2403 "Control not supported for path %s -> [%s] -> %s\n",
2404 wsource->name, control, wsink->name);
2405 ret = -EINVAL;
2406 goto err;
2407 } 2601 }
2408 } 2602 }
2409 2603
@@ -2451,6 +2645,12 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2451 source = route->source; 2645 source = route->source;
2452 } 2646 }
2453 2647
2648 wsource = dapm_wcache_lookup(&dapm->path_source_cache, source);
2649 wsink = dapm_wcache_lookup(&dapm->path_sink_cache, sink);
2650
2651 if (wsink && wsource)
2652 goto skip_search;
2653
2454 /* 2654 /*
2455 * find src and dest widgets over all widgets but favor a widget from 2655 * find src and dest widgets over all widgets but favor a widget from
2456 * current DAPM context 2656 * current DAPM context
@@ -2458,14 +2658,20 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2458 list_for_each_entry(w, &dapm->card->widgets, list) { 2658 list_for_each_entry(w, &dapm->card->widgets, list) {
2459 if (!wsink && !(strcmp(w->name, sink))) { 2659 if (!wsink && !(strcmp(w->name, sink))) {
2460 wtsink = w; 2660 wtsink = w;
2461 if (w->dapm == dapm) 2661 if (w->dapm == dapm) {
2462 wsink = w; 2662 wsink = w;
2663 if (wsource)
2664 break;
2665 }
2463 continue; 2666 continue;
2464 } 2667 }
2465 if (!wsource && !(strcmp(w->name, source))) { 2668 if (!wsource && !(strcmp(w->name, source))) {
2466 wtsource = w; 2669 wtsource = w;
2467 if (w->dapm == dapm) 2670 if (w->dapm == dapm) {
2468 wsource = w; 2671 wsource = w;
2672 if (wsink)
2673 break;
2674 }
2469 } 2675 }
2470 } 2676 }
2471 /* use widget from another DAPM context if not found from this */ 2677 /* use widget from another DAPM context if not found from this */
@@ -2485,6 +2691,10 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
2485 return -ENODEV; 2691 return -ENODEV;
2486 } 2692 }
2487 2693
2694skip_search:
2695 dapm_wcache_update(&dapm->path_sink_cache, wsink);
2696 dapm_wcache_update(&dapm->path_source_cache, wsource);
2697
2488 ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control, 2698 ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control,
2489 route->connected); 2699 route->connected);
2490 if (ret) 2700 if (ret)
@@ -2736,6 +2946,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
2736 dapm_new_mixer(w); 2946 dapm_new_mixer(w);
2737 break; 2947 break;
2738 case snd_soc_dapm_mux: 2948 case snd_soc_dapm_mux:
2949 case snd_soc_dapm_demux:
2739 dapm_new_mux(w); 2950 dapm_new_mux(w);
2740 break; 2951 break;
2741 case snd_soc_dapm_pga: 2952 case snd_soc_dapm_pga:
@@ -2902,16 +3113,21 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2902 struct snd_ctl_elem_value *ucontrol) 3113 struct snd_ctl_elem_value *ucontrol)
2903{ 3114{
2904 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 3115 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
3116 struct snd_soc_card *card = dapm->card;
2905 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 3117 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2906 unsigned int reg_val, val; 3118 unsigned int reg_val, val;
2907 3119
2908 if (e->reg != SND_SOC_NOPM) { 3120 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3121 if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) {
2909 int ret = soc_dapm_read(dapm, e->reg, &reg_val); 3122 int ret = soc_dapm_read(dapm, e->reg, &reg_val);
2910 if (ret) 3123 if (ret) {
3124 mutex_unlock(&card->dapm_mutex);
2911 return ret; 3125 return ret;
3126 }
2912 } else { 3127 } else {
2913 reg_val = dapm_kcontrol_get_value(kcontrol); 3128 reg_val = dapm_kcontrol_get_value(kcontrol);
2914 } 3129 }
3130 mutex_unlock(&card->dapm_mutex);
2915 3131
2916 val = (reg_val >> e->shift_l) & e->mask; 3132 val = (reg_val >> e->shift_l) & e->mask;
2917 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val); 3133 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val);
@@ -2941,7 +3157,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2941 struct snd_soc_card *card = dapm->card; 3157 struct snd_soc_card *card = dapm->card;
2942 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 3158 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2943 unsigned int *item = ucontrol->value.enumerated.item; 3159 unsigned int *item = ucontrol->value.enumerated.item;
2944 unsigned int val, change; 3160 unsigned int val, change, reg_change = 0;
2945 unsigned int mask; 3161 unsigned int mask;
2946 struct snd_soc_dapm_update update; 3162 struct snd_soc_dapm_update update;
2947 int ret = 0; 3163 int ret = 0;
@@ -2960,19 +3176,20 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2960 3176
2961 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 3177 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2962 3178
3179 change = dapm_kcontrol_set_value(kcontrol, val);
3180
2963 if (e->reg != SND_SOC_NOPM) 3181 if (e->reg != SND_SOC_NOPM)
2964 change = soc_dapm_test_bits(dapm, e->reg, mask, val); 3182 reg_change = soc_dapm_test_bits(dapm, e->reg, mask, val);
2965 else
2966 change = dapm_kcontrol_set_value(kcontrol, val);
2967 3183
2968 if (change) { 3184 if (change || reg_change) {
2969 if (e->reg != SND_SOC_NOPM) { 3185 if (reg_change) {
2970 update.kcontrol = kcontrol; 3186 update.kcontrol = kcontrol;
2971 update.reg = e->reg; 3187 update.reg = e->reg;
2972 update.mask = mask; 3188 update.mask = mask;
2973 update.val = val; 3189 update.val = val;
2974 card->update = &update; 3190 card->update = &update;
2975 } 3191 }
3192 change |= reg_change;
2976 3193
2977 ret = soc_dapm_mux_update_power(card, kcontrol, item[0], e); 3194 ret = soc_dapm_mux_update_power(card, kcontrol, item[0], e);
2978 3195
@@ -3053,8 +3270,25 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
3053} 3270}
3054EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); 3271EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
3055 3272
3056static struct snd_soc_dapm_widget * 3273struct snd_soc_dapm_widget *
3057snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, 3274snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3275 const struct snd_soc_dapm_widget *widget)
3276{
3277 struct snd_soc_dapm_widget *w;
3278
3279 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3280 w = snd_soc_dapm_new_control_unlocked(dapm, widget);
3281 if (!w)
3282 dev_err(dapm->dev,
3283 "ASoC: Failed to create DAPM control %s\n",
3284 widget->name);
3285
3286 mutex_unlock(&dapm->card->dapm_mutex);
3287 return w;
3288}
3289
3290struct snd_soc_dapm_widget *
3291snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
3058 const struct snd_soc_dapm_widget *widget) 3292 const struct snd_soc_dapm_widget *widget)
3059{ 3293{
3060 struct snd_soc_dapm_widget *w; 3294 struct snd_soc_dapm_widget *w;
@@ -3100,11 +3334,16 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3100 } 3334 }
3101 3335
3102 prefix = soc_dapm_prefix(dapm); 3336 prefix = soc_dapm_prefix(dapm);
3103 if (prefix) 3337 if (prefix) {
3104 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); 3338 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name);
3105 else 3339 if (widget->sname)
3340 w->sname = kasprintf(GFP_KERNEL, "%s %s", prefix,
3341 widget->sname);
3342 } else {
3106 w->name = kasprintf(GFP_KERNEL, "%s", widget->name); 3343 w->name = kasprintf(GFP_KERNEL, "%s", widget->name);
3107 3344 if (widget->sname)
3345 w->sname = kasprintf(GFP_KERNEL, "%s", widget->sname);
3346 }
3108 if (w->name == NULL) { 3347 if (w->name == NULL) {
3109 kfree(w); 3348 kfree(w);
3110 return NULL; 3349 return NULL;
@@ -3136,6 +3375,7 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3136 w->power_check = dapm_always_on_check_power; 3375 w->power_check = dapm_always_on_check_power;
3137 break; 3376 break;
3138 case snd_soc_dapm_mux: 3377 case snd_soc_dapm_mux:
3378 case snd_soc_dapm_demux:
3139 case snd_soc_dapm_switch: 3379 case snd_soc_dapm_switch:
3140 case snd_soc_dapm_mixer: 3380 case snd_soc_dapm_mixer:
3141 case snd_soc_dapm_mixer_named_ctl: 3381 case snd_soc_dapm_mixer_named_ctl:
@@ -3169,7 +3409,7 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3169 INIT_LIST_HEAD(&w->sinks); 3409 INIT_LIST_HEAD(&w->sinks);
3170 INIT_LIST_HEAD(&w->list); 3410 INIT_LIST_HEAD(&w->list);
3171 INIT_LIST_HEAD(&w->dirty); 3411 INIT_LIST_HEAD(&w->dirty);
3172 list_add(&w->list, &dapm->card->widgets); 3412 list_add_tail(&w->list, &dapm->card->widgets);
3173 3413
3174 w->inputs = -1; 3414 w->inputs = -1;
3175 w->outputs = -1; 3415 w->outputs = -1;
@@ -3199,7 +3439,7 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
3199 3439
3200 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); 3440 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
3201 for (i = 0; i < num; i++) { 3441 for (i = 0; i < num; i++) {
3202 w = snd_soc_dapm_new_control(dapm, widget); 3442 w = snd_soc_dapm_new_control_unlocked(dapm, widget);
3203 if (!w) { 3443 if (!w) {
3204 dev_err(dapm->dev, 3444 dev_err(dapm->dev,
3205 "ASoC: Failed to create DAPM control %s\n", 3445 "ASoC: Failed to create DAPM control %s\n",
@@ -3437,7 +3677,7 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3437 3677
3438 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); 3678 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
3439 3679
3440 w = snd_soc_dapm_new_control(&card->dapm, &template); 3680 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
3441 if (!w) { 3681 if (!w) {
3442 dev_err(card->dev, "ASoC: Failed to create %s widget\n", 3682 dev_err(card->dev, "ASoC: Failed to create %s widget\n",
3443 link_name); 3683 link_name);
@@ -3488,7 +3728,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3488 dev_dbg(dai->dev, "ASoC: adding %s widget\n", 3728 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3489 template.name); 3729 template.name);
3490 3730
3491 w = snd_soc_dapm_new_control(dapm, &template); 3731 w = snd_soc_dapm_new_control_unlocked(dapm, &template);
3492 if (!w) { 3732 if (!w) {
3493 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", 3733 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3494 dai->driver->playback.stream_name); 3734 dai->driver->playback.stream_name);
@@ -3507,7 +3747,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3507 dev_dbg(dai->dev, "ASoC: adding %s widget\n", 3747 dev_dbg(dai->dev, "ASoC: adding %s widget\n",
3508 template.name); 3748 template.name);
3509 3749
3510 w = snd_soc_dapm_new_control(dapm, &template); 3750 w = snd_soc_dapm_new_control_unlocked(dapm, &template);
3511 if (!w) { 3751 if (!w) {
3512 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", 3752 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3513 dai->driver->capture.stream_name); 3753 dai->driver->capture.stream_name);
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index c9917ca5de1a..6fd1906af387 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -24,6 +24,12 @@
24 24
25#include <sound/dmaengine_pcm.h> 25#include <sound/dmaengine_pcm.h>
26 26
27/*
28 * The platforms dmaengine driver does not support reporting the amount of
29 * bytes that are still left to transfer.
30 */
31#define SND_DMAENGINE_PCM_FLAG_NO_RESIDUE BIT(31)
32
27struct dmaengine_pcm { 33struct dmaengine_pcm {
28 struct dma_chan *chan[SNDRV_PCM_STREAM_LAST + 1]; 34 struct dma_chan *chan[SNDRV_PCM_STREAM_LAST + 1];
29 const struct snd_dmaengine_pcm_config *config; 35 const struct snd_dmaengine_pcm_config *config;
@@ -222,14 +228,18 @@ static struct dma_chan *dmaengine_pcm_compat_request_channel(
222 return snd_dmaengine_pcm_request_channel(fn, dma_data->filter_data); 228 return snd_dmaengine_pcm_request_channel(fn, dma_data->filter_data);
223} 229}
224 230
225static bool dmaengine_pcm_can_report_residue(struct dma_chan *chan) 231static bool dmaengine_pcm_can_report_residue(struct device *dev,
232 struct dma_chan *chan)
226{ 233{
227 struct dma_slave_caps dma_caps; 234 struct dma_slave_caps dma_caps;
228 int ret; 235 int ret;
229 236
230 ret = dma_get_slave_caps(chan, &dma_caps); 237 ret = dma_get_slave_caps(chan, &dma_caps);
231 if (ret != 0) 238 if (ret != 0) {
232 return true; 239 dev_warn(dev, "Failed to get DMA channel capabilities, falling back to period counting: %d\n",
240 ret);
241 return false;
242 }
233 243
234 if (dma_caps.residue_granularity == DMA_RESIDUE_GRANULARITY_DESCRIPTOR) 244 if (dma_caps.residue_granularity == DMA_RESIDUE_GRANULARITY_DESCRIPTOR)
235 return false; 245 return false;
@@ -289,14 +299,7 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
289 if (ret) 299 if (ret)
290 return ret; 300 return ret;
291 301
292 /* 302 if (!dmaengine_pcm_can_report_residue(dev, pcm->chan[i]))
293 * This will only return false if we know for sure that at least
294 * one channel does not support residue reporting. If the DMA
295 * driver does not implement the slave_caps API we rely having
296 * the NO_RESIDUE flag set manually in case residue reporting is
297 * not supported.
298 */
299 if (!dmaengine_pcm_can_report_residue(pcm->chan[i]))
300 pcm->flags |= SND_DMAENGINE_PCM_FLAG_NO_RESIDUE; 303 pcm->flags |= SND_DMAENGINE_PCM_FLAG_NO_RESIDUE;
301 } 304 }
302 305
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 9f60c25c4568..171c4291ea21 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -315,8 +315,11 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
315 goto undo; 315 goto undo;
316 } 316 }
317 317
318 if (gpios[i].gpiod_dev) { 318 if (gpios[i].desc) {
319 /* GPIO descriptor */ 319 /* Already have a GPIO descriptor. */
320 goto got_gpio;
321 } else if (gpios[i].gpiod_dev) {
322 /* Get a GPIO descriptor */
320 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev, 323 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev,
321 gpios[i].name, 324 gpios[i].name,
322 gpios[i].idx, GPIOD_IN); 325 gpios[i].idx, GPIOD_IN);
@@ -344,7 +347,7 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
344 347
345 gpios[i].desc = gpio_to_desc(gpios[i].gpio); 348 gpios[i].desc = gpio_to_desc(gpios[i].gpio);
346 } 349 }
347 350got_gpio:
348 INIT_DELAYED_WORK(&gpios[i].work, gpio_work); 351 INIT_DELAYED_WORK(&gpios[i].work, gpio_work);
349 gpios[i].jack = jack; 352 gpios[i].jack = jack;
350 353
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 35fe58f4fa86..256b9c91aa94 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1485,30 +1485,67 @@ unwind:
1485} 1485}
1486 1486
1487static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime, 1487static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
1488 struct snd_soc_pcm_stream *stream) 1488 struct snd_soc_pcm_stream *stream,
1489 u64 formats)
1489{ 1490{
1490 runtime->hw.rate_min = stream->rate_min; 1491 runtime->hw.rate_min = stream->rate_min;
1491 runtime->hw.rate_max = stream->rate_max; 1492 runtime->hw.rate_max = stream->rate_max;
1492 runtime->hw.channels_min = stream->channels_min; 1493 runtime->hw.channels_min = stream->channels_min;
1493 runtime->hw.channels_max = stream->channels_max; 1494 runtime->hw.channels_max = stream->channels_max;
1494 if (runtime->hw.formats) 1495 if (runtime->hw.formats)
1495 runtime->hw.formats &= stream->formats; 1496 runtime->hw.formats &= formats & stream->formats;
1496 else 1497 else
1497 runtime->hw.formats = stream->formats; 1498 runtime->hw.formats = formats & stream->formats;
1498 runtime->hw.rates = stream->rates; 1499 runtime->hw.rates = stream->rates;
1499} 1500}
1500 1501
1502static u64 dpcm_runtime_base_format(struct snd_pcm_substream *substream)
1503{
1504 struct snd_soc_pcm_runtime *fe = substream->private_data;
1505 struct snd_soc_dpcm *dpcm;
1506 u64 formats = ULLONG_MAX;
1507 int stream = substream->stream;
1508
1509 if (!fe->dai_link->dpcm_merged_format)
1510 return formats;
1511
1512 /*
1513 * It returns merged BE codec format
1514 * if FE want to use it (= dpcm_merged_format)
1515 */
1516
1517 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1518 struct snd_soc_pcm_runtime *be = dpcm->be;
1519 struct snd_soc_dai_driver *codec_dai_drv;
1520 struct snd_soc_pcm_stream *codec_stream;
1521 int i;
1522
1523 for (i = 0; i < be->num_codecs; i++) {
1524 codec_dai_drv = be->codec_dais[i]->driver;
1525 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1526 codec_stream = &codec_dai_drv->playback;
1527 else
1528 codec_stream = &codec_dai_drv->capture;
1529
1530 formats &= codec_stream->formats;
1531 }
1532 }
1533
1534 return formats;
1535}
1536
1501static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) 1537static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
1502{ 1538{
1503 struct snd_pcm_runtime *runtime = substream->runtime; 1539 struct snd_pcm_runtime *runtime = substream->runtime;
1504 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1540 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1505 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1541 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1506 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver; 1542 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
1543 u64 format = dpcm_runtime_base_format(substream);
1507 1544
1508 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1545 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1509 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback); 1546 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback, format);
1510 else 1547 else
1511 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture); 1548 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture, format);
1512} 1549}
1513 1550
1514static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd); 1551static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);
diff --git a/sound/soc/ux500/mop500_ab8500.c b/sound/soc/ux500/mop500_ab8500.c
index b81a7a4c938b..85d810d7667c 100644
--- a/sound/soc/ux500/mop500_ab8500.c
+++ b/sound/soc/ux500/mop500_ab8500.c
@@ -372,6 +372,10 @@ int mop500_ab8500_machine_init(struct snd_soc_pcm_runtime *rtd)
372 /* Create driver private-data struct */ 372 /* Create driver private-data struct */
373 drvdata = devm_kzalloc(dev, sizeof(struct mop500_ab8500_drvdata), 373 drvdata = devm_kzalloc(dev, sizeof(struct mop500_ab8500_drvdata),
374 GFP_KERNEL); 374 GFP_KERNEL);
375
376 if (!drvdata)
377 return -ENOMEM;
378
375 snd_soc_card_set_drvdata(rtd->card, drvdata); 379 snd_soc_card_set_drvdata(rtd->card, drvdata);
376 380
377 /* Setup clocks */ 381 /* Setup clocks */
diff --git a/sound/soc/ux500/ux500_pcm.c b/sound/soc/ux500/ux500_pcm.c
index 51a66a87305a..f12c01dddc8d 100644
--- a/sound/soc/ux500/ux500_pcm.c
+++ b/sound/soc/ux500/ux500_pcm.c
@@ -147,7 +147,6 @@ int ux500_pcm_register_platform(struct platform_device *pdev)
147 pcm_config = &ux500_dmaengine_pcm_config; 147 pcm_config = &ux500_dmaengine_pcm_config;
148 148
149 ret = snd_dmaengine_pcm_register(&pdev->dev, pcm_config, 149 ret = snd_dmaengine_pcm_register(&pdev->dev, pcm_config,
150 SND_DMAENGINE_PCM_FLAG_NO_RESIDUE |
151 SND_DMAENGINE_PCM_FLAG_COMPAT); 150 SND_DMAENGINE_PCM_FLAG_COMPAT);
152 if (ret < 0) { 151 if (ret < 0) {
153 dev_err(&pdev->dev, 152 dev_err(&pdev->dev,
diff --git a/sound/synth/emux/emux_oss.c b/sound/synth/emux/emux_oss.c
index ab37add269ae..82e350e9501c 100644
--- a/sound/synth/emux/emux_oss.c
+++ b/sound/synth/emux/emux_oss.c
@@ -118,12 +118,8 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
118 if (snd_BUG_ON(!arg || !emu)) 118 if (snd_BUG_ON(!arg || !emu))
119 return -ENXIO; 119 return -ENXIO;
120 120
121 mutex_lock(&emu->register_mutex); 121 if (!snd_emux_inc_count(emu))
122
123 if (!snd_emux_inc_count(emu)) {
124 mutex_unlock(&emu->register_mutex);
125 return -EFAULT; 122 return -EFAULT;
126 }
127 123
128 memset(&callback, 0, sizeof(callback)); 124 memset(&callback, 0, sizeof(callback));
129 callback.owner = THIS_MODULE; 125 callback.owner = THIS_MODULE;
@@ -135,7 +131,6 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
135 if (p == NULL) { 131 if (p == NULL) {
136 snd_printk(KERN_ERR "can't create port\n"); 132 snd_printk(KERN_ERR "can't create port\n");
137 snd_emux_dec_count(emu); 133 snd_emux_dec_count(emu);
138 mutex_unlock(&emu->register_mutex);
139 return -ENOMEM; 134 return -ENOMEM;
140 } 135 }
141 136
@@ -148,8 +143,6 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
148 reset_port_mode(p, arg->seq_mode); 143 reset_port_mode(p, arg->seq_mode);
149 144
150 snd_emux_reset_port(p); 145 snd_emux_reset_port(p);
151
152 mutex_unlock(&emu->register_mutex);
153 return 0; 146 return 0;
154} 147}
155 148
@@ -195,13 +188,11 @@ snd_emux_close_seq_oss(struct snd_seq_oss_arg *arg)
195 if (snd_BUG_ON(!emu)) 188 if (snd_BUG_ON(!emu))
196 return -ENXIO; 189 return -ENXIO;
197 190
198 mutex_lock(&emu->register_mutex);
199 snd_emux_sounds_off_all(p); 191 snd_emux_sounds_off_all(p);
200 snd_soundfont_close_check(emu->sflist, SF_CLIENT_NO(p->chset.port)); 192 snd_soundfont_close_check(emu->sflist, SF_CLIENT_NO(p->chset.port));
201 snd_seq_event_port_detach(p->chset.client, p->chset.port); 193 snd_seq_event_port_detach(p->chset.client, p->chset.port);
202 snd_emux_dec_count(emu); 194 snd_emux_dec_count(emu);
203 195
204 mutex_unlock(&emu->register_mutex);
205 return 0; 196 return 0;
206} 197}
207 198
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index 7778b8e19782..a0209204ae48 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -124,12 +124,10 @@ snd_emux_detach_seq(struct snd_emux *emu)
124 if (emu->voices) 124 if (emu->voices)
125 snd_emux_terminate_all(emu); 125 snd_emux_terminate_all(emu);
126 126
127 mutex_lock(&emu->register_mutex);
128 if (emu->client >= 0) { 127 if (emu->client >= 0) {
129 snd_seq_delete_kernel_client(emu->client); 128 snd_seq_delete_kernel_client(emu->client);
130 emu->client = -1; 129 emu->client = -1;
131 } 130 }
132 mutex_unlock(&emu->register_mutex);
133} 131}
134 132
135 133
@@ -269,8 +267,8 @@ snd_emux_event_input(struct snd_seq_event *ev, int direct, void *private_data,
269/* 267/*
270 * increment usage count 268 * increment usage count
271 */ 269 */
272int 270static int
273snd_emux_inc_count(struct snd_emux *emu) 271__snd_emux_inc_count(struct snd_emux *emu)
274{ 272{
275 emu->used++; 273 emu->used++;
276 if (!try_module_get(emu->ops.owner)) 274 if (!try_module_get(emu->ops.owner))
@@ -284,12 +282,21 @@ snd_emux_inc_count(struct snd_emux *emu)
284 return 1; 282 return 1;
285} 283}
286 284
285int snd_emux_inc_count(struct snd_emux *emu)
286{
287 int ret;
288
289 mutex_lock(&emu->register_mutex);
290 ret = __snd_emux_inc_count(emu);
291 mutex_unlock(&emu->register_mutex);
292 return ret;
293}
287 294
288/* 295/*
289 * decrease usage count 296 * decrease usage count
290 */ 297 */
291void 298static void
292snd_emux_dec_count(struct snd_emux *emu) 299__snd_emux_dec_count(struct snd_emux *emu)
293{ 300{
294 module_put(emu->card->module); 301 module_put(emu->card->module);
295 emu->used--; 302 emu->used--;
@@ -298,6 +305,12 @@ snd_emux_dec_count(struct snd_emux *emu)
298 module_put(emu->ops.owner); 305 module_put(emu->ops.owner);
299} 306}
300 307
308void snd_emux_dec_count(struct snd_emux *emu)
309{
310 mutex_lock(&emu->register_mutex);
311 __snd_emux_dec_count(emu);
312 mutex_unlock(&emu->register_mutex);
313}
301 314
302/* 315/*
303 * Routine that is called upon a first use of a particular port 316 * Routine that is called upon a first use of a particular port
@@ -317,7 +330,7 @@ snd_emux_use(void *private_data, struct snd_seq_port_subscribe *info)
317 330
318 mutex_lock(&emu->register_mutex); 331 mutex_lock(&emu->register_mutex);
319 snd_emux_init_port(p); 332 snd_emux_init_port(p);
320 snd_emux_inc_count(emu); 333 __snd_emux_inc_count(emu);
321 mutex_unlock(&emu->register_mutex); 334 mutex_unlock(&emu->register_mutex);
322 return 0; 335 return 0;
323} 336}
@@ -340,7 +353,7 @@ snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *info)
340 353
341 mutex_lock(&emu->register_mutex); 354 mutex_lock(&emu->register_mutex);
342 snd_emux_sounds_off_all(p); 355 snd_emux_sounds_off_all(p);
343 snd_emux_dec_count(emu); 356 __snd_emux_dec_count(emu);
344 mutex_unlock(&emu->register_mutex); 357 mutex_unlock(&emu->register_mutex);
345 return 0; 358 return 0;
346} 359}
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 7c5a70139278..29175346cc4f 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1117,6 +1117,8 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1117 switch (chip->usb_id) { 1117 switch (chip->usb_id) {
1118 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */ 1118 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
1119 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */ 1119 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
1120 case USB_ID(0x045E, 0x0772): /* MS Lifecam Studio */
1121 case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */
1120 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ 1122 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1121 return true; 1123 return true;
1122 } 1124 }
diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index d8fe29fc19a4..8bd960658463 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -16,7 +16,7 @@ MAKEFLAGS += --no-print-directory
16LIBFILE = $(OUTPUT)libapi.a 16LIBFILE = $(OUTPUT)libapi.a
17 17
18CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 18CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
19CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 -fPIC 19CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC
20CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 20CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
21 21
22RM = rm -f 22RM = rm -f
diff --git a/tools/lib/lockdep/Makefile b/tools/lib/lockdep/Makefile
index 0c356fb65022..18ffccf00426 100644
--- a/tools/lib/lockdep/Makefile
+++ b/tools/lib/lockdep/Makefile
@@ -14,9 +14,10 @@ define allow-override
14 $(eval $(1) = $(2))) 14 $(eval $(1) = $(2)))
15endef 15endef
16 16
17# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. 17# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
18$(call allow-override,CC,$(CROSS_COMPILE)gcc) 18$(call allow-override,CC,$(CROSS_COMPILE)gcc)
19$(call allow-override,AR,$(CROSS_COMPILE)ar) 19$(call allow-override,AR,$(CROSS_COMPILE)ar)
20$(call allow-override,LD,$(CROSS_COMPILE)ld)
20 21
21INSTALL = install 22INSTALL = install
22 23
diff --git a/tools/lib/lockdep/uinclude/linux/kernel.h b/tools/lib/lockdep/uinclude/linux/kernel.h
index a11e3c357be7..cd2cc59a5da7 100644
--- a/tools/lib/lockdep/uinclude/linux/kernel.h
+++ b/tools/lib/lockdep/uinclude/linux/kernel.h
@@ -28,6 +28,9 @@
28#define __init 28#define __init
29#define noinline 29#define noinline
30#define list_add_tail_rcu list_add_tail 30#define list_add_tail_rcu list_add_tail
31#define list_for_each_entry_rcu list_for_each_entry
32#define barrier()
33#define synchronize_sched()
31 34
32#ifndef CALLER_ADDR0 35#ifndef CALLER_ADDR0
33#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) 36#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index e0917c0f5d9f..29f94f6f0d9e 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -3865,7 +3865,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3865 } else if (el_size == 4) { 3865 } else if (el_size == 4) {
3866 trace_seq_printf(s, "%u", *(uint32_t *)num); 3866 trace_seq_printf(s, "%u", *(uint32_t *)num);
3867 } else if (el_size == 8) { 3867 } else if (el_size == 8) {
3868 trace_seq_printf(s, "%lu", *(uint64_t *)num); 3868 trace_seq_printf(s, "%"PRIu64, *(uint64_t *)num);
3869 } else { 3869 } else {
3870 trace_seq_printf(s, "BAD SIZE:%d 0x%x", 3870 trace_seq_printf(s, "BAD SIZE:%d 0x%x",
3871 el_size, *(uint8_t *)num); 3871 el_size, *(uint8_t *)num);
diff --git a/tools/net/bpf_jit_disasm.c b/tools/net/bpf_jit_disasm.c
index c5baf9c591b7..618c2bcd4eab 100644
--- a/tools/net/bpf_jit_disasm.c
+++ b/tools/net/bpf_jit_disasm.c
@@ -123,6 +123,8 @@ static int get_last_jit_image(char *haystack, size_t hlen,
123 assert(ret == 0); 123 assert(ret == 0);
124 124
125 ptr = haystack; 125 ptr = haystack;
126 memset(pmatch, 0, sizeof(pmatch));
127
126 while (1) { 128 while (1) {
127 ret = regexec(&regex, ptr, 1, pmatch, 0); 129 ret = regexec(&regex, ptr, 1, pmatch, 0);
128 if (ret == 0) { 130 if (ret == 0) {
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index c699dc35eef9..d31a7bbd7cee 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -24,7 +24,7 @@ unexport MAKEFLAGS
24# (To override it, run 'make JOBS=1' and similar.) 24# (To override it, run 'make JOBS=1' and similar.)
25# 25#
26ifeq ($(JOBS),) 26ifeq ($(JOBS),)
27 JOBS := $(shell egrep -c '^processor|^CPU' /proc/cpuinfo 2>/dev/null) 27 JOBS := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null)
28 ifeq ($(JOBS),0) 28 ifeq ($(JOBS),0)
29 JOBS := 1 29 JOBS := 1
30 endif 30 endif
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index bedff6b5b3cf..ad0d9b5342fb 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -132,6 +132,9 @@ int bench_futex_requeue(int argc, const char **argv,
132 if (!fshared) 132 if (!fshared)
133 futex_flag = FUTEX_PRIVATE_FLAG; 133 futex_flag = FUTEX_PRIVATE_FLAG;
134 134
135 if (nrequeue > nthreads)
136 nrequeue = nthreads;
137
135 printf("Run summary [PID %d]: Requeuing %d threads (from [%s] %p to %p), " 138 printf("Run summary [PID %d]: Requeuing %d threads (from [%s] %p to %p), "
136 "%d at a time.\n\n", getpid(), nthreads, 139 "%d at a time.\n\n", getpid(), nthreads,
137 fshared ? "shared":"private", &futex1, &futex2, nrequeue); 140 fshared ? "shared":"private", &futex1, &futex2, nrequeue);
@@ -161,20 +164,18 @@ int bench_futex_requeue(int argc, const char **argv,
161 164
162 /* Ok, all threads are patiently blocked, start requeueing */ 165 /* Ok, all threads are patiently blocked, start requeueing */
163 gettimeofday(&start, NULL); 166 gettimeofday(&start, NULL);
164 for (nrequeued = 0; nrequeued < nthreads; nrequeued += nrequeue) { 167 while (nrequeued < nthreads) {
165 /* 168 /*
166 * Do not wakeup any tasks blocked on futex1, allowing 169 * Do not wakeup any tasks blocked on futex1, allowing
167 * us to really measure futex_wait functionality. 170 * us to really measure futex_wait functionality.
168 */ 171 */
169 futex_cmp_requeue(&futex1, 0, &futex2, 0, 172 nrequeued += futex_cmp_requeue(&futex1, 0, &futex2, 0,
170 nrequeue, futex_flag); 173 nrequeue, futex_flag);
171 } 174 }
175
172 gettimeofday(&end, NULL); 176 gettimeofday(&end, NULL);
173 timersub(&end, &start, &runtime); 177 timersub(&end, &start, &runtime);
174 178
175 if (nrequeued > nthreads)
176 nrequeued = nthreads;
177
178 update_stats(&requeued_stats, nrequeued); 179 update_stats(&requeued_stats, nrequeued);
179 update_stats(&requeuetime_stats, runtime.tv_usec); 180 update_stats(&requeuetime_stats, runtime.tv_usec);
180 181
@@ -184,7 +185,7 @@ int bench_futex_requeue(int argc, const char **argv,
184 } 185 }
185 186
186 /* everybody should be blocked on futex2, wake'em up */ 187 /* everybody should be blocked on futex2, wake'em up */
187 nrequeued = futex_wake(&futex2, nthreads, futex_flag); 188 nrequeued = futex_wake(&futex2, nrequeued, futex_flag);
188 if (nthreads != nrequeued) 189 if (nthreads != nrequeued)
189 warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads); 190 warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads);
190 191
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index ebfa163b80b5..ba5efa4710b5 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -180,7 +180,7 @@ static const struct option options[] = {
180 OPT_INTEGER('H', "thp" , &p0.thp, "MADV_NOHUGEPAGE < 0 < MADV_HUGEPAGE"), 180 OPT_INTEGER('H', "thp" , &p0.thp, "MADV_NOHUGEPAGE < 0 < MADV_HUGEPAGE"),
181 OPT_BOOLEAN('c', "show_convergence", &p0.show_convergence, "show convergence details"), 181 OPT_BOOLEAN('c', "show_convergence", &p0.show_convergence, "show convergence details"),
182 OPT_BOOLEAN('m', "measure_convergence", &p0.measure_convergence, "measure convergence latency"), 182 OPT_BOOLEAN('m', "measure_convergence", &p0.measure_convergence, "measure convergence latency"),
183 OPT_BOOLEAN('q', "quiet" , &p0.show_quiet, "bzero the initial allocations"), 183 OPT_BOOLEAN('q', "quiet" , &p0.show_quiet, "quiet mode"),
184 OPT_BOOLEAN('S', "serialize-startup", &p0.serialize_startup,"serialize thread startup"), 184 OPT_BOOLEAN('S', "serialize-startup", &p0.serialize_startup,"serialize thread startup"),
185 185
186 /* Special option string parsing callbacks: */ 186 /* Special option string parsing callbacks: */
@@ -828,6 +828,9 @@ static int count_process_nodes(int process_nr)
828 td = g->threads + task_nr; 828 td = g->threads + task_nr;
829 829
830 node = numa_node_of_cpu(td->curr_cpu); 830 node = numa_node_of_cpu(td->curr_cpu);
831 if (node < 0) /* curr_cpu was likely still -1 */
832 return 0;
833
831 node_present[node] = 1; 834 node_present[node] = 1;
832 } 835 }
833 836
@@ -882,6 +885,11 @@ static void calc_convergence_compression(int *strong)
882 for (p = 0; p < g->p.nr_proc; p++) { 885 for (p = 0; p < g->p.nr_proc; p++) {
883 unsigned int nodes = count_process_nodes(p); 886 unsigned int nodes = count_process_nodes(p);
884 887
888 if (!nodes) {
889 *strong = 0;
890 return;
891 }
892
885 nodes_min = min(nodes, nodes_min); 893 nodes_min = min(nodes, nodes_min);
886 nodes_max = max(nodes, nodes_max); 894 nodes_max = max(nodes, nodes_max);
887 } 895 }
@@ -1395,7 +1403,7 @@ static void print_res(const char *name, double val,
1395 if (!name) 1403 if (!name)
1396 name = "main,"; 1404 name = "main,";
1397 1405
1398 if (g->p.show_quiet) 1406 if (!g->p.show_quiet)
1399 printf(" %-30s %15.3f, %-15s %s\n", name, val, txt_unit, txt_short); 1407 printf(" %-30s %15.3f, %-15s %s\n", name, val, txt_unit, txt_short);
1400 else 1408 else
1401 printf(" %14.3f %s\n", val, txt_long); 1409 printf(" %14.3f %s\n", val, txt_long);
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 63ea01349b6e..1634186d537c 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -319,7 +319,7 @@ static int page_stat_cmp(struct page_stat *a, struct page_stat *b)
319 return 0; 319 return 0;
320} 320}
321 321
322static struct page_stat *search_page_alloc_stat(struct page_stat *stat, bool create) 322static struct page_stat *search_page_alloc_stat(struct page_stat *pstat, bool create)
323{ 323{
324 struct rb_node **node = &page_alloc_tree.rb_node; 324 struct rb_node **node = &page_alloc_tree.rb_node;
325 struct rb_node *parent = NULL; 325 struct rb_node *parent = NULL;
@@ -331,7 +331,7 @@ static struct page_stat *search_page_alloc_stat(struct page_stat *stat, bool cre
331 parent = *node; 331 parent = *node;
332 data = rb_entry(*node, struct page_stat, node); 332 data = rb_entry(*node, struct page_stat, node);
333 333
334 cmp = page_stat_cmp(data, stat); 334 cmp = page_stat_cmp(data, pstat);
335 if (cmp < 0) 335 if (cmp < 0)
336 node = &parent->rb_left; 336 node = &parent->rb_left;
337 else if (cmp > 0) 337 else if (cmp > 0)
@@ -345,10 +345,10 @@ static struct page_stat *search_page_alloc_stat(struct page_stat *stat, bool cre
345 345
346 data = zalloc(sizeof(*data)); 346 data = zalloc(sizeof(*data));
347 if (data != NULL) { 347 if (data != NULL) {
348 data->page = stat->page; 348 data->page = pstat->page;
349 data->order = stat->order; 349 data->order = pstat->order;
350 data->gfp_flags = stat->gfp_flags; 350 data->gfp_flags = pstat->gfp_flags;
351 data->migrate_type = stat->migrate_type; 351 data->migrate_type = pstat->migrate_type;
352 352
353 rb_link_node(&data->node, parent, node); 353 rb_link_node(&data->node, parent, node);
354 rb_insert_color(&data->node, &page_alloc_tree); 354 rb_insert_color(&data->node, &page_alloc_tree);
@@ -375,7 +375,7 @@ static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel,
375 unsigned int migrate_type = perf_evsel__intval(evsel, sample, 375 unsigned int migrate_type = perf_evsel__intval(evsel, sample,
376 "migratetype"); 376 "migratetype");
377 u64 bytes = kmem_page_size << order; 377 u64 bytes = kmem_page_size << order;
378 struct page_stat *stat; 378 struct page_stat *pstat;
379 struct page_stat this = { 379 struct page_stat this = {
380 .order = order, 380 .order = order,
381 .gfp_flags = gfp_flags, 381 .gfp_flags = gfp_flags,
@@ -401,21 +401,21 @@ static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel,
401 * This is to find the current page (with correct gfp flags and 401 * This is to find the current page (with correct gfp flags and
402 * migrate type) at free event. 402 * migrate type) at free event.
403 */ 403 */
404 stat = search_page(page, true); 404 pstat = search_page(page, true);
405 if (stat == NULL) 405 if (pstat == NULL)
406 return -ENOMEM; 406 return -ENOMEM;
407 407
408 stat->order = order; 408 pstat->order = order;
409 stat->gfp_flags = gfp_flags; 409 pstat->gfp_flags = gfp_flags;
410 stat->migrate_type = migrate_type; 410 pstat->migrate_type = migrate_type;
411 411
412 this.page = page; 412 this.page = page;
413 stat = search_page_alloc_stat(&this, true); 413 pstat = search_page_alloc_stat(&this, true);
414 if (stat == NULL) 414 if (pstat == NULL)
415 return -ENOMEM; 415 return -ENOMEM;
416 416
417 stat->nr_alloc++; 417 pstat->nr_alloc++;
418 stat->alloc_bytes += bytes; 418 pstat->alloc_bytes += bytes;
419 419
420 order_stats[order][migrate_type]++; 420 order_stats[order][migrate_type]++;
421 421
@@ -428,7 +428,7 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,
428 u64 page; 428 u64 page;
429 unsigned int order = perf_evsel__intval(evsel, sample, "order"); 429 unsigned int order = perf_evsel__intval(evsel, sample, "order");
430 u64 bytes = kmem_page_size << order; 430 u64 bytes = kmem_page_size << order;
431 struct page_stat *stat; 431 struct page_stat *pstat;
432 struct page_stat this = { 432 struct page_stat this = {
433 .order = order, 433 .order = order,
434 }; 434 };
@@ -441,8 +441,8 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,
441 nr_page_frees++; 441 nr_page_frees++;
442 total_page_free_bytes += bytes; 442 total_page_free_bytes += bytes;
443 443
444 stat = search_page(page, false); 444 pstat = search_page(page, false);
445 if (stat == NULL) { 445 if (pstat == NULL) {
446 pr_debug2("missing free at page %"PRIx64" (order: %d)\n", 446 pr_debug2("missing free at page %"PRIx64" (order: %d)\n",
447 page, order); 447 page, order);
448 448
@@ -453,18 +453,18 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,
453 } 453 }
454 454
455 this.page = page; 455 this.page = page;
456 this.gfp_flags = stat->gfp_flags; 456 this.gfp_flags = pstat->gfp_flags;
457 this.migrate_type = stat->migrate_type; 457 this.migrate_type = pstat->migrate_type;
458 458
459 rb_erase(&stat->node, &page_tree); 459 rb_erase(&pstat->node, &page_tree);
460 free(stat); 460 free(pstat);
461 461
462 stat = search_page_alloc_stat(&this, false); 462 pstat = search_page_alloc_stat(&this, false);
463 if (stat == NULL) 463 if (pstat == NULL)
464 return -ENOENT; 464 return -ENOENT;
465 465
466 stat->nr_free++; 466 pstat->nr_free++;
467 stat->free_bytes += bytes; 467 pstat->free_bytes += bytes;
468 468
469 return 0; 469 return 0;
470} 470}
@@ -640,9 +640,9 @@ static void print_page_summary(void)
640 nr_page_frees, total_page_free_bytes / 1024); 640 nr_page_frees, total_page_free_bytes / 1024);
641 printf("\n"); 641 printf("\n");
642 642
643 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total alloc+freed requests", 643 printf("%-30s: %'16"PRIu64" [ %'16"PRIu64" KB ]\n", "Total alloc+freed requests",
644 nr_alloc_freed, (total_alloc_freed_bytes) / 1024); 644 nr_alloc_freed, (total_alloc_freed_bytes) / 1024);
645 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total alloc-only requests", 645 printf("%-30s: %'16"PRIu64" [ %'16"PRIu64" KB ]\n", "Total alloc-only requests",
646 nr_page_allocs - nr_alloc_freed, 646 nr_page_allocs - nr_alloc_freed,
647 (total_page_alloc_bytes - total_alloc_freed_bytes) / 1024); 647 (total_page_alloc_bytes - total_alloc_freed_bytes) / 1024);
648 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total free-only requests", 648 printf("%-30s: %'16lu [ %'16"PRIu64" KB ]\n", "Total free-only requests",
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 476cdf7afcca..b63aeda719be 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -329,7 +329,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
329 fprintf(stdout, "\n\n"); 329 fprintf(stdout, "\n\n");
330 } 330 }
331 331
332 if (sort_order == default_sort_order && 332 if (sort_order == NULL &&
333 parent_pattern == default_parent_pattern) { 333 parent_pattern == default_parent_pattern) {
334 fprintf(stdout, "#\n# (%s)\n#\n", help); 334 fprintf(stdout, "#\n# (%s)\n#\n", help);
335 335
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1cb3436276d1..6a4d5d41c671 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -733,7 +733,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
733"Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n" 733"Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n"
734"Check /proc/sys/kernel/kptr_restrict.\n\n" 734"Check /proc/sys/kernel/kptr_restrict.\n\n"
735"Kernel%s samples will not be resolved.\n", 735"Kernel%s samples will not be resolved.\n",
736 !RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION]) ? 736 al.map && !RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION]) ?
737 " modules" : ""); 737 " modules" : "");
738 if (use_browser <= 0) 738 if (use_browser <= 0)
739 sleep(5); 739 sleep(5);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index e124741be187..e122970361f2 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2241,10 +2241,11 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
2241 if (err < 0) 2241 if (err < 0)
2242 goto out_error_mmap; 2242 goto out_error_mmap;
2243 2243
2244 if (!target__none(&trace->opts.target))
2245 perf_evlist__enable(evlist);
2246
2244 if (forks) 2247 if (forks)
2245 perf_evlist__start_workload(evlist); 2248 perf_evlist__start_workload(evlist);
2246 else
2247 perf_evlist__enable(evlist);
2248 2249
2249 trace->multiple_threads = evlist->threads->map[0] == -1 || 2250 trace->multiple_threads = evlist->threads->map[0] == -1 ||
2250 evlist->threads->nr > 1 || 2251 evlist->threads->nr > 1 ||
@@ -2272,6 +2273,11 @@ next_event:
2272 2273
2273 if (interrupted) 2274 if (interrupted)
2274 goto out_disable; 2275 goto out_disable;
2276
2277 if (done && !draining) {
2278 perf_evlist__disable(evlist);
2279 draining = true;
2280 }
2275 } 2281 }
2276 } 2282 }
2277 2283
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d8bb616ff57c..d05b77cf35f7 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1084,6 +1084,8 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
1084 * 1084 *
1085 * TODO:Group name support 1085 * TODO:Group name support
1086 */ 1086 */
1087 if (!arg)
1088 return -EINVAL;
1087 1089
1088 ptr = strpbrk(arg, ";=@+%"); 1090 ptr = strpbrk(arg, ";=@+%");
1089 if (ptr && *ptr == '=') { /* Event name */ 1091 if (ptr && *ptr == '=') { /* Event name */
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index b5bf9d5efeaf..2a76e14db732 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -578,10 +578,12 @@ static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
578 /* Search child die for local variables and parameters. */ 578 /* Search child die for local variables and parameters. */
579 if (!die_find_variable_at(sc_die, pf->pvar->var, pf->addr, &vr_die)) { 579 if (!die_find_variable_at(sc_die, pf->pvar->var, pf->addr, &vr_die)) {
580 /* Search again in global variables */ 580 /* Search again in global variables */
581 if (!die_find_variable_at(&pf->cu_die, pf->pvar->var, 0, &vr_die)) 581 if (!die_find_variable_at(&pf->cu_die, pf->pvar->var,
582 0, &vr_die)) {
582 pr_warning("Failed to find '%s' in this function.\n", 583 pr_warning("Failed to find '%s' in this function.\n",
583 pf->pvar->var); 584 pf->pvar->var);
584 ret = -ENOENT; 585 ret = -ENOENT;
586 }
585 } 587 }
586 if (ret >= 0) 588 if (ret >= 0)
587 ret = convert_variable(&vr_die, pf); 589 ret = convert_variable(&vr_die, pf);
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index bac98ca3d4ca..323b65edfc97 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -52,6 +52,7 @@ unsigned int skip_c0;
52unsigned int skip_c1; 52unsigned int skip_c1;
53unsigned int do_nhm_cstates; 53unsigned int do_nhm_cstates;
54unsigned int do_snb_cstates; 54unsigned int do_snb_cstates;
55unsigned int do_knl_cstates;
55unsigned int do_pc2; 56unsigned int do_pc2;
56unsigned int do_pc3; 57unsigned int do_pc3;
57unsigned int do_pc6; 58unsigned int do_pc6;
@@ -91,6 +92,7 @@ unsigned int do_gfx_perf_limit_reasons;
91unsigned int do_ring_perf_limit_reasons; 92unsigned int do_ring_perf_limit_reasons;
92unsigned int crystal_hz; 93unsigned int crystal_hz;
93unsigned long long tsc_hz; 94unsigned long long tsc_hz;
95int base_cpu;
94 96
95#define RAPL_PKG (1 << 0) 97#define RAPL_PKG (1 << 0)
96 /* 0x610 MSR_PKG_POWER_LIMIT */ 98 /* 0x610 MSR_PKG_POWER_LIMIT */
@@ -316,7 +318,7 @@ void print_header(void)
316 318
317 if (do_nhm_cstates) 319 if (do_nhm_cstates)
318 outp += sprintf(outp, " CPU%%c1"); 320 outp += sprintf(outp, " CPU%%c1");
319 if (do_nhm_cstates && !do_slm_cstates) 321 if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates)
320 outp += sprintf(outp, " CPU%%c3"); 322 outp += sprintf(outp, " CPU%%c3");
321 if (do_nhm_cstates) 323 if (do_nhm_cstates)
322 outp += sprintf(outp, " CPU%%c6"); 324 outp += sprintf(outp, " CPU%%c6");
@@ -546,7 +548,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
546 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 548 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
547 goto done; 549 goto done;
548 550
549 if (do_nhm_cstates && !do_slm_cstates) 551 if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates)
550 outp += sprintf(outp, "%8.2f", 100.0 * c->c3/t->tsc); 552 outp += sprintf(outp, "%8.2f", 100.0 * c->c3/t->tsc);
551 if (do_nhm_cstates) 553 if (do_nhm_cstates)
552 outp += sprintf(outp, "%8.2f", 100.0 * c->c6/t->tsc); 554 outp += sprintf(outp, "%8.2f", 100.0 * c->c6/t->tsc);
@@ -1018,14 +1020,17 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
1018 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 1020 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
1019 return 0; 1021 return 0;
1020 1022
1021 if (do_nhm_cstates && !do_slm_cstates) { 1023 if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates) {
1022 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) 1024 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3))
1023 return -6; 1025 return -6;
1024 } 1026 }
1025 1027
1026 if (do_nhm_cstates) { 1028 if (do_nhm_cstates && !do_knl_cstates) {
1027 if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) 1029 if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6))
1028 return -7; 1030 return -7;
1031 } else if (do_knl_cstates) {
1032 if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6))
1033 return -7;
1029 } 1034 }
1030 1035
1031 if (do_snb_cstates) 1036 if (do_snb_cstates)
@@ -1150,7 +1155,7 @@ dump_nhm_platform_info(void)
1150 unsigned long long msr; 1155 unsigned long long msr;
1151 unsigned int ratio; 1156 unsigned int ratio;
1152 1157
1153 get_msr(0, MSR_NHM_PLATFORM_INFO, &msr); 1158 get_msr(base_cpu, MSR_NHM_PLATFORM_INFO, &msr);
1154 1159
1155 fprintf(stderr, "cpu0: MSR_NHM_PLATFORM_INFO: 0x%08llx\n", msr); 1160 fprintf(stderr, "cpu0: MSR_NHM_PLATFORM_INFO: 0x%08llx\n", msr);
1156 1161
@@ -1162,7 +1167,7 @@ dump_nhm_platform_info(void)
1162 fprintf(stderr, "%d * %.0f = %.0f MHz base frequency\n", 1167 fprintf(stderr, "%d * %.0f = %.0f MHz base frequency\n",
1163 ratio, bclk, ratio * bclk); 1168 ratio, bclk, ratio * bclk);
1164 1169
1165 get_msr(0, MSR_IA32_POWER_CTL, &msr); 1170 get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr);
1166 fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", 1171 fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n",
1167 msr, msr & 0x2 ? "EN" : "DIS"); 1172 msr, msr & 0x2 ? "EN" : "DIS");
1168 1173
@@ -1175,7 +1180,7 @@ dump_hsw_turbo_ratio_limits(void)
1175 unsigned long long msr; 1180 unsigned long long msr;
1176 unsigned int ratio; 1181 unsigned int ratio;
1177 1182
1178 get_msr(0, MSR_TURBO_RATIO_LIMIT2, &msr); 1183 get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr);
1179 1184
1180 fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", msr); 1185 fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", msr);
1181 1186
@@ -1197,7 +1202,7 @@ dump_ivt_turbo_ratio_limits(void)
1197 unsigned long long msr; 1202 unsigned long long msr;
1198 unsigned int ratio; 1203 unsigned int ratio;
1199 1204
1200 get_msr(0, MSR_TURBO_RATIO_LIMIT1, &msr); 1205 get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr);
1201 1206
1202 fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", msr); 1207 fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", msr);
1203 1208
@@ -1249,7 +1254,7 @@ dump_nhm_turbo_ratio_limits(void)
1249 unsigned long long msr; 1254 unsigned long long msr;
1250 unsigned int ratio; 1255 unsigned int ratio;
1251 1256
1252 get_msr(0, MSR_TURBO_RATIO_LIMIT, &msr); 1257 get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr);
1253 1258
1254 fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", msr); 1259 fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", msr);
1255 1260
@@ -1296,11 +1301,72 @@ dump_nhm_turbo_ratio_limits(void)
1296} 1301}
1297 1302
1298static void 1303static void
1304dump_knl_turbo_ratio_limits(void)
1305{
1306 int cores;
1307 unsigned int ratio;
1308 unsigned long long msr;
1309 int delta_cores;
1310 int delta_ratio;
1311 int i;
1312
1313 get_msr(base_cpu, MSR_NHM_TURBO_RATIO_LIMIT, &msr);
1314
1315 fprintf(stderr, "cpu0: MSR_NHM_TURBO_RATIO_LIMIT: 0x%08llx\n",
1316 msr);
1317
1318 /**
1319 * Turbo encoding in KNL is as follows:
1320 * [7:0] -- Base value of number of active cores of bucket 1.
1321 * [15:8] -- Base value of freq ratio of bucket 1.
1322 * [20:16] -- +ve delta of number of active cores of bucket 2.
1323 * i.e. active cores of bucket 2 =
1324 * active cores of bucket 1 + delta
1325 * [23:21] -- Negative delta of freq ratio of bucket 2.
1326 * i.e. freq ratio of bucket 2 =
1327 * freq ratio of bucket 1 - delta
1328 * [28:24]-- +ve delta of number of active cores of bucket 3.
1329 * [31:29]-- -ve delta of freq ratio of bucket 3.
1330 * [36:32]-- +ve delta of number of active cores of bucket 4.
1331 * [39:37]-- -ve delta of freq ratio of bucket 4.
1332 * [44:40]-- +ve delta of number of active cores of bucket 5.
1333 * [47:45]-- -ve delta of freq ratio of bucket 5.
1334 * [52:48]-- +ve delta of number of active cores of bucket 6.
1335 * [55:53]-- -ve delta of freq ratio of bucket 6.
1336 * [60:56]-- +ve delta of number of active cores of bucket 7.
1337 * [63:61]-- -ve delta of freq ratio of bucket 7.
1338 */
1339 cores = msr & 0xFF;
1340 ratio = (msr >> 8) && 0xFF;
1341 if (ratio > 0)
1342 fprintf(stderr,
1343 "%d * %.0f = %.0f MHz max turbo %d active cores\n",
1344 ratio, bclk, ratio * bclk, cores);
1345
1346 for (i = 16; i < 64; i = i + 8) {
1347 delta_cores = (msr >> i) & 0x1F;
1348 delta_ratio = (msr >> (i + 5)) && 0x7;
1349 if (!delta_cores || !delta_ratio)
1350 return;
1351 cores = cores + delta_cores;
1352 ratio = ratio - delta_ratio;
1353
1354 /** -ve ratios will make successive ratio calculations
1355 * negative. Hence return instead of carrying on.
1356 */
1357 if (ratio > 0)
1358 fprintf(stderr,
1359 "%d * %.0f = %.0f MHz max turbo %d active cores\n",
1360 ratio, bclk, ratio * bclk, cores);
1361 }
1362}
1363
1364static void
1299dump_nhm_cst_cfg(void) 1365dump_nhm_cst_cfg(void)
1300{ 1366{
1301 unsigned long long msr; 1367 unsigned long long msr;
1302 1368
1303 get_msr(0, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); 1369 get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr);
1304 1370
1305#define SNB_C1_AUTO_UNDEMOTE (1UL << 27) 1371#define SNB_C1_AUTO_UNDEMOTE (1UL << 27)
1306#define SNB_C3_AUTO_UNDEMOTE (1UL << 28) 1372#define SNB_C3_AUTO_UNDEMOTE (1UL << 28)
@@ -1381,12 +1447,41 @@ int parse_int_file(const char *fmt, ...)
1381} 1447}
1382 1448
1383/* 1449/*
1384 * cpu_is_first_sibling_in_core(cpu) 1450 * get_cpu_position_in_core(cpu)
1385 * return 1 if given CPU is 1st HT sibling in the core 1451 * return the position of the CPU among its HT siblings in the core
1452 * return -1 if the sibling is not in list
1386 */ 1453 */
1387int cpu_is_first_sibling_in_core(int cpu) 1454int get_cpu_position_in_core(int cpu)
1388{ 1455{
1389 return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1456 char path[64];
1457 FILE *filep;
1458 int this_cpu;
1459 char character;
1460 int i;
1461
1462 sprintf(path,
1463 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list",
1464 cpu);
1465 filep = fopen(path, "r");
1466 if (filep == NULL) {
1467 perror(path);
1468 exit(1);
1469 }
1470
1471 for (i = 0; i < topo.num_threads_per_core; i++) {
1472 fscanf(filep, "%d", &this_cpu);
1473 if (this_cpu == cpu) {
1474 fclose(filep);
1475 return i;
1476 }
1477
1478 /* Account for no separator after last thread*/
1479 if (i != (topo.num_threads_per_core - 1))
1480 fscanf(filep, "%c", &character);
1481 }
1482
1483 fclose(filep);
1484 return -1;
1390} 1485}
1391 1486
1392/* 1487/*
@@ -1412,25 +1507,31 @@ int get_num_ht_siblings(int cpu)
1412{ 1507{
1413 char path[80]; 1508 char path[80];
1414 FILE *filep; 1509 FILE *filep;
1415 int sib1, sib2; 1510 int sib1;
1416 int matches; 1511 int matches = 0;
1417 char character; 1512 char character;
1513 char str[100];
1514 char *ch;
1418 1515
1419 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1516 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
1420 filep = fopen_or_die(path, "r"); 1517 filep = fopen_or_die(path, "r");
1518
1421 /* 1519 /*
1422 * file format: 1520 * file format:
1423 * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4) 1521 * A ',' separated or '-' separated set of numbers
1424 * otherwinse 1 sibling (self). 1522 * (eg 1-2 or 1,3,4,5)
1425 */ 1523 */
1426 matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2); 1524 fscanf(filep, "%d%c\n", &sib1, &character);
1525 fseek(filep, 0, SEEK_SET);
1526 fgets(str, 100, filep);
1527 ch = strchr(str, character);
1528 while (ch != NULL) {
1529 matches++;
1530 ch = strchr(ch+1, character);
1531 }
1427 1532
1428 fclose(filep); 1533 fclose(filep);
1429 1534 return matches+1;
1430 if (matches == 3)
1431 return 2;
1432 else
1433 return 1;
1434} 1535}
1435 1536
1436/* 1537/*
@@ -1594,8 +1695,10 @@ restart:
1594void check_dev_msr() 1695void check_dev_msr()
1595{ 1696{
1596 struct stat sb; 1697 struct stat sb;
1698 char pathname[32];
1597 1699
1598 if (stat("/dev/cpu/0/msr", &sb)) 1700 sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
1701 if (stat(pathname, &sb))
1599 if (system("/sbin/modprobe msr > /dev/null 2>&1")) 1702 if (system("/sbin/modprobe msr > /dev/null 2>&1"))
1600 err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); 1703 err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" ");
1601} 1704}
@@ -1608,6 +1711,7 @@ void check_permissions()
1608 cap_user_data_t cap_data = &cap_data_data; 1711 cap_user_data_t cap_data = &cap_data_data;
1609 extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); 1712 extern int capget(cap_user_header_t hdrp, cap_user_data_t datap);
1610 int do_exit = 0; 1713 int do_exit = 0;
1714 char pathname[32];
1611 1715
1612 /* check for CAP_SYS_RAWIO */ 1716 /* check for CAP_SYS_RAWIO */
1613 cap_header->pid = getpid(); 1717 cap_header->pid = getpid();
@@ -1622,7 +1726,8 @@ void check_permissions()
1622 } 1726 }
1623 1727
1624 /* test file permissions */ 1728 /* test file permissions */
1625 if (euidaccess("/dev/cpu/0/msr", R_OK)) { 1729 sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
1730 if (euidaccess(pathname, R_OK)) {
1626 do_exit++; 1731 do_exit++;
1627 warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); 1732 warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr");
1628 } 1733 }
@@ -1704,7 +1809,7 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
1704 default: 1809 default:
1705 return 0; 1810 return 0;
1706 } 1811 }
1707 get_msr(0, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); 1812 get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr);
1708 1813
1709 pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; 1814 pkg_cstate_limit = pkg_cstate_limits[msr & 0xF];
1710 1815
@@ -1753,6 +1858,21 @@ int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model)
1753 } 1858 }
1754} 1859}
1755 1860
1861int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model)
1862{
1863 if (!genuine_intel)
1864 return 0;
1865
1866 if (family != 6)
1867 return 0;
1868
1869 switch (model) {
1870 case 0x57: /* Knights Landing */
1871 return 1;
1872 default:
1873 return 0;
1874 }
1875}
1756static void 1876static void
1757dump_cstate_pstate_config_info(family, model) 1877dump_cstate_pstate_config_info(family, model)
1758{ 1878{
@@ -1770,6 +1890,9 @@ dump_cstate_pstate_config_info(family, model)
1770 if (has_nhm_turbo_ratio_limit(family, model)) 1890 if (has_nhm_turbo_ratio_limit(family, model))
1771 dump_nhm_turbo_ratio_limits(); 1891 dump_nhm_turbo_ratio_limits();
1772 1892
1893 if (has_knl_turbo_ratio_limit(family, model))
1894 dump_knl_turbo_ratio_limits();
1895
1773 dump_nhm_cst_cfg(); 1896 dump_nhm_cst_cfg();
1774} 1897}
1775 1898
@@ -1801,7 +1924,7 @@ int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p)
1801 if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) 1924 if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr))
1802 return 0; 1925 return 0;
1803 1926
1804 switch (msr & 0x7) { 1927 switch (msr & 0xF) {
1805 case ENERGY_PERF_BIAS_PERFORMANCE: 1928 case ENERGY_PERF_BIAS_PERFORMANCE:
1806 epb_string = "performance"; 1929 epb_string = "performance";
1807 break; 1930 break;
@@ -1925,7 +2048,7 @@ double get_tdp(model)
1925 unsigned long long msr; 2048 unsigned long long msr;
1926 2049
1927 if (do_rapl & RAPL_PKG_POWER_INFO) 2050 if (do_rapl & RAPL_PKG_POWER_INFO)
1928 if (!get_msr(0, MSR_PKG_POWER_INFO, &msr)) 2051 if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr))
1929 return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; 2052 return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units;
1930 2053
1931 switch (model) { 2054 switch (model) {
@@ -1950,6 +2073,7 @@ rapl_dram_energy_units_probe(int model, double rapl_energy_units)
1950 case 0x3F: /* HSX */ 2073 case 0x3F: /* HSX */
1951 case 0x4F: /* BDX */ 2074 case 0x4F: /* BDX */
1952 case 0x56: /* BDX-DE */ 2075 case 0x56: /* BDX-DE */
2076 case 0x57: /* KNL */
1953 return (rapl_dram_energy_units = 15.3 / 1000000); 2077 return (rapl_dram_energy_units = 15.3 / 1000000);
1954 default: 2078 default:
1955 return (rapl_energy_units); 2079 return (rapl_energy_units);
@@ -1991,6 +2115,7 @@ void rapl_probe(unsigned int family, unsigned int model)
1991 case 0x3F: /* HSX */ 2115 case 0x3F: /* HSX */
1992 case 0x4F: /* BDX */ 2116 case 0x4F: /* BDX */
1993 case 0x56: /* BDX-DE */ 2117 case 0x56: /* BDX-DE */
2118 case 0x57: /* KNL */
1994 do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; 2119 do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO;
1995 break; 2120 break;
1996 case 0x2D: 2121 case 0x2D:
@@ -2006,7 +2131,7 @@ void rapl_probe(unsigned int family, unsigned int model)
2006 } 2131 }
2007 2132
2008 /* units on package 0, verify later other packages match */ 2133 /* units on package 0, verify later other packages match */
2009 if (get_msr(0, MSR_RAPL_POWER_UNIT, &msr)) 2134 if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr))
2010 return; 2135 return;
2011 2136
2012 rapl_power_units = 1.0 / (1 << (msr & 0xF)); 2137 rapl_power_units = 1.0 / (1 << (msr & 0xF));
@@ -2331,6 +2456,17 @@ int is_slm(unsigned int family, unsigned int model)
2331 return 0; 2456 return 0;
2332} 2457}
2333 2458
2459int is_knl(unsigned int family, unsigned int model)
2460{
2461 if (!genuine_intel)
2462 return 0;
2463 switch (model) {
2464 case 0x57: /* KNL */
2465 return 1;
2466 }
2467 return 0;
2468}
2469
2334#define SLM_BCLK_FREQS 5 2470#define SLM_BCLK_FREQS 5
2335double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; 2471double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0};
2336 2472
@@ -2340,7 +2476,7 @@ double slm_bclk(void)
2340 unsigned int i; 2476 unsigned int i;
2341 double freq; 2477 double freq;
2342 2478
2343 if (get_msr(0, MSR_FSB_FREQ, &msr)) 2479 if (get_msr(base_cpu, MSR_FSB_FREQ, &msr))
2344 fprintf(stderr, "SLM BCLK: unknown\n"); 2480 fprintf(stderr, "SLM BCLK: unknown\n");
2345 2481
2346 i = msr & 0xf; 2482 i = msr & 0xf;
@@ -2408,7 +2544,7 @@ int set_temperature_target(struct thread_data *t, struct core_data *c, struct pk
2408 if (!do_nhm_platform_info) 2544 if (!do_nhm_platform_info)
2409 goto guess; 2545 goto guess;
2410 2546
2411 if (get_msr(0, MSR_IA32_TEMPERATURE_TARGET, &msr)) 2547 if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr))
2412 goto guess; 2548 goto guess;
2413 2549
2414 target_c_local = (msr >> 16) & 0xFF; 2550 target_c_local = (msr >> 16) & 0xFF;
@@ -2541,6 +2677,7 @@ void process_cpuid()
2541 do_c8_c9_c10 = has_hsw_msrs(family, model); 2677 do_c8_c9_c10 = has_hsw_msrs(family, model);
2542 do_skl_residency = has_skl_msrs(family, model); 2678 do_skl_residency = has_skl_msrs(family, model);
2543 do_slm_cstates = is_slm(family, model); 2679 do_slm_cstates = is_slm(family, model);
2680 do_knl_cstates = is_knl(family, model);
2544 bclk = discover_bclk(family, model); 2681 bclk = discover_bclk(family, model);
2545 2682
2546 rapl_probe(family, model); 2683 rapl_probe(family, model);
@@ -2755,13 +2892,9 @@ int initialize_counters(int cpu_id)
2755 2892
2756 my_package_id = get_physical_package_id(cpu_id); 2893 my_package_id = get_physical_package_id(cpu_id);
2757 my_core_id = get_core_id(cpu_id); 2894 my_core_id = get_core_id(cpu_id);
2758 2895 my_thread_id = get_cpu_position_in_core(cpu_id);
2759 if (cpu_is_first_sibling_in_core(cpu_id)) { 2896 if (!my_thread_id)
2760 my_thread_id = 0;
2761 topo.num_cores++; 2897 topo.num_cores++;
2762 } else {
2763 my_thread_id = 1;
2764 }
2765 2898
2766 init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); 2899 init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id);
2767 init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); 2900 init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id);
@@ -2785,13 +2918,24 @@ void setup_all_buffers(void)
2785 for_all_proc_cpus(initialize_counters); 2918 for_all_proc_cpus(initialize_counters);
2786} 2919}
2787 2920
2921void set_base_cpu(void)
2922{
2923 base_cpu = sched_getcpu();
2924 if (base_cpu < 0)
2925 err(-ENODEV, "No valid cpus found");
2926
2927 if (debug > 1)
2928 fprintf(stderr, "base_cpu = %d\n", base_cpu);
2929}
2930
2788void turbostat_init() 2931void turbostat_init()
2789{ 2932{
2933 setup_all_buffers();
2934 set_base_cpu();
2790 check_dev_msr(); 2935 check_dev_msr();
2791 check_permissions(); 2936 check_permissions();
2792 process_cpuid(); 2937 process_cpuid();
2793 2938
2794 setup_all_buffers();
2795 2939
2796 if (debug) 2940 if (debug)
2797 for_all_cpus(print_epb, ODD_COUNTERS); 2941 for_all_cpus(print_epb, ODD_COUNTERS);
@@ -2870,7 +3014,7 @@ int get_and_dump_counters(void)
2870} 3014}
2871 3015
2872void print_version() { 3016void print_version() {
2873 fprintf(stderr, "turbostat version 4.5 2 Apr, 2015" 3017 fprintf(stderr, "turbostat version 4.7 27-May, 2015"
2874 " - Len Brown <lenb@kernel.org>\n"); 3018 " - Len Brown <lenb@kernel.org>\n");
2875} 3019}
2876 3020
diff --git a/tools/testing/selftests/powerpc/pmu/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile
index 5a161175bbd4..a9099d9f8f39 100644
--- a/tools/testing/selftests/powerpc/pmu/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -26,7 +26,7 @@ override define EMIT_TESTS
26 $(MAKE) -s -C ebb emit_tests 26 $(MAKE) -s -C ebb emit_tests
27endef 27endef
28 28
29DEFAULT_INSTALL := $(INSTALL_RULE) 29DEFAULT_INSTALL_RULE := $(INSTALL_RULE)
30override define INSTALL_RULE 30override define INSTALL_RULE
31 $(DEFAULT_INSTALL_RULE) 31 $(DEFAULT_INSTALL_RULE)
32 $(MAKE) -C ebb install 32 $(MAKE) -C ebb install
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 1b616fa79e93..6bff955e1d55 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
1TEST_PROGS := tm-resched-dscr tm-syscall 1TEST_PROGS := tm-resched-dscr
2 2
3all: $(TEST_PROGS) 3all: $(TEST_PROGS)
4 4
diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile
index ddf63569df5a..5bdb781163d1 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -1,4 +1,8 @@
1.PHONY: all all_32 all_64 check_build32 clean run_tests 1all:
2
3include ../lib.mk
4
5.PHONY: all all_32 all_64 warn_32bit_failure clean
2 6
3TARGETS_C_BOTHBITS := sigreturn single_step_syscall 7TARGETS_C_BOTHBITS := sigreturn single_step_syscall
4 8
@@ -7,42 +11,47 @@ BINARIES_64 := $(TARGETS_C_BOTHBITS:%=%_64)
7 11
8CFLAGS := -O2 -g -std=gnu99 -pthread -Wall 12CFLAGS := -O2 -g -std=gnu99 -pthread -Wall
9 13
10UNAME_P := $(shell uname -p) 14UNAME_M := $(shell uname -m)
15CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
16CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
11 17
12# Always build 32-bit tests 18ifeq ($(CAN_BUILD_I386),1)
13all: all_32 19all: all_32
20TEST_PROGS += $(BINARIES_32)
21endif
14 22
15# If we're on a 64-bit host, build 64-bit tests as well 23ifeq ($(CAN_BUILD_X86_64),1)
16ifeq ($(shell uname -p),x86_64)
17all: all_64 24all: all_64
25TEST_PROGS += $(BINARIES_64)
18endif 26endif
19 27
20all_32: check_build32 $(BINARIES_32) 28all_32: $(BINARIES_32)
21 29
22all_64: $(BINARIES_64) 30all_64: $(BINARIES_64)
23 31
24clean: 32clean:
25 $(RM) $(BINARIES_32) $(BINARIES_64) 33 $(RM) $(BINARIES_32) $(BINARIES_64)
26 34
27run_tests:
28 ./run_x86_tests.sh
29
30$(TARGETS_C_BOTHBITS:%=%_32): %_32: %.c 35$(TARGETS_C_BOTHBITS:%=%_32): %_32: %.c
31 $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl 36 $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
32 37
33$(TARGETS_C_BOTHBITS:%=%_64): %_64: %.c 38$(TARGETS_C_BOTHBITS:%=%_64): %_64: %.c
34 $(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl 39 $(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
35 40
36check_build32: 41# x86_64 users should be encouraged to install 32-bit libraries
37 @if ! $(CC) -m32 -o /dev/null trivial_32bit_program.c; then \ 42ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
38 echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ 43all: warn_32bit_failure
39 echo "environment. If you are using a Debian-like"; \ 44
40 echo " distribution, try:"; \ 45warn_32bit_failure:
41 echo ""; \ 46 @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \
42 echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ 47 echo "environment. This will reduce test coverage of 64-bit" 2>&1; \
43 echo ""; \ 48 echo "kernels. If you are using a Debian-like distribution," 2>&1; \
44 echo "If you are using a Fedora-like distribution, try:"; \ 49 echo "try:"; 2>&1; \
45 echo ""; \ 50 echo ""; \
46 echo " yum install glibc-devel.*i686"; \ 51 echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
47 exit 1; \ 52 echo ""; \
48 fi 53 echo "If you are using a Fedora-like distribution, try:"; \
54 echo ""; \
55 echo " yum install glibc-devel.*i686"; \
56 exit 0;
57endif
diff --git a/tools/testing/selftests/x86/check_cc.sh b/tools/testing/selftests/x86/check_cc.sh
new file mode 100755
index 000000000000..172d3293fb7b
--- /dev/null
+++ b/tools/testing/selftests/x86/check_cc.sh
@@ -0,0 +1,16 @@
1#!/bin/sh
2# check_cc.sh - Helper to test userspace compilation support
3# Copyright (c) 2015 Andrew Lutomirski
4# GPL v2
5
6CC="$1"
7TESTPROG="$2"
8shift 2
9
10if "$CC" -o /dev/null "$TESTPROG" -O0 "$@" 2>/dev/null; then
11 echo 1
12else
13 echo 0
14fi
15
16exit 0
diff --git a/tools/testing/selftests/x86/run_x86_tests.sh b/tools/testing/selftests/x86/run_x86_tests.sh
deleted file mode 100644
index 3fc19b376812..000000000000
--- a/tools/testing/selftests/x86/run_x86_tests.sh
+++ /dev/null
@@ -1,13 +0,0 @@
1#!/bin/bash
2
3# This is deliberately minimal. IMO kselftests should provide a standard
4# script here.
5./sigreturn_32 || exit 1
6./single_step_syscall_32 || exit 1
7
8if [[ "$uname -p" -eq "x86_64" ]]; then
9 ./sigreturn_64 || exit 1
10 ./single_step_syscall_64 || exit 1
11fi
12
13exit 0
diff --git a/tools/testing/selftests/x86/trivial_32bit_program.c b/tools/testing/selftests/x86/trivial_32bit_program.c
index 2e231beb0a39..fabdf0f51621 100644
--- a/tools/testing/selftests/x86/trivial_32bit_program.c
+++ b/tools/testing/selftests/x86/trivial_32bit_program.c
@@ -4,6 +4,10 @@
4 * GPL v2 4 * GPL v2
5 */ 5 */
6 6
7#ifndef __i386__
8# error wrong architecture
9#endif
10
7#include <stdio.h> 11#include <stdio.h>
8 12
9int main() 13int main()
diff --git a/tools/testing/selftests/x86/trivial_64bit_program.c b/tools/testing/selftests/x86/trivial_64bit_program.c
new file mode 100644
index 000000000000..b994946c40fb
--- /dev/null
+++ b/tools/testing/selftests/x86/trivial_64bit_program.c
@@ -0,0 +1,18 @@
1/*
2 * Trivial program to check that we have a valid 32-bit build environment.
3 * Copyright (c) 2015 Andy Lutomirski
4 * GPL v2
5 */
6
7#ifndef __x86_64__
8# error wrong architecture
9#endif
10
11#include <stdio.h>
12
13int main()
14{
15 printf("\n");
16
17 return 0;
18}
diff --git a/tools/thermal/tmon/Makefile b/tools/thermal/tmon/Makefile
index 0788621c8d76..2e83dd3655a2 100644
--- a/tools/thermal/tmon/Makefile
+++ b/tools/thermal/tmon/Makefile
@@ -12,10 +12,6 @@ TARGET=tmon
12INSTALL_PROGRAM=install -m 755 -p 12INSTALL_PROGRAM=install -m 755 -p
13DEL_FILE=rm -f 13DEL_FILE=rm -f
14 14
15INSTALL_CONFIGFILE=install -m 644 -p
16CONFIG_FILE=
17CONFIG_PATH=
18
19# Static builds might require -ltinfo, for instance 15# Static builds might require -ltinfo, for instance
20ifneq ($(findstring -static, $(LDFLAGS)),) 16ifneq ($(findstring -static, $(LDFLAGS)),)
21STATIC := --static 17STATIC := --static
@@ -38,13 +34,9 @@ valgrind: tmon
38install: 34install:
39 - mkdir -p $(INSTALL_ROOT)/$(BINDIR) 35 - mkdir -p $(INSTALL_ROOT)/$(BINDIR)
40 - $(INSTALL_PROGRAM) "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" 36 - $(INSTALL_PROGRAM) "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)"
41 - mkdir -p $(INSTALL_ROOT)/$(CONFIG_PATH)
42 - $(INSTALL_CONFIGFILE) "$(CONFIG_FILE)" "$(INSTALL_ROOT)/$(CONFIG_PATH)"
43 37
44uninstall: 38uninstall:
45 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" 39 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)"
46 $(CONFIG_FILE) "$(CONFIG_PATH)"
47
48 40
49clean: 41clean:
50 find . -name "*.o" | xargs $(DEL_FILE) 42 find . -name "*.o" | xargs $(DEL_FILE)
diff --git a/tools/vm/Makefile b/tools/vm/Makefile
index ac884b65a072..93aadaf7ff63 100644
--- a/tools/vm/Makefile
+++ b/tools/vm/Makefile
@@ -3,7 +3,7 @@
3TARGETS=page-types slabinfo page_owner_sort 3TARGETS=page-types slabinfo page_owner_sort
4 4
5LIB_DIR = ../lib/api 5LIB_DIR = ../lib/api
6LIBS = $(LIB_DIR)/libapikfs.a 6LIBS = $(LIB_DIR)/libapi.a
7 7
8CC = $(CROSS_COMPILE)gcc 8CC = $(CROSS_COMPILE)gcc
9CFLAGS = -Wall -Wextra -I../lib/ 9CFLAGS = -Wall -Wextra -I../lib/