summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS5
-rw-r--r--Documentation/ABI/testing/sysfs-kernel-slab4
-rw-r--r--Documentation/cgroups/memory.txt9
-rw-r--r--Documentation/devicetree/bindings/mfd/mc13xxx.txt78
-rw-r--r--Documentation/devicetree/bindings/mfd/twl-familly.txt47
-rw-r--r--Documentation/dma-buf-sharing.txt4
-rw-r--r--Documentation/filesystems/ceph.txt18
-rw-r--r--Documentation/filesystems/nfs/00-INDEX2
-rw-r--r--Documentation/filesystems/nfs/fault_injection.txt69
-rw-r--r--Documentation/filesystems/proc.txt3
-rw-r--r--Documentation/filesystems/squashfs.txt6
-rw-r--r--Documentation/mmc/mmc-dev-attrs.txt10
-rw-r--r--Documentation/mmc/mmc-dev-parts.txt13
-rw-r--r--Documentation/sysctl/kernel.txt8
-rw-r--r--Documentation/vm/slub.txt5
-rw-r--r--MAINTAINERS5
-rw-r--r--arch/Kconfig14
-rw-r--r--arch/arm/mach-sa1100/assabet.c12
-rw-r--r--arch/arm/mach-sa1100/cerf.c11
-rw-r--r--arch/arm/mach-sa1100/collie.c18
-rw-r--r--arch/arm/mach-sa1100/generic.c7
-rw-r--r--arch/arm/mach-sa1100/include/mach/mcp.h2
-rw-r--r--arch/arm/mach-sa1100/lart.c10
-rw-r--r--arch/arm/mach-sa1100/shannon.c11
-rw-r--r--arch/arm/mach-sa1100/simpad.c18
-rw-r--r--arch/arm/mach-ux500/board-mop500.c4
-rw-r--r--arch/arm/mach-ux500/board-u5500.c2
-rw-r--r--arch/arm/mach-ux500/include/mach/irqs-board-mop500.h2
-rw-r--r--arch/arm/plat-samsung/include/plat/sdhci.h1
-rw-r--r--arch/arm/plat-samsung/platformdata.c2
-rw-r--r--arch/avr32/include/asm/system.h2
-rw-r--r--arch/avr32/kernel/traps.c2
-rw-r--r--arch/ia64/include/asm/processor.h1
-rw-r--r--arch/ia64/include/asm/unistd.h3
-rw-r--r--arch/ia64/kernel/entry.S1
-rw-r--r--arch/ia64/kernel/machine_kexec.c4
-rw-r--r--arch/m68k/amiga/config.c3
-rw-r--r--arch/mips/include/asm/ptrace.h2
-rw-r--r--arch/mips/kernel/traps.c2
-rw-r--r--arch/mn10300/include/asm/exceptions.h2
-rw-r--r--arch/parisc/include/asm/processor.h2
-rw-r--r--arch/parisc/kernel/process.c1
-rw-r--r--arch/powerpc/kernel/idle.c12
-rw-r--r--arch/powerpc/kernel/machine_kexec_32.c4
-rw-r--r--arch/powerpc/kernel/machine_kexec_64.c6
-rw-r--r--arch/powerpc/mm/numa.c2
-rw-r--r--arch/powerpc/platforms/pseries/hvCall.S3
-rw-r--r--arch/powerpc/platforms/pseries/lpar.c14
-rw-r--r--arch/powerpc/platforms/pseries/nvram.c1
-rw-r--r--arch/s390/include/asm/processor.h2
-rw-r--r--arch/s390/kernel/nmi.c2
-rw-r--r--arch/sh/kernel/process_32.c2
-rw-r--r--arch/sh/kernel/process_64.c2
-rw-r--r--arch/tile/kernel/machine_kexec.c6
-rw-r--r--arch/x86/Kconfig3
-rw-r--r--arch/x86/Kconfig.cpu6
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c2
-rw-r--r--arch/x86/mm/numa.c2
-rw-r--r--arch/x86/um/Kconfig8
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/base/Kconfig2
-rw-r--r--drivers/base/memory.c17
-rw-r--r--drivers/block/rbd.c2
-rw-r--r--drivers/char/ramoops.c24
-rw-r--r--drivers/gpio/gpio-stmpe.c25
-rw-r--r--drivers/gpu/drm/gma500/cdv_intel_crt.c6
-rw-r--r--drivers/gpu/drm/gma500/cdv_intel_hdmi.c14
-rw-r--r--drivers/gpu/drm/gma500/oaktrail_hdmi.c6
-rw-r--r--drivers/gpu/drm/gma500/psb_intel_sdvo.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_acpi.c79
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_state.c1
-rw-r--r--drivers/gpu/drm/radeon/evergreen_cs.c3
-rw-r--r--drivers/gpu/drm/radeon/r100.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c2
-rw-r--r--drivers/gpu/drm/radeon/rs600.c13
-rw-r--r--drivers/gpu/drm/ttm/ttm_page_alloc_dma.c5
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c38
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-at91.c17
-rw-r--r--drivers/i2c/busses/i2c-au1550.c13
-rw-r--r--drivers/i2c/busses/i2c-cpm.c13
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c2
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c2
-rw-r--r--drivers/i2c/busses/i2c-highlander.c13
-rw-r--r--drivers/i2c/busses/i2c-hydra.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c13
-rw-r--r--drivers/i2c/busses/i2c-intel-mid.c2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c16
-rw-r--r--drivers/i2c/busses/i2c-isch.c13
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c13
-rw-r--r--drivers/i2c/busses/i2c-mpc.c13
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c15
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c4
-rw-r--r--drivers/i2c/busses/i2c-ocores.c17
-rw-r--r--drivers/i2c/busses/i2c-octeon.c16
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c14
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c17
-rw-r--r--drivers/i2c/busses/i2c-powermac.c19
-rw-r--r--drivers/i2c/busses/i2c-pxa-pci.c2
-rw-r--r--drivers/i2c/busses/i2c-sh7760.c13
-rw-r--r--drivers/i2c/busses/i2c-simtec.c18
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c6
-rw-r--r--drivers/i2c/busses/i2c-sis630.c8
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-via.c2
-rw-r--r--drivers/i2c/busses/i2c-viapro.c9
-rw-r--r--drivers/i2c/busses/i2c-xiic.c18
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/i2c-dev.c13
-rw-r--r--drivers/i2c/muxes/gpio-i2cmux.c13
-rw-r--r--drivers/input/misc/ab8500-ponkey.c2
-rw-r--r--drivers/isdn/i4l/Kconfig2
-rw-r--r--drivers/leds/Kconfig7
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/leds-max8997.c372
-rw-r--r--drivers/mfd/88pm860x-i2c.c241
-rw-r--r--drivers/mfd/Kconfig35
-rw-r--r--drivers/mfd/Makefile3
-rw-r--r--drivers/mfd/aat2870-core.c25
-rw-r--r--drivers/mfd/ab5500-core.c2
-rw-r--r--drivers/mfd/ab5500-debugfs.c2
-rw-r--r--drivers/mfd/ab8500-core.c2
-rw-r--r--drivers/mfd/ab8500-debugfs.c2
-rw-r--r--drivers/mfd/ab8500-gpadc.c4
-rw-r--r--drivers/mfd/ab8500-i2c.c2
-rw-r--r--drivers/mfd/ab8500-sysctrl.c4
-rw-r--r--drivers/mfd/cs5535-mfd.c8
-rw-r--r--drivers/mfd/dm355evm_msp.c3
-rw-r--r--drivers/mfd/intel_msic.c12
-rw-r--r--drivers/mfd/jz4740-adc.c14
-rw-r--r--drivers/mfd/lpc_sch.c2
-rw-r--r--drivers/mfd/max8925-i2c.c27
-rw-r--r--drivers/mfd/max8997.c3
-rw-r--r--drivers/mfd/max8998.c6
-rw-r--r--drivers/mfd/mc13xxx-core.c111
-rw-r--r--drivers/mfd/mcp-core.c44
-rw-r--r--drivers/mfd/mcp-sa11x0.c182
-rw-r--r--drivers/mfd/omap-usb-host.c18
-rw-r--r--drivers/mfd/pcf50633-adc.c12
-rw-r--r--drivers/mfd/s5m-core.c176
-rw-r--r--drivers/mfd/s5m-irq.c487
-rw-r--r--drivers/mfd/sm501.c2
-rw-r--r--drivers/mfd/stmpe-i2c.c109
-rw-r--r--drivers/mfd/stmpe-spi.c150
-rw-r--r--drivers/mfd/stmpe.c277
-rw-r--r--drivers/mfd/stmpe.h53
-rw-r--r--drivers/mfd/t7l66xb.c16
-rw-r--r--drivers/mfd/tc6387xb.c14
-rw-r--r--drivers/mfd/ti-ssp.c12
-rw-r--r--drivers/mfd/timberdale.c2
-rw-r--r--drivers/mfd/tps65910-irq.c3
-rw-r--r--drivers/mfd/tps65910.c7
-rw-r--r--drivers/mfd/tps65912-spi.c1
-rw-r--r--drivers/mfd/twl-core.c51
-rw-r--r--drivers/mfd/twl4030-audio.c12
-rw-r--r--drivers/mfd/twl4030-irq.c3
-rw-r--r--drivers/mfd/twl4030-madc.c14
-rw-r--r--drivers/mfd/twl4030-power.c42
-rw-r--r--drivers/mfd/twl6040-core.c20
-rw-r--r--drivers/mfd/ucb1x00-core.c48
-rw-r--r--drivers/mfd/ucb1x00-ts.c2
-rw-r--r--drivers/mfd/vx855.c2
-rw-r--r--drivers/mfd/wm831x-core.c4
-rw-r--r--drivers/mfd/wm831x-i2c.c3
-rw-r--r--drivers/mfd/wm831x-irq.c8
-rw-r--r--drivers/mfd/wm831x-spi.c4
-rw-r--r--drivers/mfd/wm8350-core.c2
-rw-r--r--drivers/mfd/wm8350-i2c.c4
-rw-r--r--drivers/mfd/wm8400-core.c7
-rw-r--r--drivers/misc/Kconfig8
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/ab8500-pwm.c2
-rw-r--r--drivers/misc/max8997-muic.c505
-rw-r--r--drivers/mmc/Makefile3
-rw-r--r--drivers/mmc/card/block.c247
-rw-r--r--drivers/mmc/card/mmc_test.c1
-rw-r--r--drivers/mmc/card/queue.c5
-rw-r--r--drivers/mmc/core/Makefile2
-rw-r--r--drivers/mmc/core/bus.c5
-rw-r--r--drivers/mmc/core/cd-gpio.c74
-rw-r--r--drivers/mmc/core/core.c95
-rw-r--r--drivers/mmc/core/core.h3
-rw-r--r--drivers/mmc/core/debugfs.c5
-rw-r--r--drivers/mmc/core/host.c53
-rw-r--r--drivers/mmc/core/mmc.c203
-rw-r--r--drivers/mmc/core/sd.c21
-rw-r--r--drivers/mmc/core/sdio.c342
-rw-r--r--drivers/mmc/core/sdio_io.c8
-rw-r--r--drivers/mmc/core/sdio_ops.c14
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/at91_mci.c8
-rw-r--r--drivers/mmc/host/bfin_sdh.c12
-rw-r--r--drivers/mmc/host/cb710-mmc.c13
-rw-r--r--drivers/mmc/host/dw_mmc.c71
-rw-r--r--drivers/mmc/host/dw_mmc.h2
-rw-r--r--drivers/mmc/host/jz4740_mmc.c12
-rw-r--r--drivers/mmc/host/mmc_spi.c1
-rw-r--r--drivers/mmc/host/mmci.c1
-rw-r--r--drivers/mmc/host/msm_sdcc.c19
-rw-r--r--drivers/mmc/host/mxcmmc.c13
-rw-r--r--drivers/mmc/host/mxs-mmc.c13
-rw-r--r--drivers/mmc/host/omap_hsmmc.c43
-rw-r--r--drivers/mmc/host/pxamci.c13
-rw-r--r--drivers/mmc/host/s3cmci.c13
-rw-r--r--drivers/mmc/host/sdhci-cns3xxx.c12
-rw-r--r--drivers/mmc/host/sdhci-dove.c12
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c12
-rw-r--r--drivers/mmc/host/sdhci-esdhc.h2
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c12
-rw-r--r--drivers/mmc/host/sdhci-of-hlwd.c12
-rw-r--r--drivers/mmc/host/sdhci-pci-data.c5
-rw-r--r--drivers/mmc/host/sdhci-pci.c181
-rw-r--r--drivers/mmc/host/sdhci-pxav2.c12
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c12
-rw-r--r--drivers/mmc/host/sdhci-s3c.c18
-rw-r--r--drivers/mmc/host/sdhci-spear.c51
-rw-r--r--drivers/mmc/host/sdhci-tegra.c12
-rw-r--r--drivers/mmc/host/sdhci.c150
-rw-r--r--drivers/mmc/host/sdhci.h1
-rw-r--r--drivers/mmc/host/sh_mmcif.c726
-rw-r--r--drivers/mmc/host/sh_mobile_sdhi.c13
-rw-r--r--drivers/mmc/host/tifm_sd.c16
-rw-r--r--drivers/mmc/host/tmio_mmc.c14
-rw-r--r--drivers/mmc/host/tmio_mmc.h4
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c30
-rw-r--r--drivers/mtd/mtdoops.c3
-rw-r--r--drivers/mtd/ubi/debug.h5
-rw-r--r--drivers/mtd/ubi/vtbl.c2
-rw-r--r--drivers/net/bonding/bond_alb.c112
-rw-r--r--drivers/net/ethernet/8390/ax88796.c3
-rw-r--r--drivers/net/ethernet/adi/bfin_mac.c3
-rw-r--r--drivers/net/ethernet/amd/au1000_eth.c3
-rw-r--r--drivers/net/ethernet/broadcom/bcm63xx_enet.c2
-rw-r--r--drivers/net/ethernet/broadcom/sb1250-mac.c3
-rw-r--r--drivers/net/ethernet/cadence/macb.c3
-rw-r--r--drivers/net/ethernet/dnet.c3
-rw-r--r--drivers/net/ethernet/freescale/fec.c12
-rw-r--r--drivers/net/ethernet/freescale/fec.h4
-rw-r--r--drivers/net/ethernet/freescale/gianfar.c34
-rw-r--r--drivers/net/ethernet/freescale/gianfar.h3
-rw-r--r--drivers/net/ethernet/lantiq_etop.c5
-rw-r--r--drivers/net/ethernet/marvell/mv643xx_eth.c3
-rw-r--r--drivers/net/ethernet/marvell/pxa168_eth.c3
-rw-r--r--drivers/net/ethernet/micrel/ksz884x.c2
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c3
-rw-r--r--drivers/net/ethernet/s6gmac.c2
-rw-r--r--drivers/net/ethernet/smsc/smsc911x.c3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/mmc_core.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c4
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c2
-rw-r--r--drivers/net/ethernet/ti/cpmac.c2
-rw-r--r--drivers/net/ethernet/ti/davinci_mdio.c3
-rw-r--r--drivers/net/ethernet/tundra/tsi108_eth.c6
-rw-r--r--drivers/net/ethernet/via/via-rhine.c668
-rw-r--r--drivers/net/ethernet/xscale/ixp4xx_eth.c2
-rw-r--r--drivers/net/phy/dp83640.c2
-rw-r--r--drivers/net/phy/fixed.c2
-rw-r--r--drivers/net/phy/mdio-gpio.c2
-rw-r--r--drivers/net/phy/mdio-octeon.c3
-rw-r--r--drivers/net/phy/mdio_bus.c24
-rw-r--r--drivers/net/ppp/pptp.c4
-rw-r--r--drivers/net/usb/asix.c15
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c8
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/fw.c4
-rw-r--r--drivers/parport/parport_pc.c4
-rw-r--r--drivers/regulator/ab8500.c2
-rw-r--r--drivers/rtc/rtc-ab8500.c2
-rw-r--r--drivers/rtc/rtc-max8925.c26
-rw-r--r--drivers/usb/otg/ab8500-usb.c2
-rw-r--r--drivers/video/nvidia/nvidia.c6
-rw-r--r--fs/aio.c11
-rw-r--r--fs/autofs4/waitq.c2
-rw-r--r--fs/block_dev.c3
-rw-r--r--fs/btrfs/disk-io.c5
-rw-r--r--fs/ceph/dir.c76
-rw-r--r--fs/ceph/export.c6
-rw-r--r--fs/ceph/inode.c3
-rw-r--r--fs/ceph/mds_client.c4
-rw-r--r--fs/ceph/super.c16
-rw-r--r--fs/ceph/super.h1
-rw-r--r--fs/ceph/xattr.c22
-rw-r--r--fs/dcache.c11
-rw-r--r--fs/direct-io.c57
-rw-r--r--fs/eventpoll.c234
-rw-r--r--fs/gfs2/glock.c2
-rw-r--r--fs/gfs2/glock.h7
-rw-r--r--fs/gfs2/incore.h60
-rw-r--r--fs/gfs2/inode.c4
-rw-r--r--fs/gfs2/lock_dlm.c993
-rw-r--r--fs/gfs2/main.c10
-rw-r--r--fs/gfs2/ops_fstype.c31
-rw-r--r--fs/gfs2/recovery.c11
-rw-r--r--fs/gfs2/rgrp.c2
-rw-r--r--fs/gfs2/sys.c33
-rw-r--r--fs/gfs2/sys.h2
-rw-r--r--fs/hugetlbfs/inode.c3
-rw-r--r--fs/nfs/internal.h2
-rw-r--r--fs/nfs/write.c4
-rw-r--r--fs/nfsd/Kconfig10
-rw-r--r--fs/nfsd/Makefile1
-rw-r--r--fs/nfsd/export.c12
-rw-r--r--fs/nfsd/fault_inject.c91
-rw-r--r--fs/nfsd/fault_inject.h28
-rw-r--r--fs/nfsd/nfs4idmap.c11
-rw-r--r--fs/nfsd/nfs4proc.c7
-rw-r--r--fs/nfsd/nfs4recover.c22
-rw-r--r--fs/nfsd/nfs4state.c328
-rw-r--r--fs/nfsd/nfs4xdr.c3
-rw-r--r--fs/nfsd/nfsctl.c10
-rw-r--r--fs/nfsd/nfsd.h20
-rw-r--r--fs/nfsd/state.h3
-rw-r--r--fs/nfsd/vfs.c17
-rw-r--r--fs/pipe.c2
-rw-r--r--fs/proc/array.c7
-rw-r--r--fs/proc/base.c2
-rw-r--r--fs/squashfs/cache.c30
-rw-r--r--fs/squashfs/inode.c4
-rw-r--r--fs/squashfs/squashfs_fs_sb.h1
-rw-r--r--fs/squashfs/super.c2
-rw-r--r--fs/ubifs/debug.c90
-rw-r--r--fs/ubifs/debug.h44
-rw-r--r--fs/ubifs/journal.c7
-rw-r--r--fs/ubifs/replay.c8
-rw-r--r--fs/ubifs/tnc.c55
-rw-r--r--fs/ubifs/tnc_misc.c10
-rw-r--r--include/asm-generic/tlb.h14
-rw-r--r--include/drm/drm_crtc.h2
-rw-r--r--include/linux/amba/mmci.h2
-rw-r--r--include/linux/crash_dump.h1
-rw-r--r--include/linux/dcache.h1
-rw-r--r--include/linux/eventpoll.h1
-rw-r--r--include/linux/fs.h14
-rw-r--r--include/linux/gfs2_ondisk.h2
-rw-r--r--include/linux/huge_mm.h2
-rw-r--r--include/linux/i2c/twl.h2
-rw-r--r--include/linux/inet_diag.h14
-rw-r--r--include/linux/kernel.h13
-rw-r--r--include/linux/kmsg_dump.h1
-rw-r--r--include/linux/linkage.h4
-rw-r--r--include/linux/memcontrol.h105
-rw-r--r--include/linux/mfd/88pm860x.h3
-rw-r--r--include/linux/mfd/abx500/ab5500.h (renamed from include/linux/mfd/ab5500/ab5500.h)0
-rw-r--r--include/linux/mfd/abx500/ab8500-gpadc.h (renamed from include/linux/mfd/ab8500/gpadc.h)0
-rw-r--r--include/linux/mfd/abx500/ab8500-gpio.h (renamed from include/linux/mfd/ab8500/gpio.h)0
-rw-r--r--include/linux/mfd/abx500/ab8500-sysctrl.h (renamed from include/linux/mfd/ab8500/sysctrl.h)0
-rw-r--r--include/linux/mfd/abx500/ab8500.h (renamed from include/linux/mfd/ab8500.h)0
-rw-r--r--include/linux/mfd/max8925.h2
-rw-r--r--include/linux/mfd/max8997.h83
-rw-r--r--include/linux/mfd/mc13xxx.h8
-rw-r--r--include/linux/mfd/mcp.h7
-rw-r--r--include/linux/mfd/s5m87xx/s5m-core.h373
-rw-r--r--include/linux/mfd/s5m87xx/s5m-pmic.h100
-rw-r--r--include/linux/mfd/s5m87xx/s5m-rtc.h84
-rw-r--r--include/linux/mfd/stmpe.h16
-rw-r--r--include/linux/mfd/ucb1x00.h5
-rw-r--r--include/linux/migrate.h23
-rw-r--r--include/linux/mm_inline.h44
-rw-r--r--include/linux/mm_types.h9
-rw-r--r--include/linux/mmc/card.h23
-rw-r--r--include/linux/mmc/cd-gpio.h19
-rw-r--r--include/linux/mmc/core.h2
-rw-r--r--include/linux/mmc/dw_mmc.h1
-rw-r--r--include/linux/mmc/host.h25
-rw-r--r--include/linux/mmc/mmc.h72
-rw-r--r--include/linux/mmc/sdhci-pci-data.h18
-rw-r--r--include/linux/mmc/sdhci.h3
-rw-r--r--include/linux/mmc/sdio.h29
-rw-r--r--include/linux/mmzone.h28
-rw-r--r--include/linux/mod_devicetable.h11
-rw-r--r--include/linux/oom.h2
-rw-r--r--include/linux/page_cgroup.h46
-rw-r--r--include/linux/pagevec.h12
-rw-r--r--include/linux/phy.h7
-rw-r--r--include/linux/pkt_sched.h20
-rw-r--r--include/linux/prctl.h12
-rw-r--r--include/linux/radix-tree.h3
-rw-r--r--include/linux/rmap.h4
-rw-r--r--include/linux/sched.h2
-rw-r--r--include/linux/sunrpc/svc_xprt.h3
-rw-r--r--include/linux/sunrpc/svcsock.h2
-rw-r--r--include/net/bluetooth/hci_core.h4
-rw-r--r--include/net/red.h3
-rw-r--r--include/trace/events/vmscan.h22
-rw-r--r--init/Kconfig11
-rw-r--r--kernel/exit.c6
-rw-r--r--kernel/kexec.c25
-rw-r--r--kernel/kprobes.c2
-rw-r--r--kernel/panic.c26
-rw-r--r--kernel/pid.c4
-rw-r--r--kernel/pid_namespace.c31
-rw-r--r--kernel/sys.c121
-rw-r--r--lib/decompress_unlzo.c2
-rw-r--r--lib/radix-tree.c154
-rw-r--r--mm/compaction.c5
-rw-r--r--mm/filemap.c18
-rw-r--r--mm/huge_memory.c93
-rw-r--r--mm/ksm.c11
-rw-r--r--mm/memcontrol.c1102
-rw-r--r--mm/memory-failure.c2
-rw-r--r--mm/memory.c4
-rw-r--r--mm/memory_hotplug.c2
-rw-r--r--mm/mempolicy.c2
-rw-r--r--mm/migrate.c173
-rw-r--r--mm/oom_kill.c42
-rw-r--r--mm/page_alloc.c55
-rw-r--r--mm/page_cgroup.c164
-rw-r--r--mm/rmap.c20
-rw-r--r--mm/slub.c9
-rw-r--r--mm/swap.c79
-rw-r--r--mm/swap_state.c10
-rw-r--r--mm/swapfile.c9
-rw-r--r--mm/vmalloc.c9
-rw-r--r--mm/vmscan.c680
-rw-r--r--mm/vmstat.c2
-rw-r--r--net/bluetooth/af_bluetooth.c8
-rw-r--r--net/bluetooth/hci_event.c22
-rw-r--r--net/bluetooth/hci_sock.c2
-rw-r--r--net/bluetooth/l2cap_core.c26
-rw-r--r--net/bluetooth/l2cap_sock.c2
-rw-r--r--net/bluetooth/mgmt.c4
-rw-r--r--net/bluetooth/rfcomm/sock.c12
-rw-r--r--net/bluetooth/rfcomm/tty.c22
-rw-r--r--net/bluetooth/sco.c8
-rw-r--r--net/ceph/crush/mapper.c11
-rw-r--r--net/ceph/crypto.c3
-rw-r--r--net/ceph/osd_client.c21
-rw-r--r--net/core/net-sysfs.c6
-rw-r--r--net/core/netpoll.c2
-rw-r--r--net/dccp/diag.c4
-rw-r--r--net/decnet/dn_dev.c4
-rw-r--r--net/ipv4/devinet.c2
-rw-r--r--net/ipv4/fib_trie.c10
-rw-r--r--net/ipv4/igmp.c8
-rw-r--r--net/ipv4/inet_diag.c42
-rw-r--r--net/ipv4/ipip.c8
-rw-r--r--net/ipv4/ipmr.c2
-rw-r--r--net/ipv4/tcp_diag.c4
-rw-r--r--net/ipv4/tcp_memcontrol.c2
-rw-r--r--net/ipv4/udp_diag.c14
-rw-r--r--net/ipv6/addrconf.c2
-rw-r--r--net/ipv6/ip6_tunnel.c8
-rw-r--r--net/ipv6/raw.c2
-rw-r--r--net/ipv6/sit.c10
-rw-r--r--net/mac80211/agg-rx.c2
-rw-r--r--net/mac80211/cfg.c4
-rw-r--r--net/mac80211/ibss.c2
-rw-r--r--net/mac80211/sta_info.c6
-rw-r--r--net/mac80211/wpa.c2
-rw-r--r--net/netfilter/nf_conntrack_core.c2
-rw-r--r--net/netfilter/nf_conntrack_ecache.c4
-rw-r--r--net/netfilter/nf_conntrack_extend.c2
-rw-r--r--net/netfilter/nf_conntrack_helper.c2
-rw-r--r--net/netfilter/nf_conntrack_netlink.c2
-rw-r--r--net/netfilter/nf_log.c6
-rw-r--r--net/netfilter/nf_queue.c2
-rw-r--r--net/netfilter/nfnetlink.c4
-rw-r--r--net/netlabel/netlabel_domainhash.c4
-rw-r--r--net/netlabel/netlabel_unlabeled.c6
-rw-r--r--net/phonet/af_phonet.c2
-rw-r--r--net/phonet/pn_dev.c2
-rw-r--r--net/phonet/socket.c2
-rw-r--r--net/rds/iw_rdma.c15
-rw-r--r--net/sched/sch_sfq.c146
-rw-r--r--net/socket.c2
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c2
-rw-r--r--net/sunrpc/cache.c2
-rw-r--r--net/sunrpc/svc.c25
-rw-r--r--net/sunrpc/svc_xprt.c62
-rw-r--r--net/sunrpc/svcsock.c8
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_transport.c2
-rw-r--r--net/wireless/nl80211.c34
-rw-r--r--net/xfrm/xfrm_user.c2
-rw-r--r--scripts/mod/file2alias.c10
-rwxr-xr-xtools/nfsd/inject_fault.sh49
-rw-r--r--tools/testing/selftests/Makefile11
-rw-r--r--tools/testing/selftests/breakpoints/Makefile20
-rw-r--r--tools/testing/selftests/breakpoints/breakpoint_test.c394
-rw-r--r--tools/testing/selftests/run_tests8
491 files changed, 11367 insertions, 4324 deletions
diff --git a/CREDITS b/CREDITS
index 44fce988eaac..370b4c7da39b 100644
--- a/CREDITS
+++ b/CREDITS
@@ -514,6 +514,11 @@ S: Bessemerstraat 21
514S: Amsterdam 514S: Amsterdam
515S: The Netherlands 515S: The Netherlands
516 516
517N: NeilBrown
518E: neil@brown.name
519P: 4096R/566281B9 1BC6 29EB D390 D870 7B5F 497A 39EC 9EDD 5662 81B9
520D: NFSD Maintainer 2000-2007
521
517N: Zach Brown 522N: Zach Brown
518E: zab@zabbo.net 523E: zab@zabbo.net
519D: maestro pci sound 524D: maestro pci sound
diff --git a/Documentation/ABI/testing/sysfs-kernel-slab b/Documentation/ABI/testing/sysfs-kernel-slab
index 8b093f8222d3..91bd6ca5440f 100644
--- a/Documentation/ABI/testing/sysfs-kernel-slab
+++ b/Documentation/ABI/testing/sysfs-kernel-slab
@@ -346,6 +346,10 @@ Description:
346 number of objects per slab. If a slab cannot be allocated 346 number of objects per slab. If a slab cannot be allocated
347 because of fragmentation, SLUB will retry with the minimum order 347 because of fragmentation, SLUB will retry with the minimum order
348 possible depending on its characteristics. 348 possible depending on its characteristics.
349 When debug_guardpage_minorder=N (N > 0) parameter is specified
350 (see Documentation/kernel-parameters.txt), the minimum possible
351 order is used and this sysfs entry can not be used to change
352 the order at run time.
349 353
350What: /sys/kernel/slab/cache/order_fallback 354What: /sys/kernel/slab/cache/order_fallback
351Date: April 2008 355Date: April 2008
diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt
index 4d8774f6f48a..4c95c0034a4b 100644
--- a/Documentation/cgroups/memory.txt
+++ b/Documentation/cgroups/memory.txt
@@ -61,7 +61,7 @@ Brief summary of control files.
61 memory.failcnt # show the number of memory usage hits limits 61 memory.failcnt # show the number of memory usage hits limits
62 memory.memsw.failcnt # show the number of memory+Swap hits limits 62 memory.memsw.failcnt # show the number of memory+Swap hits limits
63 memory.max_usage_in_bytes # show max memory usage recorded 63 memory.max_usage_in_bytes # show max memory usage recorded
64 memory.memsw.usage_in_bytes # show max memory+Swap usage recorded 64 memory.memsw.max_usage_in_bytes # show max memory+Swap usage recorded
65 memory.soft_limit_in_bytes # set/show soft limit of memory usage 65 memory.soft_limit_in_bytes # set/show soft limit of memory usage
66 memory.stat # show various statistics 66 memory.stat # show various statistics
67 memory.use_hierarchy # set/show hierarchical account enabled 67 memory.use_hierarchy # set/show hierarchical account enabled
@@ -410,8 +410,11 @@ memory.stat file includes following statistics
410cache - # of bytes of page cache memory. 410cache - # of bytes of page cache memory.
411rss - # of bytes of anonymous and swap cache memory. 411rss - # of bytes of anonymous and swap cache memory.
412mapped_file - # of bytes of mapped file (includes tmpfs/shmem) 412mapped_file - # of bytes of mapped file (includes tmpfs/shmem)
413pgpgin - # of pages paged in (equivalent to # of charging events). 413pgpgin - # of charging events to the memory cgroup. The charging
414pgpgout - # of pages paged out (equivalent to # of uncharging events). 414 event happens each time a page is accounted as either mapped
415 anon page(RSS) or cache page(Page Cache) to the cgroup.
416pgpgout - # of uncharging events to the memory cgroup. The uncharging
417 event happens each time a page is unaccounted from the cgroup.
415swap - # of bytes of swap usage 418swap - # of bytes of swap usage
416inactive_anon - # of bytes of anonymous memory and swap cache memory on 419inactive_anon - # of bytes of anonymous memory and swap cache memory on
417 LRU list. 420 LRU list.
diff --git a/Documentation/devicetree/bindings/mfd/mc13xxx.txt b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
new file mode 100644
index 000000000000..19f6af47a792
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
@@ -0,0 +1,78 @@
1* Freescale MC13783/MC13892 Power Management Integrated Circuit (PMIC)
2
3Required properties:
4- compatible : Should be "fsl,mc13783" or "fsl,mc13892"
5
6Optional properties:
7- fsl,mc13xxx-uses-adc : Indicate the ADC is being used
8- fsl,mc13xxx-uses-codec : Indicate the Audio Codec is being used
9- fsl,mc13xxx-uses-rtc : Indicate the RTC is being used
10- fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used
11
12Sub-nodes:
13- regulators : Contain the regulator nodes. The MC13892 regulators are
14 bound using their names as listed below with their registers and bits
15 for enabling.
16
17 vcoincell : regulator VCOINCELL (register 13, bit 23)
18 sw1 : regulator SW1 (register 24, bit 0)
19 sw2 : regulator SW2 (register 25, bit 0)
20 sw3 : regulator SW3 (register 26, bit 0)
21 sw4 : regulator SW4 (register 27, bit 0)
22 swbst : regulator SWBST (register 29, bit 20)
23 vgen1 : regulator VGEN1 (register 32, bit 0)
24 viohi : regulator VIOHI (register 32, bit 3)
25 vdig : regulator VDIG (register 32, bit 9)
26 vgen2 : regulator VGEN2 (register 32, bit 12)
27 vpll : regulator VPLL (register 32, bit 15)
28 vusb2 : regulator VUSB2 (register 32, bit 18)
29 vgen3 : regulator VGEN3 (register 33, bit 0)
30 vcam : regulator VCAM (register 33, bit 6)
31 vvideo : regulator VVIDEO (register 33, bit 12)
32 vaudio : regulator VAUDIO (register 33, bit 15)
33 vsd : regulator VSD (register 33, bit 18)
34 gpo1 : regulator GPO1 (register 34, bit 6)
35 gpo2 : regulator GPO2 (register 34, bit 8)
36 gpo3 : regulator GPO3 (register 34, bit 10)
37 gpo4 : regulator GPO4 (register 34, bit 12)
38 pwgt1spi : regulator PWGT1SPI (register 34, bit 15)
39 pwgt2spi : regulator PWGT2SPI (register 34, bit 16)
40 vusb : regulator VUSB (register 50, bit 3)
41
42 The bindings details of individual regulator device can be found in:
43 Documentation/devicetree/bindings/regulator/regulator.txt
44
45Examples:
46
47ecspi@70010000 { /* ECSPI1 */
48 fsl,spi-num-chipselects = <2>;
49 cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */
50 <&gpio3 25 0>; /* GPIO4_25 */
51 status = "okay";
52
53 pmic: mc13892@0 {
54 #address-cells = <1>;
55 #size-cells = <0>;
56 compatible = "fsl,mc13892";
57 spi-max-frequency = <6000000>;
58 reg = <0>;
59 interrupt-parent = <&gpio0>;
60 interrupts = <8>;
61
62 regulators {
63 sw1_reg: mc13892__sw1 {
64 regulator-min-microvolt = <600000>;
65 regulator-max-microvolt = <1375000>;
66 regulator-boot-on;
67 regulator-always-on;
68 };
69
70 sw2_reg: mc13892__sw2 {
71 regulator-min-microvolt = <900000>;
72 regulator-max-microvolt = <1850000>;
73 regulator-boot-on;
74 regulator-always-on;
75 };
76 };
77 };
78};
diff --git a/Documentation/devicetree/bindings/mfd/twl-familly.txt b/Documentation/devicetree/bindings/mfd/twl-familly.txt
new file mode 100644
index 000000000000..a66fcf946759
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/twl-familly.txt
@@ -0,0 +1,47 @@
1Texas Instruments TWL family
2
3The TWLs are Integrated Power Management Chips.
4Some version might contain much more analog function like
5USB transceiver or Audio amplifier.
6These chips are connected to an i2c bus.
7
8
9Required properties:
10- compatible : Must be "ti,twl4030";
11 For Integrated power-management/audio CODEC device used in OMAP3
12 based boards
13- compatible : Must be "ti,twl6030";
14 For Integrated power-management used in OMAP4 based boards
15- interrupts : This i2c device has an IRQ line connected to the main SoC
16- interrupt-controller : Since the twl support several interrupts internally,
17 it is considered as an interrupt controller cascaded to the SoC one.
18- #interrupt-cells = <1>;
19- interrupt-parent : The parent interrupt controller.
20
21Optional node:
22- Child nodes contain in the twl. The twl family is made of several variants
23 that support a different number of features.
24 The children nodes will thus depend of the capability of the variant.
25
26
27Example:
28/*
29 * Integrated Power Management Chip
30 * http://www.ti.com/lit/ds/symlink/twl6030.pdf
31 */
32twl@48 {
33 compatible = "ti,twl6030";
34 reg = <0x48>;
35 interrupts = <39>; /* IRQ_SYS_1N cascaded to gic */
36 interrupt-controller;
37 #interrupt-cells = <1>;
38 interrupt-parent = <&gic>;
39 #address-cells = <1>;
40 #size-cells = <0>;
41
42 twl_rtc {
43 compatible = "ti,twl_rtc";
44 interrupts = <11>;
45 reg = <0>;
46 };
47};
diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt
index 510eab32f392..225f96d88f55 100644
--- a/Documentation/dma-buf-sharing.txt
+++ b/Documentation/dma-buf-sharing.txt
@@ -219,6 +219,10 @@ NOTES:
219 If the exporter chooses not to allow an attach() operation once a 219 If the exporter chooses not to allow an attach() operation once a
220 map_dma_buf() API has been called, it simply returns an error. 220 map_dma_buf() API has been called, it simply returns an error.
221 221
222Miscellaneous notes:
223- Any exporters or users of the dma-buf buffer sharing framework must have
224 a 'select DMA_SHARED_BUFFER' in their respective Kconfigs.
225
222References: 226References:
223[1] struct dma_buf_ops in include/linux/dma-buf.h 227[1] struct dma_buf_ops in include/linux/dma-buf.h
224[2] All interfaces mentioned above defined in include/linux/dma-buf.h 228[2] All interfaces mentioned above defined in include/linux/dma-buf.h
diff --git a/Documentation/filesystems/ceph.txt b/Documentation/filesystems/ceph.txt
index 763d8ebbbebd..d6030aa33376 100644
--- a/Documentation/filesystems/ceph.txt
+++ b/Documentation/filesystems/ceph.txt
@@ -119,12 +119,20 @@ Mount Options
119 must rely on TCP's error correction to detect data corruption 119 must rely on TCP's error correction to detect data corruption
120 in the data payload. 120 in the data payload.
121 121
122 noasyncreaddir 122 dcache
123 Disable client's use its local cache to satisfy readdir 123 Use the dcache contents to perform negative lookups and
124 requests. (This does not change correctness; the client uses 124 readdir when the client has the entire directory contents in
125 cached metadata only when a lease or capability ensures it is 125 its cache. (This does not change correctness; the client uses
126 valid.) 126 cached metadata only when a lease or capability ensures it is
127 valid.)
128
129 nodcache
130 Do not use the dcache as above. This avoids a significant amount of
131 complex code, sacrificing performance without affecting correctness,
132 and is useful for tracking down bugs.
127 133
134 noasyncreaddir
135 Do not use the dcache as above for readdir.
128 136
129More Information 137More Information
130================ 138================
diff --git a/Documentation/filesystems/nfs/00-INDEX b/Documentation/filesystems/nfs/00-INDEX
index a57e12411d2a..1716874a651e 100644
--- a/Documentation/filesystems/nfs/00-INDEX
+++ b/Documentation/filesystems/nfs/00-INDEX
@@ -2,6 +2,8 @@
2 - this file (nfs-related documentation). 2 - this file (nfs-related documentation).
3Exporting 3Exporting
4 - explanation of how to make filesystems exportable. 4 - explanation of how to make filesystems exportable.
5fault_injection.txt
6 - information for using fault injection on the server
5knfsd-stats.txt 7knfsd-stats.txt
6 - statistics which the NFS server makes available to user space. 8 - statistics which the NFS server makes available to user space.
7nfs.txt 9nfs.txt
diff --git a/Documentation/filesystems/nfs/fault_injection.txt b/Documentation/filesystems/nfs/fault_injection.txt
new file mode 100644
index 000000000000..426d166089a3
--- /dev/null
+++ b/Documentation/filesystems/nfs/fault_injection.txt
@@ -0,0 +1,69 @@
1
2Fault Injection
3===============
4Fault injection is a method for forcing errors that may not normally occur, or
5may be difficult to reproduce. Forcing these errors in a controlled environment
6can help the developer find and fix bugs before their code is shipped in a
7production system. Injecting an error on the Linux NFS server will allow us to
8observe how the client reacts and if it manages to recover its state correctly.
9
10NFSD_FAULT_INJECTION must be selected when configuring the kernel to use this
11feature.
12
13
14Using Fault Injection
15=====================
16On the client, mount the fault injection server through NFS v4.0+ and do some
17work over NFS (open files, take locks, ...).
18
19On the server, mount the debugfs filesystem to <debug_dir> and ls
20<debug_dir>/nfsd. This will show a list of files that will be used for
21injecting faults on the NFS server. As root, write a number n to the file
22corresponding to the action you want the server to take. The server will then
23process the first n items it finds. So if you want to forget 5 locks, echo '5'
24to <debug_dir>/nfsd/forget_locks. A value of 0 will tell the server to forget
25all corresponding items. A log message will be created containing the number
26of items forgotten (check dmesg).
27
28Go back to work on the client and check if the client recovered from the error
29correctly.
30
31
32Available Faults
33================
34forget_clients:
35 The NFS server keeps a list of clients that have placed a mount call. If
36 this list is cleared, the server will have no knowledge of who the client
37 is, forcing the client to reauthenticate with the server.
38
39forget_openowners:
40 The NFS server keeps a list of what files are currently opened and who
41 they were opened by. Clearing this list will force the client to reopen
42 its files.
43
44forget_locks:
45 The NFS server keeps a list of what files are currently locked in the VFS.
46 Clearing this list will force the client to reclaim its locks (files are
47 unlocked through the VFS as they are cleared from this list).
48
49forget_delegations:
50 A delegation is used to assure the client that a file, or part of a file,
51 has not changed since the delegation was awarded. Clearing this list will
52 force the client to reaquire its delegation before accessing the file
53 again.
54
55recall_delegations:
56 Delegations can be recalled by the server when another client attempts to
57 access a file. This test will notify the client that its delegation has
58 been revoked, forcing the client to reaquire the delegation before using
59 the file again.
60
61
62tools/nfs/inject_faults.sh script
63=================================
64This script has been created to ease the fault injection process. This script
65will detect the mounted debugfs directory and write to the files located there
66based on the arguments passed by the user. For example, running
67`inject_faults.sh forget_locks 1` as root will instruct the server to forget
68one lock. Running `inject_faults forget_locks` will instruct the server to
69forgetall locks.
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 12fee132fbe2..a76a26a1db8a 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -307,6 +307,9 @@ Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
307 blkio_ticks time spent waiting for block IO 307 blkio_ticks time spent waiting for block IO
308 gtime guest time of the task in jiffies 308 gtime guest time of the task in jiffies
309 cgtime guest time of the task children in jiffies 309 cgtime guest time of the task children in jiffies
310 start_data address above which program data+bss is placed
311 end_data address below which program data+bss is placed
312 start_brk address above which program heap can be expanded with brk()
310.............................................................................. 313..............................................................................
311 314
312The /proc/PID/maps file containing the currently mapped memory regions and 315The /proc/PID/maps file containing the currently mapped memory regions and
diff --git a/Documentation/filesystems/squashfs.txt b/Documentation/filesystems/squashfs.txt
index 7db3ebda5a4c..403c090aca39 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -93,8 +93,8 @@ byte alignment:
93 93
94Compressed data blocks are written to the filesystem as files are read from 94Compressed data blocks are written to the filesystem as files are read from
95the source directory, and checked for duplicates. Once all file data has been 95the source directory, and checked for duplicates. Once all file data has been
96written the completed inode, directory, fragment, export and uid/gid lookup 96written the completed inode, directory, fragment, export, uid/gid lookup and
97tables are written. 97xattr tables are written.
98 98
993.1 Compression options 993.1 Compression options
100----------------------- 100-----------------------
@@ -151,7 +151,7 @@ in each metadata block. Directories are sorted in alphabetical order,
151and at lookup the index is scanned linearly looking for the first filename 151and at lookup the index is scanned linearly looking for the first filename
152alphabetically larger than the filename being looked up. At this point the 152alphabetically larger than the filename being looked up. At this point the
153location of the metadata block the filename is in has been found. 153location of the metadata block the filename is in has been found.
154The general idea of the index is ensure only one metadata block needs to be 154The general idea of the index is to ensure only one metadata block needs to be
155decompressed to do a lookup irrespective of the length of the directory. 155decompressed to do a lookup irrespective of the length of the directory.
156This scheme has the advantage that it doesn't require extra memory overhead 156This scheme has the advantage that it doesn't require extra memory overhead
157and doesn't require much extra storage on disk. 157and doesn't require much extra storage on disk.
diff --git a/Documentation/mmc/mmc-dev-attrs.txt b/Documentation/mmc/mmc-dev-attrs.txt
index 8898a95b41e5..22ae8441489f 100644
--- a/Documentation/mmc/mmc-dev-attrs.txt
+++ b/Documentation/mmc/mmc-dev-attrs.txt
@@ -64,3 +64,13 @@ Note on Erase Size and Preferred Erase Size:
64 size specified by the card. 64 size specified by the card.
65 65
66 "preferred_erase_size" is in bytes. 66 "preferred_erase_size" is in bytes.
67
68SD/MMC/SDIO Clock Gating Attribute
69==================================
70
71Read and write access is provided to following attribute.
72This attribute appears only if CONFIG_MMC_CLKGATE is enabled.
73
74 clkgate_delay Tune the clock gating delay with desired value in milliseconds.
75
76echo <desired delay> > /sys/class/mmc_host/mmcX/clkgate_delay
diff --git a/Documentation/mmc/mmc-dev-parts.txt b/Documentation/mmc/mmc-dev-parts.txt
index 2db28b8e662f..f08d078d43cf 100644
--- a/Documentation/mmc/mmc-dev-parts.txt
+++ b/Documentation/mmc/mmc-dev-parts.txt
@@ -25,3 +25,16 @@ echo 0 > /sys/block/mmcblkXbootY/force_ro
25To re-enable read-only access: 25To re-enable read-only access:
26 26
27echo 1 > /sys/block/mmcblkXbootY/force_ro 27echo 1 > /sys/block/mmcblkXbootY/force_ro
28
29The boot partitions can also be locked read only until the next power on,
30with:
31
32echo 1 > /sys/block/mmcblkXbootY/ro_lock_until_next_power_on
33
34This is a feature of the card and not of the kernel. If the card does
35not support boot partition locking, the file will not exist. If the
36feature has been disabled on the card, the file will be read-only.
37
38The boot partitions can also be locked permanently, but this feature is
39not accessible through sysfs in order to avoid accidental or malicious
40bricking.
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 6d8cd8b2c30d..8c20fbd8b42d 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -415,6 +415,14 @@ PIDs of value pid_max or larger are not allocated.
415 415
416============================================================== 416==============================================================
417 417
418ns_last_pid:
419
420The last pid allocated in the current (the one task using this sysctl
421lives in) pid namespace. When selecting a pid for a next task on fork
422kernel tries to allocate a number starting from this one.
423
424==============================================================
425
418powersave-nap: (PPC only) 426powersave-nap: (PPC only)
419 427
420If set, Linux-PPC will use the 'nap' mode of powersaving, 428If set, Linux-PPC will use the 'nap' mode of powersaving,
diff --git a/Documentation/vm/slub.txt b/Documentation/vm/slub.txt
index 2acdda9601b0..6752870c4970 100644
--- a/Documentation/vm/slub.txt
+++ b/Documentation/vm/slub.txt
@@ -131,7 +131,10 @@ slub_min_objects.
131slub_max_order specified the order at which slub_min_objects should no 131slub_max_order specified the order at which slub_min_objects should no
132longer be checked. This is useful to avoid SLUB trying to generate 132longer be checked. This is useful to avoid SLUB trying to generate
133super large order pages to fit slub_min_objects of a slab cache with 133super large order pages to fit slub_min_objects of a slab cache with
134large object sizes into one high order page. 134large object sizes into one high order page. Setting command line
135parameter debug_guardpage_minorder=N (N > 0), forces setting
136slub_max_order to 0, what cause minimum possible order of slabs
137allocation.
135 138
136SLUB Debug output 139SLUB Debug output
137----------------- 140-----------------
diff --git a/MAINTAINERS b/MAINTAINERS
index 1094edf0da17..4d1ba2022a95 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3193,6 +3193,7 @@ F: drivers/i2c/busses/i2c-stub.c
3193I2C SUBSYSTEM 3193I2C SUBSYSTEM
3194M: "Jean Delvare (PC drivers, core)" <khali@linux-fr.org> 3194M: "Jean Delvare (PC drivers, core)" <khali@linux-fr.org>
3195M: "Ben Dooks (embedded platforms)" <ben-linux@fluff.org> 3195M: "Ben Dooks (embedded platforms)" <ben-linux@fluff.org>
3196M: "Wolfram Sang (embedded platforms)" <w.sang@pengutronix.de>
3196L: linux-i2c@vger.kernel.org 3197L: linux-i2c@vger.kernel.org
3197W: http://i2c.wiki.kernel.org/ 3198W: http://i2c.wiki.kernel.org/
3198T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-i2c/ 3199T: quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-i2c/
@@ -3774,7 +3775,6 @@ S: Odd Fixes
3774 3775
3775KERNEL NFSD, SUNRPC, AND LOCKD SERVERS 3776KERNEL NFSD, SUNRPC, AND LOCKD SERVERS
3776M: "J. Bruce Fields" <bfields@fieldses.org> 3777M: "J. Bruce Fields" <bfields@fieldses.org>
3777M: Neil Brown <neilb@suse.de>
3778L: linux-nfs@vger.kernel.org 3778L: linux-nfs@vger.kernel.org
3779W: http://nfs.sourceforge.net/ 3779W: http://nfs.sourceforge.net/
3780S: Supported 3780S: Supported
@@ -4683,6 +4683,8 @@ Q: http://patchwork.kernel.org/project/linux-omap/list/
4683T: git git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git 4683T: git git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git
4684S: Maintained 4684S: Maintained
4685F: arch/arm/*omap*/ 4685F: arch/arm/*omap*/
4686F: drivers/i2c/busses/i2c-omap.c
4687F: include/linux/i2c-omap.h
4686 4688
4687OMAP CLOCK FRAMEWORK SUPPORT 4689OMAP CLOCK FRAMEWORK SUPPORT
4688M: Paul Walmsley <paul@pwsan.com> 4690M: Paul Walmsley <paul@pwsan.com>
@@ -5956,6 +5958,7 @@ L: davinci-linux-open-source@linux.davincidsp.com (subscribers-only)
5956Q: http://patchwork.kernel.org/project/linux-davinci/list/ 5958Q: http://patchwork.kernel.org/project/linux-davinci/list/
5957S: Supported 5959S: Supported
5958F: arch/arm/mach-davinci 5960F: arch/arm/mach-davinci
5961F: drivers/i2c/busses/i2c-davinci.c
5959 5962
5960SIS 190 ETHERNET DRIVER 5963SIS 190 ETHERNET DRIVER
5961M: Francois Romieu <romieu@fr.zoreil.com> 5964M: Francois Romieu <romieu@fr.zoreil.com>
diff --git a/arch/Kconfig b/arch/Kconfig
index 2505740b81d2..4f55c736be11 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -185,4 +185,18 @@ config HAVE_RCU_TABLE_FREE
185config ARCH_HAVE_NMI_SAFE_CMPXCHG 185config ARCH_HAVE_NMI_SAFE_CMPXCHG
186 bool 186 bool
187 187
188config HAVE_ALIGNED_STRUCT_PAGE
189 bool
190 help
191 This makes sure that struct pages are double word aligned and that
192 e.g. the SLUB allocator can perform double word atomic operations
193 on a struct page for better performance. However selecting this
194 might increase the size of a struct page by a word.
195
196config HAVE_CMPXCHG_LOCAL
197 bool
198
199config HAVE_CMPXCHG_DOUBLE
200 bool
201
188source "kernel/gcov/Kconfig" 202source "kernel/gcov/Kconfig"
diff --git a/arch/arm/mach-sa1100/assabet.c b/arch/arm/mach-sa1100/assabet.c
index 6b93e200bcac..5bc6b3837b20 100644
--- a/arch/arm/mach-sa1100/assabet.c
+++ b/arch/arm/mach-sa1100/assabet.c
@@ -202,6 +202,7 @@ static struct irda_platform_data assabet_irda_data = {
202static struct mcp_plat_data assabet_mcp_data = { 202static struct mcp_plat_data assabet_mcp_data = {
203 .mccr0 = MCCR0_ADM, 203 .mccr0 = MCCR0_ADM,
204 .sclk_rate = 11981000, 204 .sclk_rate = 11981000,
205 .codec = "ucb1x00",
205}; 206};
206 207
207static void __init assabet_init(void) 208static void __init assabet_init(void)
@@ -252,6 +253,17 @@ static void __init assabet_init(void)
252 sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources, 253 sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources,
253 ARRAY_SIZE(assabet_flash_resources)); 254 ARRAY_SIZE(assabet_flash_resources));
254 sa11x0_register_irda(&assabet_irda_data); 255 sa11x0_register_irda(&assabet_irda_data);
256
257 /*
258 * Setup the PPC unit correctly.
259 */
260 PPDR &= ~PPC_RXD4;
261 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
262 PSDR |= PPC_RXD4;
263 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
264 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
265
266 ASSABET_BCR_set(ASSABET_BCR_CODEC_RST);
255 sa11x0_register_mcp(&assabet_mcp_data); 267 sa11x0_register_mcp(&assabet_mcp_data);
256} 268}
257 269
diff --git a/arch/arm/mach-sa1100/cerf.c b/arch/arm/mach-sa1100/cerf.c
index 11bb6d0b9be3..d12d0f48b1dc 100644
--- a/arch/arm/mach-sa1100/cerf.c
+++ b/arch/arm/mach-sa1100/cerf.c
@@ -124,12 +124,23 @@ static void __init cerf_map_io(void)
124static struct mcp_plat_data cerf_mcp_data = { 124static struct mcp_plat_data cerf_mcp_data = {
125 .mccr0 = MCCR0_ADM, 125 .mccr0 = MCCR0_ADM,
126 .sclk_rate = 11981000, 126 .sclk_rate = 11981000,
127 .codec = "ucb1x00",
127}; 128};
128 129
129static void __init cerf_init(void) 130static void __init cerf_init(void)
130{ 131{
131 platform_add_devices(cerf_devices, ARRAY_SIZE(cerf_devices)); 132 platform_add_devices(cerf_devices, ARRAY_SIZE(cerf_devices));
132 sa11x0_register_mtd(&cerf_flash_data, &cerf_flash_resource, 1); 133 sa11x0_register_mtd(&cerf_flash_data, &cerf_flash_resource, 1);
134
135 /*
136 * Setup the PPC unit correctly.
137 */
138 PPDR &= ~PPC_RXD4;
139 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
140 PSDR |= PPC_RXD4;
141 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
142 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
143
133 sa11x0_register_mcp(&cerf_mcp_data); 144 sa11x0_register_mcp(&cerf_mcp_data);
134} 145}
135 146
diff --git a/arch/arm/mach-sa1100/collie.c b/arch/arm/mach-sa1100/collie.c
index b9060e236def..c483912d08af 100644
--- a/arch/arm/mach-sa1100/collie.c
+++ b/arch/arm/mach-sa1100/collie.c
@@ -27,6 +27,7 @@
27#include <linux/timer.h> 27#include <linux/timer.h>
28#include <linux/gpio.h> 28#include <linux/gpio.h>
29#include <linux/pda_power.h> 29#include <linux/pda_power.h>
30#include <linux/mfd/ucb1x00.h>
30 31
31#include <mach/hardware.h> 32#include <mach/hardware.h>
32#include <asm/mach-types.h> 33#include <asm/mach-types.h>
@@ -85,10 +86,15 @@ static struct scoop_pcmcia_config collie_pcmcia_config = {
85 .num_devs = 1, 86 .num_devs = 1,
86}; 87};
87 88
89static struct ucb1x00_plat_data collie_ucb1x00_data = {
90 .gpio_base = COLLIE_TC35143_GPIO_BASE,
91};
92
88static struct mcp_plat_data collie_mcp_data = { 93static struct mcp_plat_data collie_mcp_data = {
89 .mccr0 = MCCR0_ADM | MCCR0_ExtClk, 94 .mccr0 = MCCR0_ADM | MCCR0_ExtClk,
90 .sclk_rate = 9216000, 95 .sclk_rate = 9216000,
91 .gpio_base = COLLIE_TC35143_GPIO_BASE, 96 .codec = "ucb1x00",
97 .codec_pdata = &collie_ucb1x00_data,
92}; 98};
93 99
94/* 100/*
@@ -351,6 +357,16 @@ static void __init collie_init(void)
351 357
352 sa11x0_register_mtd(&collie_flash_data, collie_flash_resources, 358 sa11x0_register_mtd(&collie_flash_data, collie_flash_resources,
353 ARRAY_SIZE(collie_flash_resources)); 359 ARRAY_SIZE(collie_flash_resources));
360
361 /*
362 * Setup the PPC unit correctly.
363 */
364 PPDR &= ~PPC_RXD4;
365 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
366 PSDR |= PPC_RXD4;
367 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
368 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
369
354 sa11x0_register_mcp(&collie_mcp_data); 370 sa11x0_register_mcp(&collie_mcp_data);
355 371
356 sharpsl_save_param(); 372 sharpsl_save_param();
diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
index 480d2ea46b00..e3a28ca2a7b7 100644
--- a/arch/arm/mach-sa1100/generic.c
+++ b/arch/arm/mach-sa1100/generic.c
@@ -217,10 +217,15 @@ static struct platform_device sa11x0uart3_device = {
217static struct resource sa11x0mcp_resources[] = { 217static struct resource sa11x0mcp_resources[] = {
218 [0] = { 218 [0] = {
219 .start = __PREG(Ser4MCCR0), 219 .start = __PREG(Ser4MCCR0),
220 .end = __PREG(Ser4MCCR0) + 0xffff, 220 .end = __PREG(Ser4MCCR0) + 0x1C - 1,
221 .flags = IORESOURCE_MEM, 221 .flags = IORESOURCE_MEM,
222 }, 222 },
223 [1] = { 223 [1] = {
224 .start = __PREG(Ser4MCCR1),
225 .end = __PREG(Ser4MCCR1) + 0x4 - 1,
226 .flags = IORESOURCE_MEM,
227 },
228 [2] = {
224 .start = IRQ_Ser4MCP, 229 .start = IRQ_Ser4MCP,
225 .end = IRQ_Ser4MCP, 230 .end = IRQ_Ser4MCP,
226 .flags = IORESOURCE_IRQ, 231 .flags = IORESOURCE_IRQ,
diff --git a/arch/arm/mach-sa1100/include/mach/mcp.h b/arch/arm/mach-sa1100/include/mach/mcp.h
index ed1a331508a7..586cec898b35 100644
--- a/arch/arm/mach-sa1100/include/mach/mcp.h
+++ b/arch/arm/mach-sa1100/include/mach/mcp.h
@@ -17,6 +17,8 @@ struct mcp_plat_data {
17 u32 mccr1; 17 u32 mccr1;
18 unsigned int sclk_rate; 18 unsigned int sclk_rate;
19 int gpio_base; 19 int gpio_base;
20 const char *codec;
21 void *codec_pdata;
20}; 22};
21 23
22#endif 24#endif
diff --git a/arch/arm/mach-sa1100/lart.c b/arch/arm/mach-sa1100/lart.c
index af4e2761f3db..d117ceab6215 100644
--- a/arch/arm/mach-sa1100/lart.c
+++ b/arch/arm/mach-sa1100/lart.c
@@ -24,10 +24,20 @@
24static struct mcp_plat_data lart_mcp_data = { 24static struct mcp_plat_data lart_mcp_data = {
25 .mccr0 = MCCR0_ADM, 25 .mccr0 = MCCR0_ADM,
26 .sclk_rate = 11981000, 26 .sclk_rate = 11981000,
27 .codec = "ucb1x00",
27}; 28};
28 29
29static void __init lart_init(void) 30static void __init lart_init(void)
30{ 31{
32 /*
33 * Setup the PPC unit correctly.
34 */
35 PPDR &= ~PPC_RXD4;
36 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
37 PSDR |= PPC_RXD4;
38 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
39 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
40
31 sa11x0_register_mcp(&lart_mcp_data); 41 sa11x0_register_mcp(&lart_mcp_data);
32} 42}
33 43
diff --git a/arch/arm/mach-sa1100/shannon.c b/arch/arm/mach-sa1100/shannon.c
index 318b2b766a0b..748d34435b3f 100644
--- a/arch/arm/mach-sa1100/shannon.c
+++ b/arch/arm/mach-sa1100/shannon.c
@@ -55,11 +55,22 @@ static struct resource shannon_flash_resource = {
55static struct mcp_plat_data shannon_mcp_data = { 55static struct mcp_plat_data shannon_mcp_data = {
56 .mccr0 = MCCR0_ADM, 56 .mccr0 = MCCR0_ADM,
57 .sclk_rate = 11981000, 57 .sclk_rate = 11981000,
58 .codec = "ucb1x00",
58}; 59};
59 60
60static void __init shannon_init(void) 61static void __init shannon_init(void)
61{ 62{
62 sa11x0_register_mtd(&shannon_flash_data, &shannon_flash_resource, 1); 63 sa11x0_register_mtd(&shannon_flash_data, &shannon_flash_resource, 1);
64
65 /*
66 * Setup the PPC unit correctly.
67 */
68 PPDR &= ~PPC_RXD4;
69 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
70 PSDR |= PPC_RXD4;
71 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
72 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
73
63 sa11x0_register_mcp(&shannon_mcp_data); 74 sa11x0_register_mcp(&shannon_mcp_data);
64} 75}
65 76
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index e17c04d6e324..458ececefa58 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -14,6 +14,7 @@
14#include <linux/mtd/partitions.h> 14#include <linux/mtd/partitions.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/mfd/ucb1x00.h>
17 18
18#include <asm/irq.h> 19#include <asm/irq.h>
19#include <mach/hardware.h> 20#include <mach/hardware.h>
@@ -187,10 +188,15 @@ static struct resource simpad_flash_resources [] = {
187 } 188 }
188}; 189};
189 190
191static struct ucb1x00_plat_data simpad_ucb1x00_data = {
192 .gpio_base = SIMPAD_UCB1X00_GPIO_BASE,
193};
194
190static struct mcp_plat_data simpad_mcp_data = { 195static struct mcp_plat_data simpad_mcp_data = {
191 .mccr0 = MCCR0_ADM, 196 .mccr0 = MCCR0_ADM,
192 .sclk_rate = 11981000, 197 .sclk_rate = 11981000,
193 .gpio_base = SIMPAD_UCB1X00_GPIO_BASE, 198 .codec = "ucb1300",
199 .codec_pdata = &simpad_ucb1x00_data,
194}; 200};
195 201
196 202
@@ -378,6 +384,16 @@ static int __init simpad_init(void)
378 384
379 sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources, 385 sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
380 ARRAY_SIZE(simpad_flash_resources)); 386 ARRAY_SIZE(simpad_flash_resources));
387
388 /*
389 * Setup the PPC unit correctly.
390 */
391 PPDR &= ~PPC_RXD4;
392 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
393 PSDR |= PPC_RXD4;
394 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
395 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
396
381 sa11x0_register_mcp(&simpad_mcp_data); 397 sa11x0_register_mcp(&simpad_mcp_data);
382 398
383 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 399 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index 9361a5290177..5c00712907d1 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -19,11 +19,11 @@
19#include <linux/amba/pl022.h> 19#include <linux/amba/pl022.h>
20#include <linux/amba/serial.h> 20#include <linux/amba/serial.h>
21#include <linux/spi/spi.h> 21#include <linux/spi/spi.h>
22#include <linux/mfd/ab8500.h> 22#include <linux/mfd/abx500/ab8500.h>
23#include <linux/regulator/ab8500.h> 23#include <linux/regulator/ab8500.h>
24#include <linux/mfd/tc3589x.h> 24#include <linux/mfd/tc3589x.h>
25#include <linux/mfd/tps6105x.h> 25#include <linux/mfd/tps6105x.h>
26#include <linux/mfd/ab8500/gpio.h> 26#include <linux/mfd/abx500/ab8500-gpio.h>
27#include <linux/leds-lp5521.h> 27#include <linux/leds-lp5521.h>
28#include <linux/input.h> 28#include <linux/input.h>
29#include <linux/smsc911x.h> 29#include <linux/smsc911x.h>
diff --git a/arch/arm/mach-ux500/board-u5500.c b/arch/arm/mach-ux500/board-u5500.c
index fe1569b67c91..9de9e9c4dbbb 100644
--- a/arch/arm/mach-ux500/board-u5500.c
+++ b/arch/arm/mach-ux500/board-u5500.c
@@ -10,7 +10,7 @@
10#include <linux/amba/bus.h> 10#include <linux/amba/bus.h>
11#include <linux/irq.h> 11#include <linux/irq.h>
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/mfd/ab5500/ab5500.h> 13#include <linux/mfd/abx500/ab5500.h>
14 14
15#include <asm/hardware/gic.h> 15#include <asm/hardware/gic.h>
16#include <asm/mach/arch.h> 16#include <asm/mach/arch.h>
diff --git a/arch/arm/mach-ux500/include/mach/irqs-board-mop500.h b/arch/arm/mach-ux500/include/mach/irqs-board-mop500.h
index 47969909836c..d2d4131435a6 100644
--- a/arch/arm/mach-ux500/include/mach/irqs-board-mop500.h
+++ b/arch/arm/mach-ux500/include/mach/irqs-board-mop500.h
@@ -9,7 +9,7 @@
9#define __MACH_IRQS_BOARD_MOP500_H 9#define __MACH_IRQS_BOARD_MOP500_H
10 10
11/* Number of AB8500 irqs is taken from header file */ 11/* Number of AB8500 irqs is taken from header file */
12#include <linux/mfd/ab8500.h> 12#include <linux/mfd/abx500/ab8500.h>
13 13
14#define MOP500_AB8500_IRQ_BASE IRQ_BOARD_START 14#define MOP500_AB8500_IRQ_BASE IRQ_BOARD_START
15#define MOP500_AB8500_IRQ_END (MOP500_AB8500_IRQ_BASE \ 15#define MOP500_AB8500_IRQ_END (MOP500_AB8500_IRQ_BASE \
diff --git a/arch/arm/plat-samsung/include/plat/sdhci.h b/arch/arm/plat-samsung/include/plat/sdhci.h
index 656dc00d30ed..f82f888b91a9 100644
--- a/arch/arm/plat-samsung/include/plat/sdhci.h
+++ b/arch/arm/plat-samsung/include/plat/sdhci.h
@@ -63,6 +63,7 @@ enum clk_types {
63struct s3c_sdhci_platdata { 63struct s3c_sdhci_platdata {
64 unsigned int max_width; 64 unsigned int max_width;
65 unsigned int host_caps; 65 unsigned int host_caps;
66 unsigned int pm_caps;
66 enum cd_types cd_type; 67 enum cd_types cd_type;
67 enum clk_types clk_type; 68 enum clk_types clk_type;
68 69
diff --git a/arch/arm/plat-samsung/platformdata.c b/arch/arm/plat-samsung/platformdata.c
index ceb9fa3a80c0..0f707184eae0 100644
--- a/arch/arm/plat-samsung/platformdata.c
+++ b/arch/arm/plat-samsung/platformdata.c
@@ -53,6 +53,8 @@ void s3c_sdhci_set_platdata(struct s3c_sdhci_platdata *pd,
53 set->cfg_gpio = pd->cfg_gpio; 53 set->cfg_gpio = pd->cfg_gpio;
54 if (pd->host_caps) 54 if (pd->host_caps)
55 set->host_caps |= pd->host_caps; 55 set->host_caps |= pd->host_caps;
56 if (pd->pm_caps)
57 set->pm_caps |= pd->pm_caps;
56 if (pd->clk_type) 58 if (pd->clk_type)
57 set->clk_type = pd->clk_type; 59 set->clk_type = pd->clk_type;
58} 60}
diff --git a/arch/avr32/include/asm/system.h b/arch/avr32/include/asm/system.h
index 9702c2213e1e..62d9ded01635 100644
--- a/arch/avr32/include/asm/system.h
+++ b/arch/avr32/include/asm/system.h
@@ -169,7 +169,7 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
169#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) 169#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
170 170
171struct pt_regs; 171struct pt_regs;
172void NORET_TYPE die(const char *str, struct pt_regs *regs, long err); 172void die(const char *str, struct pt_regs *regs, long err);
173void _exception(long signr, struct pt_regs *regs, int code, 173void _exception(long signr, struct pt_regs *regs, int code,
174 unsigned long addr); 174 unsigned long addr);
175 175
diff --git a/arch/avr32/kernel/traps.c b/arch/avr32/kernel/traps.c
index 7aa25756412f..3d760c06f024 100644
--- a/arch/avr32/kernel/traps.c
+++ b/arch/avr32/kernel/traps.c
@@ -24,7 +24,7 @@
24 24
25static DEFINE_SPINLOCK(die_lock); 25static DEFINE_SPINLOCK(die_lock);
26 26
27void NORET_TYPE die(const char *str, struct pt_regs *regs, long err) 27void die(const char *str, struct pt_regs *regs, long err)
28{ 28{
29 static int die_counter; 29 static int die_counter;
30 30
diff --git a/arch/ia64/include/asm/processor.h b/arch/ia64/include/asm/processor.h
index d9f397fae03e..691be0b95c1e 100644
--- a/arch/ia64/include/asm/processor.h
+++ b/arch/ia64/include/asm/processor.h
@@ -309,7 +309,6 @@ struct thread_struct {
309} 309}
310 310
311#define start_thread(regs,new_ip,new_sp) do { \ 311#define start_thread(regs,new_ip,new_sp) do { \
312 set_fs(USER_DS); \
313 regs->cr_ipsr = ((regs->cr_ipsr | (IA64_PSR_BITS_TO_SET | IA64_PSR_CPL)) \ 312 regs->cr_ipsr = ((regs->cr_ipsr | (IA64_PSR_BITS_TO_SET | IA64_PSR_CPL)) \
314 & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_RI | IA64_PSR_IS)); \ 313 & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_RI | IA64_PSR_IS)); \
315 regs->cr_iip = new_ip; \ 314 regs->cr_iip = new_ip; \
diff --git a/arch/ia64/include/asm/unistd.h b/arch/ia64/include/asm/unistd.h
index 7617248f0d11..7a3bd2524944 100644
--- a/arch/ia64/include/asm/unistd.h
+++ b/arch/ia64/include/asm/unistd.h
@@ -323,11 +323,12 @@
323#define __NR_sendmmsg 1331 323#define __NR_sendmmsg 1331
324#define __NR_process_vm_readv 1332 324#define __NR_process_vm_readv 1332
325#define __NR_process_vm_writev 1333 325#define __NR_process_vm_writev 1333
326#define __NR_accept4 1334
326 327
327#ifdef __KERNEL__ 328#ifdef __KERNEL__
328 329
329 330
330#define NR_syscalls 310 /* length of syscall table */ 331#define NR_syscalls 311 /* length of syscall table */
331 332
332/* 333/*
333 * The following defines stop scripts/checksyscalls.sh from complaining about 334 * The following defines stop scripts/checksyscalls.sh from complaining about
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index 5b31d46aff67..1ccbe12a4d84 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -1779,6 +1779,7 @@ sys_call_table:
1779 data8 sys_sendmmsg 1779 data8 sys_sendmmsg
1780 data8 sys_process_vm_readv 1780 data8 sys_process_vm_readv
1781 data8 sys_process_vm_writev 1781 data8 sys_process_vm_writev
1782 data8 sys_accept4
1782 1783
1783 .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls 1784 .org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls
1784#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */ 1785#endif /* __IA64_ASM_PARAVIRTUALIZED_NATIVE */
diff --git a/arch/ia64/kernel/machine_kexec.c b/arch/ia64/kernel/machine_kexec.c
index 3d3aeef46947..4eed35814994 100644
--- a/arch/ia64/kernel/machine_kexec.c
+++ b/arch/ia64/kernel/machine_kexec.c
@@ -27,11 +27,11 @@
27#include <asm/sal.h> 27#include <asm/sal.h>
28#include <asm/mca.h> 28#include <asm/mca.h>
29 29
30typedef NORET_TYPE void (*relocate_new_kernel_t)( 30typedef void (*relocate_new_kernel_t)(
31 unsigned long indirection_page, 31 unsigned long indirection_page,
32 unsigned long start_address, 32 unsigned long start_address,
33 struct ia64_boot_param *boot_param, 33 struct ia64_boot_param *boot_param,
34 unsigned long pal_addr) ATTRIB_NORET; 34 unsigned long pal_addr) __noreturn;
35 35
36struct kimage *ia64_kimage; 36struct kimage *ia64_kimage;
37 37
diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
index 82a4bb51d5d8..b95a451b1c3a 100644
--- a/arch/m68k/amiga/config.c
+++ b/arch/m68k/amiga/config.c
@@ -511,8 +511,7 @@ static unsigned long amiga_gettimeoffset(void)
511 return ticks + offset; 511 return ticks + offset;
512} 512}
513 513
514static NORET_TYPE void amiga_reset(void) 514static void amiga_reset(void) __noreturn;
515 ATTRIB_NORET;
516 515
517static void amiga_reset(void) 516static void amiga_reset(void)
518{ 517{
diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
index de39b1f343ea..7b99c670e478 100644
--- a/arch/mips/include/asm/ptrace.h
+++ b/arch/mips/include/asm/ptrace.h
@@ -144,7 +144,7 @@ extern int ptrace_set_watch_regs(struct task_struct *child,
144extern asmlinkage void syscall_trace_enter(struct pt_regs *regs); 144extern asmlinkage void syscall_trace_enter(struct pt_regs *regs);
145extern asmlinkage void syscall_trace_leave(struct pt_regs *regs); 145extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
146 146
147extern NORET_TYPE void die(const char *, struct pt_regs *) ATTRIB_NORET; 147extern void die(const char *, struct pt_regs *) __noreturn;
148 148
149static inline void die_if_kernel(const char *str, struct pt_regs *regs) 149static inline void die_if_kernel(const char *str, struct pt_regs *regs)
150{ 150{
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 5c8a49d55054..bbddb86c1fa1 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -1340,7 +1340,7 @@ void ejtag_exception_handler(struct pt_regs *regs)
1340/* 1340/*
1341 * NMI exception handler. 1341 * NMI exception handler.
1342 */ 1342 */
1343NORET_TYPE void ATTRIB_NORET nmi_exception_handler(struct pt_regs *regs) 1343void __noreturn nmi_exception_handler(struct pt_regs *regs)
1344{ 1344{
1345 bust_spinlocks(1); 1345 bust_spinlocks(1);
1346 printk("NMI taken!!!!\n"); 1346 printk("NMI taken!!!!\n");
diff --git a/arch/mn10300/include/asm/exceptions.h b/arch/mn10300/include/asm/exceptions.h
index ca3e20508c77..95a4d42c3a06 100644
--- a/arch/mn10300/include/asm/exceptions.h
+++ b/arch/mn10300/include/asm/exceptions.h
@@ -110,7 +110,7 @@ extern asmlinkage void nmi_handler(void);
110extern asmlinkage void misalignment(struct pt_regs *, enum exception_code); 110extern asmlinkage void misalignment(struct pt_regs *, enum exception_code);
111 111
112extern void die(const char *, struct pt_regs *, enum exception_code) 112extern void die(const char *, struct pt_regs *, enum exception_code)
113 ATTRIB_NORET; 113 __noreturn;
114 114
115extern int die_if_no_fixup(const char *, struct pt_regs *, enum exception_code); 115extern int die_if_no_fixup(const char *, struct pt_regs *, enum exception_code);
116 116
diff --git a/arch/parisc/include/asm/processor.h b/arch/parisc/include/asm/processor.h
index 9ce66e9d1c2b..7213ec9e594c 100644
--- a/arch/parisc/include/asm/processor.h
+++ b/arch/parisc/include/asm/processor.h
@@ -196,7 +196,6 @@ typedef unsigned int elf_caddr_t;
196 /* offset pc for priv. level */ \ 196 /* offset pc for priv. level */ \
197 pc |= 3; \ 197 pc |= 3; \
198 \ 198 \
199 set_fs(USER_DS); \
200 regs->iasq[0] = spaceid; \ 199 regs->iasq[0] = spaceid; \
201 regs->iasq[1] = spaceid; \ 200 regs->iasq[1] = spaceid; \
202 regs->iaoq[0] = pc; \ 201 regs->iaoq[0] = pc; \
@@ -299,7 +298,6 @@ on downward growing arches, it looks like this:
299 elf_addr_t pc = (elf_addr_t)new_pc | 3; \ 298 elf_addr_t pc = (elf_addr_t)new_pc | 3; \
300 elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1; \ 299 elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1; \
301 \ 300 \
302 set_fs(USER_DS); \
303 regs->iasq[0] = spaceid; \ 301 regs->iasq[0] = spaceid; \
304 regs->iasq[1] = spaceid; \ 302 regs->iasq[1] = spaceid; \
305 regs->iaoq[0] = pc; \ 303 regs->iaoq[0] = pc; \
diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index 4b4b9181a1a0..62c60b87d039 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -192,7 +192,6 @@ void flush_thread(void)
192 /* Only needs to handle fpu stuff or perf monitors. 192 /* Only needs to handle fpu stuff or perf monitors.
193 ** REVISIT: several arches implement a "lazy fpu state". 193 ** REVISIT: several arches implement a "lazy fpu state".
194 */ 194 */
195 set_fs(USER_DS);
196} 195}
197 196
198void release_thread(struct task_struct *dead_task) 197void release_thread(struct task_struct *dead_task)
diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index 7c66ce13da89..0a48bf5db6c8 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -50,12 +50,6 @@ static int __init powersave_off(char *arg)
50} 50}
51__setup("powersave=off", powersave_off); 51__setup("powersave=off", powersave_off);
52 52
53#if defined(CONFIG_PPC_PSERIES) && defined(CONFIG_TRACEPOINTS)
54static const bool idle_uses_rcu = 1;
55#else
56static const bool idle_uses_rcu;
57#endif
58
59/* 53/*
60 * The body of the idle task. 54 * The body of the idle task.
61 */ 55 */
@@ -67,8 +61,7 @@ void cpu_idle(void)
67 set_thread_flag(TIF_POLLING_NRFLAG); 61 set_thread_flag(TIF_POLLING_NRFLAG);
68 while (1) { 62 while (1) {
69 tick_nohz_idle_enter(); 63 tick_nohz_idle_enter();
70 if (!idle_uses_rcu) 64 rcu_idle_enter();
71 rcu_idle_enter();
72 65
73 while (!need_resched() && !cpu_should_die()) { 66 while (!need_resched() && !cpu_should_die()) {
74 ppc64_runlatch_off(); 67 ppc64_runlatch_off();
@@ -106,8 +99,7 @@ void cpu_idle(void)
106 99
107 HMT_medium(); 100 HMT_medium();
108 ppc64_runlatch_on(); 101 ppc64_runlatch_on();
109 if (!idle_uses_rcu) 102 rcu_idle_exit();
110 rcu_idle_exit();
111 tick_nohz_idle_exit(); 103 tick_nohz_idle_exit();
112 preempt_enable_no_resched(); 104 preempt_enable_no_resched();
113 if (cpu_should_die()) 105 if (cpu_should_die())
diff --git a/arch/powerpc/kernel/machine_kexec_32.c b/arch/powerpc/kernel/machine_kexec_32.c
index e63f2e7d2efb..affe5dcce7f4 100644
--- a/arch/powerpc/kernel/machine_kexec_32.c
+++ b/arch/powerpc/kernel/machine_kexec_32.c
@@ -16,10 +16,10 @@
16#include <asm/hw_irq.h> 16#include <asm/hw_irq.h>
17#include <asm/io.h> 17#include <asm/io.h>
18 18
19typedef NORET_TYPE void (*relocate_new_kernel_t)( 19typedef void (*relocate_new_kernel_t)(
20 unsigned long indirection_page, 20 unsigned long indirection_page,
21 unsigned long reboot_code_buffer, 21 unsigned long reboot_code_buffer,
22 unsigned long start_address) ATTRIB_NORET; 22 unsigned long start_address) __noreturn;
23 23
24/* 24/*
25 * This is a generic machine_kexec function suitable at least for 25 * This is a generic machine_kexec function suitable at least for
diff --git a/arch/powerpc/kernel/machine_kexec_64.c b/arch/powerpc/kernel/machine_kexec_64.c
index 26ccbf77dd41..d7f609086a99 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -307,9 +307,9 @@ static union thread_union kexec_stack __init_task_data =
307struct paca_struct kexec_paca; 307struct paca_struct kexec_paca;
308 308
309/* Our assembly helper, in kexec_stub.S */ 309/* Our assembly helper, in kexec_stub.S */
310extern NORET_TYPE void kexec_sequence(void *newstack, unsigned long start, 310extern void kexec_sequence(void *newstack, unsigned long start,
311 void *image, void *control, 311 void *image, void *control,
312 void (*clear_all)(void)) ATTRIB_NORET; 312 void (*clear_all)(void)) __noreturn;
313 313
314/* too late to fail here */ 314/* too late to fail here */
315void default_machine_kexec(struct kimage *image) 315void default_machine_kexec(struct kimage *image)
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 4ff3d8e411a7..3feefc3842a8 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -58,7 +58,7 @@ static int distance_lookup_table[MAX_NUMNODES][MAX_DISTANCE_REF_POINTS];
58 * Allocate node_to_cpumask_map based on number of available nodes 58 * Allocate node_to_cpumask_map based on number of available nodes
59 * Requires node_possible_map to be valid. 59 * Requires node_possible_map to be valid.
60 * 60 *
61 * Note: node_to_cpumask() is not valid until after this is done. 61 * Note: cpumask_of_node() is not valid until after this is done.
62 */ 62 */
63static void __init setup_node_to_cpumask_map(void) 63static void __init setup_node_to_cpumask_map(void)
64{ 64{
diff --git a/arch/powerpc/platforms/pseries/hvCall.S b/arch/powerpc/platforms/pseries/hvCall.S
index fd05fdee576a..3ce73d0052b1 100644
--- a/arch/powerpc/platforms/pseries/hvCall.S
+++ b/arch/powerpc/platforms/pseries/hvCall.S
@@ -36,6 +36,7 @@ BEGIN_FTR_SECTION; \
36 b 1f; \ 36 b 1f; \
37END_FTR_SECTION(0, 1); \ 37END_FTR_SECTION(0, 1); \
38 ld r12,hcall_tracepoint_refcount@toc(r2); \ 38 ld r12,hcall_tracepoint_refcount@toc(r2); \
39 std r12,32(r1); \
39 cmpdi r12,0; \ 40 cmpdi r12,0; \
40 beq+ 1f; \ 41 beq+ 1f; \
41 mflr r0; \ 42 mflr r0; \
@@ -74,7 +75,7 @@ END_FTR_SECTION(0, 1); \
74BEGIN_FTR_SECTION; \ 75BEGIN_FTR_SECTION; \
75 b 1f; \ 76 b 1f; \
76END_FTR_SECTION(0, 1); \ 77END_FTR_SECTION(0, 1); \
77 ld r12,hcall_tracepoint_refcount@toc(r2); \ 78 ld r12,32(r1); \
78 cmpdi r12,0; \ 79 cmpdi r12,0; \
79 beq+ 1f; \ 80 beq+ 1f; \
80 mflr r0; \ 81 mflr r0; \
diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index 948e0e3b3547..7bc73af6c7b9 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -546,6 +546,13 @@ void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
546 unsigned long flags; 546 unsigned long flags;
547 unsigned int *depth; 547 unsigned int *depth;
548 548
549 /*
550 * We cannot call tracepoints inside RCU idle regions which
551 * means we must not trace H_CEDE.
552 */
553 if (opcode == H_CEDE)
554 return;
555
549 local_irq_save(flags); 556 local_irq_save(flags);
550 557
551 depth = &__get_cpu_var(hcall_trace_depth); 558 depth = &__get_cpu_var(hcall_trace_depth);
@@ -556,8 +563,6 @@ void __trace_hcall_entry(unsigned long opcode, unsigned long *args)
556 (*depth)++; 563 (*depth)++;
557 preempt_disable(); 564 preempt_disable();
558 trace_hcall_entry(opcode, args); 565 trace_hcall_entry(opcode, args);
559 if (opcode == H_CEDE)
560 rcu_idle_enter();
561 (*depth)--; 566 (*depth)--;
562 567
563out: 568out:
@@ -570,6 +575,9 @@ void __trace_hcall_exit(long opcode, unsigned long retval,
570 unsigned long flags; 575 unsigned long flags;
571 unsigned int *depth; 576 unsigned int *depth;
572 577
578 if (opcode == H_CEDE)
579 return;
580
573 local_irq_save(flags); 581 local_irq_save(flags);
574 582
575 depth = &__get_cpu_var(hcall_trace_depth); 583 depth = &__get_cpu_var(hcall_trace_depth);
@@ -578,8 +586,6 @@ void __trace_hcall_exit(long opcode, unsigned long retval,
578 goto out; 586 goto out;
579 587
580 (*depth)++; 588 (*depth)++;
581 if (opcode == H_CEDE)
582 rcu_idle_exit();
583 trace_hcall_exit(opcode, retval, retbuf); 589 trace_hcall_exit(opcode, retval, retbuf);
584 preempt_enable(); 590 preempt_enable();
585 (*depth)--; 591 (*depth)--;
diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c
index 330a57b7c17c..36f957f31842 100644
--- a/arch/powerpc/platforms/pseries/nvram.c
+++ b/arch/powerpc/platforms/pseries/nvram.c
@@ -638,7 +638,6 @@ static void oops_to_nvram(struct kmsg_dumper *dumper,
638 /* These are almost always orderly shutdowns. */ 638 /* These are almost always orderly shutdowns. */
639 return; 639 return;
640 case KMSG_DUMP_OOPS: 640 case KMSG_DUMP_OOPS:
641 case KMSG_DUMP_KEXEC:
642 break; 641 break;
643 case KMSG_DUMP_PANIC: 642 case KMSG_DUMP_PANIC:
644 panicking = true; 643 panicking = true;
diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
index 27272f6a14c2..d25843a6a915 100644
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@ -236,7 +236,7 @@ static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
236/* 236/*
237 * Function to drop a processor into disabled wait state 237 * Function to drop a processor into disabled wait state
238 */ 238 */
239static inline void ATTRIB_NORET disabled_wait(unsigned long code) 239static inline void __noreturn disabled_wait(unsigned long code)
240{ 240{
241 unsigned long ctl_buf; 241 unsigned long ctl_buf;
242 psw_t dw_psw; 242 psw_t dw_psw;
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index fab88431a06f..0fd2e863e114 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -30,7 +30,7 @@ struct mcck_struct {
30 30
31static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck); 31static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
32 32
33static NORET_TYPE void s390_handle_damage(char *msg) 33static void s390_handle_damage(char *msg)
34{ 34{
35 smp_send_stop(); 35 smp_send_stop();
36 disabled_wait((unsigned long) __builtin_return_address(0)); 36 disabled_wait((unsigned long) __builtin_return_address(0));
diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c
index aaf6d59c2012..7ec665178125 100644
--- a/arch/sh/kernel/process_32.c
+++ b/arch/sh/kernel/process_32.c
@@ -70,7 +70,7 @@ void show_regs(struct pt_regs * regs)
70/* 70/*
71 * Create a kernel thread 71 * Create a kernel thread
72 */ 72 */
73ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *)) 73__noreturn void kernel_thread_helper(void *arg, int (*fn)(void *))
74{ 74{
75 do_exit(fn(arg)); 75 do_exit(fn(arg));
76} 76}
diff --git a/arch/sh/kernel/process_64.c b/arch/sh/kernel/process_64.c
index 210c1cabcb7f..cbd4e4bb9fc5 100644
--- a/arch/sh/kernel/process_64.c
+++ b/arch/sh/kernel/process_64.c
@@ -285,7 +285,7 @@ void show_regs(struct pt_regs *regs)
285/* 285/*
286 * Create a kernel thread 286 * Create a kernel thread
287 */ 287 */
288ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *)) 288__noreturn void kernel_thread_helper(void *arg, int (*fn)(void *))
289{ 289{
290 do_exit(fn(arg)); 290 do_exit(fn(arg));
291} 291}
diff --git a/arch/tile/kernel/machine_kexec.c b/arch/tile/kernel/machine_kexec.c
index e00d7179989e..6255f2eab112 100644
--- a/arch/tile/kernel/machine_kexec.c
+++ b/arch/tile/kernel/machine_kexec.c
@@ -248,11 +248,11 @@ static void setup_quasi_va_is_pa(void)
248} 248}
249 249
250 250
251NORET_TYPE void machine_kexec(struct kimage *image) 251void machine_kexec(struct kimage *image)
252{ 252{
253 void *reboot_code_buffer; 253 void *reboot_code_buffer;
254 NORET_TYPE void (*rnk)(unsigned long, void *, unsigned long) 254 void (*rnk)(unsigned long, void *, unsigned long)
255 ATTRIB_NORET; 255 __noreturn;
256 256
257 /* Mask all interrupts before starting to reboot. */ 257 /* Mask all interrupts before starting to reboot. */
258 interrupt_mask_set_mask(~0ULL); 258 interrupt_mask_set_mask(~0ULL);
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index a150f4c35e94..6c14ecd851d0 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -60,6 +60,9 @@ config X86
60 select PERF_EVENTS 60 select PERF_EVENTS
61 select HAVE_PERF_EVENTS_NMI 61 select HAVE_PERF_EVENTS_NMI
62 select ANON_INODES 62 select ANON_INODES
63 select HAVE_ALIGNED_STRUCT_PAGE if SLUB && !M386
64 select HAVE_CMPXCHG_LOCAL if !M386
65 select HAVE_CMPXCHG_DOUBLE
63 select HAVE_ARCH_KMEMCHECK 66 select HAVE_ARCH_KMEMCHECK
64 select HAVE_USER_RETURN_NOTIFIER 67 select HAVE_USER_RETURN_NOTIFIER
65 select ARCH_BINFMT_ELF_RANDOMIZE_PIE 68 select ARCH_BINFMT_ELF_RANDOMIZE_PIE
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index e3ca7e0d858c..3c57033e2211 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -309,12 +309,6 @@ config X86_INTERNODE_CACHE_SHIFT
309config X86_CMPXCHG 309config X86_CMPXCHG
310 def_bool X86_64 || (X86_32 && !M386) 310 def_bool X86_64 || (X86_32 && !M386)
311 311
312config CMPXCHG_LOCAL
313 def_bool X86_64 || (X86_32 && !M386)
314
315config CMPXCHG_DOUBLE
316 def_bool y
317
318config X86_L1_CACHE_SHIFT 312config X86_L1_CACHE_SHIFT
319 int 313 int
320 default "7" if MPENTIUM4 || MPSC 314 default "7" if MPENTIUM4 || MPSC
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index f22a9f7f6390..29ba3297e480 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -2011,7 +2011,7 @@ static __cpuinit int mce_device_create(unsigned int cpu)
2011 if (!mce_available(&boot_cpu_data)) 2011 if (!mce_available(&boot_cpu_data))
2012 return -EIO; 2012 return -EIO;
2013 2013
2014 memset(&dev->kobj, 0, sizeof(struct kobject)); 2014 memset(dev, 0, sizeof(struct device));
2015 dev->id = cpu; 2015 dev->id = cpu;
2016 dev->bus = &mce_subsys; 2016 dev->bus = &mce_subsys;
2017 2017
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 020cd2e80873..19d3fa08b119 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -110,7 +110,7 @@ void __cpuinit numa_clear_node(int cpu)
110 * Allocate node_to_cpumask_map based on number of available nodes 110 * Allocate node_to_cpumask_map based on number of available nodes
111 * Requires node_possible_map to be valid. 111 * Requires node_possible_map to be valid.
112 * 112 *
113 * Note: node_to_cpumask() is not valid until after this is done. 113 * Note: cpumask_of_node() is not valid until after this is done.
114 * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.) 114 * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
115 */ 115 */
116void __init setup_node_to_cpumask_map(void) 116void __init setup_node_to_cpumask_map(void)
diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig
index 1d97bd84b6fb..b2b54d2edf53 100644
--- a/arch/x86/um/Kconfig
+++ b/arch/x86/um/Kconfig
@@ -6,14 +6,6 @@ menu "UML-specific options"
6 6
7menu "Host processor type and features" 7menu "Host processor type and features"
8 8
9config CMPXCHG_LOCAL
10 bool
11 default n
12
13config CMPXCHG_DOUBLE
14 bool
15 default n
16
17source "arch/x86/Kconfig.cpu" 9source "arch/x86/Kconfig.cpu"
18 10
19endmenu 11endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 1b3142127bf5..c07be024b962 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -97,7 +97,7 @@ obj-$(CONFIG_EISA) += eisa/
97obj-y += lguest/ 97obj-y += lguest/
98obj-$(CONFIG_CPU_FREQ) += cpufreq/ 98obj-$(CONFIG_CPU_FREQ) += cpufreq/
99obj-$(CONFIG_CPU_IDLE) += cpuidle/ 99obj-$(CONFIG_CPU_IDLE) += cpuidle/
100obj-$(CONFIG_MMC) += mmc/ 100obj-y += mmc/
101obj-$(CONFIG_MEMSTICK) += memstick/ 101obj-$(CONFIG_MEMSTICK) += memstick/
102obj-y += leds/ 102obj-y += leds/
103obj-$(CONFIG_INFINIBAND) += infiniband/ 103obj-$(CONFIG_INFINIBAND) += infiniband/
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index fcbec8ac134d..7be9f79018e9 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -179,7 +179,7 @@ config GENERIC_CPU_DEVICES
179source "drivers/base/regmap/Kconfig" 179source "drivers/base/regmap/Kconfig"
180 180
181config DMA_SHARED_BUFFER 181config DMA_SHARED_BUFFER
182 bool "Buffer framework to be shared between drivers" 182 bool
183 default n 183 default n
184 select ANON_INODES 184 select ANON_INODES
185 depends on EXPERIMENTAL 185 depends on EXPERIMENTAL
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index f17e3ea041c0..ed5de58c340f 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -295,11 +295,22 @@ static int memory_block_change_state(struct memory_block *mem,
295 295
296 ret = memory_block_action(mem->start_section_nr, to_state); 296 ret = memory_block_action(mem->start_section_nr, to_state);
297 297
298 if (ret) 298 if (ret) {
299 mem->state = from_state_req; 299 mem->state = from_state_req;
300 else 300 goto out;
301 mem->state = to_state; 301 }
302 302
303 mem->state = to_state;
304 switch (mem->state) {
305 case MEM_OFFLINE:
306 kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE);
307 break;
308 case MEM_ONLINE:
309 kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE);
310 break;
311 default:
312 break;
313 }
303out: 314out:
304 mutex_unlock(&mem->state_mutex); 315 mutex_unlock(&mem->state_mutex);
305 return ret; 316 return ret;
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 148ab944378d..3fd31dec8c9c 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2184,6 +2184,8 @@ static ssize_t rbd_add(struct bus_type *bus,
2184 INIT_LIST_HEAD(&rbd_dev->node); 2184 INIT_LIST_HEAD(&rbd_dev->node);
2185 INIT_LIST_HEAD(&rbd_dev->snaps); 2185 INIT_LIST_HEAD(&rbd_dev->snaps);
2186 2186
2187 init_rwsem(&rbd_dev->header.snap_rwsem);
2188
2187 /* generate unique id: find highest unique id, add one */ 2189 /* generate unique id: find highest unique id, add one */
2188 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 2190 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2189 2191
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c
index 7c7f42a1f880..9fec3232b736 100644
--- a/drivers/char/ramoops.c
+++ b/drivers/char/ramoops.c
@@ -83,8 +83,7 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
83 struct timeval timestamp; 83 struct timeval timestamp;
84 84
85 if (reason != KMSG_DUMP_OOPS && 85 if (reason != KMSG_DUMP_OOPS &&
86 reason != KMSG_DUMP_PANIC && 86 reason != KMSG_DUMP_PANIC)
87 reason != KMSG_DUMP_KEXEC)
88 return; 87 return;
89 88
90 /* Only dump oopses if dump_oops is set */ 89 /* Only dump oopses if dump_oops is set */
@@ -126,8 +125,8 @@ static int __init ramoops_probe(struct platform_device *pdev)
126 goto fail3; 125 goto fail3;
127 } 126 }
128 127
129 rounddown_pow_of_two(pdata->mem_size); 128 pdata->mem_size = rounddown_pow_of_two(pdata->mem_size);
130 rounddown_pow_of_two(pdata->record_size); 129 pdata->record_size = rounddown_pow_of_two(pdata->record_size);
131 130
132 /* Check for the minimum memory size */ 131 /* Check for the minimum memory size */
133 if (pdata->mem_size < MIN_MEM_SIZE && 132 if (pdata->mem_size < MIN_MEM_SIZE &&
@@ -148,14 +147,6 @@ static int __init ramoops_probe(struct platform_device *pdev)
148 cxt->phys_addr = pdata->mem_address; 147 cxt->phys_addr = pdata->mem_address;
149 cxt->record_size = pdata->record_size; 148 cxt->record_size = pdata->record_size;
150 cxt->dump_oops = pdata->dump_oops; 149 cxt->dump_oops = pdata->dump_oops;
151 /*
152 * Update the module parameter variables as well so they are visible
153 * through /sys/module/ramoops/parameters/
154 */
155 mem_size = pdata->mem_size;
156 mem_address = pdata->mem_address;
157 record_size = pdata->record_size;
158 dump_oops = pdata->dump_oops;
159 150
160 if (!request_mem_region(cxt->phys_addr, cxt->size, "ramoops")) { 151 if (!request_mem_region(cxt->phys_addr, cxt->size, "ramoops")) {
161 pr_err("request mem region failed\n"); 152 pr_err("request mem region failed\n");
@@ -176,6 +167,15 @@ static int __init ramoops_probe(struct platform_device *pdev)
176 goto fail1; 167 goto fail1;
177 } 168 }
178 169
170 /*
171 * Update the module parameter variables as well so they are visible
172 * through /sys/module/ramoops/parameters/
173 */
174 mem_size = pdata->mem_size;
175 mem_address = pdata->mem_address;
176 record_size = pdata->record_size;
177 dump_oops = pdata->dump_oops;
178
179 return 0; 179 return 0;
180 180
181fail1: 181fail1:
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index 4c980b573328..87a68a896abf 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -65,7 +65,14 @@ static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
65 u8 reg = stmpe->regs[which] - (offset / 8); 65 u8 reg = stmpe->regs[which] - (offset / 8);
66 u8 mask = 1 << (offset % 8); 66 u8 mask = 1 << (offset % 8);
67 67
68 stmpe_reg_write(stmpe, reg, mask); 68 /*
69 * Some variants have single register for gpio set/clear functionality.
70 * For them we need to write 0 to clear and 1 to set.
71 */
72 if (stmpe->regs[STMPE_IDX_GPSR_LSB] == stmpe->regs[STMPE_IDX_GPCR_LSB])
73 stmpe_set_bits(stmpe, reg, mask, val ? mask : 0);
74 else
75 stmpe_reg_write(stmpe, reg, mask);
69} 76}
70 77
71static int stmpe_gpio_direction_output(struct gpio_chip *chip, 78static int stmpe_gpio_direction_output(struct gpio_chip *chip,
@@ -132,6 +139,10 @@ static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
132 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) 139 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
133 return -EINVAL; 140 return -EINVAL;
134 141
142 /* STMPE801 doesn't have RE and FE registers */
143 if (stmpe_gpio->stmpe->partnum == STMPE801)
144 return 0;
145
135 if (type == IRQ_TYPE_EDGE_RISING) 146 if (type == IRQ_TYPE_EDGE_RISING)
136 stmpe_gpio->regs[REG_RE][regoffset] |= mask; 147 stmpe_gpio->regs[REG_RE][regoffset] |= mask;
137 else 148 else
@@ -165,6 +176,11 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
165 int i, j; 176 int i, j;
166 177
167 for (i = 0; i < CACHE_NR_REGS; i++) { 178 for (i = 0; i < CACHE_NR_REGS; i++) {
179 /* STMPE801 doesn't have RE and FE registers */
180 if ((stmpe->partnum == STMPE801) &&
181 (i != REG_IE))
182 continue;
183
168 for (j = 0; j < num_banks; j++) { 184 for (j = 0; j < num_banks; j++) {
169 u8 old = stmpe_gpio->oldregs[i][j]; 185 u8 old = stmpe_gpio->oldregs[i][j];
170 u8 new = stmpe_gpio->regs[i][j]; 186 u8 new = stmpe_gpio->regs[i][j];
@@ -241,8 +257,11 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
241 } 257 }
242 258
243 stmpe_reg_write(stmpe, statmsbreg + i, status[i]); 259 stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
244 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB] + i, 260
245 status[i]); 261 /* Edge detect register is not present on 801 */
262 if (stmpe->partnum != STMPE801)
263 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB]
264 + i, status[i]);
246 } 265 }
247 266
248 return IRQ_HANDLED; 267 return IRQ_HANDLED;
diff --git a/drivers/gpu/drm/gma500/cdv_intel_crt.c b/drivers/gpu/drm/gma500/cdv_intel_crt.c
index 6d0f10b7569c..c100f3e9c920 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_crt.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_crt.c
@@ -66,6 +66,7 @@ static void cdv_intel_crt_dpms(struct drm_encoder *encoder, int mode)
66static int cdv_intel_crt_mode_valid(struct drm_connector *connector, 66static int cdv_intel_crt_mode_valid(struct drm_connector *connector,
67 struct drm_display_mode *mode) 67 struct drm_display_mode *mode)
68{ 68{
69 struct drm_psb_private *dev_priv = connector->dev->dev_private;
69 int max_clock = 0; 70 int max_clock = 0;
70 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 71 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
71 return MODE_NO_DBLESCAN; 72 return MODE_NO_DBLESCAN;
@@ -82,6 +83,11 @@ static int cdv_intel_crt_mode_valid(struct drm_connector *connector,
82 if (mode->hdisplay > 1680 || mode->vdisplay > 1050) 83 if (mode->hdisplay > 1680 || mode->vdisplay > 1050)
83 return MODE_PANEL; 84 return MODE_PANEL;
84 85
86 /* We assume worst case scenario of 32 bpp here, since we don't know */
87 if ((ALIGN(mode->hdisplay * 4, 64) * mode->vdisplay) >
88 dev_priv->vram_stolen_size)
89 return MODE_MEM;
90
85 return MODE_OK; 91 return MODE_OK;
86} 92}
87 93
diff --git a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
index 50d7cfb51662..de25560e629d 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_hdmi.c
@@ -241,6 +241,7 @@ static int cdv_hdmi_get_modes(struct drm_connector *connector)
241static int cdv_hdmi_mode_valid(struct drm_connector *connector, 241static int cdv_hdmi_mode_valid(struct drm_connector *connector,
242 struct drm_display_mode *mode) 242 struct drm_display_mode *mode)
243{ 243{
244 struct drm_psb_private *dev_priv = connector->dev->dev_private;
244 245
245 if (mode->clock > 165000) 246 if (mode->clock > 165000)
246 return MODE_CLOCK_HIGH; 247 return MODE_CLOCK_HIGH;
@@ -255,14 +256,11 @@ static int cdv_hdmi_mode_valid(struct drm_connector *connector,
255 if (mode->flags & DRM_MODE_FLAG_INTERLACE) 256 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
256 return MODE_NO_INTERLACE; 257 return MODE_NO_INTERLACE;
257 258
258 /* 259 /* We assume worst case scenario of 32 bpp here, since we don't know */
259 * FIXME: for now we limit the size to 1680x1050 on CDV, otherwise it 260 if ((ALIGN(mode->hdisplay * 4, 64) * mode->vdisplay) >
260 * will go beyond the stolen memory size allocated to the framebuffer 261 dev_priv->vram_stolen_size)
261 */ 262 return MODE_MEM;
262 if (mode->hdisplay > 1680) 263
263 return MODE_PANEL;
264 if (mode->vdisplay > 1050)
265 return MODE_PANEL;
266 return MODE_OK; 264 return MODE_OK;
267} 265}
268 266
diff --git a/drivers/gpu/drm/gma500/oaktrail_hdmi.c b/drivers/gpu/drm/gma500/oaktrail_hdmi.c
index 36878a60080d..025d30970cc0 100644
--- a/drivers/gpu/drm/gma500/oaktrail_hdmi.c
+++ b/drivers/gpu/drm/gma500/oaktrail_hdmi.c
@@ -506,6 +506,7 @@ int oaktrail_crtc_hdmi_mode_set(struct drm_crtc *crtc,
506static int oaktrail_hdmi_mode_valid(struct drm_connector *connector, 506static int oaktrail_hdmi_mode_valid(struct drm_connector *connector,
507 struct drm_display_mode *mode) 507 struct drm_display_mode *mode)
508{ 508{
509 struct drm_psb_private *dev_priv = connector->dev->dev_private;
509 if (mode->clock > 165000) 510 if (mode->clock > 165000)
510 return MODE_CLOCK_HIGH; 511 return MODE_CLOCK_HIGH;
511 if (mode->clock < 20000) 512 if (mode->clock < 20000)
@@ -514,6 +515,11 @@ static int oaktrail_hdmi_mode_valid(struct drm_connector *connector,
514 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 515 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
515 return MODE_NO_DBLESCAN; 516 return MODE_NO_DBLESCAN;
516 517
518 /* We assume worst case scenario of 32 bpp here, since we don't know */
519 if ((ALIGN(mode->hdisplay * 4, 64) * mode->vdisplay) >
520 dev_priv->vram_stolen_size)
521 return MODE_MEM;
522
517 return MODE_OK; 523 return MODE_OK;
518} 524}
519 525
diff --git a/drivers/gpu/drm/gma500/psb_intel_sdvo.c b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
index 4882b29119e0..88b42971c0fd 100644
--- a/drivers/gpu/drm/gma500/psb_intel_sdvo.c
+++ b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
@@ -1141,6 +1141,7 @@ static void psb_intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1141static int psb_intel_sdvo_mode_valid(struct drm_connector *connector, 1141static int psb_intel_sdvo_mode_valid(struct drm_connector *connector,
1142 struct drm_display_mode *mode) 1142 struct drm_display_mode *mode)
1143{ 1143{
1144 struct drm_psb_private *dev_priv = connector->dev->dev_private;
1144 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector); 1145 struct psb_intel_sdvo *psb_intel_sdvo = intel_attached_sdvo(connector);
1145 1146
1146 if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 1147 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
@@ -1160,6 +1161,11 @@ static int psb_intel_sdvo_mode_valid(struct drm_connector *connector,
1160 return MODE_PANEL; 1161 return MODE_PANEL;
1161 } 1162 }
1162 1163
1164 /* We assume worst case scenario of 32 bpp here, since we don't know */
1165 if ((ALIGN(mode->hdisplay * 4, 64) * mode->vdisplay) >
1166 dev_priv->vram_stolen_size)
1167 return MODE_MEM;
1168
1163 return MODE_OK; 1169 return MODE_OK;
1164} 1170}
1165 1171
diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c
index 525744d593c1..7814a760c164 100644
--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c
@@ -18,12 +18,6 @@
18 18
19#include <linux/vga_switcheroo.h> 19#include <linux/vga_switcheroo.h>
20 20
21#define NOUVEAU_DSM_SUPPORTED 0x00
22#define NOUVEAU_DSM_SUPPORTED_FUNCTIONS 0x00
23
24#define NOUVEAU_DSM_ACTIVE 0x01
25#define NOUVEAU_DSM_ACTIVE_QUERY 0x00
26
27#define NOUVEAU_DSM_LED 0x02 21#define NOUVEAU_DSM_LED 0x02
28#define NOUVEAU_DSM_LED_STATE 0x00 22#define NOUVEAU_DSM_LED_STATE 0x00
29#define NOUVEAU_DSM_LED_OFF 0x10 23#define NOUVEAU_DSM_LED_OFF 0x10
@@ -35,6 +29,9 @@
35#define NOUVEAU_DSM_POWER_SPEED 0x01 29#define NOUVEAU_DSM_POWER_SPEED 0x01
36#define NOUVEAU_DSM_POWER_STAMINA 0x02 30#define NOUVEAU_DSM_POWER_STAMINA 0x02
37 31
32#define NOUVEAU_DSM_OPTIMUS_FN 0x1A
33#define NOUVEAU_DSM_OPTIMUS_ARGS 0x03000001
34
38static struct nouveau_dsm_priv { 35static struct nouveau_dsm_priv {
39 bool dsm_detected; 36 bool dsm_detected;
40 bool optimus_detected; 37 bool optimus_detected;
@@ -61,7 +58,8 @@ static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *
61 struct acpi_object_list input; 58 struct acpi_object_list input;
62 union acpi_object params[4]; 59 union acpi_object params[4];
63 union acpi_object *obj; 60 union acpi_object *obj;
64 int err; 61 int i, err;
62 char args_buff[4];
65 63
66 input.count = 4; 64 input.count = 4;
67 input.pointer = params; 65 input.pointer = params;
@@ -73,7 +71,11 @@ static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *
73 params[2].type = ACPI_TYPE_INTEGER; 71 params[2].type = ACPI_TYPE_INTEGER;
74 params[2].integer.value = func; 72 params[2].integer.value = func;
75 params[3].type = ACPI_TYPE_BUFFER; 73 params[3].type = ACPI_TYPE_BUFFER;
76 params[3].buffer.length = 0; 74 params[3].buffer.length = 4;
75 /* ACPI is little endian, AABBCCDD becomes {DD,CC,BB,AA} */
76 for (i = 0; i < 4; i++)
77 args_buff[i] = (arg >> i * 8) & 0xFF;
78 params[3].buffer.pointer = args_buff;
77 79
78 err = acpi_evaluate_object(handle, "_DSM", &input, &output); 80 err = acpi_evaluate_object(handle, "_DSM", &input, &output);
79 if (err) { 81 if (err) {
@@ -148,6 +150,23 @@ static int nouveau_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
148 return 0; 150 return 0;
149} 151}
150 152
153/* Returns 1 if a DSM function is usable and 0 otherwise */
154static int nouveau_test_dsm(acpi_handle test_handle,
155 int (*dsm_func)(acpi_handle, int, int, uint32_t *),
156 int sfnc)
157{
158 u32 result = 0;
159
160 /* Function 0 returns a Buffer containing available functions. The args
161 * parameter is ignored for function 0, so just put 0 in it */
162 if (dsm_func(test_handle, 0, 0, &result))
163 return 0;
164
165 /* ACPI Spec v4 9.14.1: if bit 0 is zero, no function is supported. If
166 * the n-th bit is enabled, function n is supported */
167 return result & 1 && result & (1 << sfnc);
168}
169
151static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id) 170static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
152{ 171{
153 mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0); 172 mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
@@ -168,6 +187,10 @@ static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switchero
168 187
169static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id) 188static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
170{ 189{
190 /* perhaps the _DSM functions are mutually exclusive, but prepare for
191 * the future */
192 if (!nouveau_dsm_priv.dsm_detected && nouveau_dsm_priv.optimus_detected)
193 return 0;
171 if (id == VGA_SWITCHEROO_IGD) 194 if (id == VGA_SWITCHEROO_IGD)
172 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA); 195 return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
173 else 196 else
@@ -180,6 +203,11 @@ static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
180 if (id == VGA_SWITCHEROO_IGD) 203 if (id == VGA_SWITCHEROO_IGD)
181 return 0; 204 return 0;
182 205
206 /* Optimus laptops have the card already disabled in
207 * nouveau_switcheroo_set_state */
208 if (!nouveau_dsm_priv.dsm_detected && nouveau_dsm_priv.optimus_detected)
209 return 0;
210
183 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state); 211 return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
184} 212}
185 213
@@ -212,8 +240,7 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
212{ 240{
213 acpi_handle dhandle, nvidia_handle; 241 acpi_handle dhandle, nvidia_handle;
214 acpi_status status; 242 acpi_status status;
215 int ret, retval = 0; 243 int retval = 0;
216 uint32_t result;
217 244
218 dhandle = DEVICE_ACPI_HANDLE(&pdev->dev); 245 dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
219 if (!dhandle) 246 if (!dhandle)
@@ -224,13 +251,11 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
224 return false; 251 return false;
225 } 252 }
226 253
227 ret = nouveau_dsm(dhandle, NOUVEAU_DSM_SUPPORTED, 254 if (nouveau_test_dsm(dhandle, nouveau_dsm, NOUVEAU_DSM_POWER))
228 NOUVEAU_DSM_SUPPORTED_FUNCTIONS, &result);
229 if (ret == 0)
230 retval |= NOUVEAU_DSM_HAS_MUX; 255 retval |= NOUVEAU_DSM_HAS_MUX;
231 256
232 ret = nouveau_optimus_dsm(dhandle, 0, 0, &result); 257 if (nouveau_test_dsm(dhandle, nouveau_optimus_dsm,
233 if (ret == 0) 258 NOUVEAU_DSM_OPTIMUS_FN))
234 retval |= NOUVEAU_DSM_HAS_OPT; 259 retval |= NOUVEAU_DSM_HAS_OPT;
235 260
236 if (retval) 261 if (retval)
@@ -269,15 +294,22 @@ static bool nouveau_dsm_detect(void)
269 } 294 }
270 295
271 if (vga_count == 2 && has_dsm && guid_valid) { 296 if (vga_count == 2 && has_dsm && guid_valid) {
272 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME, &buffer); 297 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
298 &buffer);
273 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n", 299 printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
274 acpi_method_name); 300 acpi_method_name);
275 nouveau_dsm_priv.dsm_detected = true; 301 nouveau_dsm_priv.dsm_detected = true;
276 ret = true; 302 ret = true;
277 } 303 }
278 304
279 if (has_optimus == 1) 305 if (has_optimus == 1) {
306 acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
307 &buffer);
308 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
309 acpi_method_name);
280 nouveau_dsm_priv.optimus_detected = true; 310 nouveau_dsm_priv.optimus_detected = true;
311 ret = true;
312 }
281 313
282 return ret; 314 return ret;
283} 315}
@@ -293,6 +325,17 @@ void nouveau_register_dsm_handler(void)
293 vga_switcheroo_register_handler(&nouveau_dsm_handler); 325 vga_switcheroo_register_handler(&nouveau_dsm_handler);
294} 326}
295 327
328/* Must be called for Optimus models before the card can be turned off */
329void nouveau_switcheroo_optimus_dsm(void)
330{
331 u32 result = 0;
332 if (!nouveau_dsm_priv.optimus_detected)
333 return;
334
335 nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FN,
336 NOUVEAU_DSM_OPTIMUS_ARGS, &result);
337}
338
296void nouveau_unregister_dsm_handler(void) 339void nouveau_unregister_dsm_handler(void)
297{ 340{
298 vga_switcheroo_unregister_handler(); 341 vga_switcheroo_unregister_handler();
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index 38134a9c7578..b82709828931 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -1055,12 +1055,14 @@ extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size);
1055#if defined(CONFIG_ACPI) 1055#if defined(CONFIG_ACPI)
1056void nouveau_register_dsm_handler(void); 1056void nouveau_register_dsm_handler(void);
1057void nouveau_unregister_dsm_handler(void); 1057void nouveau_unregister_dsm_handler(void);
1058void nouveau_switcheroo_optimus_dsm(void);
1058int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len); 1059int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
1059bool nouveau_acpi_rom_supported(struct pci_dev *pdev); 1060bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
1060int nouveau_acpi_edid(struct drm_device *, struct drm_connector *); 1061int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
1061#else 1062#else
1062static inline void nouveau_register_dsm_handler(void) {} 1063static inline void nouveau_register_dsm_handler(void) {}
1063static inline void nouveau_unregister_dsm_handler(void) {} 1064static inline void nouveau_unregister_dsm_handler(void) {}
1065static inline void nouveau_switcheroo_optimus_dsm(void) {}
1064static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; } 1066static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
1065static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; } 1067static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
1066static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; } 1068static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
index f5e98910d17f..f80c5e0762ff 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -525,6 +525,7 @@ static void nouveau_switcheroo_set_state(struct pci_dev *pdev,
525 printk(KERN_ERR "VGA switcheroo: switched nouveau off\n"); 525 printk(KERN_ERR "VGA switcheroo: switched nouveau off\n");
526 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; 526 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
527 drm_kms_helper_poll_disable(dev); 527 drm_kms_helper_poll_disable(dev);
528 nouveau_switcheroo_optimus_dsm();
528 nouveau_pci_suspend(pdev, pmm); 529 nouveau_pci_suspend(pdev, pmm);
529 dev->switch_power_state = DRM_SWITCH_POWER_OFF; 530 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
530 } 531 }
diff --git a/drivers/gpu/drm/radeon/evergreen_cs.c b/drivers/gpu/drm/radeon/evergreen_cs.c
index f7442e62c03f..8e8cd85e5c00 100644
--- a/drivers/gpu/drm/radeon/evergreen_cs.c
+++ b/drivers/gpu/drm/radeon/evergreen_cs.c
@@ -1793,10 +1793,12 @@ int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
1793 ret = -EINVAL; 1793 ret = -EINVAL;
1794 break; 1794 break;
1795 case PACKET_TYPE2: 1795 case PACKET_TYPE2:
1796 idx += 1;
1796 break; 1797 break;
1797 case PACKET_TYPE3: 1798 case PACKET_TYPE3:
1798 pkt.opcode = CP_PACKET3_GET_OPCODE(ib->ptr[idx]); 1799 pkt.opcode = CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
1799 ret = evergreen_vm_packet3_check(rdev, ib->ptr, &pkt); 1800 ret = evergreen_vm_packet3_check(rdev, ib->ptr, &pkt);
1801 idx += pkt.count + 2;
1800 break; 1802 break;
1801 default: 1803 default:
1802 dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type); 1804 dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
@@ -1805,7 +1807,6 @@ int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
1805 } 1807 }
1806 if (ret) 1808 if (ret)
1807 break; 1809 break;
1808 idx += pkt.count + 2;
1809 } while (idx < ib->length_dw); 1810 } while (idx < ib->length_dw);
1810 1811
1811 return ret; 1812 return ret;
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 3ec81c3d5108..bfd36ab643a6 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -2186,7 +2186,6 @@ bool r100_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
2186void r100_bm_disable(struct radeon_device *rdev) 2186void r100_bm_disable(struct radeon_device *rdev)
2187{ 2187{
2188 u32 tmp; 2188 u32 tmp;
2189 u16 tmp16;
2190 2189
2191 /* disable bus mastering */ 2190 /* disable bus mastering */
2192 tmp = RREG32(R_000030_BUS_CNTL); 2191 tmp = RREG32(R_000030_BUS_CNTL);
@@ -2197,8 +2196,7 @@ void r100_bm_disable(struct radeon_device *rdev)
2197 WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000040); 2196 WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000040);
2198 tmp = RREG32(RADEON_BUS_CNTL); 2197 tmp = RREG32(RADEON_BUS_CNTL);
2199 mdelay(1); 2198 mdelay(1);
2200 pci_read_config_word(rdev->pdev, 0x4, &tmp16); 2199 pci_clear_master(rdev->pdev);
2201 pci_write_config_word(rdev->pdev, 0x4, tmp16 & 0xFFFB);
2202 mdelay(1); 2200 mdelay(1);
2203} 2201}
2204 2202
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 31da622eef63..8032f1fedb11 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -145,7 +145,7 @@ module_param_named(vramlimit, radeon_vram_limit, int, 0600);
145MODULE_PARM_DESC(agpmode, "AGP Mode (-1 == PCI)"); 145MODULE_PARM_DESC(agpmode, "AGP Mode (-1 == PCI)");
146module_param_named(agpmode, radeon_agpmode, int, 0444); 146module_param_named(agpmode, radeon_agpmode, int, 0444);
147 147
148MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32,64, etc)\n"); 148MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32, 64, etc)");
149module_param_named(gartsize, radeon_gart_size, int, 0600); 149module_param_named(gartsize, radeon_gart_size, int, 0600);
150 150
151MODULE_PARM_DESC(benchmark, "Run benchmark"); 151MODULE_PARM_DESC(benchmark, "Run benchmark");
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index 803e0d3c1773..ec46eb45e34c 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -322,16 +322,6 @@ void rs600_hpd_fini(struct radeon_device *rdev)
322 } 322 }
323} 323}
324 324
325void rs600_bm_disable(struct radeon_device *rdev)
326{
327 u16 tmp;
328
329 /* disable bus mastering */
330 pci_read_config_word(rdev->pdev, 0x4, &tmp);
331 pci_write_config_word(rdev->pdev, 0x4, tmp & 0xFFFB);
332 mdelay(1);
333}
334
335int rs600_asic_reset(struct radeon_device *rdev) 325int rs600_asic_reset(struct radeon_device *rdev)
336{ 326{
337 struct rv515_mc_save save; 327 struct rv515_mc_save save;
@@ -355,7 +345,8 @@ int rs600_asic_reset(struct radeon_device *rdev)
355 WREG32(RADEON_CP_RB_CNTL, tmp); 345 WREG32(RADEON_CP_RB_CNTL, tmp);
356 pci_save_state(rdev->pdev); 346 pci_save_state(rdev->pdev);
357 /* disable bus mastering */ 347 /* disable bus mastering */
358 rs600_bm_disable(rdev); 348 pci_clear_master(rdev->pdev);
349 mdelay(1);
359 /* reset GA+VAP */ 350 /* reset GA+VAP */
360 WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_VAP(1) | 351 WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_VAP(1) |
361 S_0000F0_SOFT_RESET_GA(1)); 352 S_0000F0_SOFT_RESET_GA(1));
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index 37ead6995c87..0c46d8cdc6ea 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -952,10 +952,9 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
952 952
953 type = ttm_to_type(ttm->page_flags, ttm->caching_state); 953 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
954 pool = ttm_dma_find_pool(dev, type); 954 pool = ttm_dma_find_pool(dev, type);
955 if (!pool) { 955 if (!pool)
956 WARN_ON(!pool);
957 return; 956 return;
958 } 957
959 is_cached = (ttm_dma_find_pool(pool->dev, 958 is_cached = (ttm_dma_find_pool(pool->dev,
960 ttm_to_type(ttm->page_flags, tt_cached)) == pool); 959 ttm_to_type(ttm->page_flags, tt_cached)) == pool);
961 960
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index b6807db7b36f..e66d248fc126 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -132,7 +132,8 @@
132#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */ 132#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */
133 133
134static struct pci_driver ali1535_driver; 134static struct pci_driver ali1535_driver;
135static unsigned short ali1535_smba; 135static unsigned long ali1535_smba;
136static unsigned short ali1535_offset;
136 137
137/* Detect whether a ALI1535 can be found, and initialize it, where necessary. 138/* Detect whether a ALI1535 can be found, and initialize it, where necessary.
138 Note the differences between kernels with the old PCI BIOS interface and 139 Note the differences between kernels with the old PCI BIOS interface and
@@ -140,7 +141,7 @@ static unsigned short ali1535_smba;
140 defined to make the transition easier. */ 141 defined to make the transition easier. */
141static int __devinit ali1535_setup(struct pci_dev *dev) 142static int __devinit ali1535_setup(struct pci_dev *dev)
142{ 143{
143 int retval = -ENODEV; 144 int retval;
144 unsigned char temp; 145 unsigned char temp;
145 146
146 /* Check the following things: 147 /* Check the following things:
@@ -149,15 +150,28 @@ static int __devinit ali1535_setup(struct pci_dev *dev)
149 - We can use the addresses 150 - We can use the addresses
150 */ 151 */
151 152
153 retval = pci_enable_device(dev);
154 if (retval) {
155 dev_err(&dev->dev, "ALI1535_smb can't enable device\n");
156 goto exit;
157 }
158
152 /* Determine the address of the SMBus area */ 159 /* Determine the address of the SMBus area */
153 pci_read_config_word(dev, SMBBA, &ali1535_smba); 160 pci_read_config_word(dev, SMBBA, &ali1535_offset);
154 ali1535_smba &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1)); 161 dev_dbg(&dev->dev, "ALI1535_smb is at offset 0x%04x\n", ali1535_offset);
155 if (ali1535_smba == 0) { 162 ali1535_offset &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
163 if (ali1535_offset == 0) {
156 dev_warn(&dev->dev, 164 dev_warn(&dev->dev,
157 "ALI1535_smb region uninitialized - upgrade BIOS?\n"); 165 "ALI1535_smb region uninitialized - upgrade BIOS?\n");
166 retval = -ENODEV;
158 goto exit; 167 goto exit;
159 } 168 }
160 169
170 if (pci_resource_flags(dev, 0) & IORESOURCE_IO)
171 ali1535_smba = pci_resource_start(dev, 0) + ali1535_offset;
172 else
173 ali1535_smba = ali1535_offset;
174
161 retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE, 175 retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE,
162 ali1535_driver.name); 176 ali1535_driver.name);
163 if (retval) 177 if (retval)
@@ -165,8 +179,9 @@ static int __devinit ali1535_setup(struct pci_dev *dev)
165 179
166 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE, 180 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
167 ali1535_driver.name)) { 181 ali1535_driver.name)) {
168 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n", 182 dev_err(&dev->dev, "ALI1535_smb region 0x%lx already in use!\n",
169 ali1535_smba); 183 ali1535_smba);
184 retval = -EBUSY;
170 goto exit; 185 goto exit;
171 } 186 }
172 187
@@ -174,6 +189,7 @@ static int __devinit ali1535_setup(struct pci_dev *dev)
174 pci_read_config_byte(dev, SMBCFG, &temp); 189 pci_read_config_byte(dev, SMBCFG, &temp);
175 if ((temp & ALI1535_SMBIO_EN) == 0) { 190 if ((temp & ALI1535_SMBIO_EN) == 0) {
176 dev_err(&dev->dev, "SMB device not enabled - upgrade BIOS?\n"); 191 dev_err(&dev->dev, "SMB device not enabled - upgrade BIOS?\n");
192 retval = -ENODEV;
177 goto exit_free; 193 goto exit_free;
178 } 194 }
179 195
@@ -181,6 +197,7 @@ static int __devinit ali1535_setup(struct pci_dev *dev)
181 pci_read_config_byte(dev, SMBHSTCFG, &temp); 197 pci_read_config_byte(dev, SMBHSTCFG, &temp);
182 if ((temp & 1) == 0) { 198 if ((temp & 1) == 0) {
183 dev_err(&dev->dev, "SMBus controller not enabled - upgrade BIOS?\n"); 199 dev_err(&dev->dev, "SMBus controller not enabled - upgrade BIOS?\n");
200 retval = -ENODEV;
184 goto exit_free; 201 goto exit_free;
185 } 202 }
186 203
@@ -196,14 +213,13 @@ static int __devinit ali1535_setup(struct pci_dev *dev)
196 */ 213 */
197 pci_read_config_byte(dev, SMBREV, &temp); 214 pci_read_config_byte(dev, SMBREV, &temp);
198 dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp); 215 dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp);
199 dev_dbg(&dev->dev, "ALI1535_smba = 0x%X\n", ali1535_smba); 216 dev_dbg(&dev->dev, "ALI1535_smba = 0x%lx\n", ali1535_smba);
200 217
201 retval = 0; 218 return 0;
202exit:
203 return retval;
204 219
205exit_free: 220exit_free:
206 release_region(ali1535_smba, ALI1535_SMB_IOSIZE); 221 release_region(ali1535_smba, ALI1535_SMB_IOSIZE);
222exit:
207 return retval; 223 return retval;
208} 224}
209 225
@@ -498,7 +514,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
498 ali1535_adapter.dev.parent = &dev->dev; 514 ali1535_adapter.dev.parent = &dev->dev;
499 515
500 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name), 516 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
501 "SMBus ALI1535 adapter at %04x", ali1535_smba); 517 "SMBus ALI1535 adapter at %04x", ali1535_offset);
502 return i2c_add_adapter(&ali1535_adapter); 518 return i2c_add_adapter(&ali1535_adapter);
503} 519}
504 520
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index a409cfcf0629..47ae0091e027 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -417,7 +417,7 @@ static void __devexit ali1563_remove(struct pci_dev * dev)
417 ali1563_shutdown(dev); 417 ali1563_shutdown(dev);
418} 418}
419 419
420static const struct pci_device_id ali1563_id_table[] __devinitconst = { 420static DEFINE_PCI_DEVICE_TABLE(ali1563_id_table) = {
421 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) }, 421 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1563) },
422 {}, 422 {},
423}; 423};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 83e8a60cdc86..087ea9caa74d 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -477,7 +477,7 @@ static struct i2c_adapter ali15x3_adapter = {
477 .algo = &smbus_algorithm, 477 .algo = &smbus_algorithm,
478}; 478};
479 479
480static const struct pci_device_id ali15x3_ids[] = { 480static DEFINE_PCI_DEVICE_TABLE(ali15x3_ids) = {
481 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) }, 481 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
482 { 0, } 482 { 0, }
483}; 483};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 03bcd07c4697..eb778bf15c18 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -308,7 +308,7 @@ static const char* chipname[] = {
308 "nVidia nForce", "AMD8111", 308 "nVidia nForce", "AMD8111",
309}; 309};
310 310
311static const struct pci_device_id amd756_ids[] = { 311static DEFINE_PCI_DEVICE_TABLE(amd756_ids) = {
312 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B), 312 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B),
313 .driver_data = AMD756 }, 313 .driver_data = AMD756 },
314 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413), 314 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413),
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 6b6a6b1d7025..e5ac53b99b04 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -415,7 +415,7 @@ static const struct i2c_algorithm smbus_algorithm = {
415}; 415};
416 416
417 417
418static const struct pci_device_id amd8111_ids[] = { 418static DEFINE_PCI_DEVICE_TABLE(amd8111_ids) = {
419 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) }, 419 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) },
420 { 0, } 420 { 0, }
421}; 421};
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 305c07504f7e..1679deef9c89 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -295,9 +295,6 @@ static int at91_i2c_resume(struct platform_device *pdev)
295#define at91_i2c_resume NULL 295#define at91_i2c_resume NULL
296#endif 296#endif
297 297
298/* work with "modprobe at91_i2c" from hotplugging or coldplugging */
299MODULE_ALIAS("platform:at91_i2c");
300
301static struct platform_driver at91_i2c_driver = { 298static struct platform_driver at91_i2c_driver = {
302 .probe = at91_i2c_probe, 299 .probe = at91_i2c_probe,
303 .remove = __devexit_p(at91_i2c_remove), 300 .remove = __devexit_p(at91_i2c_remove),
@@ -309,19 +306,9 @@ static struct platform_driver at91_i2c_driver = {
309 }, 306 },
310}; 307};
311 308
312static int __init at91_i2c_init(void) 309module_platform_driver(at91_i2c_driver);
313{
314 return platform_driver_register(&at91_i2c_driver);
315}
316
317static void __exit at91_i2c_exit(void)
318{
319 platform_driver_unregister(&at91_i2c_driver);
320}
321
322module_init(at91_i2c_init);
323module_exit(at91_i2c_exit);
324 310
325MODULE_AUTHOR("Rick Bronson"); 311MODULE_AUTHOR("Rick Bronson");
326MODULE_DESCRIPTION("I2C (TWI) driver for Atmel AT91"); 312MODULE_DESCRIPTION("I2C (TWI) driver for Atmel AT91");
327MODULE_LICENSE("GPL"); 313MODULE_LICENSE("GPL");
314MODULE_ALIAS("platform:at91_i2c");
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index f314d7f433d3..582d616db346 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -426,20 +426,9 @@ static struct platform_driver au1xpsc_smbus_driver = {
426 .remove = __devexit_p(i2c_au1550_remove), 426 .remove = __devexit_p(i2c_au1550_remove),
427}; 427};
428 428
429static int __init i2c_au1550_init(void) 429module_platform_driver(au1xpsc_smbus_driver);
430{
431 return platform_driver_register(&au1xpsc_smbus_driver);
432}
433
434static void __exit i2c_au1550_exit(void)
435{
436 platform_driver_unregister(&au1xpsc_smbus_driver);
437}
438 430
439MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC."); 431MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC.");
440MODULE_DESCRIPTION("SMBus adapter Alchemy pb1550"); 432MODULE_DESCRIPTION("SMBus adapter Alchemy pb1550");
441MODULE_LICENSE("GPL"); 433MODULE_LICENSE("GPL");
442MODULE_ALIAS("platform:au1xpsc_smbus"); 434MODULE_ALIAS("platform:au1xpsc_smbus");
443
444module_init (i2c_au1550_init);
445module_exit (i2c_au1550_exit);
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index b1d9cd28d8da..c1e1096ba069 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -724,18 +724,7 @@ static struct platform_driver cpm_i2c_driver = {
724 }, 724 },
725}; 725};
726 726
727static int __init cpm_i2c_init(void) 727module_platform_driver(cpm_i2c_driver);
728{
729 return platform_driver_register(&cpm_i2c_driver);
730}
731
732static void __exit cpm_i2c_exit(void)
733{
734 platform_driver_unregister(&cpm_i2c_driver);
735}
736
737module_init(cpm_i2c_init);
738module_exit(cpm_i2c_exit);
739 728
740MODULE_AUTHOR("Jochen Friedrich <jochen@scram.de>"); 729MODULE_AUTHOR("Jochen Friedrich <jochen@scram.de>");
741MODULE_DESCRIPTION("I2C-Bus adapter routines for CPM boards"); 730MODULE_DESCRIPTION("I2C-Bus adapter routines for CPM boards");
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 9e89e7313d62..37f42113af31 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -349,7 +349,7 @@ static void __devexit i2c_dw_pci_remove(struct pci_dev *pdev)
349/* work with hotplug and coldplug */ 349/* work with hotplug and coldplug */
350MODULE_ALIAS("i2c_designware-pci"); 350MODULE_ALIAS("i2c_designware-pci");
351 351
352DEFINE_PCI_DEVICE_TABLE(i2_designware_pci_ids) = { 352static DEFINE_PCI_DEVICE_TABLE(i2_designware_pci_ids) = {
353 /* Moorestown */ 353 /* Moorestown */
354 { PCI_VDEVICE(INTEL, 0x0802), moorestown_0 }, 354 { PCI_VDEVICE(INTEL, 0x0802), moorestown_0 },
355 { PCI_VDEVICE(INTEL, 0x0803), moorestown_1 }, 355 { PCI_VDEVICE(INTEL, 0x0803), moorestown_1 },
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index 18936ac9d51c..3ef3557b6e32 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -185,7 +185,7 @@ static DEFINE_MUTEX(pch_mutex);
185#define PCI_DEVICE_ID_ML7213_I2C 0x802D 185#define PCI_DEVICE_ID_ML7213_I2C 0x802D
186#define PCI_DEVICE_ID_ML7223_I2C 0x8010 186#define PCI_DEVICE_ID_ML7223_I2C 0x8010
187 187
188static struct pci_device_id __devinitdata pch_pcidev_id[] = { 188static DEFINE_PCI_DEVICE_TABLE(pch_pcidev_id) = {
189 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, }, 189 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, },
190 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, }, 190 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, },
191 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, }, 191 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, },
diff --git a/drivers/i2c/busses/i2c-highlander.c b/drivers/i2c/busses/i2c-highlander.c
index fa88868cb556..19515df61021 100644
--- a/drivers/i2c/busses/i2c-highlander.c
+++ b/drivers/i2c/busses/i2c-highlander.c
@@ -468,18 +468,7 @@ static struct platform_driver highlander_i2c_driver = {
468 .remove = __devexit_p(highlander_i2c_remove), 468 .remove = __devexit_p(highlander_i2c_remove),
469}; 469};
470 470
471static int __init highlander_i2c_init(void) 471module_platform_driver(highlander_i2c_driver);
472{
473 return platform_driver_register(&highlander_i2c_driver);
474}
475
476static void __exit highlander_i2c_exit(void)
477{
478 platform_driver_unregister(&highlander_i2c_driver);
479}
480
481module_init(highlander_i2c_init);
482module_exit(highlander_i2c_exit);
483 472
484MODULE_AUTHOR("Paul Mundt"); 473MODULE_AUTHOR("Paul Mundt");
485MODULE_DESCRIPTION("Renesas Highlander FPGA I2C/SMBus adapter"); 474MODULE_DESCRIPTION("Renesas Highlander FPGA I2C/SMBus adapter");
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index 9ff1695d8458..c527de17db4f 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -105,7 +105,7 @@ static struct i2c_adapter hydra_adap = {
105 .algo_data = &hydra_bit_data, 105 .algo_data = &hydra_bit_data,
106}; 106};
107 107
108static const struct pci_device_id hydra_ids[] = { 108static DEFINE_PCI_DEVICE_TABLE(hydra_ids) = {
109 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, 109 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) },
110 { 0, } 110 { 0, }
111}; 111};
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index ab26840d0c70..5d2e2816831f 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -609,7 +609,7 @@ static const struct i2c_algorithm smbus_algorithm = {
609 .functionality = i801_func, 609 .functionality = i801_func,
610}; 610};
611 611
612static const struct pci_device_id i801_ids[] = { 612static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
613 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) }, 613 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
614 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) }, 614 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
615 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) }, 615 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index c08ceb957aa7..806e225f3de7 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -815,15 +815,4 @@ static struct platform_driver ibm_iic_driver = {
815 .remove = __devexit_p(iic_remove), 815 .remove = __devexit_p(iic_remove),
816}; 816};
817 817
818static int __init iic_init(void) 818module_platform_driver(ibm_iic_driver);
819{
820 return platform_driver_register(&ibm_iic_driver);
821}
822
823static void __exit iic_exit(void)
824{
825 platform_driver_unregister(&ibm_iic_driver);
826}
827
828module_init(iic_init);
829module_exit(iic_exit);
diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c
index e828ac85cfa7..365bad5b890b 100644
--- a/drivers/i2c/busses/i2c-intel-mid.c
+++ b/drivers/i2c/busses/i2c-intel-mid.c
@@ -1093,7 +1093,7 @@ static void __devexit intel_mid_i2c_remove(struct pci_dev *dev)
1093 pci_release_region(dev, 0); 1093 pci_release_region(dev, 0);
1094} 1094}
1095 1095
1096static struct pci_device_id intel_mid_i2c_ids[] = { 1096static DEFINE_PCI_DEVICE_TABLE(intel_mid_i2c_ids) = {
1097 /* Moorestown */ 1097 /* Moorestown */
1098 { PCI_VDEVICE(INTEL, 0x0802), 0 }, 1098 { PCI_VDEVICE(INTEL, 0x0802), 0 },
1099 { PCI_VDEVICE(INTEL, 0x0803), 1 }, 1099 { PCI_VDEVICE(INTEL, 0x0803), 1 },
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index f09c9319a2ba..93f147a96b62 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -523,21 +523,7 @@ static struct platform_driver iop3xx_i2c_driver = {
523 }, 523 },
524}; 524};
525 525
526static int __init 526module_platform_driver(iop3xx_i2c_driver);
527i2c_iop3xx_init (void)
528{
529 return platform_driver_register(&iop3xx_i2c_driver);
530}
531
532static void __exit
533i2c_iop3xx_exit (void)
534{
535 platform_driver_unregister(&iop3xx_i2c_driver);
536 return;
537}
538
539module_init (i2c_iop3xx_init);
540module_exit (i2c_iop3xx_exit);
541 527
542MODULE_AUTHOR("D-TACQ Solutions Ltd <www.d-tacq.com>"); 528MODULE_AUTHOR("D-TACQ Solutions Ltd <www.d-tacq.com>");
543MODULE_DESCRIPTION("IOP3xx iic algorithm and driver"); 529MODULE_DESCRIPTION("IOP3xx iic algorithm and driver");
diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
index 0682f8f277b0..6561d275b8cf 100644
--- a/drivers/i2c/busses/i2c-isch.c
+++ b/drivers/i2c/busses/i2c-isch.c
@@ -306,20 +306,9 @@ static struct platform_driver smbus_sch_driver = {
306 .remove = __devexit_p(smbus_sch_remove), 306 .remove = __devexit_p(smbus_sch_remove),
307}; 307};
308 308
309static int __init i2c_sch_init(void) 309module_platform_driver(smbus_sch_driver);
310{
311 return platform_driver_register(&smbus_sch_driver);
312}
313
314static void __exit i2c_sch_exit(void)
315{
316 platform_driver_unregister(&smbus_sch_driver);
317}
318 310
319MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@intel.com>"); 311MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@intel.com>");
320MODULE_DESCRIPTION("Intel SCH SMBus driver"); 312MODULE_DESCRIPTION("Intel SCH SMBus driver");
321MODULE_LICENSE("GPL"); 313MODULE_LICENSE("GPL");
322
323module_init(i2c_sch_init);
324module_exit(i2c_sch_exit);
325MODULE_ALIAS("platform:isch_smbus"); 314MODULE_ALIAS("platform:isch_smbus");
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index c01e9519f6c1..5d263f9014d6 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -148,18 +148,7 @@ static struct platform_driver ixp2000_i2c_driver = {
148 }, 148 },
149}; 149};
150 150
151static int __init ixp2000_i2c_init(void) 151module_platform_driver(ixp2000_i2c_driver);
152{
153 return platform_driver_register(&ixp2000_i2c_driver);
154}
155
156static void __exit ixp2000_i2c_exit(void)
157{
158 platform_driver_unregister(&ixp2000_i2c_driver);
159}
160
161module_init(ixp2000_i2c_init);
162module_exit(ixp2000_i2c_exit);
163 152
164MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>"); 153MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>");
165MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver"); 154MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver");
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 107397a606b4..a8ebb84e23f9 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -715,18 +715,7 @@ static struct platform_driver mpc_i2c_driver = {
715 }, 715 },
716}; 716};
717 717
718static int __init fsl_i2c_init(void) 718module_platform_driver(mpc_i2c_driver);
719{
720 return platform_driver_register(&mpc_i2c_driver);
721}
722
723static void __exit fsl_i2c_exit(void)
724{
725 platform_driver_unregister(&mpc_i2c_driver);
726}
727
728module_init(fsl_i2c_init);
729module_exit(fsl_i2c_exit);
730 719
731MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 720MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
732MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and " 721MODULE_DESCRIPTION("I2C-Bus adapter for MPC107 bridge and "
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index a9941c65f226..4f44a33017b0 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -611,20 +611,7 @@ static struct platform_driver mv64xxx_i2c_driver = {
611 }, 611 },
612}; 612};
613 613
614static int __init 614module_platform_driver(mv64xxx_i2c_driver);
615mv64xxx_i2c_init(void)
616{
617 return platform_driver_register(&mv64xxx_i2c_driver);
618}
619
620static void __exit
621mv64xxx_i2c_exit(void)
622{
623 platform_driver_unregister(&mv64xxx_i2c_driver);
624}
625
626module_init(mv64xxx_i2c_init);
627module_exit(mv64xxx_i2c_exit);
628 615
629MODULE_AUTHOR("Mark A. Greer <mgreer@mvista.com>"); 616MODULE_AUTHOR("Mark A. Greer <mgreer@mvista.com>");
630MODULE_DESCRIPTION("Marvell mv64xxx host bridge i2c ctlr driver"); 617MODULE_DESCRIPTION("Marvell mv64xxx host bridge i2c ctlr driver");
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index ff1e127dfea8..43a96a123920 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -309,7 +309,7 @@ static struct i2c_algorithm smbus_algorithm = {
309}; 309};
310 310
311 311
312static const struct pci_device_id nforce2_ids[] = { 312static DEFINE_PCI_DEVICE_TABLE(nforce2_ids) = {
313 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, 313 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) },
314 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) }, 314 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) },
315 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) }, 315 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) },
@@ -356,7 +356,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
356 error = acpi_check_region(smbus->base, smbus->size, 356 error = acpi_check_region(smbus->base, smbus->size,
357 nforce2_driver.name); 357 nforce2_driver.name);
358 if (error) 358 if (error)
359 return -1; 359 return error;
360 360
361 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) { 361 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) {
362 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", 362 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n",
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 1b46a9d9f907..18068dee48f1 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -394,9 +394,6 @@ static struct of_device_id ocores_i2c_match[] = {
394}; 394};
395MODULE_DEVICE_TABLE(of, ocores_i2c_match); 395MODULE_DEVICE_TABLE(of, ocores_i2c_match);
396 396
397/* work with hotplug and coldplug */
398MODULE_ALIAS("platform:ocores-i2c");
399
400static struct platform_driver ocores_i2c_driver = { 397static struct platform_driver ocores_i2c_driver = {
401 .probe = ocores_i2c_probe, 398 .probe = ocores_i2c_probe,
402 .remove = __devexit_p(ocores_i2c_remove), 399 .remove = __devexit_p(ocores_i2c_remove),
@@ -409,19 +406,9 @@ static struct platform_driver ocores_i2c_driver = {
409 }, 406 },
410}; 407};
411 408
412static int __init ocores_i2c_init(void) 409module_platform_driver(ocores_i2c_driver);
413{
414 return platform_driver_register(&ocores_i2c_driver);
415}
416
417static void __exit ocores_i2c_exit(void)
418{
419 platform_driver_unregister(&ocores_i2c_driver);
420}
421
422module_init(ocores_i2c_init);
423module_exit(ocores_i2c_exit);
424 410
425MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>"); 411MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
426MODULE_DESCRIPTION("OpenCores I2C bus driver"); 412MODULE_DESCRIPTION("OpenCores I2C bus driver");
427MODULE_LICENSE("GPL"); 413MODULE_LICENSE("GPL");
414MODULE_ALIAS("platform:ocores-i2c");
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index 56dbe54e8811..ee139a598814 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -629,24 +629,10 @@ static struct platform_driver octeon_i2c_driver = {
629 }, 629 },
630}; 630};
631 631
632static int __init octeon_i2c_init(void) 632module_platform_driver(octeon_i2c_driver);
633{
634 int rv;
635
636 rv = platform_driver_register(&octeon_i2c_driver);
637 return rv;
638}
639
640static void __exit octeon_i2c_exit(void)
641{
642 platform_driver_unregister(&octeon_i2c_driver);
643}
644 633
645MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>"); 634MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>");
646MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors"); 635MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
647MODULE_LICENSE("GPL"); 636MODULE_LICENSE("GPL");
648MODULE_VERSION(DRV_VERSION); 637MODULE_VERSION(DRV_VERSION);
649MODULE_ALIAS("platform:" DRV_NAME); 638MODULE_ALIAS("platform:" DRV_NAME);
650
651module_init(octeon_i2c_init);
652module_exit(octeon_i2c_exit);
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 837b8c1aa02a..eaaea73209c5 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -401,7 +401,7 @@ static void __devexit pasemi_smb_remove(struct pci_dev *dev)
401 kfree(smbus); 401 kfree(smbus);
402} 402}
403 403
404static const struct pci_device_id pasemi_smb_ids[] = { 404static DEFINE_PCI_DEVICE_TABLE(pasemi_smb_ids) = {
405 { PCI_DEVICE(0x1959, 0xa003) }, 405 { PCI_DEVICE(0x1959, 0xa003) },
406 { 0, } 406 { 0, }
407}; 407};
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index ace67995d7de..2adbf1a8fdea 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -286,20 +286,8 @@ static struct platform_driver i2c_pca_pf_driver = {
286 }, 286 },
287}; 287};
288 288
289static int __init i2c_pca_pf_init(void) 289module_platform_driver(i2c_pca_pf_driver);
290{
291 return platform_driver_register(&i2c_pca_pf_driver);
292}
293
294static void __exit i2c_pca_pf_exit(void)
295{
296 platform_driver_unregister(&i2c_pca_pf_driver);
297}
298 290
299MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>"); 291MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
300MODULE_DESCRIPTION("I2C-PCA9564/PCA9665 platform driver"); 292MODULE_DESCRIPTION("I2C-PCA9564/PCA9665 platform driver");
301MODULE_LICENSE("GPL"); 293MODULE_LICENSE("GPL");
302
303module_init(i2c_pca_pf_init);
304module_exit(i2c_pca_pf_exit);
305
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 6d14ac2e3c41..c14d48dd601a 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -472,7 +472,7 @@ static struct i2c_adapter piix4_adapter = {
472 .algo = &smbus_algorithm, 472 .algo = &smbus_algorithm,
473}; 473};
474 474
475static const struct pci_device_id piix4_ids[] = { 475static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = {
476 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, 476 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
477 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, 477 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
478 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, 478 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
index 127051b06921..07b7447ecbc9 100644
--- a/drivers/i2c/busses/i2c-pmcmsp.c
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -627,9 +627,6 @@ static struct i2c_adapter pmcmsptwi_adapter = {
627 .name = DRV_NAME, 627 .name = DRV_NAME,
628}; 628};
629 629
630/* work with hotplug and coldplug */
631MODULE_ALIAS("platform:" DRV_NAME);
632
633static struct platform_driver pmcmsptwi_driver = { 630static struct platform_driver pmcmsptwi_driver = {
634 .probe = pmcmsptwi_probe, 631 .probe = pmcmsptwi_probe,
635 .remove = __devexit_p(pmcmsptwi_remove), 632 .remove = __devexit_p(pmcmsptwi_remove),
@@ -639,18 +636,8 @@ static struct platform_driver pmcmsptwi_driver = {
639 }, 636 },
640}; 637};
641 638
642static int __init pmcmsptwi_init(void) 639module_platform_driver(pmcmsptwi_driver);
643{
644 return platform_driver_register(&pmcmsptwi_driver);
645}
646
647static void __exit pmcmsptwi_exit(void)
648{
649 platform_driver_unregister(&pmcmsptwi_driver);
650}
651 640
652MODULE_DESCRIPTION("PMC MSP TWI/SMBus/I2C driver"); 641MODULE_DESCRIPTION("PMC MSP TWI/SMBus/I2C driver");
653MODULE_LICENSE("GPL"); 642MODULE_LICENSE("GPL");
654 643MODULE_ALIAS("platform:" DRV_NAME);
655module_init(pmcmsptwi_init);
656module_exit(pmcmsptwi_exit);
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index b289ec99eeba..7b397c6f607e 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -312,10 +312,6 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
312 return rc; 312 return rc;
313} 313}
314 314
315
316/* work with hotplug and coldplug */
317MODULE_ALIAS("platform:i2c-powermac");
318
319static struct platform_driver i2c_powermac_driver = { 315static struct platform_driver i2c_powermac_driver = {
320 .probe = i2c_powermac_probe, 316 .probe = i2c_powermac_probe,
321 .remove = __devexit_p(i2c_powermac_remove), 317 .remove = __devexit_p(i2c_powermac_remove),
@@ -325,17 +321,6 @@ static struct platform_driver i2c_powermac_driver = {
325 }, 321 },
326}; 322};
327 323
328static int __init i2c_powermac_init(void) 324module_platform_driver(i2c_powermac_driver);
329{
330 platform_driver_register(&i2c_powermac_driver);
331 return 0;
332}
333 325
334 326MODULE_ALIAS("platform:i2c-powermac");
335static void __exit i2c_powermac_cleanup(void)
336{
337 platform_driver_unregister(&i2c_powermac_driver);
338}
339
340module_init(i2c_powermac_init);
341module_exit(i2c_powermac_cleanup);
diff --git a/drivers/i2c/busses/i2c-pxa-pci.c b/drivers/i2c/busses/i2c-pxa-pci.c
index 632e088760a3..a05817980556 100644
--- a/drivers/i2c/busses/i2c-pxa-pci.c
+++ b/drivers/i2c/busses/i2c-pxa-pci.c
@@ -150,7 +150,7 @@ static void __devexit ce4100_i2c_remove(struct pci_dev *dev)
150 kfree(sds); 150 kfree(sds);
151} 151}
152 152
153static struct pci_device_id ce4100_i2c_devices[] __devinitdata = { 153static DEFINE_PCI_DEVICE_TABLE(ce4100_i2c_devices) = {
154 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)}, 154 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)},
155 { }, 155 { },
156}; 156};
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c
index a67132b2e092..c0c9dffbdb12 100644
--- a/drivers/i2c/busses/i2c-sh7760.c
+++ b/drivers/i2c/busses/i2c-sh7760.c
@@ -560,18 +560,7 @@ static struct platform_driver sh7760_i2c_drv = {
560 .remove = __devexit_p(sh7760_i2c_remove), 560 .remove = __devexit_p(sh7760_i2c_remove),
561}; 561};
562 562
563static int __init sh7760_i2c_init(void) 563module_platform_driver(sh7760_i2c_drv);
564{
565 return platform_driver_register(&sh7760_i2c_drv);
566}
567
568static void __exit sh7760_i2c_exit(void)
569{
570 platform_driver_unregister(&sh7760_i2c_drv);
571}
572
573module_init(sh7760_i2c_init);
574module_exit(sh7760_i2c_exit);
575 564
576MODULE_LICENSE("GPL"); 565MODULE_LICENSE("GPL");
577MODULE_DESCRIPTION("SH7760 I2C bus driver"); 566MODULE_DESCRIPTION("SH7760 I2C bus driver");
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
index 2fc08fbf67a2..4fc87e7c94c9 100644
--- a/drivers/i2c/busses/i2c-simtec.c
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -156,12 +156,8 @@ static int simtec_i2c_remove(struct platform_device *dev)
156 return 0; 156 return 0;
157} 157}
158 158
159
160/* device driver */ 159/* device driver */
161 160
162/* work with hotplug and coldplug */
163MODULE_ALIAS("platform:simtec-i2c");
164
165static struct platform_driver simtec_i2c_driver = { 161static struct platform_driver simtec_i2c_driver = {
166 .driver = { 162 .driver = {
167 .name = "simtec-i2c", 163 .name = "simtec-i2c",
@@ -171,19 +167,9 @@ static struct platform_driver simtec_i2c_driver = {
171 .remove = simtec_i2c_remove, 167 .remove = simtec_i2c_remove,
172}; 168};
173 169
174static int __init i2c_adap_simtec_init(void) 170module_platform_driver(simtec_i2c_driver);
175{
176 return platform_driver_register(&simtec_i2c_driver);
177}
178
179static void __exit i2c_adap_simtec_exit(void)
180{
181 platform_driver_unregister(&simtec_i2c_driver);
182}
183
184module_init(i2c_adap_simtec_init);
185module_exit(i2c_adap_simtec_exit);
186 171
187MODULE_DESCRIPTION("Simtec Generic I2C Bus driver"); 172MODULE_DESCRIPTION("Simtec Generic I2C Bus driver");
188MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 173MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
189MODULE_LICENSE("GPL"); 174MODULE_LICENSE("GPL");
175MODULE_ALIAS("platform:simtec-i2c");
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 437586611d4a..87e5126d449c 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -147,7 +147,7 @@ static int __devinit sis5595_setup(struct pci_dev *SIS5595_dev)
147 u16 a; 147 u16 a;
148 u8 val; 148 u8 val;
149 int *i; 149 int *i;
150 int retval = -ENODEV; 150 int retval;
151 151
152 /* Look for imposters */ 152 /* Look for imposters */
153 for (i = blacklist; *i != 0; i++) { 153 for (i = blacklist; *i != 0; i++) {
@@ -223,7 +223,7 @@ static int __devinit sis5595_setup(struct pci_dev *SIS5595_dev)
223 223
224error: 224error:
225 release_region(sis5595_base + SMB_INDEX, 2); 225 release_region(sis5595_base + SMB_INDEX, 2);
226 return retval; 226 return -ENODEV;
227} 227}
228 228
229static int sis5595_transaction(struct i2c_adapter *adap) 229static int sis5595_transaction(struct i2c_adapter *adap)
@@ -369,7 +369,7 @@ static struct i2c_adapter sis5595_adapter = {
369 .algo = &smbus_algorithm, 369 .algo = &smbus_algorithm,
370}; 370};
371 371
372static const struct pci_device_id sis5595_ids[] __devinitconst = { 372static DEFINE_PCI_DEVICE_TABLE(sis5595_ids) = {
373 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 373 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
374 { 0, } 374 { 0, }
375}; 375};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 58893772c3d8..15cf78f65ce0 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -393,7 +393,7 @@ static int __devinit sis630_setup(struct pci_dev *sis630_dev)
393{ 393{
394 unsigned char b; 394 unsigned char b;
395 struct pci_dev *dummy = NULL; 395 struct pci_dev *dummy = NULL;
396 int retval = -ENODEV, i; 396 int retval, i;
397 397
398 /* check for supported SiS devices */ 398 /* check for supported SiS devices */
399 for (i=0; supported[i] > 0 ; i++) { 399 for (i=0; supported[i] > 0 ; i++) {
@@ -418,18 +418,21 @@ static int __devinit sis630_setup(struct pci_dev *sis630_dev)
418 */ 418 */
419 if (pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG,&b)) { 419 if (pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG,&b)) {
420 dev_err(&sis630_dev->dev, "Error: Can't read bios ctl reg\n"); 420 dev_err(&sis630_dev->dev, "Error: Can't read bios ctl reg\n");
421 retval = -ENODEV;
421 goto exit; 422 goto exit;
422 } 423 }
423 /* if ACPI already enabled , do nothing */ 424 /* if ACPI already enabled , do nothing */
424 if (!(b & 0x80) && 425 if (!(b & 0x80) &&
425 pci_write_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, b | 0x80)) { 426 pci_write_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, b | 0x80)) {
426 dev_err(&sis630_dev->dev, "Error: Can't enable ACPI\n"); 427 dev_err(&sis630_dev->dev, "Error: Can't enable ACPI\n");
428 retval = -ENODEV;
427 goto exit; 429 goto exit;
428 } 430 }
429 431
430 /* Determine the ACPI base address */ 432 /* Determine the ACPI base address */
431 if (pci_read_config_word(sis630_dev,SIS630_ACPI_BASE_REG,&acpi_base)) { 433 if (pci_read_config_word(sis630_dev,SIS630_ACPI_BASE_REG,&acpi_base)) {
432 dev_err(&sis630_dev->dev, "Error: Can't determine ACPI base address\n"); 434 dev_err(&sis630_dev->dev, "Error: Can't determine ACPI base address\n");
435 retval = -ENODEV;
433 goto exit; 436 goto exit;
434 } 437 }
435 438
@@ -445,6 +448,7 @@ static int __devinit sis630_setup(struct pci_dev *sis630_dev)
445 sis630_driver.name)) { 448 sis630_driver.name)) {
446 dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already " 449 dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already "
447 "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA); 450 "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA);
451 retval = -EBUSY;
448 goto exit; 452 goto exit;
449 } 453 }
450 454
@@ -468,7 +472,7 @@ static struct i2c_adapter sis630_adapter = {
468 .algo = &smbus_algorithm, 472 .algo = &smbus_algorithm,
469}; 473};
470 474
471static const struct pci_device_id sis630_ids[] __devinitconst = { 475static DEFINE_PCI_DEVICE_TABLE(sis630_ids) = {
472 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 476 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
473 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) }, 477 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
474 { 0, } 478 { 0, }
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 86837f0c4cb9..cc5d149413f7 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -245,7 +245,7 @@ static struct i2c_adapter sis96x_adapter = {
245 .algo = &smbus_algorithm, 245 .algo = &smbus_algorithm,
246}; 246};
247 247
248static const struct pci_device_id sis96x_ids[] = { 248static DEFINE_PCI_DEVICE_TABLE(sis96x_ids) = {
249 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) }, 249 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
250 { 0, } 250 { 0, }
251}; 251};
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 7799fe5bda88..713d31ade26b 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -89,7 +89,7 @@ static struct i2c_adapter vt586b_adapter = {
89}; 89};
90 90
91 91
92static const struct pci_device_id vt586b_ids[] __devinitconst = { 92static DEFINE_PCI_DEVICE_TABLE(vt586b_ids) = {
93 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) }, 93 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) },
94 { 0, } 94 { 0, }
95}; 95};
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 2a62c998044a..333011c83d52 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -324,7 +324,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
324 const struct pci_device_id *id) 324 const struct pci_device_id *id)
325{ 325{
326 unsigned char temp; 326 unsigned char temp;
327 int error = -ENODEV; 327 int error;
328 328
329 /* Determine the address of the SMBus areas */ 329 /* Determine the address of the SMBus areas */
330 if (force_addr) { 330 if (force_addr) {
@@ -390,6 +390,7 @@ found:
390 dev_err(&pdev->dev, "SMBUS: Error: Host SMBus " 390 dev_err(&pdev->dev, "SMBUS: Error: Host SMBus "
391 "controller not enabled! - upgrade BIOS or " 391 "controller not enabled! - upgrade BIOS or "
392 "use force=1\n"); 392 "use force=1\n");
393 error = -ENODEV;
393 goto release_region; 394 goto release_region;
394 } 395 }
395 } 396 }
@@ -422,9 +423,11 @@ found:
422 "SMBus Via Pro adapter at %04x", vt596_smba); 423 "SMBus Via Pro adapter at %04x", vt596_smba);
423 424
424 vt596_pdev = pci_dev_get(pdev); 425 vt596_pdev = pci_dev_get(pdev);
425 if (i2c_add_adapter(&vt596_adapter)) { 426 error = i2c_add_adapter(&vt596_adapter);
427 if (error) {
426 pci_dev_put(vt596_pdev); 428 pci_dev_put(vt596_pdev);
427 vt596_pdev = NULL; 429 vt596_pdev = NULL;
430 goto release_region;
428 } 431 }
429 432
430 /* Always return failure here. This is to allow other drivers to bind 433 /* Always return failure here. This is to allow other drivers to bind
@@ -438,7 +441,7 @@ release_region:
438 return error; 441 return error;
439} 442}
440 443
441static const struct pci_device_id vt596_ids[] = { 444static DEFINE_PCI_DEVICE_TABLE(vt596_ids) = {
442 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3), 445 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596_3),
443 .driver_data = SMBBA1 }, 446 .driver_data = SMBBA1 },
444 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3), 447 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596B_3),
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index ac083a28ae08..2bded7647ef2 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -795,10 +795,6 @@ static int __devexit xiic_i2c_remove(struct platform_device* pdev)
795 return 0; 795 return 0;
796} 796}
797 797
798
799/* work with hotplug and coldplug */
800MODULE_ALIAS("platform:"DRIVER_NAME);
801
802static struct platform_driver xiic_i2c_driver = { 798static struct platform_driver xiic_i2c_driver = {
803 .probe = xiic_i2c_probe, 799 .probe = xiic_i2c_probe,
804 .remove = __devexit_p(xiic_i2c_remove), 800 .remove = __devexit_p(xiic_i2c_remove),
@@ -808,19 +804,9 @@ static struct platform_driver xiic_i2c_driver = {
808 }, 804 },
809}; 805};
810 806
811static int __init xiic_i2c_init(void) 807module_platform_driver(xiic_i2c_driver);
812{
813 return platform_driver_register(&xiic_i2c_driver);
814}
815
816static void __exit xiic_i2c_exit(void)
817{
818 platform_driver_unregister(&xiic_i2c_driver);
819}
820
821module_init(xiic_i2c_init);
822module_exit(xiic_i2c_exit);
823 808
824MODULE_AUTHOR("info@mocean-labs.com"); 809MODULE_AUTHOR("info@mocean-labs.com");
825MODULE_DESCRIPTION("Xilinx I2C bus driver"); 810MODULE_DESCRIPTION("Xilinx I2C bus driver");
826MODULE_LICENSE("GPL v2"); 811MODULE_LICENSE("GPL v2");
812MODULE_ALIAS("platform:"DRIVER_NAME);
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 91e349c884c5..2eacb7784d56 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -559,7 +559,7 @@ static struct platform_driver scx200_pci_driver = {
559 .remove = __devexit_p(scx200_remove), 559 .remove = __devexit_p(scx200_remove),
560}; 560};
561 561
562static const struct pci_device_id scx200_isa[] __initconst = { 562static DEFINE_PCI_DEVICE_TABLE(scx200_isa) = {
563 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) }, 563 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
564 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) }, 564 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
565 { 0, } 565 { 0, }
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 57a45ce84b2d..10e7f1e76586 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -251,15 +251,10 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
251 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) 251 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
252 return -EINVAL; 252 return -EINVAL;
253 253
254 rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL); 254 rdwr_pa = memdup_user(rdwr_arg.msgs,
255 if (!rdwr_pa) 255 rdwr_arg.nmsgs * sizeof(struct i2c_msg));
256 return -ENOMEM; 256 if (IS_ERR(rdwr_pa))
257 257 return PTR_ERR(rdwr_pa);
258 if (copy_from_user(rdwr_pa, rdwr_arg.msgs,
259 rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {
260 kfree(rdwr_pa);
261 return -EFAULT;
262 }
263 258
264 data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL); 259 data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);
265 if (data_ptrs == NULL) { 260 if (data_ptrs == NULL) {
diff --git a/drivers/i2c/muxes/gpio-i2cmux.c b/drivers/i2c/muxes/gpio-i2cmux.c
index 7b6ce624cd6e..e5fa695eb0fa 100644
--- a/drivers/i2c/muxes/gpio-i2cmux.c
+++ b/drivers/i2c/muxes/gpio-i2cmux.c
@@ -165,18 +165,7 @@ static struct platform_driver gpiomux_driver = {
165 }, 165 },
166}; 166};
167 167
168static int __init gpiomux_init(void) 168module_platform_driver(gpiomux_driver);
169{
170 return platform_driver_register(&gpiomux_driver);
171}
172
173static void __exit gpiomux_exit(void)
174{
175 platform_driver_unregister(&gpiomux_driver);
176}
177
178module_init(gpiomux_init);
179module_exit(gpiomux_exit);
180 169
181MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver"); 170MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver");
182MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>"); 171MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>");
diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c
index 79d901633635..350fd0c385d2 100644
--- a/drivers/input/misc/ab8500-ponkey.c
+++ b/drivers/input/misc/ab8500-ponkey.c
@@ -12,7 +12,7 @@
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/input.h> 13#include <linux/input.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/mfd/ab8500.h> 15#include <linux/mfd/abx500/ab8500.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17
18/** 18/**
diff --git a/drivers/isdn/i4l/Kconfig b/drivers/isdn/i4l/Kconfig
index 9c6650ea848e..2302fbe70ac6 100644
--- a/drivers/isdn/i4l/Kconfig
+++ b/drivers/isdn/i4l/Kconfig
@@ -6,7 +6,7 @@ if ISDN_I4L
6 6
7config ISDN_PPP 7config ISDN_PPP
8 bool "Support synchronous PPP" 8 bool "Support synchronous PPP"
9 depends on INET 9 depends on INET && NETDEVICES
10 select SLHC 10 select SLHC
11 help 11 help
12 Over digital connections such as ISDN, there is no need to 12 Over digital connections such as ISDN, there is no need to
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 897a77dfa9d7..c957c344233f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -396,6 +396,13 @@ config LEDS_TCA6507
396 LED driver chips accessed via the I2C bus. 396 LED driver chips accessed via the I2C bus.
397 Driver support brightness control and hardware-assisted blinking. 397 Driver support brightness control and hardware-assisted blinking.
398 398
399config LEDS_MAX8997
400 tristate "LED support for MAX8997 PMIC"
401 depends on LEDS_CLASS && MFD_MAX8997
402 help
403 This option enables support for on-chip LED drivers on
404 MAXIM MAX8997 PMIC.
405
399config LEDS_TRIGGERS 406config LEDS_TRIGGERS
400 bool "LED Trigger support" 407 bool "LED Trigger support"
401 depends on LEDS_CLASS 408 depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 5c9dc4b000d5..b8a9723477f0 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_LEDS_NS2) += leds-ns2.o
44obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o 44obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o
45obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o 45obj-$(CONFIG_LEDS_ASIC3) += leds-asic3.o
46obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o 46obj-$(CONFIG_LEDS_RENESAS_TPU) += leds-renesas-tpu.o
47obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
47 48
48# LED SPI Drivers 49# LED SPI Drivers
49obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o 50obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/leds-max8997.c b/drivers/leds/leds-max8997.c
new file mode 100644
index 000000000000..f4c0e37fad1e
--- /dev/null
+++ b/drivers/leds/leds-max8997.c
@@ -0,0 +1,372 @@
1/*
2 * leds-max8997.c - LED class driver for MAX8997 LEDs.
3 *
4 * Copyright (C) 2011 Samsung Electronics
5 * Donggeun Kim <dg77.kim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/err.h>
15#include <linux/slab.h>
16#include <linux/workqueue.h>
17#include <linux/leds.h>
18#include <linux/mfd/max8997.h>
19#include <linux/mfd/max8997-private.h>
20#include <linux/platform_device.h>
21
22#define MAX8997_LED_FLASH_SHIFT 3
23#define MAX8997_LED_FLASH_CUR_MASK 0xf8
24#define MAX8997_LED_MOVIE_SHIFT 4
25#define MAX8997_LED_MOVIE_CUR_MASK 0xf0
26
27#define MAX8997_LED_FLASH_MAX_BRIGHTNESS 0x1f
28#define MAX8997_LED_MOVIE_MAX_BRIGHTNESS 0xf
29#define MAX8997_LED_NONE_MAX_BRIGHTNESS 0
30
31#define MAX8997_LED0_FLASH_MASK 0x1
32#define MAX8997_LED0_FLASH_PIN_MASK 0x5
33#define MAX8997_LED0_MOVIE_MASK 0x8
34#define MAX8997_LED0_MOVIE_PIN_MASK 0x28
35
36#define MAX8997_LED1_FLASH_MASK 0x2
37#define MAX8997_LED1_FLASH_PIN_MASK 0x6
38#define MAX8997_LED1_MOVIE_MASK 0x10
39#define MAX8997_LED1_MOVIE_PIN_MASK 0x30
40
41#define MAX8997_LED_BOOST_ENABLE_MASK (1 << 6)
42
43struct max8997_led {
44 struct max8997_dev *iodev;
45 struct led_classdev cdev;
46 bool enabled;
47 int id;
48 enum max8997_led_mode led_mode;
49 struct mutex mutex;
50};
51
52static void max8997_led_clear_mode(struct max8997_led *led,
53 enum max8997_led_mode mode)
54{
55 struct i2c_client *client = led->iodev->i2c;
56 u8 val = 0, mask = 0;
57 int ret;
58
59 switch (mode) {
60 case MAX8997_FLASH_MODE:
61 mask = led->id ?
62 MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK;
63 break;
64 case MAX8997_MOVIE_MODE:
65 mask = led->id ?
66 MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK;
67 break;
68 case MAX8997_FLASH_PIN_CONTROL_MODE:
69 mask = led->id ?
70 MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK;
71 break;
72 case MAX8997_MOVIE_PIN_CONTROL_MODE:
73 mask = led->id ?
74 MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK;
75 break;
76 default:
77 break;
78 }
79
80 if (mask) {
81 ret = max8997_update_reg(client,
82 MAX8997_REG_LEN_CNTL, val, mask);
83 if (ret)
84 dev_err(led->iodev->dev,
85 "failed to update register(%d)\n", ret);
86 }
87}
88
89static void max8997_led_set_mode(struct max8997_led *led,
90 enum max8997_led_mode mode)
91{
92 int ret;
93 struct i2c_client *client = led->iodev->i2c;
94 u8 mask = 0;
95
96 /* First, clear the previous mode */
97 max8997_led_clear_mode(led, led->led_mode);
98
99 switch (mode) {
100 case MAX8997_FLASH_MODE:
101 mask = led->id ?
102 MAX8997_LED1_FLASH_MASK : MAX8997_LED0_FLASH_MASK;
103 led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS;
104 break;
105 case MAX8997_MOVIE_MODE:
106 mask = led->id ?
107 MAX8997_LED1_MOVIE_MASK : MAX8997_LED0_MOVIE_MASK;
108 led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS;
109 break;
110 case MAX8997_FLASH_PIN_CONTROL_MODE:
111 mask = led->id ?
112 MAX8997_LED1_FLASH_PIN_MASK : MAX8997_LED0_FLASH_PIN_MASK;
113 led->cdev.max_brightness = MAX8997_LED_FLASH_MAX_BRIGHTNESS;
114 break;
115 case MAX8997_MOVIE_PIN_CONTROL_MODE:
116 mask = led->id ?
117 MAX8997_LED1_MOVIE_PIN_MASK : MAX8997_LED0_MOVIE_PIN_MASK;
118 led->cdev.max_brightness = MAX8997_LED_MOVIE_MAX_BRIGHTNESS;
119 break;
120 default:
121 led->cdev.max_brightness = MAX8997_LED_NONE_MAX_BRIGHTNESS;
122 break;
123 }
124
125 if (mask) {
126 ret = max8997_update_reg(client,
127 MAX8997_REG_LEN_CNTL, mask, mask);
128 if (ret)
129 dev_err(led->iodev->dev,
130 "failed to update register(%d)\n", ret);
131 }
132
133 led->led_mode = mode;
134}
135
136static void max8997_led_enable(struct max8997_led *led, bool enable)
137{
138 int ret;
139 struct i2c_client *client = led->iodev->i2c;
140 u8 val = 0, mask = MAX8997_LED_BOOST_ENABLE_MASK;
141
142 if (led->enabled == enable)
143 return;
144
145 val = enable ? MAX8997_LED_BOOST_ENABLE_MASK : 0;
146
147 ret = max8997_update_reg(client, MAX8997_REG_BOOST_CNTL, val, mask);
148 if (ret)
149 dev_err(led->iodev->dev,
150 "failed to update register(%d)\n", ret);
151
152 led->enabled = enable;
153}
154
155static void max8997_led_set_current(struct max8997_led *led,
156 enum led_brightness value)
157{
158 int ret;
159 struct i2c_client *client = led->iodev->i2c;
160 u8 val = 0, mask = 0, reg = 0;
161
162 switch (led->led_mode) {
163 case MAX8997_FLASH_MODE:
164 case MAX8997_FLASH_PIN_CONTROL_MODE:
165 val = value << MAX8997_LED_FLASH_SHIFT;
166 mask = MAX8997_LED_FLASH_CUR_MASK;
167 reg = led->id ? MAX8997_REG_FLASH2_CUR : MAX8997_REG_FLASH1_CUR;
168 break;
169 case MAX8997_MOVIE_MODE:
170 case MAX8997_MOVIE_PIN_CONTROL_MODE:
171 val = value << MAX8997_LED_MOVIE_SHIFT;
172 mask = MAX8997_LED_MOVIE_CUR_MASK;
173 reg = MAX8997_REG_MOVIE_CUR;
174 break;
175 default:
176 break;
177 }
178
179 if (mask) {
180 ret = max8997_update_reg(client, reg, val, mask);
181 if (ret)
182 dev_err(led->iodev->dev,
183 "failed to update register(%d)\n", ret);
184 }
185}
186
187static void max8997_led_brightness_set(struct led_classdev *led_cdev,
188 enum led_brightness value)
189{
190 struct max8997_led *led =
191 container_of(led_cdev, struct max8997_led, cdev);
192
193 if (value) {
194 max8997_led_set_current(led, value);
195 max8997_led_enable(led, true);
196 } else {
197 max8997_led_set_current(led, value);
198 max8997_led_enable(led, false);
199 }
200}
201
202static ssize_t max8997_led_show_mode(struct device *dev,
203 struct device_attribute *attr, char *buf)
204{
205 struct led_classdev *led_cdev = dev_get_drvdata(dev);
206 struct max8997_led *led =
207 container_of(led_cdev, struct max8997_led, cdev);
208 ssize_t ret = 0;
209
210 mutex_lock(&led->mutex);
211
212 switch (led->led_mode) {
213 case MAX8997_FLASH_MODE:
214 ret += sprintf(buf, "FLASH\n");
215 break;
216 case MAX8997_MOVIE_MODE:
217 ret += sprintf(buf, "MOVIE\n");
218 break;
219 case MAX8997_FLASH_PIN_CONTROL_MODE:
220 ret += sprintf(buf, "FLASH_PIN_CONTROL\n");
221 break;
222 case MAX8997_MOVIE_PIN_CONTROL_MODE:
223 ret += sprintf(buf, "MOVIE_PIN_CONTROL\n");
224 break;
225 default:
226 ret += sprintf(buf, "NONE\n");
227 break;
228 }
229
230 mutex_unlock(&led->mutex);
231
232 return ret;
233}
234
235static ssize_t max8997_led_store_mode(struct device *dev,
236 struct device_attribute *attr,
237 const char *buf, size_t size)
238{
239 struct led_classdev *led_cdev = dev_get_drvdata(dev);
240 struct max8997_led *led =
241 container_of(led_cdev, struct max8997_led, cdev);
242 enum max8997_led_mode mode;
243
244 mutex_lock(&led->mutex);
245
246 if (!strncmp(buf, "FLASH_PIN_CONTROL", 17))
247 mode = MAX8997_FLASH_PIN_CONTROL_MODE;
248 else if (!strncmp(buf, "MOVIE_PIN_CONTROL", 17))
249 mode = MAX8997_MOVIE_PIN_CONTROL_MODE;
250 else if (!strncmp(buf, "FLASH", 5))
251 mode = MAX8997_FLASH_MODE;
252 else if (!strncmp(buf, "MOVIE", 5))
253 mode = MAX8997_MOVIE_MODE;
254 else
255 mode = MAX8997_NONE;
256
257 max8997_led_set_mode(led, mode);
258
259 mutex_unlock(&led->mutex);
260
261 return size;
262}
263
264static DEVICE_ATTR(mode, 0644, max8997_led_show_mode, max8997_led_store_mode);
265
266static int __devinit max8997_led_probe(struct platform_device *pdev)
267{
268 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
269 struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev);
270 struct max8997_led *led;
271 char name[20];
272 int ret = 0;
273
274 if (pdata == NULL) {
275 dev_err(&pdev->dev, "no platform data\n");
276 return -ENODEV;
277 }
278
279 led = kzalloc(sizeof(*led), GFP_KERNEL);
280 if (led == NULL) {
281 ret = -ENOMEM;
282 goto err_mem;
283 }
284
285 led->id = pdev->id;
286 snprintf(name, sizeof(name), "max8997-led%d", pdev->id);
287
288 led->cdev.name = name;
289 led->cdev.brightness_set = max8997_led_brightness_set;
290 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
291 led->cdev.brightness = 0;
292 led->iodev = iodev;
293
294 /* initialize mode and brightness according to platform_data */
295 if (pdata->led_pdata) {
296 u8 mode = 0, brightness = 0;
297
298 mode = pdata->led_pdata->mode[led->id];
299 brightness = pdata->led_pdata->brightness[led->id];
300
301 max8997_led_set_mode(led, pdata->led_pdata->mode[led->id]);
302
303 if (brightness > led->cdev.max_brightness)
304 brightness = led->cdev.max_brightness;
305 max8997_led_set_current(led, brightness);
306 led->cdev.brightness = brightness;
307 } else {
308 max8997_led_set_mode(led, MAX8997_NONE);
309 max8997_led_set_current(led, 0);
310 }
311
312 mutex_init(&led->mutex);
313
314 platform_set_drvdata(pdev, led);
315
316 ret = led_classdev_register(&pdev->dev, &led->cdev);
317 if (ret < 0)
318 goto err_led;
319
320 ret = device_create_file(led->cdev.dev, &dev_attr_mode);
321 if (ret != 0) {
322 dev_err(&pdev->dev,
323 "failed to create file: %d\n", ret);
324 goto err_file;
325 }
326
327 return 0;
328
329err_file:
330 led_classdev_unregister(&led->cdev);
331err_led:
332 kfree(led);
333err_mem:
334 return ret;
335}
336
337static int __devexit max8997_led_remove(struct platform_device *pdev)
338{
339 struct max8997_led *led = platform_get_drvdata(pdev);
340
341 device_remove_file(led->cdev.dev, &dev_attr_mode);
342 led_classdev_unregister(&led->cdev);
343 kfree(led);
344
345 return 0;
346}
347
348static struct platform_driver max8997_led_driver = {
349 .driver = {
350 .name = "max8997-led",
351 .owner = THIS_MODULE,
352 },
353 .probe = max8997_led_probe,
354 .remove = __devexit_p(max8997_led_remove),
355};
356
357static int __init max8997_led_init(void)
358{
359 return platform_driver_register(&max8997_led_driver);
360}
361module_init(max8997_led_init);
362
363static void __exit max8997_led_exit(void)
364{
365 platform_driver_unregister(&max8997_led_driver);
366}
367module_exit(max8997_led_exit);
368
369MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
370MODULE_DESCRIPTION("MAX8997 LED driver");
371MODULE_LICENSE("GPL");
372MODULE_ALIAS("platform:max8997-led");
diff --git a/drivers/mfd/88pm860x-i2c.c b/drivers/mfd/88pm860x-i2c.c
index e017dc88622a..f93dd9571c3c 100644
--- a/drivers/mfd/88pm860x-i2c.c
+++ b/drivers/mfd/88pm860x-i2c.c
@@ -12,51 +12,20 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/err.h>
16#include <linux/regmap.h>
15#include <linux/mfd/88pm860x.h> 17#include <linux/mfd/88pm860x.h>
16#include <linux/slab.h> 18#include <linux/slab.h>
17 19
18static inline int pm860x_read_device(struct i2c_client *i2c,
19 int reg, int bytes, void *dest)
20{
21 unsigned char data;
22 int ret;
23
24 data = (unsigned char)reg;
25 ret = i2c_master_send(i2c, &data, 1);
26 if (ret < 0)
27 return ret;
28
29 ret = i2c_master_recv(i2c, dest, bytes);
30 if (ret < 0)
31 return ret;
32 return 0;
33}
34
35static inline int pm860x_write_device(struct i2c_client *i2c,
36 int reg, int bytes, void *src)
37{
38 unsigned char buf[bytes + 1];
39 int ret;
40
41 buf[0] = (unsigned char)reg;
42 memcpy(&buf[1], src, bytes);
43
44 ret = i2c_master_send(i2c, buf, bytes + 1);
45 if (ret < 0)
46 return ret;
47 return 0;
48}
49
50int pm860x_reg_read(struct i2c_client *i2c, int reg) 20int pm860x_reg_read(struct i2c_client *i2c, int reg)
51{ 21{
52 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 22 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
53 unsigned char data; 23 struct regmap *map = (i2c == chip->client) ? chip->regmap
24 : chip->regmap_companion;
25 unsigned int data;
54 int ret; 26 int ret;
55 27
56 mutex_lock(&chip->io_lock); 28 ret = regmap_read(map, reg, &data);
57 ret = pm860x_read_device(i2c, reg, 1, &data);
58 mutex_unlock(&chip->io_lock);
59
60 if (ret < 0) 29 if (ret < 0)
61 return ret; 30 return ret;
62 else 31 else
@@ -68,12 +37,11 @@ int pm860x_reg_write(struct i2c_client *i2c, int reg,
68 unsigned char data) 37 unsigned char data)
69{ 38{
70 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 39 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
40 struct regmap *map = (i2c == chip->client) ? chip->regmap
41 : chip->regmap_companion;
71 int ret; 42 int ret;
72 43
73 mutex_lock(&chip->io_lock); 44 ret = regmap_write(map, reg, data);
74 ret = pm860x_write_device(i2c, reg, 1, &data);
75 mutex_unlock(&chip->io_lock);
76
77 return ret; 45 return ret;
78} 46}
79EXPORT_SYMBOL(pm860x_reg_write); 47EXPORT_SYMBOL(pm860x_reg_write);
@@ -82,12 +50,11 @@ int pm860x_bulk_read(struct i2c_client *i2c, int reg,
82 int count, unsigned char *buf) 50 int count, unsigned char *buf)
83{ 51{
84 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 52 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
53 struct regmap *map = (i2c == chip->client) ? chip->regmap
54 : chip->regmap_companion;
85 int ret; 55 int ret;
86 56
87 mutex_lock(&chip->io_lock); 57 ret = regmap_raw_read(map, reg, buf, count);
88 ret = pm860x_read_device(i2c, reg, count, buf);
89 mutex_unlock(&chip->io_lock);
90
91 return ret; 58 return ret;
92} 59}
93EXPORT_SYMBOL(pm860x_bulk_read); 60EXPORT_SYMBOL(pm860x_bulk_read);
@@ -96,12 +63,11 @@ int pm860x_bulk_write(struct i2c_client *i2c, int reg,
96 int count, unsigned char *buf) 63 int count, unsigned char *buf)
97{ 64{
98 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 65 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
66 struct regmap *map = (i2c == chip->client) ? chip->regmap
67 : chip->regmap_companion;
99 int ret; 68 int ret;
100 69
101 mutex_lock(&chip->io_lock); 70 ret = regmap_raw_write(map, reg, buf, count);
102 ret = pm860x_write_device(i2c, reg, count, buf);
103 mutex_unlock(&chip->io_lock);
104
105 return ret; 71 return ret;
106} 72}
107EXPORT_SYMBOL(pm860x_bulk_write); 73EXPORT_SYMBOL(pm860x_bulk_write);
@@ -110,39 +76,78 @@ int pm860x_set_bits(struct i2c_client *i2c, int reg,
110 unsigned char mask, unsigned char data) 76 unsigned char mask, unsigned char data)
111{ 77{
112 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 78 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
113 unsigned char value; 79 struct regmap *map = (i2c == chip->client) ? chip->regmap
80 : chip->regmap_companion;
114 int ret; 81 int ret;
115 82
116 mutex_lock(&chip->io_lock); 83 ret = regmap_update_bits(map, reg, mask, data);
117 ret = pm860x_read_device(i2c, reg, 1, &value);
118 if (ret < 0)
119 goto out;
120 value &= ~mask;
121 value |= data;
122 ret = pm860x_write_device(i2c, reg, 1, &value);
123out:
124 mutex_unlock(&chip->io_lock);
125 return ret; 84 return ret;
126} 85}
127EXPORT_SYMBOL(pm860x_set_bits); 86EXPORT_SYMBOL(pm860x_set_bits);
128 87
88static int read_device(struct i2c_client *i2c, int reg,
89 int bytes, void *dest)
90{
91 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX + 3];
92 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX + 2];
93 struct i2c_adapter *adap = i2c->adapter;
94 struct i2c_msg msg[2] = {{i2c->addr, 0, 1, msgbuf0},
95 {i2c->addr, I2C_M_RD, 0, msgbuf1},
96 };
97 int num = 1, ret = 0;
98
99 if (dest == NULL)
100 return -EINVAL;
101 msgbuf0[0] = (unsigned char)reg; /* command */
102 msg[1].len = bytes;
103
104 /* if data needs to read back, num should be 2 */
105 if (bytes > 0)
106 num = 2;
107 ret = adap->algo->master_xfer(adap, msg, num);
108 memcpy(dest, msgbuf1, bytes);
109 if (ret < 0)
110 return ret;
111 return 0;
112}
113
114static int write_device(struct i2c_client *i2c, int reg,
115 int bytes, void *src)
116{
117 unsigned char buf[bytes + 1];
118 struct i2c_adapter *adap = i2c->adapter;
119 struct i2c_msg msg;
120 int ret;
121
122 buf[0] = (unsigned char)reg;
123 memcpy(&buf[1], src, bytes);
124 msg.addr = i2c->addr;
125 msg.flags = 0;
126 msg.len = bytes + 1;
127 msg.buf = buf;
128
129 ret = adap->algo->master_xfer(adap, &msg, 1);
130 if (ret < 0)
131 return ret;
132 return 0;
133}
134
129int pm860x_page_reg_read(struct i2c_client *i2c, int reg) 135int pm860x_page_reg_read(struct i2c_client *i2c, int reg)
130{ 136{
131 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
132 unsigned char zero = 0; 137 unsigned char zero = 0;
133 unsigned char data; 138 unsigned char data;
134 int ret; 139 int ret;
135 140
136 mutex_lock(&chip->io_lock); 141 i2c_lock_adapter(i2c->adapter);
137 pm860x_write_device(i2c, 0xFA, 0, &zero); 142 read_device(i2c, 0xFA, 0, &zero);
138 pm860x_write_device(i2c, 0xFB, 0, &zero); 143 read_device(i2c, 0xFB, 0, &zero);
139 pm860x_write_device(i2c, 0xFF, 0, &zero); 144 read_device(i2c, 0xFF, 0, &zero);
140 ret = pm860x_read_device(i2c, reg, 1, &data); 145 ret = read_device(i2c, reg, 1, &data);
141 if (ret >= 0) 146 if (ret >= 0)
142 ret = (int)data; 147 ret = (int)data;
143 pm860x_write_device(i2c, 0xFE, 0, &zero); 148 read_device(i2c, 0xFE, 0, &zero);
144 pm860x_write_device(i2c, 0xFC, 0, &zero); 149 read_device(i2c, 0xFC, 0, &zero);
145 mutex_unlock(&chip->io_lock); 150 i2c_unlock_adapter(i2c->adapter);
146 return ret; 151 return ret;
147} 152}
148EXPORT_SYMBOL(pm860x_page_reg_read); 153EXPORT_SYMBOL(pm860x_page_reg_read);
@@ -150,18 +155,17 @@ EXPORT_SYMBOL(pm860x_page_reg_read);
150int pm860x_page_reg_write(struct i2c_client *i2c, int reg, 155int pm860x_page_reg_write(struct i2c_client *i2c, int reg,
151 unsigned char data) 156 unsigned char data)
152{ 157{
153 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
154 unsigned char zero; 158 unsigned char zero;
155 int ret; 159 int ret;
156 160
157 mutex_lock(&chip->io_lock); 161 i2c_lock_adapter(i2c->adapter);
158 pm860x_write_device(i2c, 0xFA, 0, &zero); 162 read_device(i2c, 0xFA, 0, &zero);
159 pm860x_write_device(i2c, 0xFB, 0, &zero); 163 read_device(i2c, 0xFB, 0, &zero);
160 pm860x_write_device(i2c, 0xFF, 0, &zero); 164 read_device(i2c, 0xFF, 0, &zero);
161 ret = pm860x_write_device(i2c, reg, 1, &data); 165 ret = write_device(i2c, reg, 1, &data);
162 pm860x_write_device(i2c, 0xFE, 0, &zero); 166 read_device(i2c, 0xFE, 0, &zero);
163 pm860x_write_device(i2c, 0xFC, 0, &zero); 167 read_device(i2c, 0xFC, 0, &zero);
164 mutex_unlock(&chip->io_lock); 168 i2c_unlock_adapter(i2c->adapter);
165 return ret; 169 return ret;
166} 170}
167EXPORT_SYMBOL(pm860x_page_reg_write); 171EXPORT_SYMBOL(pm860x_page_reg_write);
@@ -169,18 +173,17 @@ EXPORT_SYMBOL(pm860x_page_reg_write);
169int pm860x_page_bulk_read(struct i2c_client *i2c, int reg, 173int pm860x_page_bulk_read(struct i2c_client *i2c, int reg,
170 int count, unsigned char *buf) 174 int count, unsigned char *buf)
171{ 175{
172 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
173 unsigned char zero = 0; 176 unsigned char zero = 0;
174 int ret; 177 int ret;
175 178
176 mutex_lock(&chip->io_lock); 179 i2c_lock_adapter(i2c->adapter);
177 pm860x_write_device(i2c, 0xFA, 0, &zero); 180 read_device(i2c, 0xfa, 0, &zero);
178 pm860x_write_device(i2c, 0xFB, 0, &zero); 181 read_device(i2c, 0xfb, 0, &zero);
179 pm860x_write_device(i2c, 0xFF, 0, &zero); 182 read_device(i2c, 0xff, 0, &zero);
180 ret = pm860x_read_device(i2c, reg, count, buf); 183 ret = read_device(i2c, reg, count, buf);
181 pm860x_write_device(i2c, 0xFE, 0, &zero); 184 read_device(i2c, 0xFE, 0, &zero);
182 pm860x_write_device(i2c, 0xFC, 0, &zero); 185 read_device(i2c, 0xFC, 0, &zero);
183 mutex_unlock(&chip->io_lock); 186 i2c_unlock_adapter(i2c->adapter);
184 return ret; 187 return ret;
185} 188}
186EXPORT_SYMBOL(pm860x_page_bulk_read); 189EXPORT_SYMBOL(pm860x_page_bulk_read);
@@ -188,18 +191,18 @@ EXPORT_SYMBOL(pm860x_page_bulk_read);
188int pm860x_page_bulk_write(struct i2c_client *i2c, int reg, 191int pm860x_page_bulk_write(struct i2c_client *i2c, int reg,
189 int count, unsigned char *buf) 192 int count, unsigned char *buf)
190{ 193{
191 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
192 unsigned char zero = 0; 194 unsigned char zero = 0;
193 int ret; 195 int ret;
194 196
195 mutex_lock(&chip->io_lock); 197 i2c_lock_adapter(i2c->adapter);
196 pm860x_write_device(i2c, 0xFA, 0, &zero); 198 read_device(i2c, 0xFA, 0, &zero);
197 pm860x_write_device(i2c, 0xFB, 0, &zero); 199 read_device(i2c, 0xFB, 0, &zero);
198 pm860x_write_device(i2c, 0xFF, 0, &zero); 200 read_device(i2c, 0xFF, 0, &zero);
199 ret = pm860x_write_device(i2c, reg, count, buf); 201 ret = write_device(i2c, reg, count, buf);
200 pm860x_write_device(i2c, 0xFE, 0, &zero); 202 read_device(i2c, 0xFE, 0, &zero);
201 pm860x_write_device(i2c, 0xFC, 0, &zero); 203 read_device(i2c, 0xFC, 0, &zero);
202 mutex_unlock(&chip->io_lock); 204 i2c_unlock_adapter(i2c->adapter);
205 i2c_unlock_adapter(i2c->adapter);
203 return ret; 206 return ret;
204} 207}
205EXPORT_SYMBOL(pm860x_page_bulk_write); 208EXPORT_SYMBOL(pm860x_page_bulk_write);
@@ -207,25 +210,24 @@ EXPORT_SYMBOL(pm860x_page_bulk_write);
207int pm860x_page_set_bits(struct i2c_client *i2c, int reg, 210int pm860x_page_set_bits(struct i2c_client *i2c, int reg,
208 unsigned char mask, unsigned char data) 211 unsigned char mask, unsigned char data)
209{ 212{
210 struct pm860x_chip *chip = i2c_get_clientdata(i2c);
211 unsigned char zero; 213 unsigned char zero;
212 unsigned char value; 214 unsigned char value;
213 int ret; 215 int ret;
214 216
215 mutex_lock(&chip->io_lock); 217 i2c_lock_adapter(i2c->adapter);
216 pm860x_write_device(i2c, 0xFA, 0, &zero); 218 read_device(i2c, 0xFA, 0, &zero);
217 pm860x_write_device(i2c, 0xFB, 0, &zero); 219 read_device(i2c, 0xFB, 0, &zero);
218 pm860x_write_device(i2c, 0xFF, 0, &zero); 220 read_device(i2c, 0xFF, 0, &zero);
219 ret = pm860x_read_device(i2c, reg, 1, &value); 221 ret = read_device(i2c, reg, 1, &value);
220 if (ret < 0) 222 if (ret < 0)
221 goto out; 223 goto out;
222 value &= ~mask; 224 value &= ~mask;
223 value |= data; 225 value |= data;
224 ret = pm860x_write_device(i2c, reg, 1, &value); 226 ret = write_device(i2c, reg, 1, &value);
225out: 227out:
226 pm860x_write_device(i2c, 0xFE, 0, &zero); 228 read_device(i2c, 0xFE, 0, &zero);
227 pm860x_write_device(i2c, 0xFC, 0, &zero); 229 read_device(i2c, 0xFC, 0, &zero);
228 mutex_unlock(&chip->io_lock); 230 i2c_unlock_adapter(i2c->adapter);
229 return ret; 231 return ret;
230} 232}
231EXPORT_SYMBOL(pm860x_page_set_bits); 233EXPORT_SYMBOL(pm860x_page_set_bits);
@@ -257,11 +259,17 @@ static int verify_addr(struct i2c_client *i2c)
257 return 0; 259 return 0;
258} 260}
259 261
262static struct regmap_config pm860x_regmap_config = {
263 .reg_bits = 8,
264 .val_bits = 8,
265};
266
260static int __devinit pm860x_probe(struct i2c_client *client, 267static int __devinit pm860x_probe(struct i2c_client *client,
261 const struct i2c_device_id *id) 268 const struct i2c_device_id *id)
262{ 269{
263 struct pm860x_platform_data *pdata = client->dev.platform_data; 270 struct pm860x_platform_data *pdata = client->dev.platform_data;
264 struct pm860x_chip *chip; 271 struct pm860x_chip *chip;
272 int ret;
265 273
266 if (!pdata) { 274 if (!pdata) {
267 pr_info("No platform data in %s!\n", __func__); 275 pr_info("No platform data in %s!\n", __func__);
@@ -273,10 +281,17 @@ static int __devinit pm860x_probe(struct i2c_client *client,
273 return -ENOMEM; 281 return -ENOMEM;
274 282
275 chip->id = verify_addr(client); 283 chip->id = verify_addr(client);
284 chip->regmap = regmap_init_i2c(client, &pm860x_regmap_config);
285 if (IS_ERR(chip->regmap)) {
286 ret = PTR_ERR(chip->regmap);
287 dev_err(&client->dev, "Failed to allocate register map: %d\n",
288 ret);
289 kfree(chip);
290 return ret;
291 }
276 chip->client = client; 292 chip->client = client;
277 i2c_set_clientdata(client, chip); 293 i2c_set_clientdata(client, chip);
278 chip->dev = &client->dev; 294 chip->dev = &client->dev;
279 mutex_init(&chip->io_lock);
280 dev_set_drvdata(chip->dev, chip); 295 dev_set_drvdata(chip->dev, chip);
281 296
282 /* 297 /*
@@ -290,6 +305,14 @@ static int __devinit pm860x_probe(struct i2c_client *client,
290 chip->companion_addr = pdata->companion_addr; 305 chip->companion_addr = pdata->companion_addr;
291 chip->companion = i2c_new_dummy(chip->client->adapter, 306 chip->companion = i2c_new_dummy(chip->client->adapter,
292 chip->companion_addr); 307 chip->companion_addr);
308 chip->regmap_companion = regmap_init_i2c(chip->companion,
309 &pm860x_regmap_config);
310 if (IS_ERR(chip->regmap_companion)) {
311 ret = PTR_ERR(chip->regmap_companion);
312 dev_err(&chip->companion->dev,
313 "Failed to allocate register map: %d\n", ret);
314 return ret;
315 }
293 i2c_set_clientdata(chip->companion, chip); 316 i2c_set_clientdata(chip->companion, chip);
294 } 317 }
295 318
@@ -302,7 +325,11 @@ static int __devexit pm860x_remove(struct i2c_client *client)
302 struct pm860x_chip *chip = i2c_get_clientdata(client); 325 struct pm860x_chip *chip = i2c_get_clientdata(client);
303 326
304 pm860x_device_exit(chip); 327 pm860x_device_exit(chip);
305 i2c_unregister_device(chip->companion); 328 if (chip->companion) {
329 regmap_exit(chip->regmap_companion);
330 i2c_unregister_device(chip->companion);
331 }
332 regmap_exit(chip->regmap);
306 kfree(chip); 333 kfree(chip);
307 return 0; 334 return 0;
308} 335}
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 053208d31fb9..cd13e9f2f5e6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -12,6 +12,7 @@ config MFD_CORE
12config MFD_88PM860X 12config MFD_88PM860X
13 bool "Support Marvell 88PM8606/88PM8607" 13 bool "Support Marvell 88PM8606/88PM8607"
14 depends on I2C=y && GENERIC_HARDIRQS 14 depends on I2C=y && GENERIC_HARDIRQS
15 select REGMAP_I2C
15 select MFD_CORE 16 select MFD_CORE
16 help 17 help
17 This supports for Marvell 88PM8606/88PM8607 Power Management IC. 18 This supports for Marvell 88PM8606/88PM8607 Power Management IC.
@@ -199,7 +200,7 @@ config MENELAUS
199 200
200config TWL4030_CORE 201config TWL4030_CORE
201 bool "Texas Instruments TWL4030/TWL5030/TWL6030/TPS659x0 Support" 202 bool "Texas Instruments TWL4030/TWL5030/TWL6030/TPS659x0 Support"
202 depends on I2C=y && GENERIC_HARDIRQS 203 depends on I2C=y && GENERIC_HARDIRQS && IRQ_DOMAIN
203 help 204 help
204 Say yes here if you have TWL4030 / TWL6030 family chip on your board. 205 Say yes here if you have TWL4030 / TWL6030 family chip on your board.
205 This core driver provides register access and IRQ handling 206 This core driver provides register access and IRQ handling
@@ -257,7 +258,7 @@ config TWL6040_CORE
257 258
258config MFD_STMPE 259config MFD_STMPE
259 bool "Support STMicroelectronics STMPE" 260 bool "Support STMicroelectronics STMPE"
260 depends on I2C=y && GENERIC_HARDIRQS 261 depends on (I2C=y || SPI_MASTER=y) && GENERIC_HARDIRQS
261 select MFD_CORE 262 select MFD_CORE
262 help 263 help
263 Support for the STMPE family of I/O Expanders from 264 Support for the STMPE family of I/O Expanders from
@@ -278,6 +279,23 @@ config MFD_STMPE
278 Keypad: stmpe-keypad 279 Keypad: stmpe-keypad
279 Touchscreen: stmpe-ts 280 Touchscreen: stmpe-ts
280 281
282menu "STMPE Interface Drivers"
283depends on MFD_STMPE
284
285config STMPE_I2C
286 bool "STMPE I2C Inteface"
287 depends on I2C=y
288 default y
289 help
290 This is used to enable I2C interface of STMPE
291
292config STMPE_SPI
293 bool "STMPE SPI Inteface"
294 depends on SPI_MASTER
295 help
296 This is used to enable SPI interface of STMPE
297endmenu
298
281config MFD_TC3589X 299config MFD_TC3589X
282 bool "Support Toshiba TC35892 and variants" 300 bool "Support Toshiba TC35892 and variants"
283 depends on I2C=y && GENERIC_HARDIRQS 301 depends on I2C=y && GENERIC_HARDIRQS
@@ -311,7 +329,7 @@ config MFD_TC6387XB
311 329
312config MFD_TC6393XB 330config MFD_TC6393XB
313 bool "Support Toshiba TC6393XB" 331 bool "Support Toshiba TC6393XB"
314 depends on GPIOLIB && ARM 332 depends on GPIOLIB && ARM && HAVE_CLK
315 select MFD_CORE 333 select MFD_CORE
316 select MFD_TMIO 334 select MFD_TMIO
317 help 335 help
@@ -399,6 +417,17 @@ config MFD_MAX8998
399 additional drivers must be enabled in order to use the functionality 417 additional drivers must be enabled in order to use the functionality
400 of the device. 418 of the device.
401 419
420config MFD_S5M_CORE
421 bool "SAMSUNG S5M Series Support"
422 depends on I2C=y && GENERIC_HARDIRQS
423 select MFD_CORE
424 select REGMAP_I2C
425 help
426 Support for the Samsung Electronics S5M MFD series.
427 This driver provies common support for accessing the device,
428 additional drivers must be enabled in order to use the functionality
429 of the device
430
402config MFD_WM8400 431config MFD_WM8400
403 tristate "Support Wolfson Microelectronics WM8400" 432 tristate "Support Wolfson Microelectronics WM8400"
404 select MFD_CORE 433 select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 47591fc7d0d2..b953bab934f7 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -16,6 +16,8 @@ obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o
16obj-$(CONFIG_MFD_TI_SSP) += ti-ssp.o 16obj-$(CONFIG_MFD_TI_SSP) += ti-ssp.o
17 17
18obj-$(CONFIG_MFD_STMPE) += stmpe.o 18obj-$(CONFIG_MFD_STMPE) += stmpe.o
19obj-$(CONFIG_STMPE_I2C) += stmpe-i2c.o
20obj-$(CONFIG_STMPE_SPI) += stmpe-spi.o
19obj-$(CONFIG_MFD_TC3589X) += tc3589x.o 21obj-$(CONFIG_MFD_TC3589X) += tc3589x.o
20obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o 22obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o
21obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o 23obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o
@@ -109,3 +111,4 @@ obj-$(CONFIG_MFD_PM8XXX_IRQ) += pm8xxx-irq.o
109obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o 111obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o
110obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o 112obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
111obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o 113obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o
114obj-$(CONFIG_MFD_S5M_CORE) += s5m-core.o s5m-irq.o
diff --git a/drivers/mfd/aat2870-core.c b/drivers/mfd/aat2870-core.c
index 02c42015ba51..3aa36eb5c79b 100644
--- a/drivers/mfd/aat2870-core.c
+++ b/drivers/mfd/aat2870-core.c
@@ -407,13 +407,13 @@ static int aat2870_i2c_probe(struct i2c_client *client,
407 aat2870->init(aat2870); 407 aat2870->init(aat2870);
408 408
409 if (aat2870->en_pin >= 0) { 409 if (aat2870->en_pin >= 0) {
410 ret = gpio_request(aat2870->en_pin, "aat2870-en"); 410 ret = gpio_request_one(aat2870->en_pin, GPIOF_OUT_INIT_HIGH,
411 "aat2870-en");
411 if (ret < 0) { 412 if (ret < 0) {
412 dev_err(&client->dev, 413 dev_err(&client->dev,
413 "Failed to request GPIO %d\n", aat2870->en_pin); 414 "Failed to request GPIO %d\n", aat2870->en_pin);
414 goto out_kfree; 415 goto out_kfree;
415 } 416 }
416 gpio_direction_output(aat2870->en_pin, 1);
417 } 417 }
418 418
419 aat2870_enable(aat2870); 419 aat2870_enable(aat2870);
@@ -468,9 +468,10 @@ static int aat2870_i2c_remove(struct i2c_client *client)
468 return 0; 468 return 0;
469} 469}
470 470
471#ifdef CONFIG_PM 471#ifdef CONFIG_PM_SLEEP
472static int aat2870_i2c_suspend(struct i2c_client *client, pm_message_t state) 472static int aat2870_i2c_suspend(struct device *dev)
473{ 473{
474 struct i2c_client *client = to_i2c_client(dev);
474 struct aat2870_data *aat2870 = i2c_get_clientdata(client); 475 struct aat2870_data *aat2870 = i2c_get_clientdata(client);
475 476
476 aat2870_disable(aat2870); 477 aat2870_disable(aat2870);
@@ -478,8 +479,9 @@ static int aat2870_i2c_suspend(struct i2c_client *client, pm_message_t state)
478 return 0; 479 return 0;
479} 480}
480 481
481static int aat2870_i2c_resume(struct i2c_client *client) 482static int aat2870_i2c_resume(struct device *dev)
482{ 483{
484 struct i2c_client *client = to_i2c_client(dev);
483 struct aat2870_data *aat2870 = i2c_get_clientdata(client); 485 struct aat2870_data *aat2870 = i2c_get_clientdata(client);
484 struct aat2870_register *reg = NULL; 486 struct aat2870_register *reg = NULL;
485 int i; 487 int i;
@@ -495,12 +497,12 @@ static int aat2870_i2c_resume(struct i2c_client *client)
495 497
496 return 0; 498 return 0;
497} 499}
498#else 500#endif /* CONFIG_PM_SLEEP */
499#define aat2870_i2c_suspend NULL 501
500#define aat2870_i2c_resume NULL 502static SIMPLE_DEV_PM_OPS(aat2870_pm_ops, aat2870_i2c_suspend,
501#endif /* CONFIG_PM */ 503 aat2870_i2c_resume);
502 504
503static struct i2c_device_id aat2870_i2c_id_table[] = { 505static const struct i2c_device_id aat2870_i2c_id_table[] = {
504 { "aat2870", 0 }, 506 { "aat2870", 0 },
505 { } 507 { }
506}; 508};
@@ -510,11 +512,10 @@ static struct i2c_driver aat2870_i2c_driver = {
510 .driver = { 512 .driver = {
511 .name = "aat2870", 513 .name = "aat2870",
512 .owner = THIS_MODULE, 514 .owner = THIS_MODULE,
515 .pm = &aat2870_pm_ops,
513 }, 516 },
514 .probe = aat2870_i2c_probe, 517 .probe = aat2870_i2c_probe,
515 .remove = aat2870_i2c_remove, 518 .remove = aat2870_i2c_remove,
516 .suspend = aat2870_i2c_suspend,
517 .resume = aat2870_i2c_resume,
518 .id_table = aat2870_i2c_id_table, 519 .id_table = aat2870_i2c_id_table,
519}; 520};
520 521
diff --git a/drivers/mfd/ab5500-core.c b/drivers/mfd/ab5500-core.c
index ec10629a0b0b..bd56a764dea1 100644
--- a/drivers/mfd/ab5500-core.c
+++ b/drivers/mfd/ab5500-core.c
@@ -22,8 +22,8 @@
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/random.h> 24#include <linux/random.h>
25#include <linux/mfd/ab5500/ab5500.h>
26#include <linux/mfd/abx500.h> 25#include <linux/mfd/abx500.h>
26#include <linux/mfd/abx500/ab5500.h>
27#include <linux/list.h> 27#include <linux/list.h>
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
diff --git a/drivers/mfd/ab5500-debugfs.c b/drivers/mfd/ab5500-debugfs.c
index b7b2d3483fd4..72006940937a 100644
--- a/drivers/mfd/ab5500-debugfs.c
+++ b/drivers/mfd/ab5500-debugfs.c
@@ -7,8 +7,8 @@
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/debugfs.h> 8#include <linux/debugfs.h>
9#include <linux/seq_file.h> 9#include <linux/seq_file.h>
10#include <linux/mfd/ab5500/ab5500.h>
11#include <linux/mfd/abx500.h> 10#include <linux/mfd/abx500.h>
11#include <linux/mfd/abx500/ab5500.h>
12#include <linux/uaccess.h> 12#include <linux/uaccess.h>
13 13
14#include "ab5500-core.h" 14#include "ab5500-core.h"
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index d3d572b2317b..53e2a80f42fa 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/mfd/core.h> 18#include <linux/mfd/core.h>
19#include <linux/mfd/abx500.h> 19#include <linux/mfd/abx500.h>
20#include <linux/mfd/ab8500.h> 20#include <linux/mfd/abx500/ab8500.h>
21#include <linux/regulator/ab8500.h> 21#include <linux/regulator/ab8500.h>
22 22
23/* 23/*
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index dedb7f65cea6..9a0211aa8897 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -13,7 +13,7 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14 14
15#include <linux/mfd/abx500.h> 15#include <linux/mfd/abx500.h>
16#include <linux/mfd/ab8500.h> 16#include <linux/mfd/abx500/ab8500.h>
17 17
18static u32 debug_bank; 18static u32 debug_bank;
19static u32 debug_address; 19static u32 debug_address;
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index e985d1701a83..c39fc716e1dc 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -18,9 +18,9 @@
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/mfd/ab8500.h>
22#include <linux/mfd/abx500.h> 21#include <linux/mfd/abx500.h>
23#include <linux/mfd/ab8500/gpadc.h> 22#include <linux/mfd/abx500/ab8500.h>
23#include <linux/mfd/abx500/ab8500-gpadc.h>
24 24
25/* 25/*
26 * GPADC register offsets 26 * GPADC register offsets
diff --git a/drivers/mfd/ab8500-i2c.c b/drivers/mfd/ab8500-i2c.c
index 9be541c6b004..087fecd71ce0 100644
--- a/drivers/mfd/ab8500-i2c.c
+++ b/drivers/mfd/ab8500-i2c.c
@@ -10,7 +10,7 @@
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/mfd/ab8500.h> 13#include <linux/mfd/abx500/ab8500.h>
14#include <linux/mfd/db8500-prcmu.h> 14#include <linux/mfd/db8500-prcmu.h>
15 15
16static int ab8500_i2c_write(struct ab8500 *ab8500, u16 addr, u8 data) 16static int ab8500_i2c_write(struct ab8500 *ab8500, u16 addr, u8 data)
diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index f20feefac190..c28d4eb1eff0 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -7,9 +7,9 @@
7#include <linux/err.h> 7#include <linux/err.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/platform_device.h> 9#include <linux/platform_device.h>
10#include <linux/mfd/ab8500.h>
11#include <linux/mfd/abx500.h> 10#include <linux/mfd/abx500.h>
12#include <linux/mfd/ab8500/sysctrl.h> 11#include <linux/mfd/abx500/ab8500.h>
12#include <linux/mfd/abx500/ab8500-sysctrl.h>
13 13
14static struct device *sysctrl_dev; 14static struct device *sysctrl_dev;
15 15
diff --git a/drivers/mfd/cs5535-mfd.c b/drivers/mfd/cs5535-mfd.c
index 155fa0407882..315fef5d466a 100644
--- a/drivers/mfd/cs5535-mfd.c
+++ b/drivers/mfd/cs5535-mfd.c
@@ -172,14 +172,14 @@ static void __devexit cs5535_mfd_remove(struct pci_dev *pdev)
172 pci_disable_device(pdev); 172 pci_disable_device(pdev);
173} 173}
174 174
175static struct pci_device_id cs5535_mfd_pci_tbl[] = { 175static DEFINE_PCI_DEVICE_TABLE(cs5535_mfd_pci_tbl) = {
176 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) }, 176 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
177 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, 177 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
178 { 0, } 178 { 0, }
179}; 179};
180MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl); 180MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
181 181
182static struct pci_driver cs5535_mfd_drv = { 182static struct pci_driver cs5535_mfd_driver = {
183 .name = DRV_NAME, 183 .name = DRV_NAME,
184 .id_table = cs5535_mfd_pci_tbl, 184 .id_table = cs5535_mfd_pci_tbl,
185 .probe = cs5535_mfd_probe, 185 .probe = cs5535_mfd_probe,
@@ -188,12 +188,12 @@ static struct pci_driver cs5535_mfd_drv = {
188 188
189static int __init cs5535_mfd_init(void) 189static int __init cs5535_mfd_init(void)
190{ 190{
191 return pci_register_driver(&cs5535_mfd_drv); 191 return pci_register_driver(&cs5535_mfd_driver);
192} 192}
193 193
194static void __exit cs5535_mfd_exit(void) 194static void __exit cs5535_mfd_exit(void)
195{ 195{
196 pci_unregister_driver(&cs5535_mfd_drv); 196 pci_unregister_driver(&cs5535_mfd_driver);
197} 197}
198 198
199module_init(cs5535_mfd_init); 199module_init(cs5535_mfd_init);
diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 8ad88da647b9..7710227d284e 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -308,8 +308,7 @@ static int add_children(struct i2c_client *client)
308 for (i = 0; i < ARRAY_SIZE(config_inputs); i++) { 308 for (i = 0; i < ARRAY_SIZE(config_inputs); i++) {
309 int gpio = dm355evm_msp_gpio.base + config_inputs[i].offset; 309 int gpio = dm355evm_msp_gpio.base + config_inputs[i].offset;
310 310
311 gpio_request(gpio, config_inputs[i].label); 311 gpio_request_one(gpio, GPIOF_IN, config_inputs[i].label);
312 gpio_direction_input(gpio);
313 312
314 /* make it easy for userspace to see these */ 313 /* make it easy for userspace to see these */
315 gpio_export(gpio, false); 314 gpio_export(gpio, false);
diff --git a/drivers/mfd/intel_msic.c b/drivers/mfd/intel_msic.c
index 97c27762174f..b76657eb0c51 100644
--- a/drivers/mfd/intel_msic.c
+++ b/drivers/mfd/intel_msic.c
@@ -485,17 +485,7 @@ static struct platform_driver intel_msic_driver = {
485 }, 485 },
486}; 486};
487 487
488static int __init intel_msic_init(void) 488module_platform_driver(intel_msic_driver);
489{
490 return platform_driver_register(&intel_msic_driver);
491}
492module_init(intel_msic_init);
493
494static void __exit intel_msic_exit(void)
495{
496 platform_driver_unregister(&intel_msic_driver);
497}
498module_exit(intel_msic_exit);
499 489
500MODULE_DESCRIPTION("Driver for Intel MSIC"); 490MODULE_DESCRIPTION("Driver for Intel MSIC");
501MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); 491MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
diff --git a/drivers/mfd/jz4740-adc.c b/drivers/mfd/jz4740-adc.c
index ef39528088f2..87662a17dec6 100644
--- a/drivers/mfd/jz4740-adc.c
+++ b/drivers/mfd/jz4740-adc.c
@@ -181,7 +181,7 @@ static struct resource jz4740_battery_resources[] = {
181 }, 181 },
182}; 182};
183 183
184const struct mfd_cell jz4740_adc_cells[] = { 184static struct mfd_cell jz4740_adc_cells[] = {
185 { 185 {
186 .id = 0, 186 .id = 0,
187 .name = "jz4740-hwmon", 187 .name = "jz4740-hwmon",
@@ -338,17 +338,7 @@ static struct platform_driver jz4740_adc_driver = {
338 }, 338 },
339}; 339};
340 340
341static int __init jz4740_adc_init(void) 341module_platform_driver(jz4740_adc_driver);
342{
343 return platform_driver_register(&jz4740_adc_driver);
344}
345module_init(jz4740_adc_init);
346
347static void __exit jz4740_adc_exit(void)
348{
349 platform_driver_unregister(&jz4740_adc_driver);
350}
351module_exit(jz4740_adc_exit);
352 342
353MODULE_DESCRIPTION("JZ4740 SoC ADC driver"); 343MODULE_DESCRIPTION("JZ4740 SoC ADC driver");
354MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 344MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
diff --git a/drivers/mfd/lpc_sch.c b/drivers/mfd/lpc_sch.c
index ea1169b04779..abc421364a45 100644
--- a/drivers/mfd/lpc_sch.c
+++ b/drivers/mfd/lpc_sch.c
@@ -74,7 +74,7 @@ static struct mfd_cell tunnelcreek_cells[] = {
74 }, 74 },
75}; 75};
76 76
77static struct pci_device_id lpc_sch_ids[] = { 77static DEFINE_PCI_DEVICE_TABLE(lpc_sch_ids) = {
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC) }, 78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ITC_LPC) }, 79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ITC_LPC) },
80 { 0, } 80 { 0, }
diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
index 0219115e00c7..d9e4b36edee9 100644
--- a/drivers/mfd/max8925-i2c.c
+++ b/drivers/mfd/max8925-i2c.c
@@ -161,6 +161,8 @@ static int __devinit max8925_probe(struct i2c_client *client,
161 chip->adc = i2c_new_dummy(chip->i2c->adapter, ADC_I2C_ADDR); 161 chip->adc = i2c_new_dummy(chip->i2c->adapter, ADC_I2C_ADDR);
162 i2c_set_clientdata(chip->adc, chip); 162 i2c_set_clientdata(chip->adc, chip);
163 163
164 device_init_wakeup(&client->dev, 1);
165
164 max8925_device_init(chip, pdata); 166 max8925_device_init(chip, pdata);
165 167
166 return 0; 168 return 0;
@@ -177,10 +179,35 @@ static int __devexit max8925_remove(struct i2c_client *client)
177 return 0; 179 return 0;
178} 180}
179 181
182#ifdef CONFIG_PM_SLEEP
183static int max8925_suspend(struct device *dev)
184{
185 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
186 struct max8925_chip *chip = i2c_get_clientdata(client);
187
188 if (device_may_wakeup(dev) && chip->wakeup_flag)
189 enable_irq_wake(chip->core_irq);
190 return 0;
191}
192
193static int max8925_resume(struct device *dev)
194{
195 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
196 struct max8925_chip *chip = i2c_get_clientdata(client);
197
198 if (device_may_wakeup(dev) && chip->wakeup_flag)
199 disable_irq_wake(chip->core_irq);
200 return 0;
201}
202#endif
203
204static SIMPLE_DEV_PM_OPS(max8925_pm_ops, max8925_suspend, max8925_resume);
205
180static struct i2c_driver max8925_driver = { 206static struct i2c_driver max8925_driver = {
181 .driver = { 207 .driver = {
182 .name = "max8925", 208 .name = "max8925",
183 .owner = THIS_MODULE, 209 .owner = THIS_MODULE,
210 .pm = &max8925_pm_ops,
184 }, 211 },
185 .probe = max8925_probe, 212 .probe = max8925_probe,
186 .remove = __devexit_p(max8925_remove), 213 .remove = __devexit_p(max8925_remove),
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index 5be53ae9b61c..cb83a7ab53e7 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -43,7 +43,8 @@ static struct mfd_cell max8997_devs[] = {
43 { .name = "max8997-battery", }, 43 { .name = "max8997-battery", },
44 { .name = "max8997-haptic", }, 44 { .name = "max8997-haptic", },
45 { .name = "max8997-muic", }, 45 { .name = "max8997-muic", },
46 { .name = "max8997-flash", }, 46 { .name = "max8997-led", .id = 1 },
47 { .name = "max8997-led", .id = 2 },
47}; 48};
48 49
49int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) 50int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest)
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
index de4096aee248..6ef56d28c056 100644
--- a/drivers/mfd/max8998.c
+++ b/drivers/mfd/max8998.c
@@ -176,6 +176,8 @@ static int max8998_i2c_probe(struct i2c_client *i2c,
176 if (ret < 0) 176 if (ret < 0)
177 goto err; 177 goto err;
178 178
179 device_init_wakeup(max8998->dev, max8998->wakeup);
180
179 return ret; 181 return ret;
180 182
181err: 183err:
@@ -210,7 +212,7 @@ static int max8998_suspend(struct device *dev)
210 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); 212 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
211 struct max8998_dev *max8998 = i2c_get_clientdata(i2c); 213 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
212 214
213 if (max8998->wakeup) 215 if (device_may_wakeup(dev))
214 irq_set_irq_wake(max8998->irq, 1); 216 irq_set_irq_wake(max8998->irq, 1);
215 return 0; 217 return 0;
216} 218}
@@ -220,7 +222,7 @@ static int max8998_resume(struct device *dev)
220 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); 222 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
221 struct max8998_dev *max8998 = i2c_get_clientdata(i2c); 223 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
222 224
223 if (max8998->wakeup) 225 if (device_may_wakeup(dev))
224 irq_set_irq_wake(max8998->irq, 0); 226 irq_set_irq_wake(max8998->irq, 0);
225 /* 227 /*
226 * In LP3974, if IRQ registers are not "read & clear" 228 * In LP3974, if IRQ registers are not "read & clear"
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index e9619acc0237..7122386b4e3c 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -18,11 +18,15 @@
18#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
19#include <linux/mfd/core.h> 19#include <linux/mfd/core.h>
20#include <linux/mfd/mc13xxx.h> 20#include <linux/mfd/mc13xxx.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
23#include <linux/of_gpio.h>
21 24
22struct mc13xxx { 25struct mc13xxx {
23 struct spi_device *spidev; 26 struct spi_device *spidev;
24 struct mutex lock; 27 struct mutex lock;
25 int irq; 28 int irq;
29 int flags;
26 30
27 irq_handler_t irqhandler[MC13XXX_NUM_IRQ]; 31 irq_handler_t irqhandler[MC13XXX_NUM_IRQ];
28 void *irqdata[MC13XXX_NUM_IRQ]; 32 void *irqdata[MC13XXX_NUM_IRQ];
@@ -550,10 +554,7 @@ static const char *mc13xxx_get_chipname(struct mc13xxx *mc13xxx)
550 554
551int mc13xxx_get_flags(struct mc13xxx *mc13xxx) 555int mc13xxx_get_flags(struct mc13xxx *mc13xxx)
552{ 556{
553 struct mc13xxx_platform_data *pdata = 557 return mc13xxx->flags;
554 dev_get_platdata(&mc13xxx->spidev->dev);
555
556 return pdata->flags;
557} 558}
558EXPORT_SYMBOL(mc13xxx_get_flags); 559EXPORT_SYMBOL(mc13xxx_get_flags);
559 560
@@ -615,13 +616,13 @@ int mc13xxx_adc_do_conversion(struct mc13xxx *mc13xxx, unsigned int mode,
615 break; 616 break;
616 617
617 case MC13XXX_ADC_MODE_SINGLE_CHAN: 618 case MC13XXX_ADC_MODE_SINGLE_CHAN:
618 adc0 |= old_adc0 & MC13XXX_ADC0_TSMOD_MASK; 619 adc0 |= old_adc0 & MC13XXX_ADC0_CONFIG_MASK;
619 adc1 |= (channel & 0x7) << MC13XXX_ADC1_CHAN0_SHIFT; 620 adc1 |= (channel & 0x7) << MC13XXX_ADC1_CHAN0_SHIFT;
620 adc1 |= MC13XXX_ADC1_RAND; 621 adc1 |= MC13XXX_ADC1_RAND;
621 break; 622 break;
622 623
623 case MC13XXX_ADC_MODE_MULT_CHAN: 624 case MC13XXX_ADC_MODE_MULT_CHAN:
624 adc0 |= old_adc0 & MC13XXX_ADC0_TSMOD_MASK; 625 adc0 |= old_adc0 & MC13XXX_ADC0_CONFIG_MASK;
625 adc1 |= 4 << MC13XXX_ADC1_CHAN1_SHIFT; 626 adc1 |= 4 << MC13XXX_ADC1_CHAN1_SHIFT;
626 break; 627 break;
627 628
@@ -696,17 +697,67 @@ static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *format)
696 return mc13xxx_add_subdevice_pdata(mc13xxx, format, NULL, 0); 697 return mc13xxx_add_subdevice_pdata(mc13xxx, format, NULL, 0);
697} 698}
698 699
700#ifdef CONFIG_OF
701static int mc13xxx_probe_flags_dt(struct mc13xxx *mc13xxx)
702{
703 struct device_node *np = mc13xxx->spidev->dev.of_node;
704
705 if (!np)
706 return -ENODEV;
707
708 if (of_get_property(np, "fsl,mc13xxx-uses-adc", NULL))
709 mc13xxx->flags |= MC13XXX_USE_ADC;
710
711 if (of_get_property(np, "fsl,mc13xxx-uses-codec", NULL))
712 mc13xxx->flags |= MC13XXX_USE_CODEC;
713
714 if (of_get_property(np, "fsl,mc13xxx-uses-rtc", NULL))
715 mc13xxx->flags |= MC13XXX_USE_RTC;
716
717 if (of_get_property(np, "fsl,mc13xxx-uses-touch", NULL))
718 mc13xxx->flags |= MC13XXX_USE_TOUCHSCREEN;
719
720 return 0;
721}
722#else
723static inline int mc13xxx_probe_flags_dt(struct mc13xxx *mc13xxx)
724{
725 return -ENODEV;
726}
727#endif
728
729static const struct spi_device_id mc13xxx_device_id[] = {
730 {
731 .name = "mc13783",
732 .driver_data = MC13XXX_ID_MC13783,
733 }, {
734 .name = "mc13892",
735 .driver_data = MC13XXX_ID_MC13892,
736 }, {
737 /* sentinel */
738 }
739};
740MODULE_DEVICE_TABLE(spi, mc13xxx_device_id);
741
742static const struct of_device_id mc13xxx_dt_ids[] = {
743 { .compatible = "fsl,mc13783", .data = (void *) MC13XXX_ID_MC13783, },
744 { .compatible = "fsl,mc13892", .data = (void *) MC13XXX_ID_MC13892, },
745 { /* sentinel */ }
746};
747MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
748
699static int mc13xxx_probe(struct spi_device *spi) 749static int mc13xxx_probe(struct spi_device *spi)
700{ 750{
751 const struct of_device_id *of_id;
752 struct spi_driver *sdrv = to_spi_driver(spi->dev.driver);
701 struct mc13xxx *mc13xxx; 753 struct mc13xxx *mc13xxx;
702 struct mc13xxx_platform_data *pdata = dev_get_platdata(&spi->dev); 754 struct mc13xxx_platform_data *pdata = dev_get_platdata(&spi->dev);
703 enum mc13xxx_id id; 755 enum mc13xxx_id id;
704 int ret; 756 int ret;
705 757
706 if (!pdata) { 758 of_id = of_match_device(mc13xxx_dt_ids, &spi->dev);
707 dev_err(&spi->dev, "invalid platform data\n"); 759 if (of_id)
708 return -EINVAL; 760 sdrv->id_table = &mc13xxx_device_id[(enum mc13xxx_id) of_id->data];
709 }
710 761
711 mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL); 762 mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL);
712 if (!mc13xxx) 763 if (!mc13xxx)
@@ -749,28 +800,33 @@ err_revision:
749 800
750 mc13xxx_unlock(mc13xxx); 801 mc13xxx_unlock(mc13xxx);
751 802
752 if (pdata->flags & MC13XXX_USE_ADC) 803 if (mc13xxx_probe_flags_dt(mc13xxx) < 0 && pdata)
804 mc13xxx->flags = pdata->flags;
805
806 if (mc13xxx->flags & MC13XXX_USE_ADC)
753 mc13xxx_add_subdevice(mc13xxx, "%s-adc"); 807 mc13xxx_add_subdevice(mc13xxx, "%s-adc");
754 808
755 if (pdata->flags & MC13XXX_USE_CODEC) 809 if (mc13xxx->flags & MC13XXX_USE_CODEC)
756 mc13xxx_add_subdevice(mc13xxx, "%s-codec"); 810 mc13xxx_add_subdevice(mc13xxx, "%s-codec");
757 811
758 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-regulator", 812 if (mc13xxx->flags & MC13XXX_USE_RTC)
759 &pdata->regulators, sizeof(pdata->regulators));
760
761 if (pdata->flags & MC13XXX_USE_RTC)
762 mc13xxx_add_subdevice(mc13xxx, "%s-rtc"); 813 mc13xxx_add_subdevice(mc13xxx, "%s-rtc");
763 814
764 if (pdata->flags & MC13XXX_USE_TOUCHSCREEN) 815 if (mc13xxx->flags & MC13XXX_USE_TOUCHSCREEN)
765 mc13xxx_add_subdevice(mc13xxx, "%s-ts"); 816 mc13xxx_add_subdevice(mc13xxx, "%s-ts");
766 817
767 if (pdata->leds) 818 if (pdata) {
819 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-regulator",
820 &pdata->regulators, sizeof(pdata->regulators));
768 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led", 821 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
769 pdata->leds, sizeof(*pdata->leds)); 822 pdata->leds, sizeof(*pdata->leds));
770
771 if (pdata->buttons)
772 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton", 823 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton",
773 pdata->buttons, sizeof(*pdata->buttons)); 824 pdata->buttons, sizeof(*pdata->buttons));
825 } else {
826 mc13xxx_add_subdevice(mc13xxx, "%s-regulator");
827 mc13xxx_add_subdevice(mc13xxx, "%s-led");
828 mc13xxx_add_subdevice(mc13xxx, "%s-pwrbutton");
829 }
774 830
775 return 0; 831 return 0;
776} 832}
@@ -788,25 +844,12 @@ static int __devexit mc13xxx_remove(struct spi_device *spi)
788 return 0; 844 return 0;
789} 845}
790 846
791static const struct spi_device_id mc13xxx_device_id[] = {
792 {
793 .name = "mc13783",
794 .driver_data = MC13XXX_ID_MC13783,
795 }, {
796 .name = "mc13892",
797 .driver_data = MC13XXX_ID_MC13892,
798 }, {
799 /* sentinel */
800 }
801};
802MODULE_DEVICE_TABLE(spi, mc13xxx_device_id);
803
804static struct spi_driver mc13xxx_driver = { 847static struct spi_driver mc13xxx_driver = {
805 .id_table = mc13xxx_device_id, 848 .id_table = mc13xxx_device_id,
806 .driver = { 849 .driver = {
807 .name = "mc13xxx", 850 .name = "mc13xxx",
808 .bus = &spi_bus_type,
809 .owner = THIS_MODULE, 851 .owner = THIS_MODULE,
852 .of_match_table = mc13xxx_dt_ids,
810 }, 853 },
811 .probe = mc13xxx_probe, 854 .probe = mc13xxx_probe,
812 .remove = __devexit_p(mc13xxx_remove), 855 .remove = __devexit_p(mc13xxx_remove),
diff --git a/drivers/mfd/mcp-core.c b/drivers/mfd/mcp-core.c
index 84815f9ef636..63be60bc3455 100644
--- a/drivers/mfd/mcp-core.c
+++ b/drivers/mfd/mcp-core.c
@@ -26,9 +26,35 @@
26#define to_mcp(d) container_of(d, struct mcp, attached_device) 26#define to_mcp(d) container_of(d, struct mcp, attached_device)
27#define to_mcp_driver(d) container_of(d, struct mcp_driver, drv) 27#define to_mcp_driver(d) container_of(d, struct mcp_driver, drv)
28 28
29static const struct mcp_device_id *mcp_match_id(const struct mcp_device_id *id,
30 const char *codec)
31{
32 while (id->name[0]) {
33 if (strcmp(codec, id->name) == 0)
34 return id;
35 id++;
36 }
37 return NULL;
38}
39
40const struct mcp_device_id *mcp_get_device_id(const struct mcp *mcp)
41{
42 const struct mcp_driver *driver =
43 to_mcp_driver(mcp->attached_device.driver);
44
45 return mcp_match_id(driver->id_table, mcp->codec);
46}
47EXPORT_SYMBOL(mcp_get_device_id);
48
29static int mcp_bus_match(struct device *dev, struct device_driver *drv) 49static int mcp_bus_match(struct device *dev, struct device_driver *drv)
30{ 50{
31 return 1; 51 const struct mcp *mcp = to_mcp(dev);
52 const struct mcp_driver *driver = to_mcp_driver(drv);
53
54 if (driver->id_table)
55 return !!mcp_match_id(driver->id_table, mcp->codec);
56
57 return 0;
32} 58}
33 59
34static int mcp_bus_probe(struct device *dev) 60static int mcp_bus_probe(struct device *dev)
@@ -74,9 +100,18 @@ static int mcp_bus_resume(struct device *dev)
74 return ret; 100 return ret;
75} 101}
76 102
103static int mcp_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
104{
105 struct mcp *mcp = to_mcp(dev);
106
107 add_uevent_var(env, "MODALIAS=%s%s", MCP_MODULE_PREFIX, mcp->codec);
108 return 0;
109}
110
77static struct bus_type mcp_bus_type = { 111static struct bus_type mcp_bus_type = {
78 .name = "mcp", 112 .name = "mcp",
79 .match = mcp_bus_match, 113 .match = mcp_bus_match,
114 .uevent = mcp_bus_uevent,
80 .probe = mcp_bus_probe, 115 .probe = mcp_bus_probe,
81 .remove = mcp_bus_remove, 116 .remove = mcp_bus_remove,
82 .suspend = mcp_bus_suspend, 117 .suspend = mcp_bus_suspend,
@@ -212,9 +247,14 @@ struct mcp *mcp_host_alloc(struct device *parent, size_t size)
212} 247}
213EXPORT_SYMBOL(mcp_host_alloc); 248EXPORT_SYMBOL(mcp_host_alloc);
214 249
215int mcp_host_register(struct mcp *mcp) 250int mcp_host_register(struct mcp *mcp, void *pdata)
216{ 251{
252 if (!mcp->codec)
253 return -EINVAL;
254
255 mcp->attached_device.platform_data = pdata;
217 dev_set_name(&mcp->attached_device, "mcp0"); 256 dev_set_name(&mcp->attached_device, "mcp0");
257 request_module("%s%s", MCP_MODULE_PREFIX, mcp->codec);
218 return device_register(&mcp->attached_device); 258 return device_register(&mcp->attached_device);
219} 259}
220EXPORT_SYMBOL(mcp_host_register); 260EXPORT_SYMBOL(mcp_host_register);
diff --git a/drivers/mfd/mcp-sa11x0.c b/drivers/mfd/mcp-sa11x0.c
index 2dab02d9ac8b..9adc2eb69492 100644
--- a/drivers/mfd/mcp-sa11x0.c
+++ b/drivers/mfd/mcp-sa11x0.c
@@ -19,6 +19,7 @@
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/mfd/mcp.h> 21#include <linux/mfd/mcp.h>
22#include <linux/io.h>
22 23
23#include <mach/dma.h> 24#include <mach/dma.h>
24#include <mach/hardware.h> 25#include <mach/hardware.h>
@@ -26,12 +27,19 @@
26#include <asm/system.h> 27#include <asm/system.h>
27#include <mach/mcp.h> 28#include <mach/mcp.h>
28 29
29#include <mach/assabet.h> 30/* Register offsets */
30 31#define MCCR0 0x00
32#define MCDR0 0x08
33#define MCDR1 0x0C
34#define MCDR2 0x10
35#define MCSR 0x18
36#define MCCR1 0x00
31 37
32struct mcp_sa11x0 { 38struct mcp_sa11x0 {
33 u32 mccr0; 39 u32 mccr0;
34 u32 mccr1; 40 u32 mccr1;
41 unsigned char *mccr0_base;
42 unsigned char *mccr1_base;
35}; 43};
36 44
37#define priv(mcp) ((struct mcp_sa11x0 *)mcp_priv(mcp)) 45#define priv(mcp) ((struct mcp_sa11x0 *)mcp_priv(mcp))
@@ -39,25 +47,25 @@ struct mcp_sa11x0 {
39static void 47static void
40mcp_sa11x0_set_telecom_divisor(struct mcp *mcp, unsigned int divisor) 48mcp_sa11x0_set_telecom_divisor(struct mcp *mcp, unsigned int divisor)
41{ 49{
42 unsigned int mccr0; 50 struct mcp_sa11x0 *priv = priv(mcp);
43 51
44 divisor /= 32; 52 divisor /= 32;
45 53
46 mccr0 = Ser4MCCR0 & ~0x00007f00; 54 priv->mccr0 &= ~0x00007f00;
47 mccr0 |= divisor << 8; 55 priv->mccr0 |= divisor << 8;
48 Ser4MCCR0 = mccr0; 56 __raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
49} 57}
50 58
51static void 59static void
52mcp_sa11x0_set_audio_divisor(struct mcp *mcp, unsigned int divisor) 60mcp_sa11x0_set_audio_divisor(struct mcp *mcp, unsigned int divisor)
53{ 61{
54 unsigned int mccr0; 62 struct mcp_sa11x0 *priv = priv(mcp);
55 63
56 divisor /= 32; 64 divisor /= 32;
57 65
58 mccr0 = Ser4MCCR0 & ~0x0000007f; 66 priv->mccr0 &= ~0x0000007f;
59 mccr0 |= divisor; 67 priv->mccr0 |= divisor;
60 Ser4MCCR0 = mccr0; 68 __raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
61} 69}
62 70
63/* 71/*
@@ -71,12 +79,16 @@ mcp_sa11x0_write(struct mcp *mcp, unsigned int reg, unsigned int val)
71{ 79{
72 int ret = -ETIME; 80 int ret = -ETIME;
73 int i; 81 int i;
82 u32 mcpreg;
83 struct mcp_sa11x0 *priv = priv(mcp);
74 84
75 Ser4MCDR2 = reg << 17 | MCDR2_Wr | (val & 0xffff); 85 mcpreg = reg << 17 | MCDR2_Wr | (val & 0xffff);
86 __raw_writel(mcpreg, priv->mccr0_base + MCDR2);
76 87
77 for (i = 0; i < 2; i++) { 88 for (i = 0; i < 2; i++) {
78 udelay(mcp->rw_timeout); 89 udelay(mcp->rw_timeout);
79 if (Ser4MCSR & MCSR_CWC) { 90 mcpreg = __raw_readl(priv->mccr0_base + MCSR);
91 if (mcpreg & MCSR_CWC) {
80 ret = 0; 92 ret = 0;
81 break; 93 break;
82 } 94 }
@@ -97,13 +109,18 @@ mcp_sa11x0_read(struct mcp *mcp, unsigned int reg)
97{ 109{
98 int ret = -ETIME; 110 int ret = -ETIME;
99 int i; 111 int i;
112 u32 mcpreg;
113 struct mcp_sa11x0 *priv = priv(mcp);
100 114
101 Ser4MCDR2 = reg << 17 | MCDR2_Rd; 115 mcpreg = reg << 17 | MCDR2_Rd;
116 __raw_writel(mcpreg, priv->mccr0_base + MCDR2);
102 117
103 for (i = 0; i < 2; i++) { 118 for (i = 0; i < 2; i++) {
104 udelay(mcp->rw_timeout); 119 udelay(mcp->rw_timeout);
105 if (Ser4MCSR & MCSR_CRC) { 120 mcpreg = __raw_readl(priv->mccr0_base + MCSR);
106 ret = Ser4MCDR2 & 0xffff; 121 if (mcpreg & MCSR_CRC) {
122 ret = __raw_readl(priv->mccr0_base + MCDR2)
123 & 0xffff;
107 break; 124 break;
108 } 125 }
109 } 126 }
@@ -116,13 +133,19 @@ mcp_sa11x0_read(struct mcp *mcp, unsigned int reg)
116 133
117static void mcp_sa11x0_enable(struct mcp *mcp) 134static void mcp_sa11x0_enable(struct mcp *mcp)
118{ 135{
119 Ser4MCSR = -1; 136 struct mcp_sa11x0 *priv = priv(mcp);
120 Ser4MCCR0 |= MCCR0_MCE; 137
138 __raw_writel(-1, priv->mccr0_base + MCSR);
139 priv->mccr0 |= MCCR0_MCE;
140 __raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
121} 141}
122 142
123static void mcp_sa11x0_disable(struct mcp *mcp) 143static void mcp_sa11x0_disable(struct mcp *mcp)
124{ 144{
125 Ser4MCCR0 &= ~MCCR0_MCE; 145 struct mcp_sa11x0 *priv = priv(mcp);
146
147 priv->mccr0 &= ~MCCR0_MCE;
148 __raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
126} 149}
127 150
128/* 151/*
@@ -142,50 +165,69 @@ static int mcp_sa11x0_probe(struct platform_device *pdev)
142 struct mcp_plat_data *data = pdev->dev.platform_data; 165 struct mcp_plat_data *data = pdev->dev.platform_data;
143 struct mcp *mcp; 166 struct mcp *mcp;
144 int ret; 167 int ret;
168 struct mcp_sa11x0 *priv;
169 struct resource *res_mem0, *res_mem1;
170 u32 size0, size1;
145 171
146 if (!data) 172 if (!data)
147 return -ENODEV; 173 return -ENODEV;
148 174
149 if (!request_mem_region(0x80060000, 0x60, "sa11x0-mcp")) 175 if (!data->codec)
176 return -ENODEV;
177
178 res_mem0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
179 if (!res_mem0)
180 return -ENODEV;
181 size0 = res_mem0->end - res_mem0->start + 1;
182
183 res_mem1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
184 if (!res_mem1)
185 return -ENODEV;
186 size1 = res_mem1->end - res_mem1->start + 1;
187
188 if (!request_mem_region(res_mem0->start, size0, "sa11x0-mcp"))
150 return -EBUSY; 189 return -EBUSY;
151 190
191 if (!request_mem_region(res_mem1->start, size1, "sa11x0-mcp")) {
192 ret = -EBUSY;
193 goto release;
194 }
195
152 mcp = mcp_host_alloc(&pdev->dev, sizeof(struct mcp_sa11x0)); 196 mcp = mcp_host_alloc(&pdev->dev, sizeof(struct mcp_sa11x0));
153 if (!mcp) { 197 if (!mcp) {
154 ret = -ENOMEM; 198 ret = -ENOMEM;
155 goto release; 199 goto release2;
156 } 200 }
157 201
202 priv = priv(mcp);
203
158 mcp->owner = THIS_MODULE; 204 mcp->owner = THIS_MODULE;
159 mcp->ops = &mcp_sa11x0; 205 mcp->ops = &mcp_sa11x0;
160 mcp->sclk_rate = data->sclk_rate; 206 mcp->sclk_rate = data->sclk_rate;
161 mcp->dma_audio_rd = DMA_Ser4MCP0Rd; 207 mcp->dma_audio_rd = DDAR_DevAdd(res_mem0->start + MCDR0)
162 mcp->dma_audio_wr = DMA_Ser4MCP0Wr; 208 + DDAR_DevRd + DDAR_Brst4 + DDAR_8BitDev;
163 mcp->dma_telco_rd = DMA_Ser4MCP1Rd; 209 mcp->dma_audio_wr = DDAR_DevAdd(res_mem0->start + MCDR0)
164 mcp->dma_telco_wr = DMA_Ser4MCP1Wr; 210 + DDAR_DevWr + DDAR_Brst4 + DDAR_8BitDev;
165 mcp->gpio_base = data->gpio_base; 211 mcp->dma_telco_rd = DDAR_DevAdd(res_mem0->start + MCDR1)
212 + DDAR_DevRd + DDAR_Brst4 + DDAR_8BitDev;
213 mcp->dma_telco_wr = DDAR_DevAdd(res_mem0->start + MCDR1)
214 + DDAR_DevWr + DDAR_Brst4 + DDAR_8BitDev;
215 mcp->codec = data->codec;
166 216
167 platform_set_drvdata(pdev, mcp); 217 platform_set_drvdata(pdev, mcp);
168 218
169 if (machine_is_assabet()) {
170 ASSABET_BCR_set(ASSABET_BCR_CODEC_RST);
171 }
172
173 /*
174 * Setup the PPC unit correctly.
175 */
176 PPDR &= ~PPC_RXD4;
177 PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
178 PSDR |= PPC_RXD4;
179 PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
180 PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
181
182 /* 219 /*
183 * Initialise device. Note that we initially 220 * Initialise device. Note that we initially
184 * set the sampling rate to minimum. 221 * set the sampling rate to minimum.
185 */ 222 */
186 Ser4MCSR = -1; 223 priv->mccr0_base = ioremap(res_mem0->start, size0);
187 Ser4MCCR1 = data->mccr1; 224 priv->mccr1_base = ioremap(res_mem1->start, size1);
188 Ser4MCCR0 = data->mccr0 | 0x7f7f; 225
226 __raw_writel(-1, priv->mccr0_base + MCSR);
227 priv->mccr1 = data->mccr1;
228 priv->mccr0 = data->mccr0 | 0x7f7f;
229 __raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
230 __raw_writel(priv->mccr1, priv->mccr1_base + MCCR1);
189 231
190 /* 232 /*
191 * Calculate the read/write timeout (us) from the bit clock 233 * Calculate the read/write timeout (us) from the bit clock
@@ -195,36 +237,53 @@ static int mcp_sa11x0_probe(struct platform_device *pdev)
195 mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) / 237 mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) /
196 mcp->sclk_rate; 238 mcp->sclk_rate;
197 239
198 ret = mcp_host_register(mcp); 240 ret = mcp_host_register(mcp, data->codec_pdata);
199 if (ret == 0) 241 if (ret == 0)
200 goto out; 242 goto out;
201 243
244 release2:
245 release_mem_region(res_mem1->start, size1);
202 release: 246 release:
203 release_mem_region(0x80060000, 0x60); 247 release_mem_region(res_mem0->start, size0);
204 platform_set_drvdata(pdev, NULL); 248 platform_set_drvdata(pdev, NULL);
205 249
206 out: 250 out:
207 return ret; 251 return ret;
208} 252}
209 253
210static int mcp_sa11x0_remove(struct platform_device *dev) 254static int mcp_sa11x0_remove(struct platform_device *pdev)
211{ 255{
212 struct mcp *mcp = platform_get_drvdata(dev); 256 struct mcp *mcp = platform_get_drvdata(pdev);
257 struct mcp_sa11x0 *priv = priv(mcp);
258 struct resource *res_mem;
259 u32 size;
213 260
214 platform_set_drvdata(dev, NULL); 261 platform_set_drvdata(pdev, NULL);
215 mcp_host_unregister(mcp); 262 mcp_host_unregister(mcp);
216 release_mem_region(0x80060000, 0x60);
217 263
264 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
265 if (res_mem) {
266 size = res_mem->end - res_mem->start + 1;
267 release_mem_region(res_mem->start, size);
268 }
269 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
270 if (res_mem) {
271 size = res_mem->end - res_mem->start + 1;
272 release_mem_region(res_mem->start, size);
273 }
274 iounmap(priv->mccr0_base);
275 iounmap(priv->mccr1_base);
218 return 0; 276 return 0;
219} 277}
220 278
221static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state) 279static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state)
222{ 280{
223 struct mcp *mcp = platform_get_drvdata(dev); 281 struct mcp *mcp = platform_get_drvdata(dev);
282 struct mcp_sa11x0 *priv = priv(mcp);
283 u32 mccr0;
224 284
225 priv(mcp)->mccr0 = Ser4MCCR0; 285 mccr0 = priv->mccr0 & ~MCCR0_MCE;
226 priv(mcp)->mccr1 = Ser4MCCR1; 286 __raw_writel(mccr0, priv->mccr0_base + MCCR0);
227 Ser4MCCR0 &= ~MCCR0_MCE;
228 287
229 return 0; 288 return 0;
230} 289}
@@ -232,9 +291,10 @@ static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state)
232static int mcp_sa11x0_resume(struct platform_device *dev) 291static int mcp_sa11x0_resume(struct platform_device *dev)
233{ 292{
234 struct mcp *mcp = platform_get_drvdata(dev); 293 struct mcp *mcp = platform_get_drvdata(dev);
294 struct mcp_sa11x0 *priv = priv(mcp);
235 295
236 Ser4MCCR1 = priv(mcp)->mccr1; 296 __raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
237 Ser4MCCR0 = priv(mcp)->mccr0; 297 __raw_writel(priv->mccr1, priv->mccr1_base + MCCR1);
238 298
239 return 0; 299 return 0;
240} 300}
@@ -251,24 +311,14 @@ static struct platform_driver mcp_sa11x0_driver = {
251 .resume = mcp_sa11x0_resume, 311 .resume = mcp_sa11x0_resume,
252 .driver = { 312 .driver = {
253 .name = "sa11x0-mcp", 313 .name = "sa11x0-mcp",
314 .owner = THIS_MODULE,
254 }, 315 },
255}; 316};
256 317
257/* 318/*
258 * This needs re-working 319 * This needs re-working
259 */ 320 */
260static int __init mcp_sa11x0_init(void) 321module_platform_driver(mcp_sa11x0_driver);
261{
262 return platform_driver_register(&mcp_sa11x0_driver);
263}
264
265static void __exit mcp_sa11x0_exit(void)
266{
267 platform_driver_unregister(&mcp_sa11x0_driver);
268}
269
270module_init(mcp_sa11x0_init);
271module_exit(mcp_sa11x0_exit);
272 322
273MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); 323MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
274MODULE_DESCRIPTION("SA11x0 multimedia communications port driver"); 324MODULE_DESCRIPTION("SA11x0 multimedia communications port driver");
diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 3f565ef3e149..68ac2c55d5ae 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -503,19 +503,13 @@ static void omap_usbhs_init(struct device *dev)
503 spin_lock_irqsave(&omap->lock, flags); 503 spin_lock_irqsave(&omap->lock, flags);
504 504
505 if (pdata->ehci_data->phy_reset) { 505 if (pdata->ehci_data->phy_reset) {
506 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) { 506 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
507 gpio_request(pdata->ehci_data->reset_gpio_port[0], 507 gpio_request_one(pdata->ehci_data->reset_gpio_port[0],
508 "USB1 PHY reset"); 508 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
509 gpio_direction_output
510 (pdata->ehci_data->reset_gpio_port[0], 0);
511 }
512 509
513 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) { 510 if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
514 gpio_request(pdata->ehci_data->reset_gpio_port[1], 511 gpio_request_one(pdata->ehci_data->reset_gpio_port[1],
515 "USB2 PHY reset"); 512 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
516 gpio_direction_output
517 (pdata->ehci_data->reset_gpio_port[1], 0);
518 }
519 513
520 /* Hold the PHY in RESET for enough time till DIR is high */ 514 /* Hold the PHY in RESET for enough time till DIR is high */
521 udelay(10); 515 udelay(10);
diff --git a/drivers/mfd/pcf50633-adc.c b/drivers/mfd/pcf50633-adc.c
index aed0d2a9b032..3927c17e4175 100644
--- a/drivers/mfd/pcf50633-adc.c
+++ b/drivers/mfd/pcf50633-adc.c
@@ -249,17 +249,7 @@ static struct platform_driver pcf50633_adc_driver = {
249 .remove = __devexit_p(pcf50633_adc_remove), 249 .remove = __devexit_p(pcf50633_adc_remove),
250}; 250};
251 251
252static int __init pcf50633_adc_init(void) 252module_platform_driver(pcf50633_adc_driver);
253{
254 return platform_driver_register(&pcf50633_adc_driver);
255}
256module_init(pcf50633_adc_init);
257
258static void __exit pcf50633_adc_exit(void)
259{
260 platform_driver_unregister(&pcf50633_adc_driver);
261}
262module_exit(pcf50633_adc_exit);
263 253
264MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>"); 254MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
265MODULE_DESCRIPTION("PCF50633 adc driver"); 255MODULE_DESCRIPTION("PCF50633 adc driver");
diff --git a/drivers/mfd/s5m-core.c b/drivers/mfd/s5m-core.c
new file mode 100644
index 000000000000..e075c113eec6
--- /dev/null
+++ b/drivers/mfd/s5m-core.c
@@ -0,0 +1,176 @@
1/*
2 * s5m87xx.c
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/err.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/interrupt.h>
21#include <linux/pm_runtime.h>
22#include <linux/mutex.h>
23#include <linux/mfd/core.h>
24#include <linux/mfd/s5m87xx/s5m-core.h>
25#include <linux/mfd/s5m87xx/s5m-pmic.h>
26#include <linux/mfd/s5m87xx/s5m-rtc.h>
27#include <linux/regmap.h>
28
29static struct mfd_cell s5m87xx_devs[] = {
30 {
31 .name = "s5m8767-pmic",
32 }, {
33 .name = "s5m-rtc",
34 },
35};
36
37int s5m_reg_read(struct s5m87xx_dev *s5m87xx, u8 reg, void *dest)
38{
39 return regmap_read(s5m87xx->regmap, reg, dest);
40}
41EXPORT_SYMBOL_GPL(s5m_reg_read);
42
43int s5m_bulk_read(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf)
44{
45 return regmap_bulk_read(s5m87xx->regmap, reg, buf, count);;
46}
47EXPORT_SYMBOL_GPL(s5m_bulk_read);
48
49int s5m_reg_write(struct s5m87xx_dev *s5m87xx, u8 reg, u8 value)
50{
51 return regmap_write(s5m87xx->regmap, reg, value);
52}
53EXPORT_SYMBOL_GPL(s5m_reg_write);
54
55int s5m_bulk_write(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf)
56{
57 return regmap_raw_write(s5m87xx->regmap, reg, buf, count * sizeof(u16));
58}
59EXPORT_SYMBOL_GPL(s5m_bulk_write);
60
61int s5m_reg_update(struct s5m87xx_dev *s5m87xx, u8 reg, u8 val, u8 mask)
62{
63 return regmap_update_bits(s5m87xx->regmap, reg, mask, val);
64}
65EXPORT_SYMBOL_GPL(s5m_reg_update);
66
67static struct regmap_config s5m_regmap_config = {
68 .reg_bits = 8,
69 .val_bits = 8,
70};
71
72static int s5m87xx_i2c_probe(struct i2c_client *i2c,
73 const struct i2c_device_id *id)
74{
75 struct s5m_platform_data *pdata = i2c->dev.platform_data;
76 struct s5m87xx_dev *s5m87xx;
77 int ret = 0;
78 int error;
79
80 s5m87xx = kzalloc(sizeof(struct s5m87xx_dev), GFP_KERNEL);
81 if (s5m87xx == NULL)
82 return -ENOMEM;
83
84 i2c_set_clientdata(i2c, s5m87xx);
85 s5m87xx->dev = &i2c->dev;
86 s5m87xx->i2c = i2c;
87 s5m87xx->irq = i2c->irq;
88 s5m87xx->type = id->driver_data;
89
90 if (pdata) {
91 s5m87xx->device_type = pdata->device_type;
92 s5m87xx->ono = pdata->ono;
93 s5m87xx->irq_base = pdata->irq_base;
94 s5m87xx->wakeup = pdata->wakeup;
95 }
96
97 s5m87xx->regmap = regmap_init_i2c(i2c, &s5m_regmap_config);
98 if (IS_ERR(s5m87xx->regmap)) {
99 error = PTR_ERR(s5m87xx->regmap);
100 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
101 error);
102 goto err;
103 }
104
105 s5m87xx->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR);
106 i2c_set_clientdata(s5m87xx->rtc, s5m87xx);
107
108 if (pdata->cfg_pmic_irq)
109 pdata->cfg_pmic_irq();
110
111 s5m_irq_init(s5m87xx);
112
113 pm_runtime_set_active(s5m87xx->dev);
114
115 ret = mfd_add_devices(s5m87xx->dev, -1,
116 s5m87xx_devs, ARRAY_SIZE(s5m87xx_devs),
117 NULL, 0);
118
119 if (ret < 0)
120 goto err;
121
122 return ret;
123
124err:
125 mfd_remove_devices(s5m87xx->dev);
126 s5m_irq_exit(s5m87xx);
127 i2c_unregister_device(s5m87xx->rtc);
128 regmap_exit(s5m87xx->regmap);
129 kfree(s5m87xx);
130 return ret;
131}
132
133static int s5m87xx_i2c_remove(struct i2c_client *i2c)
134{
135 struct s5m87xx_dev *s5m87xx = i2c_get_clientdata(i2c);
136
137 mfd_remove_devices(s5m87xx->dev);
138 s5m_irq_exit(s5m87xx);
139 i2c_unregister_device(s5m87xx->rtc);
140 regmap_exit(s5m87xx->regmap);
141 kfree(s5m87xx);
142 return 0;
143}
144
145static const struct i2c_device_id s5m87xx_i2c_id[] = {
146 { "s5m87xx", 0 },
147 { }
148};
149MODULE_DEVICE_TABLE(i2c, s5m87xx_i2c_id);
150
151static struct i2c_driver s5m87xx_i2c_driver = {
152 .driver = {
153 .name = "s5m87xx",
154 .owner = THIS_MODULE,
155 },
156 .probe = s5m87xx_i2c_probe,
157 .remove = s5m87xx_i2c_remove,
158 .id_table = s5m87xx_i2c_id,
159};
160
161static int __init s5m87xx_i2c_init(void)
162{
163 return i2c_add_driver(&s5m87xx_i2c_driver);
164}
165
166subsys_initcall(s5m87xx_i2c_init);
167
168static void __exit s5m87xx_i2c_exit(void)
169{
170 i2c_del_driver(&s5m87xx_i2c_driver);
171}
172module_exit(s5m87xx_i2c_exit);
173
174MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
175MODULE_DESCRIPTION("Core support for the S5M MFD");
176MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/s5m-irq.c b/drivers/mfd/s5m-irq.c
new file mode 100644
index 000000000000..de76dfb6f0ad
--- /dev/null
+++ b/drivers/mfd/s5m-irq.c
@@ -0,0 +1,487 @@
1/*
2 * s5m-irq.c
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/device.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
17#include <linux/mfd/s5m87xx/s5m-core.h>
18
19struct s5m_irq_data {
20 int reg;
21 int mask;
22};
23
24static struct s5m_irq_data s5m8767_irqs[] = {
25 [S5M8767_IRQ_PWRR] = {
26 .reg = 1,
27 .mask = S5M8767_IRQ_PWRR_MASK,
28 },
29 [S5M8767_IRQ_PWRF] = {
30 .reg = 1,
31 .mask = S5M8767_IRQ_PWRF_MASK,
32 },
33 [S5M8767_IRQ_PWR1S] = {
34 .reg = 1,
35 .mask = S5M8767_IRQ_PWR1S_MASK,
36 },
37 [S5M8767_IRQ_JIGR] = {
38 .reg = 1,
39 .mask = S5M8767_IRQ_JIGR_MASK,
40 },
41 [S5M8767_IRQ_JIGF] = {
42 .reg = 1,
43 .mask = S5M8767_IRQ_JIGF_MASK,
44 },
45 [S5M8767_IRQ_LOWBAT2] = {
46 .reg = 1,
47 .mask = S5M8767_IRQ_LOWBAT2_MASK,
48 },
49 [S5M8767_IRQ_LOWBAT1] = {
50 .reg = 1,
51 .mask = S5M8767_IRQ_LOWBAT1_MASK,
52 },
53 [S5M8767_IRQ_MRB] = {
54 .reg = 2,
55 .mask = S5M8767_IRQ_MRB_MASK,
56 },
57 [S5M8767_IRQ_DVSOK2] = {
58 .reg = 2,
59 .mask = S5M8767_IRQ_DVSOK2_MASK,
60 },
61 [S5M8767_IRQ_DVSOK3] = {
62 .reg = 2,
63 .mask = S5M8767_IRQ_DVSOK3_MASK,
64 },
65 [S5M8767_IRQ_DVSOK4] = {
66 .reg = 2,
67 .mask = S5M8767_IRQ_DVSOK4_MASK,
68 },
69 [S5M8767_IRQ_RTC60S] = {
70 .reg = 3,
71 .mask = S5M8767_IRQ_RTC60S_MASK,
72 },
73 [S5M8767_IRQ_RTCA1] = {
74 .reg = 3,
75 .mask = S5M8767_IRQ_RTCA1_MASK,
76 },
77 [S5M8767_IRQ_RTCA2] = {
78 .reg = 3,
79 .mask = S5M8767_IRQ_RTCA2_MASK,
80 },
81 [S5M8767_IRQ_SMPL] = {
82 .reg = 3,
83 .mask = S5M8767_IRQ_SMPL_MASK,
84 },
85 [S5M8767_IRQ_RTC1S] = {
86 .reg = 3,
87 .mask = S5M8767_IRQ_RTC1S_MASK,
88 },
89 [S5M8767_IRQ_WTSR] = {
90 .reg = 3,
91 .mask = S5M8767_IRQ_WTSR_MASK,
92 },
93};
94
95static struct s5m_irq_data s5m8763_irqs[] = {
96 [S5M8763_IRQ_DCINF] = {
97 .reg = 1,
98 .mask = S5M8763_IRQ_DCINF_MASK,
99 },
100 [S5M8763_IRQ_DCINR] = {
101 .reg = 1,
102 .mask = S5M8763_IRQ_DCINR_MASK,
103 },
104 [S5M8763_IRQ_JIGF] = {
105 .reg = 1,
106 .mask = S5M8763_IRQ_JIGF_MASK,
107 },
108 [S5M8763_IRQ_JIGR] = {
109 .reg = 1,
110 .mask = S5M8763_IRQ_JIGR_MASK,
111 },
112 [S5M8763_IRQ_PWRONF] = {
113 .reg = 1,
114 .mask = S5M8763_IRQ_PWRONF_MASK,
115 },
116 [S5M8763_IRQ_PWRONR] = {
117 .reg = 1,
118 .mask = S5M8763_IRQ_PWRONR_MASK,
119 },
120 [S5M8763_IRQ_WTSREVNT] = {
121 .reg = 2,
122 .mask = S5M8763_IRQ_WTSREVNT_MASK,
123 },
124 [S5M8763_IRQ_SMPLEVNT] = {
125 .reg = 2,
126 .mask = S5M8763_IRQ_SMPLEVNT_MASK,
127 },
128 [S5M8763_IRQ_ALARM1] = {
129 .reg = 2,
130 .mask = S5M8763_IRQ_ALARM1_MASK,
131 },
132 [S5M8763_IRQ_ALARM0] = {
133 .reg = 2,
134 .mask = S5M8763_IRQ_ALARM0_MASK,
135 },
136 [S5M8763_IRQ_ONKEY1S] = {
137 .reg = 3,
138 .mask = S5M8763_IRQ_ONKEY1S_MASK,
139 },
140 [S5M8763_IRQ_TOPOFFR] = {
141 .reg = 3,
142 .mask = S5M8763_IRQ_TOPOFFR_MASK,
143 },
144 [S5M8763_IRQ_DCINOVPR] = {
145 .reg = 3,
146 .mask = S5M8763_IRQ_DCINOVPR_MASK,
147 },
148 [S5M8763_IRQ_CHGRSTF] = {
149 .reg = 3,
150 .mask = S5M8763_IRQ_CHGRSTF_MASK,
151 },
152 [S5M8763_IRQ_DONER] = {
153 .reg = 3,
154 .mask = S5M8763_IRQ_DONER_MASK,
155 },
156 [S5M8763_IRQ_CHGFAULT] = {
157 .reg = 3,
158 .mask = S5M8763_IRQ_CHGFAULT_MASK,
159 },
160 [S5M8763_IRQ_LOBAT1] = {
161 .reg = 4,
162 .mask = S5M8763_IRQ_LOBAT1_MASK,
163 },
164 [S5M8763_IRQ_LOBAT2] = {
165 .reg = 4,
166 .mask = S5M8763_IRQ_LOBAT2_MASK,
167 },
168};
169
170static inline struct s5m_irq_data *
171irq_to_s5m8767_irq(struct s5m87xx_dev *s5m87xx, int irq)
172{
173 return &s5m8767_irqs[irq - s5m87xx->irq_base];
174}
175
176static void s5m8767_irq_lock(struct irq_data *data)
177{
178 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
179
180 mutex_lock(&s5m87xx->irqlock);
181}
182
183static void s5m8767_irq_sync_unlock(struct irq_data *data)
184{
185 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
186 int i;
187
188 for (i = 0; i < ARRAY_SIZE(s5m87xx->irq_masks_cur); i++) {
189 if (s5m87xx->irq_masks_cur[i] != s5m87xx->irq_masks_cache[i]) {
190 s5m87xx->irq_masks_cache[i] = s5m87xx->irq_masks_cur[i];
191 s5m_reg_write(s5m87xx, S5M8767_REG_INT1M + i,
192 s5m87xx->irq_masks_cur[i]);
193 }
194 }
195
196 mutex_unlock(&s5m87xx->irqlock);
197}
198
199static void s5m8767_irq_unmask(struct irq_data *data)
200{
201 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
202 struct s5m_irq_data *irq_data = irq_to_s5m8767_irq(s5m87xx,
203 data->irq);
204
205 s5m87xx->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask;
206}
207
208static void s5m8767_irq_mask(struct irq_data *data)
209{
210 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
211 struct s5m_irq_data *irq_data = irq_to_s5m8767_irq(s5m87xx,
212 data->irq);
213
214 s5m87xx->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask;
215}
216
217static struct irq_chip s5m8767_irq_chip = {
218 .name = "s5m8767",
219 .irq_bus_lock = s5m8767_irq_lock,
220 .irq_bus_sync_unlock = s5m8767_irq_sync_unlock,
221 .irq_mask = s5m8767_irq_mask,
222 .irq_unmask = s5m8767_irq_unmask,
223};
224
225static inline struct s5m_irq_data *
226irq_to_s5m8763_irq(struct s5m87xx_dev *s5m87xx, int irq)
227{
228 return &s5m8763_irqs[irq - s5m87xx->irq_base];
229}
230
231static void s5m8763_irq_lock(struct irq_data *data)
232{
233 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
234
235 mutex_lock(&s5m87xx->irqlock);
236}
237
238static void s5m8763_irq_sync_unlock(struct irq_data *data)
239{
240 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
241 int i;
242
243 for (i = 0; i < ARRAY_SIZE(s5m87xx->irq_masks_cur); i++) {
244 if (s5m87xx->irq_masks_cur[i] != s5m87xx->irq_masks_cache[i]) {
245 s5m87xx->irq_masks_cache[i] = s5m87xx->irq_masks_cur[i];
246 s5m_reg_write(s5m87xx, S5M8763_REG_IRQM1 + i,
247 s5m87xx->irq_masks_cur[i]);
248 }
249 }
250
251 mutex_unlock(&s5m87xx->irqlock);
252}
253
254static void s5m8763_irq_unmask(struct irq_data *data)
255{
256 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
257 struct s5m_irq_data *irq_data = irq_to_s5m8763_irq(s5m87xx,
258 data->irq);
259
260 s5m87xx->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask;
261}
262
263static void s5m8763_irq_mask(struct irq_data *data)
264{
265 struct s5m87xx_dev *s5m87xx = irq_data_get_irq_chip_data(data);
266 struct s5m_irq_data *irq_data = irq_to_s5m8763_irq(s5m87xx,
267 data->irq);
268
269 s5m87xx->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask;
270}
271
272static struct irq_chip s5m8763_irq_chip = {
273 .name = "s5m8763",
274 .irq_bus_lock = s5m8763_irq_lock,
275 .irq_bus_sync_unlock = s5m8763_irq_sync_unlock,
276 .irq_mask = s5m8763_irq_mask,
277 .irq_unmask = s5m8763_irq_unmask,
278};
279
280
281static irqreturn_t s5m8767_irq_thread(int irq, void *data)
282{
283 struct s5m87xx_dev *s5m87xx = data;
284 u8 irq_reg[NUM_IRQ_REGS-1];
285 int ret;
286 int i;
287
288
289 ret = s5m_bulk_read(s5m87xx, S5M8767_REG_INT1,
290 NUM_IRQ_REGS - 1, irq_reg);
291 if (ret < 0) {
292 dev_err(s5m87xx->dev, "Failed to read interrupt register: %d\n",
293 ret);
294 return IRQ_NONE;
295 }
296
297 for (i = 0; i < NUM_IRQ_REGS - 1; i++)
298 irq_reg[i] &= ~s5m87xx->irq_masks_cur[i];
299
300 for (i = 0; i < S5M8767_IRQ_NR; i++) {
301 if (irq_reg[s5m8767_irqs[i].reg - 1] & s5m8767_irqs[i].mask)
302 handle_nested_irq(s5m87xx->irq_base + i);
303 }
304
305 return IRQ_HANDLED;
306}
307
308static irqreturn_t s5m8763_irq_thread(int irq, void *data)
309{
310 struct s5m87xx_dev *s5m87xx = data;
311 u8 irq_reg[NUM_IRQ_REGS];
312 int ret;
313 int i;
314
315 ret = s5m_bulk_read(s5m87xx, S5M8763_REG_IRQ1,
316 NUM_IRQ_REGS, irq_reg);
317 if (ret < 0) {
318 dev_err(s5m87xx->dev, "Failed to read interrupt register: %d\n",
319 ret);
320 return IRQ_NONE;
321 }
322
323 for (i = 0; i < NUM_IRQ_REGS; i++)
324 irq_reg[i] &= ~s5m87xx->irq_masks_cur[i];
325
326 for (i = 0; i < S5M8763_IRQ_NR; i++) {
327 if (irq_reg[s5m8763_irqs[i].reg - 1] & s5m8763_irqs[i].mask)
328 handle_nested_irq(s5m87xx->irq_base + i);
329 }
330
331 return IRQ_HANDLED;
332}
333
334int s5m_irq_resume(struct s5m87xx_dev *s5m87xx)
335{
336 if (s5m87xx->irq && s5m87xx->irq_base){
337 switch (s5m87xx->device_type) {
338 case S5M8763X:
339 s5m8763_irq_thread(s5m87xx->irq_base, s5m87xx);
340 break;
341 case S5M8767X:
342 s5m8767_irq_thread(s5m87xx->irq_base, s5m87xx);
343 break;
344 default:
345 break;
346
347 }
348 }
349 return 0;
350}
351
352int s5m_irq_init(struct s5m87xx_dev *s5m87xx)
353{
354 int i;
355 int cur_irq;
356 int ret = 0;
357 int type = s5m87xx->device_type;
358
359 if (!s5m87xx->irq) {
360 dev_warn(s5m87xx->dev,
361 "No interrupt specified, no interrupts\n");
362 s5m87xx->irq_base = 0;
363 return 0;
364 }
365
366 if (!s5m87xx->irq_base) {
367 dev_err(s5m87xx->dev,
368 "No interrupt base specified, no interrupts\n");
369 return 0;
370 }
371
372 mutex_init(&s5m87xx->irqlock);
373
374 switch (type) {
375 case S5M8763X:
376 for (i = 0; i < NUM_IRQ_REGS; i++) {
377 s5m87xx->irq_masks_cur[i] = 0xff;
378 s5m87xx->irq_masks_cache[i] = 0xff;
379 s5m_reg_write(s5m87xx, S5M8763_REG_IRQM1 + i,
380 0xff);
381 }
382
383 s5m_reg_write(s5m87xx, S5M8763_REG_STATUSM1, 0xff);
384 s5m_reg_write(s5m87xx, S5M8763_REG_STATUSM2, 0xff);
385
386 for (i = 0; i < S5M8763_IRQ_NR; i++) {
387 cur_irq = i + s5m87xx->irq_base;
388 irq_set_chip_data(cur_irq, s5m87xx);
389 irq_set_chip_and_handler(cur_irq, &s5m8763_irq_chip,
390 handle_edge_irq);
391 irq_set_nested_thread(cur_irq, 1);
392#ifdef CONFIG_ARM
393 set_irq_flags(cur_irq, IRQF_VALID);
394#else
395 irq_set_noprobe(cur_irq);
396#endif
397 }
398
399 ret = request_threaded_irq(s5m87xx->irq, NULL,
400 s5m8763_irq_thread,
401 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
402 "s5m87xx-irq", s5m87xx);
403 if (ret) {
404 dev_err(s5m87xx->dev, "Failed to request IRQ %d: %d\n",
405 s5m87xx->irq, ret);
406 return ret;
407 }
408 break;
409 case S5M8767X:
410 for (i = 0; i < NUM_IRQ_REGS - 1; i++) {
411 s5m87xx->irq_masks_cur[i] = 0xff;
412 s5m87xx->irq_masks_cache[i] = 0xff;
413 s5m_reg_write(s5m87xx, S5M8767_REG_INT1M + i,
414 0xff);
415 }
416 for (i = 0; i < S5M8767_IRQ_NR; i++) {
417 cur_irq = i + s5m87xx->irq_base;
418 irq_set_chip_data(cur_irq, s5m87xx);
419 if (ret) {
420 dev_err(s5m87xx->dev,
421 "Failed to irq_set_chip_data %d: %d\n",
422 s5m87xx->irq, ret);
423 return ret;
424 }
425
426 irq_set_chip_and_handler(cur_irq, &s5m8767_irq_chip,
427 handle_edge_irq);
428 irq_set_nested_thread(cur_irq, 1);
429#ifdef CONFIG_ARM
430 set_irq_flags(cur_irq, IRQF_VALID);
431#else
432 irq_set_noprobe(cur_irq);
433#endif
434 }
435
436 ret = request_threaded_irq(s5m87xx->irq, NULL,
437 s5m8767_irq_thread,
438 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
439 "s5m87xx-irq", s5m87xx);
440 if (ret) {
441 dev_err(s5m87xx->dev, "Failed to request IRQ %d: %d\n",
442 s5m87xx->irq, ret);
443 return ret;
444 }
445 break;
446 default:
447 break;
448 }
449
450 if (!s5m87xx->ono)
451 return 0;
452
453 switch (type) {
454 case S5M8763X:
455 ret = request_threaded_irq(s5m87xx->ono, NULL,
456 s5m8763_irq_thread,
457 IRQF_TRIGGER_FALLING |
458 IRQF_TRIGGER_RISING |
459 IRQF_ONESHOT, "s5m87xx-ono",
460 s5m87xx);
461 break;
462 case S5M8767X:
463 ret = request_threaded_irq(s5m87xx->ono, NULL,
464 s5m8767_irq_thread,
465 IRQF_TRIGGER_FALLING |
466 IRQF_TRIGGER_RISING |
467 IRQF_ONESHOT, "s5m87xx-ono", s5m87xx);
468 break;
469 default:
470 break;
471 }
472
473 if (ret)
474 dev_err(s5m87xx->dev, "Failed to request IRQ %d: %d\n",
475 s5m87xx->ono, ret);
476
477 return 0;
478}
479
480void s5m_irq_exit(struct s5m87xx_dev *s5m87xx)
481{
482 if (s5m87xx->ono)
483 free_irq(s5m87xx->ono, s5m87xx);
484
485 if (s5m87xx->irq)
486 free_irq(s5m87xx->irq, s5m87xx);
487}
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index df3702c1756d..f4d86117f44a 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -1720,7 +1720,7 @@ static int sm501_plat_remove(struct platform_device *dev)
1720 return 0; 1720 return 0;
1721} 1721}
1722 1722
1723static struct pci_device_id sm501_pci_tbl[] = { 1723static DEFINE_PCI_DEVICE_TABLE(sm501_pci_tbl) = {
1724 { 0x126f, 0x0501, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 1724 { 0x126f, 0x0501, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1725 { 0, }, 1725 { 0, },
1726}; 1726};
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
new file mode 100644
index 000000000000..373f423b1181
--- /dev/null
+++ b/drivers/mfd/stmpe-i2c.c
@@ -0,0 +1,109 @@
1/*
2 * ST Microelectronics MFD: stmpe's i2c client specific driver
3 *
4 * Copyright (C) ST-Ericsson SA 2010
5 * Copyright (C) ST Microelectronics SA 2011
6 *
7 * License Terms: GNU General Public License, version 2
8 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
9 * Author: Viresh Kumar <viresh.kumar@st.com> for ST Microelectronics
10 */
11
12#include <linux/i2c.h>
13#include <linux/interrupt.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/types.h>
17#include "stmpe.h"
18
19static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
20{
21 struct i2c_client *i2c = stmpe->client;
22
23 return i2c_smbus_read_byte_data(i2c, reg);
24}
25
26static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
27{
28 struct i2c_client *i2c = stmpe->client;
29
30 return i2c_smbus_write_byte_data(i2c, reg, val);
31}
32
33static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
34{
35 struct i2c_client *i2c = stmpe->client;
36
37 return i2c_smbus_read_i2c_block_data(i2c, reg, length, values);
38}
39
40static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
41 const u8 *values)
42{
43 struct i2c_client *i2c = stmpe->client;
44
45 return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
46}
47
48static struct stmpe_client_info i2c_ci = {
49 .read_byte = i2c_reg_read,
50 .write_byte = i2c_reg_write,
51 .read_block = i2c_block_read,
52 .write_block = i2c_block_write,
53};
54
55static int __devinit
56stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
57{
58 i2c_ci.data = (void *)id;
59 i2c_ci.irq = i2c->irq;
60 i2c_ci.client = i2c;
61 i2c_ci.dev = &i2c->dev;
62
63 return stmpe_probe(&i2c_ci, id->driver_data);
64}
65
66static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
67{
68 struct stmpe *stmpe = dev_get_drvdata(&i2c->dev);
69
70 return stmpe_remove(stmpe);
71}
72
73static const struct i2c_device_id stmpe_i2c_id[] = {
74 { "stmpe610", STMPE610 },
75 { "stmpe801", STMPE801 },
76 { "stmpe811", STMPE811 },
77 { "stmpe1601", STMPE1601 },
78 { "stmpe2401", STMPE2401 },
79 { "stmpe2403", STMPE2403 },
80 { }
81};
82MODULE_DEVICE_TABLE(i2c, stmpe_id);
83
84static struct i2c_driver stmpe_i2c_driver = {
85 .driver.name = "stmpe-i2c",
86 .driver.owner = THIS_MODULE,
87#ifdef CONFIG_PM
88 .driver.pm = &stmpe_dev_pm_ops,
89#endif
90 .probe = stmpe_i2c_probe,
91 .remove = __devexit_p(stmpe_i2c_remove),
92 .id_table = stmpe_i2c_id,
93};
94
95static int __init stmpe_init(void)
96{
97 return i2c_add_driver(&stmpe_i2c_driver);
98}
99subsys_initcall(stmpe_init);
100
101static void __exit stmpe_exit(void)
102{
103 i2c_del_driver(&stmpe_i2c_driver);
104}
105module_exit(stmpe_exit);
106
107MODULE_LICENSE("GPL v2");
108MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver");
109MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/mfd/stmpe-spi.c b/drivers/mfd/stmpe-spi.c
new file mode 100644
index 000000000000..b58c43c7ea93
--- /dev/null
+++ b/drivers/mfd/stmpe-spi.c
@@ -0,0 +1,150 @@
1/*
2 * ST Microelectronics MFD: stmpe's spi client specific driver
3 *
4 * Copyright (C) ST Microelectronics SA 2011
5 *
6 * License Terms: GNU General Public License, version 2
7 * Author: Viresh Kumar <viresh.kumar@st.com> for ST Microelectronics
8 */
9
10#include <linux/spi/spi.h>
11#include <linux/interrupt.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/types.h>
15#include "stmpe.h"
16
17#define READ_CMD (1 << 7)
18
19static int spi_reg_read(struct stmpe *stmpe, u8 reg)
20{
21 struct spi_device *spi = stmpe->client;
22 int status = spi_w8r16(spi, reg | READ_CMD);
23
24 return (status < 0) ? status : status >> 8;
25}
26
27static int spi_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
28{
29 struct spi_device *spi = stmpe->client;
30 u16 cmd = (val << 8) | reg;
31
32 return spi_write(spi, (const u8 *)&cmd, 2);
33}
34
35static int spi_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
36{
37 int ret, i;
38
39 for (i = 0; i < length; i++) {
40 ret = spi_reg_read(stmpe, reg + i);
41 if (ret < 0)
42 return ret;
43 *(values + i) = ret;
44 }
45
46 return 0;
47}
48
49static int spi_block_write(struct stmpe *stmpe, u8 reg, u8 length,
50 const u8 *values)
51{
52 int ret = 0, i;
53
54 for (i = length; i > 0; i--, reg++) {
55 ret = spi_reg_write(stmpe, reg, *(values + i - 1));
56 if (ret < 0)
57 return ret;
58 }
59
60 return ret;
61}
62
63static void spi_init(struct stmpe *stmpe)
64{
65 struct spi_device *spi = stmpe->client;
66
67 spi->bits_per_word = 8;
68
69 /* This register is only present for stmpe811 */
70 if (stmpe->variant->id_val == 0x0811)
71 spi_reg_write(stmpe, STMPE811_REG_SPI_CFG, spi->mode);
72
73 if (spi_setup(spi) < 0)
74 dev_dbg(&spi->dev, "spi_setup failed\n");
75}
76
77static struct stmpe_client_info spi_ci = {
78 .read_byte = spi_reg_read,
79 .write_byte = spi_reg_write,
80 .read_block = spi_block_read,
81 .write_block = spi_block_write,
82 .init = spi_init,
83};
84
85static int __devinit
86stmpe_spi_probe(struct spi_device *spi)
87{
88 const struct spi_device_id *id = spi_get_device_id(spi);
89
90 /* don't exceed max specified rate - 1MHz - Limitation of STMPE */
91 if (spi->max_speed_hz > 1000000) {
92 dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
93 (spi->max_speed_hz/1000));
94 return -EINVAL;
95 }
96
97 spi_ci.irq = spi->irq;
98 spi_ci.client = spi;
99 spi_ci.dev = &spi->dev;
100
101 return stmpe_probe(&spi_ci, id->driver_data);
102}
103
104static int __devexit stmpe_spi_remove(struct spi_device *spi)
105{
106 struct stmpe *stmpe = dev_get_drvdata(&spi->dev);
107
108 return stmpe_remove(stmpe);
109}
110
111static const struct spi_device_id stmpe_spi_id[] = {
112 { "stmpe610", STMPE610 },
113 { "stmpe801", STMPE801 },
114 { "stmpe811", STMPE811 },
115 { "stmpe1601", STMPE1601 },
116 { "stmpe2401", STMPE2401 },
117 { "stmpe2403", STMPE2403 },
118 { }
119};
120MODULE_DEVICE_TABLE(spi, stmpe_id);
121
122static struct spi_driver stmpe_spi_driver = {
123 .driver = {
124 .name = "stmpe-spi",
125 .bus = &spi_bus_type,
126 .owner = THIS_MODULE,
127#ifdef CONFIG_PM
128 .pm = &stmpe_dev_pm_ops,
129#endif
130 },
131 .probe = stmpe_spi_probe,
132 .remove = __devexit_p(stmpe_spi_remove),
133 .id_table = stmpe_spi_id,
134};
135
136static int __init stmpe_init(void)
137{
138 return spi_register_driver(&stmpe_spi_driver);
139}
140subsys_initcall(stmpe_init);
141
142static void __exit stmpe_exit(void)
143{
144 spi_unregister_driver(&stmpe_spi_driver);
145}
146module_exit(stmpe_exit);
147
148MODULE_LICENSE("GPL v2");
149MODULE_DESCRIPTION("STMPE MFD SPI Interface Driver");
150MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>");
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index 2963689cf45c..e07947e56b2a 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -1,18 +1,20 @@
1/* 1/*
2 * ST Microelectronics MFD: stmpe's driver
3 *
2 * Copyright (C) ST-Ericsson SA 2010 4 * Copyright (C) ST-Ericsson SA 2010
3 * 5 *
4 * License Terms: GNU General Public License, version 2 6 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson 7 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */ 8 */
7 9
10#include <linux/gpio.h>
11#include <linux/export.h>
8#include <linux/kernel.h> 12#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/interrupt.h> 13#include <linux/interrupt.h>
11#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/pm.h>
12#include <linux/slab.h> 16#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
15#include <linux/mfd/stmpe.h>
16#include "stmpe.h" 18#include "stmpe.h"
17 19
18static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks) 20static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
@@ -29,10 +31,9 @@ static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
29{ 31{
30 int ret; 32 int ret;
31 33
32 ret = i2c_smbus_read_byte_data(stmpe->i2c, reg); 34 ret = stmpe->ci->read_byte(stmpe, reg);
33 if (ret < 0) 35 if (ret < 0)
34 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", 36 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret);
35 reg, ret);
36 37
37 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret); 38 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
38 39
@@ -45,10 +46,9 @@ static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
45 46
46 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val); 47 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
47 48
48 ret = i2c_smbus_write_byte_data(stmpe->i2c, reg, val); 49 ret = stmpe->ci->write_byte(stmpe, reg, val);
49 if (ret < 0) 50 if (ret < 0)
50 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", 51 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret);
51 reg, ret);
52 52
53 return ret; 53 return ret;
54} 54}
@@ -72,10 +72,9 @@ static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
72{ 72{
73 int ret; 73 int ret;
74 74
75 ret = i2c_smbus_read_i2c_block_data(stmpe->i2c, reg, length, values); 75 ret = stmpe->ci->read_block(stmpe, reg, length, values);
76 if (ret < 0) 76 if (ret < 0)
77 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", 77 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret);
78 reg, ret);
79 78
80 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret); 79 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
81 stmpe_dump_bytes("stmpe rd: ", values, length); 80 stmpe_dump_bytes("stmpe rd: ", values, length);
@@ -91,11 +90,9 @@ static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
91 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length); 90 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
92 stmpe_dump_bytes("stmpe wr: ", values, length); 91 stmpe_dump_bytes("stmpe wr: ", values, length);
93 92
94 ret = i2c_smbus_write_i2c_block_data(stmpe->i2c, reg, length, 93 ret = stmpe->ci->write_block(stmpe, reg, length, values);
95 values);
96 if (ret < 0) 94 if (ret < 0)
97 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", 95 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret);
98 reg, ret);
99 96
100 return ret; 97 return ret;
101} 98}
@@ -245,12 +242,14 @@ int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block)
245 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB]; 242 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB];
246 int af_bits = variant->af_bits; 243 int af_bits = variant->af_bits;
247 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8); 244 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8);
248 int afperreg = 8 / af_bits;
249 int mask = (1 << af_bits) - 1; 245 int mask = (1 << af_bits) - 1;
250 u8 regs[numregs]; 246 u8 regs[numregs];
251 int af; 247 int af, afperreg, ret;
252 int ret; 248
249 if (!variant->get_altfunc)
250 return 0;
253 251
252 afperreg = 8 / af_bits;
254 mutex_lock(&stmpe->lock); 253 mutex_lock(&stmpe->lock);
255 254
256 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO); 255 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
@@ -325,7 +324,51 @@ static struct mfd_cell stmpe_keypad_cell = {
325}; 324};
326 325
327/* 326/*
328 * Touchscreen (STMPE811) 327 * STMPE801
328 */
329static const u8 stmpe801_regs[] = {
330 [STMPE_IDX_CHIP_ID] = STMPE801_REG_CHIP_ID,
331 [STMPE_IDX_ICR_LSB] = STMPE801_REG_SYS_CTRL,
332 [STMPE_IDX_GPMR_LSB] = STMPE801_REG_GPIO_MP_STA,
333 [STMPE_IDX_GPSR_LSB] = STMPE801_REG_GPIO_SET_PIN,
334 [STMPE_IDX_GPCR_LSB] = STMPE801_REG_GPIO_SET_PIN,
335 [STMPE_IDX_GPDR_LSB] = STMPE801_REG_GPIO_DIR,
336 [STMPE_IDX_IEGPIOR_LSB] = STMPE801_REG_GPIO_INT_EN,
337 [STMPE_IDX_ISGPIOR_MSB] = STMPE801_REG_GPIO_INT_STA,
338
339};
340
341static struct stmpe_variant_block stmpe801_blocks[] = {
342 {
343 .cell = &stmpe_gpio_cell,
344 .irq = 0,
345 .block = STMPE_BLOCK_GPIO,
346 },
347};
348
349static int stmpe801_enable(struct stmpe *stmpe, unsigned int blocks,
350 bool enable)
351{
352 if (blocks & STMPE_BLOCK_GPIO)
353 return 0;
354 else
355 return -EINVAL;
356}
357
358static struct stmpe_variant_info stmpe801 = {
359 .name = "stmpe801",
360 .id_val = STMPE801_ID,
361 .id_mask = 0xffff,
362 .num_gpios = 8,
363 .regs = stmpe801_regs,
364 .blocks = stmpe801_blocks,
365 .num_blocks = ARRAY_SIZE(stmpe801_blocks),
366 .num_irqs = STMPE801_NR_INTERNAL_IRQS,
367 .enable = stmpe801_enable,
368};
369
370/*
371 * Touchscreen (STMPE811 or STMPE610)
329 */ 372 */
330 373
331static struct resource stmpe_ts_resources[] = { 374static struct resource stmpe_ts_resources[] = {
@@ -350,7 +393,7 @@ static struct mfd_cell stmpe_ts_cell = {
350}; 393};
351 394
352/* 395/*
353 * STMPE811 396 * STMPE811 or STMPE610
354 */ 397 */
355 398
356static const u8 stmpe811_regs[] = { 399static const u8 stmpe811_regs[] = {
@@ -421,6 +464,21 @@ static struct stmpe_variant_info stmpe811 = {
421 .get_altfunc = stmpe811_get_altfunc, 464 .get_altfunc = stmpe811_get_altfunc,
422}; 465};
423 466
467/* Similar to 811, except number of gpios */
468static struct stmpe_variant_info stmpe610 = {
469 .name = "stmpe610",
470 .id_val = 0x0811,
471 .id_mask = 0xffff,
472 .num_gpios = 6,
473 .af_bits = 1,
474 .regs = stmpe811_regs,
475 .blocks = stmpe811_blocks,
476 .num_blocks = ARRAY_SIZE(stmpe811_blocks),
477 .num_irqs = STMPE811_NR_INTERNAL_IRQS,
478 .enable = stmpe811_enable,
479 .get_altfunc = stmpe811_get_altfunc,
480};
481
424/* 482/*
425 * STMPE1601 483 * STMPE1601
426 */ 484 */
@@ -655,6 +713,8 @@ static struct stmpe_variant_info stmpe2403 = {
655}; 713};
656 714
657static struct stmpe_variant_info *stmpe_variant_info[] = { 715static struct stmpe_variant_info *stmpe_variant_info[] = {
716 [STMPE610] = &stmpe610,
717 [STMPE801] = &stmpe801,
658 [STMPE811] = &stmpe811, 718 [STMPE811] = &stmpe811,
659 [STMPE1601] = &stmpe1601, 719 [STMPE1601] = &stmpe1601,
660 [STMPE2401] = &stmpe2401, 720 [STMPE2401] = &stmpe2401,
@@ -671,6 +731,11 @@ static irqreturn_t stmpe_irq(int irq, void *data)
671 int ret; 731 int ret;
672 int i; 732 int i;
673 733
734 if (variant->id_val == STMPE801_ID) {
735 handle_nested_irq(stmpe->irq_base);
736 return IRQ_HANDLED;
737 }
738
674 ret = stmpe_block_read(stmpe, israddr, num, isr); 739 ret = stmpe_block_read(stmpe, israddr, num, isr);
675 if (ret < 0) 740 if (ret < 0)
676 return IRQ_NONE; 741 return IRQ_NONE;
@@ -757,14 +822,17 @@ static struct irq_chip stmpe_irq_chip = {
757 822
758static int __devinit stmpe_irq_init(struct stmpe *stmpe) 823static int __devinit stmpe_irq_init(struct stmpe *stmpe)
759{ 824{
825 struct irq_chip *chip = NULL;
760 int num_irqs = stmpe->variant->num_irqs; 826 int num_irqs = stmpe->variant->num_irqs;
761 int base = stmpe->irq_base; 827 int base = stmpe->irq_base;
762 int irq; 828 int irq;
763 829
830 if (stmpe->variant->id_val != STMPE801_ID)
831 chip = &stmpe_irq_chip;
832
764 for (irq = base; irq < base + num_irqs; irq++) { 833 for (irq = base; irq < base + num_irqs; irq++) {
765 irq_set_chip_data(irq, stmpe); 834 irq_set_chip_data(irq, stmpe);
766 irq_set_chip_and_handler(irq, &stmpe_irq_chip, 835 irq_set_chip_and_handler(irq, chip, handle_edge_irq);
767 handle_edge_irq);
768 irq_set_nested_thread(irq, 1); 836 irq_set_nested_thread(irq, 1);
769#ifdef CONFIG_ARM 837#ifdef CONFIG_ARM
770 set_irq_flags(irq, IRQF_VALID); 838 set_irq_flags(irq, IRQF_VALID);
@@ -796,7 +864,7 @@ static int __devinit stmpe_chip_init(struct stmpe *stmpe)
796 unsigned int irq_trigger = stmpe->pdata->irq_trigger; 864 unsigned int irq_trigger = stmpe->pdata->irq_trigger;
797 int autosleep_timeout = stmpe->pdata->autosleep_timeout; 865 int autosleep_timeout = stmpe->pdata->autosleep_timeout;
798 struct stmpe_variant_info *variant = stmpe->variant; 866 struct stmpe_variant_info *variant = stmpe->variant;
799 u8 icr = STMPE_ICR_LSB_GIM; 867 u8 icr;
800 unsigned int id; 868 unsigned int id;
801 u8 data[2]; 869 u8 data[2];
802 int ret; 870 int ret;
@@ -819,16 +887,32 @@ static int __devinit stmpe_chip_init(struct stmpe *stmpe)
819 if (ret) 887 if (ret)
820 return ret; 888 return ret;
821 889
822 if (irq_trigger == IRQF_TRIGGER_FALLING || 890 if (id == STMPE801_ID)
823 irq_trigger == IRQF_TRIGGER_RISING) 891 icr = STMPE801_REG_SYS_CTRL_INT_EN;
824 icr |= STMPE_ICR_LSB_EDGE; 892 else
893 icr = STMPE_ICR_LSB_GIM;
894
895 /* STMPE801 doesn't support Edge interrupts */
896 if (id != STMPE801_ID) {
897 if (irq_trigger == IRQF_TRIGGER_FALLING ||
898 irq_trigger == IRQF_TRIGGER_RISING)
899 icr |= STMPE_ICR_LSB_EDGE;
900 }
825 901
826 if (irq_trigger == IRQF_TRIGGER_RISING || 902 if (irq_trigger == IRQF_TRIGGER_RISING ||
827 irq_trigger == IRQF_TRIGGER_HIGH) 903 irq_trigger == IRQF_TRIGGER_HIGH) {
828 icr |= STMPE_ICR_LSB_HIGH; 904 if (id == STMPE801_ID)
905 icr |= STMPE801_REG_SYS_CTRL_INT_HI;
906 else
907 icr |= STMPE_ICR_LSB_HIGH;
908 }
829 909
830 if (stmpe->pdata->irq_invert_polarity) 910 if (stmpe->pdata->irq_invert_polarity) {
831 icr ^= STMPE_ICR_LSB_HIGH; 911 if (id == STMPE801_ID)
912 icr ^= STMPE801_REG_SYS_CTRL_INT_HI;
913 else
914 icr ^= STMPE_ICR_LSB_HIGH;
915 }
832 916
833 if (stmpe->pdata->autosleep) { 917 if (stmpe->pdata->autosleep) {
834 ret = stmpe_autosleep(stmpe, autosleep_timeout); 918 ret = stmpe_autosleep(stmpe, autosleep_timeout);
@@ -873,32 +957,10 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
873 return ret; 957 return ret;
874} 958}
875 959
876#ifdef CONFIG_PM 960/* Called from client specific probe routines */
877static int stmpe_suspend(struct device *dev) 961int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
878{
879 struct i2c_client *i2c = to_i2c_client(dev);
880
881 if (device_may_wakeup(&i2c->dev))
882 enable_irq_wake(i2c->irq);
883
884 return 0;
885}
886
887static int stmpe_resume(struct device *dev)
888{
889 struct i2c_client *i2c = to_i2c_client(dev);
890
891 if (device_may_wakeup(&i2c->dev))
892 disable_irq_wake(i2c->irq);
893
894 return 0;
895}
896#endif
897
898static int __devinit stmpe_probe(struct i2c_client *i2c,
899 const struct i2c_device_id *id)
900{ 962{
901 struct stmpe_platform_data *pdata = i2c->dev.platform_data; 963 struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev);
902 struct stmpe *stmpe; 964 struct stmpe *stmpe;
903 int ret; 965 int ret;
904 966
@@ -912,30 +974,43 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
912 mutex_init(&stmpe->irq_lock); 974 mutex_init(&stmpe->irq_lock);
913 mutex_init(&stmpe->lock); 975 mutex_init(&stmpe->lock);
914 976
915 stmpe->dev = &i2c->dev; 977 stmpe->dev = ci->dev;
916 stmpe->i2c = i2c; 978 stmpe->client = ci->client;
917
918 stmpe->pdata = pdata; 979 stmpe->pdata = pdata;
919 stmpe->irq_base = pdata->irq_base; 980 stmpe->irq_base = pdata->irq_base;
920 981 stmpe->ci = ci;
921 stmpe->partnum = id->driver_data; 982 stmpe->partnum = partnum;
922 stmpe->variant = stmpe_variant_info[stmpe->partnum]; 983 stmpe->variant = stmpe_variant_info[partnum];
923 stmpe->regs = stmpe->variant->regs; 984 stmpe->regs = stmpe->variant->regs;
924 stmpe->num_gpios = stmpe->variant->num_gpios; 985 stmpe->num_gpios = stmpe->variant->num_gpios;
986 dev_set_drvdata(stmpe->dev, stmpe);
925 987
926 i2c_set_clientdata(i2c, stmpe); 988 if (ci->init)
989 ci->init(stmpe);
990
991 if (pdata->irq_over_gpio) {
992 ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
993 if (ret) {
994 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
995 ret);
996 goto out_free;
997 }
998
999 stmpe->irq = gpio_to_irq(pdata->irq_gpio);
1000 } else {
1001 stmpe->irq = ci->irq;
1002 }
927 1003
928 ret = stmpe_chip_init(stmpe); 1004 ret = stmpe_chip_init(stmpe);
929 if (ret) 1005 if (ret)
930 goto out_free; 1006 goto free_gpio;
931 1007
932 ret = stmpe_irq_init(stmpe); 1008 ret = stmpe_irq_init(stmpe);
933 if (ret) 1009 if (ret)
934 goto out_free; 1010 goto free_gpio;
935 1011
936 ret = request_threaded_irq(stmpe->i2c->irq, NULL, stmpe_irq, 1012 ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
937 pdata->irq_trigger | IRQF_ONESHOT, 1013 pdata->irq_trigger | IRQF_ONESHOT, "stmpe", stmpe);
938 "stmpe", stmpe);
939 if (ret) { 1014 if (ret) {
940 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret); 1015 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
941 goto out_removeirq; 1016 goto out_removeirq;
@@ -951,67 +1026,55 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
951 1026
952out_removedevs: 1027out_removedevs:
953 mfd_remove_devices(stmpe->dev); 1028 mfd_remove_devices(stmpe->dev);
954 free_irq(stmpe->i2c->irq, stmpe); 1029 free_irq(stmpe->irq, stmpe);
955out_removeirq: 1030out_removeirq:
956 stmpe_irq_remove(stmpe); 1031 stmpe_irq_remove(stmpe);
1032free_gpio:
1033 if (pdata->irq_over_gpio)
1034 gpio_free(pdata->irq_gpio);
957out_free: 1035out_free:
958 kfree(stmpe); 1036 kfree(stmpe);
959 return ret; 1037 return ret;
960} 1038}
961 1039
962static int __devexit stmpe_remove(struct i2c_client *client) 1040int stmpe_remove(struct stmpe *stmpe)
963{ 1041{
964 struct stmpe *stmpe = i2c_get_clientdata(client);
965
966 mfd_remove_devices(stmpe->dev); 1042 mfd_remove_devices(stmpe->dev);
967 1043
968 free_irq(stmpe->i2c->irq, stmpe); 1044 free_irq(stmpe->irq, stmpe);
969 stmpe_irq_remove(stmpe); 1045 stmpe_irq_remove(stmpe);
970 1046
1047 if (stmpe->pdata->irq_over_gpio)
1048 gpio_free(stmpe->pdata->irq_gpio);
1049
971 kfree(stmpe); 1050 kfree(stmpe);
972 1051
973 return 0; 1052 return 0;
974} 1053}
975 1054
976static const struct i2c_device_id stmpe_id[] = {
977 { "stmpe811", STMPE811 },
978 { "stmpe1601", STMPE1601 },
979 { "stmpe2401", STMPE2401 },
980 { "stmpe2403", STMPE2403 },
981 { }
982};
983MODULE_DEVICE_TABLE(i2c, stmpe_id);
984
985#ifdef CONFIG_PM 1055#ifdef CONFIG_PM
986static const struct dev_pm_ops stmpe_dev_pm_ops = { 1056static int stmpe_suspend(struct device *dev)
987 .suspend = stmpe_suspend, 1057{
988 .resume = stmpe_resume, 1058 struct stmpe *stmpe = dev_get_drvdata(dev);
989};
990#endif
991 1059
992static struct i2c_driver stmpe_driver = { 1060 if (device_may_wakeup(dev))
993 .driver.name = "stmpe", 1061 enable_irq_wake(stmpe->irq);
994 .driver.owner = THIS_MODULE,
995#ifdef CONFIG_PM
996 .driver.pm = &stmpe_dev_pm_ops,
997#endif
998 .probe = stmpe_probe,
999 .remove = __devexit_p(stmpe_remove),
1000 .id_table = stmpe_id,
1001};
1002 1062
1003static int __init stmpe_init(void) 1063 return 0;
1004{
1005 return i2c_add_driver(&stmpe_driver);
1006} 1064}
1007subsys_initcall(stmpe_init);
1008 1065
1009static void __exit stmpe_exit(void) 1066static int stmpe_resume(struct device *dev)
1010{ 1067{
1011 i2c_del_driver(&stmpe_driver); 1068 struct stmpe *stmpe = dev_get_drvdata(dev);
1069
1070 if (device_may_wakeup(dev))
1071 disable_irq_wake(stmpe->irq);
1072
1073 return 0;
1012} 1074}
1013module_exit(stmpe_exit);
1014 1075
1015MODULE_LICENSE("GPL v2"); 1076const struct dev_pm_ops stmpe_dev_pm_ops = {
1016MODULE_DESCRIPTION("STMPE MFD core driver"); 1077 .suspend = stmpe_suspend,
1017MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>"); 1078 .resume = stmpe_resume,
1079};
1080#endif
diff --git a/drivers/mfd/stmpe.h b/drivers/mfd/stmpe.h
index e4ee38956583..7b8e13f5b764 100644
--- a/drivers/mfd/stmpe.h
+++ b/drivers/mfd/stmpe.h
@@ -8,6 +8,14 @@
8#ifndef __STMPE_H 8#ifndef __STMPE_H
9#define __STMPE_H 9#define __STMPE_H
10 10
11#include <linux/device.h>
12#include <linux/mfd/core.h>
13#include <linux/mfd/stmpe.h>
14#include <linux/printk.h>
15#include <linux/types.h>
16
17extern const struct dev_pm_ops stmpe_dev_pm_ops;
18
11#ifdef STMPE_DUMP_BYTES 19#ifdef STMPE_DUMP_BYTES
12static inline void stmpe_dump_bytes(const char *str, const void *buf, 20static inline void stmpe_dump_bytes(const char *str, const void *buf,
13 size_t len) 21 size_t len)
@@ -67,11 +75,55 @@ struct stmpe_variant_info {
67 int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout); 75 int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
68}; 76};
69 77
78/**
79 * struct stmpe_client_info - i2c or spi specific routines/info
80 * @data: client specific data
81 * @read_byte: read single byte
82 * @write_byte: write single byte
83 * @read_block: read block or multiple bytes
84 * @write_block: write block or multiple bytes
85 * @init: client init routine, called during probe
86 */
87struct stmpe_client_info {
88 void *data;
89 int irq;
90 void *client;
91 struct device *dev;
92 int (*read_byte)(struct stmpe *stmpe, u8 reg);
93 int (*write_byte)(struct stmpe *stmpe, u8 reg, u8 val);
94 int (*read_block)(struct stmpe *stmpe, u8 reg, u8 len, u8 *values);
95 int (*write_block)(struct stmpe *stmpe, u8 reg, u8 len,
96 const u8 *values);
97 void (*init)(struct stmpe *stmpe);
98};
99
100int stmpe_probe(struct stmpe_client_info *ci, int partnum);
101int stmpe_remove(struct stmpe *stmpe);
102
70#define STMPE_ICR_LSB_HIGH (1 << 2) 103#define STMPE_ICR_LSB_HIGH (1 << 2)
71#define STMPE_ICR_LSB_EDGE (1 << 1) 104#define STMPE_ICR_LSB_EDGE (1 << 1)
72#define STMPE_ICR_LSB_GIM (1 << 0) 105#define STMPE_ICR_LSB_GIM (1 << 0)
73 106
74/* 107/*
108 * STMPE801
109 */
110#define STMPE801_ID 0x0108
111#define STMPE801_NR_INTERNAL_IRQS 1
112
113#define STMPE801_REG_CHIP_ID 0x00
114#define STMPE801_REG_VERSION_ID 0x02
115#define STMPE801_REG_SYS_CTRL 0x04
116#define STMPE801_REG_GPIO_INT_EN 0x08
117#define STMPE801_REG_GPIO_INT_STA 0x09
118#define STMPE801_REG_GPIO_MP_STA 0x10
119#define STMPE801_REG_GPIO_SET_PIN 0x11
120#define STMPE801_REG_GPIO_DIR 0x12
121
122#define STMPE801_REG_SYS_CTRL_RESET (1 << 7)
123#define STMPE801_REG_SYS_CTRL_INT_EN (1 << 2)
124#define STMPE801_REG_SYS_CTRL_INT_HI (1 << 0)
125
126/*
75 * STMPE811 127 * STMPE811
76 */ 128 */
77 129
@@ -87,6 +139,7 @@ struct stmpe_variant_info {
87 139
88#define STMPE811_REG_CHIP_ID 0x00 140#define STMPE811_REG_CHIP_ID 0x00
89#define STMPE811_REG_SYS_CTRL2 0x04 141#define STMPE811_REG_SYS_CTRL2 0x04
142#define STMPE811_REG_SPI_CFG 0x08
90#define STMPE811_REG_INT_CTRL 0x09 143#define STMPE811_REG_INT_CTRL 0x09
91#define STMPE811_REG_INT_EN 0x0A 144#define STMPE811_REG_INT_EN 0x0A
92#define STMPE811_REG_INT_STA 0x0B 145#define STMPE811_REG_INT_STA 0x0B
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 91ad21ef7721..2d9e8799e733 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -442,21 +442,7 @@ static struct platform_driver t7l66xb_platform_driver = {
442 442
443/*--------------------------------------------------------------------------*/ 443/*--------------------------------------------------------------------------*/
444 444
445static int __init t7l66xb_init(void) 445module_platform_driver(t7l66xb_platform_driver);
446{
447 int retval = 0;
448
449 retval = platform_driver_register(&t7l66xb_platform_driver);
450 return retval;
451}
452
453static void __exit t7l66xb_exit(void)
454{
455 platform_driver_unregister(&t7l66xb_platform_driver);
456}
457
458module_init(t7l66xb_init);
459module_exit(t7l66xb_exit);
460 446
461MODULE_DESCRIPTION("Toshiba T7L66XB core driver"); 447MODULE_DESCRIPTION("Toshiba T7L66XB core driver");
462MODULE_LICENSE("GPL v2"); 448MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index 71bc835324d8..d20a284ad4ba 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -234,19 +234,7 @@ static struct platform_driver tc6387xb_platform_driver = {
234 .resume = tc6387xb_resume, 234 .resume = tc6387xb_resume,
235}; 235};
236 236
237 237module_platform_driver(tc6387xb_platform_driver);
238static int __init tc6387xb_init(void)
239{
240 return platform_driver_register(&tc6387xb_platform_driver);
241}
242
243static void __exit tc6387xb_exit(void)
244{
245 platform_driver_unregister(&tc6387xb_platform_driver);
246}
247
248module_init(tc6387xb_init);
249module_exit(tc6387xb_exit);
250 238
251MODULE_DESCRIPTION("Toshiba TC6387XB core driver"); 239MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
252MODULE_LICENSE("GPL v2"); 240MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/ti-ssp.c b/drivers/mfd/ti-ssp.c
index af9ab0e5ca64..4fb0e6c8e8fe 100644
--- a/drivers/mfd/ti-ssp.c
+++ b/drivers/mfd/ti-ssp.c
@@ -458,17 +458,7 @@ static struct platform_driver ti_ssp_driver = {
458 } 458 }
459}; 459};
460 460
461static int __init ti_ssp_init(void) 461module_platform_driver(ti_ssp_driver);
462{
463 return platform_driver_register(&ti_ssp_driver);
464}
465module_init(ti_ssp_init);
466
467static void __exit ti_ssp_exit(void)
468{
469 platform_driver_unregister(&ti_ssp_driver);
470}
471module_exit(ti_ssp_exit);
472 462
473MODULE_DESCRIPTION("Sequencer Serial Port (SSP) Driver"); 463MODULE_DESCRIPTION("Sequencer Serial Port (SSP) Driver");
474MODULE_AUTHOR("Cyril Chemparathy"); 464MODULE_AUTHOR("Cyril Chemparathy");
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index 02d65692ceb4..0ba26fb12cf5 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -857,7 +857,7 @@ static void __devexit timb_remove(struct pci_dev *dev)
857 kfree(priv); 857 kfree(priv);
858} 858}
859 859
860static struct pci_device_id timberdale_pci_tbl[] = { 860static DEFINE_PCI_DEVICE_TABLE(timberdale_pci_tbl) = {
861 { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) }, 861 { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) },
862 { 0 } 862 { 0 }
863}; 863};
diff --git a/drivers/mfd/tps65910-irq.c b/drivers/mfd/tps65910-irq.c
index a56be931551c..95c0d7978bec 100644
--- a/drivers/mfd/tps65910-irq.c
+++ b/drivers/mfd/tps65910-irq.c
@@ -215,6 +215,7 @@ int tps65910_irq_init(struct tps65910 *tps65910, int irq,
215 215
216int tps65910_irq_exit(struct tps65910 *tps65910) 216int tps65910_irq_exit(struct tps65910 *tps65910)
217{ 217{
218 free_irq(tps65910->chip_irq, tps65910); 218 if (tps65910->chip_irq)
219 free_irq(tps65910->chip_irq, tps65910);
219 return 0; 220 return 0;
220} 221}
diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index c1da84bc1573..01cf5012a08f 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -172,15 +172,12 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
172 172
173 tps65910_gpio_init(tps65910, pmic_plat_data->gpio_base); 173 tps65910_gpio_init(tps65910, pmic_plat_data->gpio_base);
174 174
175 ret = tps65910_irq_init(tps65910, init_data->irq, init_data); 175 tps65910_irq_init(tps65910, init_data->irq, init_data);
176 if (ret < 0)
177 goto err;
178 176
179 kfree(init_data); 177 kfree(init_data);
180 return ret; 178 return ret;
181 179
182err: 180err:
183 mfd_remove_devices(tps65910->dev);
184 kfree(tps65910); 181 kfree(tps65910);
185 kfree(init_data); 182 kfree(init_data);
186 return ret; 183 return ret;
@@ -190,8 +187,8 @@ static int tps65910_i2c_remove(struct i2c_client *i2c)
190{ 187{
191 struct tps65910 *tps65910 = i2c_get_clientdata(i2c); 188 struct tps65910 *tps65910 = i2c_get_clientdata(i2c);
192 189
193 mfd_remove_devices(tps65910->dev);
194 tps65910_irq_exit(tps65910); 190 tps65910_irq_exit(tps65910);
191 mfd_remove_devices(tps65910->dev);
195 kfree(tps65910); 192 kfree(tps65910);
196 193
197 return 0; 194 return 0;
diff --git a/drivers/mfd/tps65912-spi.c b/drivers/mfd/tps65912-spi.c
index 6d71e0d25744..27d3302d56b8 100644
--- a/drivers/mfd/tps65912-spi.c
+++ b/drivers/mfd/tps65912-spi.c
@@ -111,7 +111,6 @@ static int __devexit tps65912_spi_remove(struct spi_device *spi)
111static struct spi_driver tps65912_spi_driver = { 111static struct spi_driver tps65912_spi_driver = {
112 .driver = { 112 .driver = {
113 .name = "tps65912", 113 .name = "tps65912",
114 .bus = &spi_bus_type,
115 .owner = THIS_MODULE, 114 .owner = THIS_MODULE,
116 }, 115 },
117 .probe = tps65912_spi_probe, 116 .probe = tps65912_spi_probe,
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 61e70cfaa774..e04e04ddc15e 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -34,6 +34,11 @@
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/err.h> 36#include <linux/err.h>
37#include <linux/device.h>
38#include <linux/of.h>
39#include <linux/of_irq.h>
40#include <linux/of_platform.h>
41#include <linux/irqdomain.h>
37 42
38#include <linux/regulator/machine.h> 43#include <linux/regulator/machine.h>
39 44
@@ -144,6 +149,9 @@
144 149
145#define TWL_MODULE_LAST TWL4030_MODULE_LAST 150#define TWL_MODULE_LAST TWL4030_MODULE_LAST
146 151
152#define TWL4030_NR_IRQS 8
153#define TWL6030_NR_IRQS 20
154
147/* Base Address defns for twl4030_map[] */ 155/* Base Address defns for twl4030_map[] */
148 156
149/* subchip/slave 0 - USB ID */ 157/* subchip/slave 0 - USB ID */
@@ -255,6 +263,7 @@ struct twl_client {
255 263
256static struct twl_client twl_modules[TWL_NUM_SLAVES]; 264static struct twl_client twl_modules[TWL_NUM_SLAVES];
257 265
266static struct irq_domain domain;
258 267
259/* mapping the module id to slave id and base address */ 268/* mapping the module id to slave id and base address */
260struct twl_mapping { 269struct twl_mapping {
@@ -1183,14 +1192,48 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1183 int status; 1192 int status;
1184 unsigned i; 1193 unsigned i;
1185 struct twl4030_platform_data *pdata = client->dev.platform_data; 1194 struct twl4030_platform_data *pdata = client->dev.platform_data;
1195 struct device_node *node = client->dev.of_node;
1186 u8 temp; 1196 u8 temp;
1187 int ret = 0; 1197 int ret = 0;
1198 int nr_irqs = TWL4030_NR_IRQS;
1199
1200 if ((id->driver_data) & TWL6030_CLASS)
1201 nr_irqs = TWL6030_NR_IRQS;
1202
1203 if (node && !pdata) {
1204 /*
1205 * XXX: Temporary pdata until the information is correctly
1206 * retrieved by every TWL modules from DT.
1207 */
1208 pdata = devm_kzalloc(&client->dev,
1209 sizeof(struct twl4030_platform_data),
1210 GFP_KERNEL);
1211 if (!pdata)
1212 return -ENOMEM;
1213 }
1188 1214
1189 if (!pdata) { 1215 if (!pdata) {
1190 dev_dbg(&client->dev, "no platform data?\n"); 1216 dev_dbg(&client->dev, "no platform data?\n");
1191 return -EINVAL; 1217 return -EINVAL;
1192 } 1218 }
1193 1219
1220 status = irq_alloc_descs(-1, pdata->irq_base, nr_irqs, 0);
1221 if (IS_ERR_VALUE(status)) {
1222 dev_err(&client->dev, "Fail to allocate IRQ descs\n");
1223 return status;
1224 }
1225
1226 pdata->irq_base = status;
1227 pdata->irq_end = pdata->irq_base + nr_irqs;
1228
1229 domain.irq_base = pdata->irq_base;
1230 domain.nr_irq = nr_irqs;
1231#ifdef CONFIG_OF_IRQ
1232 domain.of_node = of_node_get(node);
1233 domain.ops = &irq_domain_simple_ops;
1234#endif
1235 irq_domain_add(&domain);
1236
1194 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { 1237 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1195 dev_dbg(&client->dev, "can't talk I2C?\n"); 1238 dev_dbg(&client->dev, "can't talk I2C?\n");
1196 return -EIO; 1239 return -EIO;
@@ -1270,7 +1313,13 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1270 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); 1313 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
1271 } 1314 }
1272 1315
1273 status = add_children(pdata, id->driver_data); 1316#ifdef CONFIG_OF_DEVICE
1317 if (node)
1318 status = of_platform_populate(node, NULL, NULL, &client->dev);
1319 else
1320#endif
1321 status = add_children(pdata, id->driver_data);
1322
1274fail: 1323fail:
1275 if (status < 0) 1324 if (status < 0)
1276 twl_remove(client); 1325 twl_remove(client);
diff --git a/drivers/mfd/twl4030-audio.c b/drivers/mfd/twl4030-audio.c
index ae51ab5d0e5d..838ce4eb444e 100644
--- a/drivers/mfd/twl4030-audio.c
+++ b/drivers/mfd/twl4030-audio.c
@@ -261,17 +261,7 @@ static struct platform_driver twl4030_audio_driver = {
261 }, 261 },
262}; 262};
263 263
264static int __devinit twl4030_audio_init(void) 264module_platform_driver(twl4030_audio_driver);
265{
266 return platform_driver_register(&twl4030_audio_driver);
267}
268module_init(twl4030_audio_init);
269
270static void __devexit twl4030_audio_exit(void)
271{
272 platform_driver_unregister(&twl4030_audio_driver);
273}
274module_exit(twl4030_audio_exit);
275 265
276MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>"); 266MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
277MODULE_LICENSE("GPL"); 267MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
index 29f11e0765fe..b69bb517b102 100644
--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -492,7 +492,7 @@ static void twl4030_sih_bus_sync_unlock(struct irq_data *data)
492 u8 bytes[4]; 492 u8 bytes[4];
493 } imr; 493 } imr;
494 494
495 /* byte[0] gets overwriten as we write ... */ 495 /* byte[0] gets overwritten as we write ... */
496 imr.word = cpu_to_le32(agent->imr << 8); 496 imr.word = cpu_to_le32(agent->imr << 8);
497 agent->imr_change_pending = false; 497 agent->imr_change_pending = false;
498 498
@@ -667,6 +667,7 @@ int twl4030_sih_setup(int module)
667 irq_set_chip_data(irq, agent); 667 irq_set_chip_data(irq, agent);
668 irq_set_chip_and_handler(irq, &twl4030_sih_irq_chip, 668 irq_set_chip_and_handler(irq, &twl4030_sih_irq_chip,
669 handle_edge_irq); 669 handle_edge_irq);
670 irq_set_nested_thread(irq, 1);
670 activate_irq(irq); 671 activate_irq(irq);
671 } 672 }
672 673
diff --git a/drivers/mfd/twl4030-madc.c b/drivers/mfd/twl4030-madc.c
index 834f824d3c11..456ecb5ac4fe 100644
--- a/drivers/mfd/twl4030-madc.c
+++ b/drivers/mfd/twl4030-madc.c
@@ -807,19 +807,7 @@ static struct platform_driver twl4030_madc_driver = {
807 }, 807 },
808}; 808};
809 809
810static int __init twl4030_madc_init(void) 810module_platform_driver(twl4030_madc_driver);
811{
812 return platform_driver_register(&twl4030_madc_driver);
813}
814
815module_init(twl4030_madc_init);
816
817static void __exit twl4030_madc_exit(void)
818{
819 platform_driver_unregister(&twl4030_madc_driver);
820}
821
822module_exit(twl4030_madc_exit);
823 811
824MODULE_DESCRIPTION("TWL4030 ADC driver"); 812MODULE_DESCRIPTION("TWL4030 ADC driver");
825MODULE_LICENSE("GPL"); 813MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index a764676f0922..d905f5171153 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -34,7 +34,8 @@
34static u8 twl4030_start_script_address = 0x2b; 34static u8 twl4030_start_script_address = 0x2b;
35 35
36#define PWR_P1_SW_EVENTS 0x10 36#define PWR_P1_SW_EVENTS 0x10
37#define PWR_DEVOFF (1<<0) 37#define PWR_DEVOFF (1 << 0)
38#define SEQ_OFFSYNC (1 << 0)
38 39
39#define PHY_TO_OFF_PM_MASTER(p) (p - 0x36) 40#define PHY_TO_OFF_PM_MASTER(p) (p - 0x36)
40#define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b) 41#define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b)
@@ -511,12 +512,27 @@ int twl4030_remove_script(u8 flags)
511 return err; 512 return err;
512} 513}
513 514
515/*
516 * In master mode, start the power off sequence.
517 * After a successful execution, TWL shuts down the power to the SoC
518 * and all peripherals connected to it.
519 */
520void twl4030_power_off(void)
521{
522 int err;
523
524 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, PWR_DEVOFF,
525 TWL4030_PM_MASTER_P1_SW_EVENTS);
526 if (err)
527 pr_err("TWL4030 Unable to power off\n");
528}
529
514void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts) 530void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts)
515{ 531{
516 int err = 0; 532 int err = 0;
517 int i; 533 int i;
518 struct twl4030_resconfig *resconfig; 534 struct twl4030_resconfig *resconfig;
519 u8 address = twl4030_start_script_address; 535 u8 val, address = twl4030_start_script_address;
520 536
521 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 537 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
522 TWL4030_PM_MASTER_KEY_CFG1, 538 TWL4030_PM_MASTER_KEY_CFG1,
@@ -548,6 +564,28 @@ void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts)
548 } 564 }
549 } 565 }
550 566
567 /* Board has to be wired properly to use this feature */
568 if (twl4030_scripts->use_poweroff && !pm_power_off) {
569 /* Default for SEQ_OFFSYNC is set, lets ensure this */
570 err = twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val,
571 TWL4030_PM_MASTER_CFG_P123_TRANSITION);
572 if (err) {
573 pr_warning("TWL4030 Unable to read registers\n");
574
575 } else if (!(val & SEQ_OFFSYNC)) {
576 val |= SEQ_OFFSYNC;
577 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, val,
578 TWL4030_PM_MASTER_CFG_P123_TRANSITION);
579 if (err) {
580 pr_err("TWL4030 Unable to setup SEQ_OFFSYNC\n");
581 goto relock;
582 }
583 }
584
585 pm_power_off = twl4030_power_off;
586 }
587
588relock:
551 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, 589 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0,
552 TWL4030_PM_MASTER_PROTECT_KEY); 590 TWL4030_PM_MASTER_PROTECT_KEY);
553 if (err) 591 if (err)
diff --git a/drivers/mfd/twl6040-core.c b/drivers/mfd/twl6040-core.c
index 268f80fd0439..dda86293dc9f 100644
--- a/drivers/mfd/twl6040-core.c
+++ b/drivers/mfd/twl6040-core.c
@@ -509,13 +509,10 @@ static int __devinit twl6040_probe(struct platform_device *pdev)
509 twl6040->audpwron = -EINVAL; 509 twl6040->audpwron = -EINVAL;
510 510
511 if (gpio_is_valid(twl6040->audpwron)) { 511 if (gpio_is_valid(twl6040->audpwron)) {
512 ret = gpio_request(twl6040->audpwron, "audpwron"); 512 ret = gpio_request_one(twl6040->audpwron, GPIOF_OUT_INIT_LOW,
513 "audpwron");
513 if (ret) 514 if (ret)
514 goto gpio1_err; 515 goto gpio1_err;
515
516 ret = gpio_direction_output(twl6040->audpwron, 0);
517 if (ret)
518 goto gpio2_err;
519 } 516 }
520 517
521 /* codec interrupt */ 518 /* codec interrupt */
@@ -619,18 +616,7 @@ static struct platform_driver twl6040_driver = {
619 }, 616 },
620}; 617};
621 618
622static int __devinit twl6040_init(void) 619module_platform_driver(twl6040_driver);
623{
624 return platform_driver_register(&twl6040_driver);
625}
626module_init(twl6040_init);
627
628static void __devexit twl6040_exit(void)
629{
630 platform_driver_unregister(&twl6040_driver);
631}
632
633module_exit(twl6040_exit);
634 620
635MODULE_DESCRIPTION("TWL6040 MFD"); 621MODULE_DESCRIPTION("TWL6040 MFD");
636MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); 622MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index b281217334eb..91c4f25e0e55 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -36,6 +36,15 @@ static DEFINE_MUTEX(ucb1x00_mutex);
36static LIST_HEAD(ucb1x00_drivers); 36static LIST_HEAD(ucb1x00_drivers);
37static LIST_HEAD(ucb1x00_devices); 37static LIST_HEAD(ucb1x00_devices);
38 38
39static struct mcp_device_id ucb1x00_id[] = {
40 { "ucb1x00", 0 }, /* auto-detection */
41 { "ucb1200", UCB_ID_1200 },
42 { "ucb1300", UCB_ID_1300 },
43 { "tc35143", UCB_ID_TC35143 },
44 { }
45};
46MODULE_DEVICE_TABLE(mcp, ucb1x00_id);
47
39/** 48/**
40 * ucb1x00_io_set_dir - set IO direction 49 * ucb1x00_io_set_dir - set IO direction
41 * @ucb: UCB1x00 structure describing chip 50 * @ucb: UCB1x00 structure describing chip
@@ -527,17 +536,33 @@ static struct class ucb1x00_class = {
527 536
528static int ucb1x00_probe(struct mcp *mcp) 537static int ucb1x00_probe(struct mcp *mcp)
529{ 538{
539 const struct mcp_device_id *mid;
530 struct ucb1x00 *ucb; 540 struct ucb1x00 *ucb;
531 struct ucb1x00_driver *drv; 541 struct ucb1x00_driver *drv;
542 struct ucb1x00_plat_data *pdata;
532 unsigned int id; 543 unsigned int id;
533 int ret = -ENODEV; 544 int ret = -ENODEV;
534 int temp; 545 int temp;
535 546
536 mcp_enable(mcp); 547 mcp_enable(mcp);
537 id = mcp_reg_read(mcp, UCB_ID); 548 id = mcp_reg_read(mcp, UCB_ID);
549 mid = mcp_get_device_id(mcp);
538 550
539 if (id != UCB_ID_1200 && id != UCB_ID_1300 && id != UCB_ID_TC35143) { 551 if (mid && mid->driver_data) {
540 printk(KERN_WARNING "UCB1x00 ID not found: %04x\n", id); 552 if (id != mid->driver_data) {
553 printk(KERN_WARNING "%s wrong ID %04x found: %04x\n",
554 mid->name, (unsigned int) mid->driver_data, id);
555 goto err_disable;
556 }
557 } else {
558 mid = &ucb1x00_id[1];
559 while (mid->driver_data) {
560 if (id == mid->driver_data)
561 break;
562 mid++;
563 }
564 printk(KERN_WARNING "%s ID not found: %04x\n",
565 ucb1x00_id[0].name, id);
541 goto err_disable; 566 goto err_disable;
542 } 567 }
543 568
@@ -546,28 +571,28 @@ static int ucb1x00_probe(struct mcp *mcp)
546 if (!ucb) 571 if (!ucb)
547 goto err_disable; 572 goto err_disable;
548 573
549 574 pdata = mcp->attached_device.platform_data;
550 ucb->dev.class = &ucb1x00_class; 575 ucb->dev.class = &ucb1x00_class;
551 ucb->dev.parent = &mcp->attached_device; 576 ucb->dev.parent = &mcp->attached_device;
552 dev_set_name(&ucb->dev, "ucb1x00"); 577 dev_set_name(&ucb->dev, mid->name);
553 578
554 spin_lock_init(&ucb->lock); 579 spin_lock_init(&ucb->lock);
555 spin_lock_init(&ucb->io_lock); 580 spin_lock_init(&ucb->io_lock);
556 sema_init(&ucb->adc_sem, 1); 581 sema_init(&ucb->adc_sem, 1);
557 582
558 ucb->id = id; 583 ucb->id = mid;
559 ucb->mcp = mcp; 584 ucb->mcp = mcp;
560 ucb->irq = ucb1x00_detect_irq(ucb); 585 ucb->irq = ucb1x00_detect_irq(ucb);
561 if (ucb->irq == NO_IRQ) { 586 if (ucb->irq == NO_IRQ) {
562 printk(KERN_ERR "UCB1x00: IRQ probe failed\n"); 587 printk(KERN_ERR "%s: IRQ probe failed\n", mid->name);
563 ret = -ENODEV; 588 ret = -ENODEV;
564 goto err_free; 589 goto err_free;
565 } 590 }
566 591
567 ucb->gpio.base = -1; 592 ucb->gpio.base = -1;
568 if (mcp->gpio_base != 0) { 593 if (pdata && (pdata->gpio_base >= 0)) {
569 ucb->gpio.label = dev_name(&ucb->dev); 594 ucb->gpio.label = dev_name(&ucb->dev);
570 ucb->gpio.base = mcp->gpio_base; 595 ucb->gpio.base = pdata->gpio_base;
571 ucb->gpio.ngpio = 10; 596 ucb->gpio.ngpio = 10;
572 ucb->gpio.set = ucb1x00_gpio_set; 597 ucb->gpio.set = ucb1x00_gpio_set;
573 ucb->gpio.get = ucb1x00_gpio_get; 598 ucb->gpio.get = ucb1x00_gpio_get;
@@ -580,10 +605,10 @@ static int ucb1x00_probe(struct mcp *mcp)
580 dev_info(&ucb->dev, "gpio_base not set so no gpiolib support"); 605 dev_info(&ucb->dev, "gpio_base not set so no gpiolib support");
581 606
582 ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING, 607 ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING,
583 "UCB1x00", ucb); 608 mid->name, ucb);
584 if (ret) { 609 if (ret) {
585 printk(KERN_ERR "ucb1x00: unable to grab irq%d: %d\n", 610 printk(KERN_ERR "%s: unable to grab irq%d: %d\n",
586 ucb->irq, ret); 611 mid->name, ucb->irq, ret);
587 goto err_gpio; 612 goto err_gpio;
588 } 613 }
589 614
@@ -705,6 +730,7 @@ static struct mcp_driver ucb1x00_driver = {
705 .remove = ucb1x00_remove, 730 .remove = ucb1x00_remove,
706 .suspend = ucb1x00_suspend, 731 .suspend = ucb1x00_suspend,
707 .resume = ucb1x00_resume, 732 .resume = ucb1x00_resume,
733 .id_table = ucb1x00_id,
708}; 734};
709 735
710static int __init ucb1x00_init(void) 736static int __init ucb1x00_init(void)
diff --git a/drivers/mfd/ucb1x00-ts.c b/drivers/mfd/ucb1x00-ts.c
index 38ffbd50a0d2..40ec3c118868 100644
--- a/drivers/mfd/ucb1x00-ts.c
+++ b/drivers/mfd/ucb1x00-ts.c
@@ -382,7 +382,7 @@ static int ucb1x00_ts_add(struct ucb1x00_dev *dev)
382 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC; 382 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC;
383 383
384 idev->name = "Touchscreen panel"; 384 idev->name = "Touchscreen panel";
385 idev->id.product = ts->ucb->id; 385 idev->id.product = ts->ucb->id->driver_data;
386 idev->open = ucb1x00_ts_open; 386 idev->open = ucb1x00_ts_open;
387 idev->close = ucb1x00_ts_close; 387 idev->close = ucb1x00_ts_close;
388 388
diff --git a/drivers/mfd/vx855.c b/drivers/mfd/vx855.c
index d698703dbd46..b73cc15e0081 100644
--- a/drivers/mfd/vx855.c
+++ b/drivers/mfd/vx855.c
@@ -118,7 +118,7 @@ static void __devexit vx855_remove(struct pci_dev *pdev)
118 pci_disable_device(pdev); 118 pci_disable_device(pdev);
119} 119}
120 120
121static struct pci_device_id vx855_pci_tbl[] = { 121static DEFINE_PCI_DEVICE_TABLE(vx855_pci_tbl) = {
122 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) }, 122 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) },
123 { 0, } 123 { 0, }
124}; 124};
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index 0a2b8d41a702..f5e54fae8ada 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -559,6 +559,8 @@ static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
559 dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n", 559 dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
560 buf[i], reg + i, reg + i); 560 buf[i], reg + i, reg + i);
561 ret = regmap_write(wm831x->regmap, reg + i, buf[i]); 561 ret = regmap_write(wm831x->regmap, reg + i, buf[i]);
562 if (ret != 0)
563 return ret;
562 } 564 }
563 565
564 return 0; 566 return 0;
@@ -1875,7 +1877,6 @@ err_irq:
1875err_regmap: 1877err_regmap:
1876 mfd_remove_devices(wm831x->dev); 1878 mfd_remove_devices(wm831x->dev);
1877 regmap_exit(wm831x->regmap); 1879 regmap_exit(wm831x->regmap);
1878 kfree(wm831x);
1879 return ret; 1880 return ret;
1880} 1881}
1881 1882
@@ -1887,7 +1888,6 @@ void wm831x_device_exit(struct wm831x *wm831x)
1887 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x); 1888 free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
1888 wm831x_irq_exit(wm831x); 1889 wm831x_irq_exit(wm831x);
1889 regmap_exit(wm831x->regmap); 1890 regmap_exit(wm831x->regmap);
1890 kfree(wm831x);
1891} 1891}
1892 1892
1893int wm831x_device_suspend(struct wm831x *wm831x) 1893int wm831x_device_suspend(struct wm831x *wm831x)
diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c
index ac8da1d439da..cb15609b0a48 100644
--- a/drivers/mfd/wm831x-i2c.c
+++ b/drivers/mfd/wm831x-i2c.c
@@ -30,7 +30,7 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
30 struct wm831x *wm831x; 30 struct wm831x *wm831x;
31 int ret; 31 int ret;
32 32
33 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); 33 wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
34 if (wm831x == NULL) 34 if (wm831x == NULL)
35 return -ENOMEM; 35 return -ENOMEM;
36 36
@@ -42,7 +42,6 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
42 ret = PTR_ERR(wm831x->regmap); 42 ret = PTR_ERR(wm831x->regmap);
43 dev_err(wm831x->dev, "Failed to allocate register map: %d\n", 43 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
44 ret); 44 ret);
45 kfree(wm831x);
46 return ret; 45 return ret;
47 } 46 }
48 47
diff --git a/drivers/mfd/wm831x-irq.c b/drivers/mfd/wm831x-irq.c
index f4747a4a9a93..bec4d0539160 100644
--- a/drivers/mfd/wm831x-irq.c
+++ b/drivers/mfd/wm831x-irq.c
@@ -325,11 +325,6 @@ static inline int irq_data_to_status_reg(struct wm831x_irq_data *irq_data)
325 return WM831X_INTERRUPT_STATUS_1 - 1 + irq_data->reg; 325 return WM831X_INTERRUPT_STATUS_1 - 1 + irq_data->reg;
326} 326}
327 327
328static inline int irq_data_to_mask_reg(struct wm831x_irq_data *irq_data)
329{
330 return WM831X_INTERRUPT_STATUS_1_MASK - 1 + irq_data->reg;
331}
332
333static inline struct wm831x_irq_data *irq_to_wm831x_irq(struct wm831x *wm831x, 328static inline struct wm831x_irq_data *irq_to_wm831x_irq(struct wm831x *wm831x,
334 int irq) 329 int irq)
335{ 330{
@@ -477,8 +472,7 @@ static irqreturn_t wm831x_irq_thread(int irq, void *data)
477 handle_nested_irq(wm831x->irq_base + WM831X_IRQ_TCHPD); 472 handle_nested_irq(wm831x->irq_base + WM831X_IRQ_TCHPD);
478 if (primary & WM831X_TCHDATA_INT) 473 if (primary & WM831X_TCHDATA_INT)
479 handle_nested_irq(wm831x->irq_base + WM831X_IRQ_TCHDATA); 474 handle_nested_irq(wm831x->irq_base + WM831X_IRQ_TCHDATA);
480 if (primary & (WM831X_TCHDATA_EINT | WM831X_TCHPD_EINT)) 475 primary &= ~(WM831X_TCHDATA_EINT | WM831X_TCHPD_EINT);
481 goto out;
482 476
483 for (i = 0; i < ARRAY_SIZE(wm831x_irqs); i++) { 477 for (i = 0; i < ARRAY_SIZE(wm831x_irqs); i++) {
484 int offset = wm831x_irqs[i].reg - 1; 478 int offset = wm831x_irqs[i].reg - 1;
diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index 8d6a9a969dbc..62ef3254105f 100644
--- a/drivers/mfd/wm831x-spi.c
+++ b/drivers/mfd/wm831x-spi.c
@@ -30,7 +30,7 @@ static int __devinit wm831x_spi_probe(struct spi_device *spi)
30 30
31 type = (enum wm831x_parent)id->driver_data; 31 type = (enum wm831x_parent)id->driver_data;
32 32
33 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); 33 wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
34 if (wm831x == NULL) 34 if (wm831x == NULL)
35 return -ENOMEM; 35 return -ENOMEM;
36 36
@@ -45,7 +45,6 @@ static int __devinit wm831x_spi_probe(struct spi_device *spi)
45 ret = PTR_ERR(wm831x->regmap); 45 ret = PTR_ERR(wm831x->regmap);
46 dev_err(wm831x->dev, "Failed to allocate register map: %d\n", 46 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
47 ret); 47 ret);
48 kfree(wm831x);
49 return ret; 48 return ret;
50 } 49 }
51 50
@@ -95,7 +94,6 @@ MODULE_DEVICE_TABLE(spi, wm831x_spi_id);
95static struct spi_driver wm831x_spi_driver = { 94static struct spi_driver wm831x_spi_driver = {
96 .driver = { 95 .driver = {
97 .name = "wm831x", 96 .name = "wm831x",
98 .bus = &spi_bus_type,
99 .owner = THIS_MODULE, 97 .owner = THIS_MODULE,
100 .pm = &wm831x_spi_pm, 98 .pm = &wm831x_spi_pm,
101 }, 99 },
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
index e81cc31e4202..dd1caaac55e4 100644
--- a/drivers/mfd/wm8350-core.c
+++ b/drivers/mfd/wm8350-core.c
@@ -573,6 +573,8 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
573 u16 id1, id2, mask_rev; 573 u16 id1, id2, mask_rev;
574 u16 cust_id, mode, chip_rev; 574 u16 cust_id, mode, chip_rev;
575 575
576 dev_set_drvdata(wm8350->dev, wm8350);
577
576 /* get WM8350 revision and config mode */ 578 /* get WM8350 revision and config mode */
577 ret = wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1); 579 ret = wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1);
578 if (ret != 0) { 580 if (ret != 0) {
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
index 5fe5de166adb..d955faaf27c4 100644
--- a/drivers/mfd/wm8350-i2c.c
+++ b/drivers/mfd/wm8350-i2c.c
@@ -63,7 +63,7 @@ static int wm8350_i2c_probe(struct i2c_client *i2c,
63 struct wm8350 *wm8350; 63 struct wm8350 *wm8350;
64 int ret = 0; 64 int ret = 0;
65 65
66 wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL); 66 wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
67 if (wm8350 == NULL) 67 if (wm8350 == NULL)
68 return -ENOMEM; 68 return -ENOMEM;
69 69
@@ -80,7 +80,6 @@ static int wm8350_i2c_probe(struct i2c_client *i2c,
80 return ret; 80 return ret;
81 81
82err: 82err:
83 kfree(wm8350);
84 return ret; 83 return ret;
85} 84}
86 85
@@ -89,7 +88,6 @@ static int wm8350_i2c_remove(struct i2c_client *i2c)
89 struct wm8350 *wm8350 = i2c_get_clientdata(i2c); 88 struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
90 89
91 wm8350_device_exit(wm8350); 90 wm8350_device_exit(wm8350);
92 kfree(wm8350);
93 91
94 return 0; 92 return 0;
95} 93}
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
index 62b4626f4561..2204893444a6 100644
--- a/drivers/mfd/wm8400-core.c
+++ b/drivers/mfd/wm8400-core.c
@@ -344,7 +344,7 @@ static int wm8400_i2c_probe(struct i2c_client *i2c,
344 struct wm8400 *wm8400; 344 struct wm8400 *wm8400;
345 int ret; 345 int ret;
346 346
347 wm8400 = kzalloc(sizeof(struct wm8400), GFP_KERNEL); 347 wm8400 = devm_kzalloc(&i2c->dev, sizeof(struct wm8400), GFP_KERNEL);
348 if (wm8400 == NULL) { 348 if (wm8400 == NULL) {
349 ret = -ENOMEM; 349 ret = -ENOMEM;
350 goto err; 350 goto err;
@@ -353,7 +353,7 @@ static int wm8400_i2c_probe(struct i2c_client *i2c,
353 wm8400->regmap = regmap_init_i2c(i2c, &wm8400_regmap_config); 353 wm8400->regmap = regmap_init_i2c(i2c, &wm8400_regmap_config);
354 if (IS_ERR(wm8400->regmap)) { 354 if (IS_ERR(wm8400->regmap)) {
355 ret = PTR_ERR(wm8400->regmap); 355 ret = PTR_ERR(wm8400->regmap);
356 goto struct_err; 356 goto err;
357 } 357 }
358 358
359 wm8400->dev = &i2c->dev; 359 wm8400->dev = &i2c->dev;
@@ -367,8 +367,6 @@ static int wm8400_i2c_probe(struct i2c_client *i2c,
367 367
368map_err: 368map_err:
369 regmap_exit(wm8400->regmap); 369 regmap_exit(wm8400->regmap);
370struct_err:
371 kfree(wm8400);
372err: 370err:
373 return ret; 371 return ret;
374} 372}
@@ -379,7 +377,6 @@ static int wm8400_i2c_remove(struct i2c_client *i2c)
379 377
380 wm8400_release(wm8400); 378 wm8400_release(wm8400);
381 regmap_exit(wm8400->regmap); 379 regmap_exit(wm8400->regmap);
382 kfree(wm8400);
383 380
384 return 0; 381 return 0;
385} 382}
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 5664696f2d3a..6a1a092db146 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -500,6 +500,14 @@ config USB_SWITCH_FSA9480
500 stereo and mono audio, video, microphone and UART data to use 500 stereo and mono audio, video, microphone and UART data to use
501 a common connector port. 501 a common connector port.
502 502
503config MAX8997_MUIC
504 tristate "MAX8997 MUIC Support"
505 depends on MFD_MAX8997
506 help
507 If you say yes here you get support for the MUIC device of
508 Maxim MAX8997 PMIC.
509 The MAX8997 MUIC is a USB port accessory detector and switch.
510
503source "drivers/misc/c2port/Kconfig" 511source "drivers/misc/c2port/Kconfig"
504source "drivers/misc/eeprom/Kconfig" 512source "drivers/misc/eeprom/Kconfig"
505source "drivers/misc/cb710/Kconfig" 513source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b26495a02554..3e1d80106f04 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -48,3 +48,4 @@ obj-y += lis3lv02d/
48obj-y += carma/ 48obj-y += carma/
49obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o 49obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
50obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ 50obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
51obj-$(CONFIG_MAX8997_MUIC) += max8997-muic.o
diff --git a/drivers/misc/ab8500-pwm.c b/drivers/misc/ab8500-pwm.c
index 2208a9d52622..d7a9aa14e5d5 100644
--- a/drivers/misc/ab8500-pwm.c
+++ b/drivers/misc/ab8500-pwm.c
@@ -8,8 +8,8 @@
8#include <linux/platform_device.h> 8#include <linux/platform_device.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/pwm.h> 10#include <linux/pwm.h>
11#include <linux/mfd/ab8500.h>
12#include <linux/mfd/abx500.h> 11#include <linux/mfd/abx500.h>
12#include <linux/mfd/abx500/ab8500.h>
13#include <linux/module.h> 13#include <linux/module.h>
14 14
15/* 15/*
diff --git a/drivers/misc/max8997-muic.c b/drivers/misc/max8997-muic.c
new file mode 100644
index 000000000000..d74ef41aabd5
--- /dev/null
+++ b/drivers/misc/max8997-muic.c
@@ -0,0 +1,505 @@
1/*
2 * max8997-muic.c - MAX8997 muic driver for the Maxim 8997
3 *
4 * Copyright (C) 2011 Samsung Electrnoics
5 * Donggeun Kim <dg77.kim@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/i2c.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <linux/err.h>
29#include <linux/platform_device.h>
30#include <linux/kobject.h>
31#include <linux/mfd/max8997.h>
32#include <linux/mfd/max8997-private.h>
33
34/* MAX8997-MUIC STATUS1 register */
35#define STATUS1_ADC_SHIFT 0
36#define STATUS1_ADCLOW_SHIFT 5
37#define STATUS1_ADCERR_SHIFT 6
38#define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT)
39#define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT)
40#define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT)
41
42/* MAX8997-MUIC STATUS2 register */
43#define STATUS2_CHGTYP_SHIFT 0
44#define STATUS2_CHGDETRUN_SHIFT 3
45#define STATUS2_DCDTMR_SHIFT 4
46#define STATUS2_DBCHG_SHIFT 5
47#define STATUS2_VBVOLT_SHIFT 6
48#define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT)
49#define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT)
50#define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT)
51#define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT)
52#define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT)
53
54/* MAX8997-MUIC STATUS3 register */
55#define STATUS3_OVP_SHIFT 2
56#define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT)
57
58/* MAX8997-MUIC CONTROL1 register */
59#define COMN1SW_SHIFT 0
60#define COMP2SW_SHIFT 3
61#define COMN1SW_MASK (0x7 << COMN1SW_SHIFT)
62#define COMP2SW_MASK (0x7 << COMP2SW_SHIFT)
63#define SW_MASK (COMP2SW_MASK | COMN1SW_MASK)
64
65#define MAX8997_SW_USB ((1 << COMP2SW_SHIFT) | (1 << COMN1SW_SHIFT))
66#define MAX8997_SW_AUDIO ((2 << COMP2SW_SHIFT) | (2 << COMN1SW_SHIFT))
67#define MAX8997_SW_UART ((3 << COMP2SW_SHIFT) | (3 << COMN1SW_SHIFT))
68#define MAX8997_SW_OPEN ((0 << COMP2SW_SHIFT) | (0 << COMN1SW_SHIFT))
69
70#define MAX8997_ADC_GROUND 0x00
71#define MAX8997_ADC_MHL 0x01
72#define MAX8997_ADC_JIG_USB_1 0x18
73#define MAX8997_ADC_JIG_USB_2 0x19
74#define MAX8997_ADC_DESKDOCK 0x1a
75#define MAX8997_ADC_JIG_UART 0x1c
76#define MAX8997_ADC_CARDOCK 0x1d
77#define MAX8997_ADC_OPEN 0x1f
78
79struct max8997_muic_irq {
80 unsigned int irq;
81 const char *name;
82};
83
84static struct max8997_muic_irq muic_irqs[] = {
85 { MAX8997_MUICIRQ_ADCError, "muic-ADC_error" },
86 { MAX8997_MUICIRQ_ADCLow, "muic-ADC_low" },
87 { MAX8997_MUICIRQ_ADC, "muic-ADC" },
88 { MAX8997_MUICIRQ_VBVolt, "muic-VB_voltage" },
89 { MAX8997_MUICIRQ_DBChg, "muic-DB_charger" },
90 { MAX8997_MUICIRQ_DCDTmr, "muic-DCD_timer" },
91 { MAX8997_MUICIRQ_ChgDetRun, "muic-CDR_status" },
92 { MAX8997_MUICIRQ_ChgTyp, "muic-charger_type" },
93 { MAX8997_MUICIRQ_OVP, "muic-over_voltage" },
94};
95
96struct max8997_muic_info {
97 struct device *dev;
98 struct max8997_dev *iodev;
99 struct i2c_client *muic;
100 struct max8997_muic_platform_data *muic_pdata;
101
102 int irq;
103 struct work_struct irq_work;
104
105 enum max8997_muic_charger_type pre_charger_type;
106 int pre_adc;
107
108 struct mutex mutex;
109};
110
111static int max8997_muic_handle_usb(struct max8997_muic_info *info,
112 enum max8997_muic_usb_type usb_type, bool attached)
113{
114 struct max8997_muic_platform_data *mdata = info->muic_pdata;
115 int ret = 0;
116
117 if (usb_type == MAX8997_USB_HOST) {
118 /* switch to USB */
119 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
120 attached ? MAX8997_SW_USB : MAX8997_SW_OPEN,
121 SW_MASK);
122 if (ret) {
123 dev_err(info->dev, "failed to update muic register\n");
124 goto out;
125 }
126 }
127
128 if (mdata->usb_callback)
129 mdata->usb_callback(usb_type, attached);
130out:
131 return ret;
132}
133
134static void max8997_muic_handle_mhl(struct max8997_muic_info *info,
135 bool attached)
136{
137 struct max8997_muic_platform_data *mdata = info->muic_pdata;
138
139 if (mdata->mhl_callback)
140 mdata->mhl_callback(attached);
141}
142
143static int max8997_muic_handle_dock(struct max8997_muic_info *info,
144 int adc, bool attached)
145{
146 struct max8997_muic_platform_data *mdata = info->muic_pdata;
147 int ret = 0;
148
149 /* switch to AUDIO */
150 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
151 attached ? MAX8997_SW_AUDIO : MAX8997_SW_OPEN,
152 SW_MASK);
153 if (ret) {
154 dev_err(info->dev, "failed to update muic register\n");
155 goto out;
156 }
157
158 switch (adc) {
159 case MAX8997_ADC_DESKDOCK:
160 if (mdata->deskdock_callback)
161 mdata->deskdock_callback(attached);
162 break;
163 case MAX8997_ADC_CARDOCK:
164 if (mdata->cardock_callback)
165 mdata->cardock_callback(attached);
166 break;
167 default:
168 break;
169 }
170out:
171 return ret;
172}
173
174static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
175 bool attached)
176{
177 struct max8997_muic_platform_data *mdata = info->muic_pdata;
178 int ret = 0;
179
180 /* switch to UART */
181 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
182 attached ? MAX8997_SW_UART : MAX8997_SW_OPEN,
183 SW_MASK);
184 if (ret) {
185 dev_err(info->dev, "failed to update muic register\n");
186 goto out;
187 }
188
189 if (mdata->uart_callback)
190 mdata->uart_callback(attached);
191out:
192 return ret;
193}
194
195static int max8997_muic_handle_adc_detach(struct max8997_muic_info *info)
196{
197 int ret = 0;
198
199 switch (info->pre_adc) {
200 case MAX8997_ADC_GROUND:
201 ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, false);
202 break;
203 case MAX8997_ADC_MHL:
204 max8997_muic_handle_mhl(info, false);
205 break;
206 case MAX8997_ADC_JIG_USB_1:
207 case MAX8997_ADC_JIG_USB_2:
208 ret = max8997_muic_handle_usb(info, MAX8997_USB_DEVICE, false);
209 break;
210 case MAX8997_ADC_DESKDOCK:
211 case MAX8997_ADC_CARDOCK:
212 ret = max8997_muic_handle_dock(info, info->pre_adc, false);
213 break;
214 case MAX8997_ADC_JIG_UART:
215 ret = max8997_muic_handle_jig_uart(info, false);
216 break;
217 default:
218 break;
219 }
220
221 return ret;
222}
223
224static int max8997_muic_handle_adc(struct max8997_muic_info *info, int adc)
225{
226 int ret = 0;
227
228 switch (adc) {
229 case MAX8997_ADC_GROUND:
230 ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, true);
231 break;
232 case MAX8997_ADC_MHL:
233 max8997_muic_handle_mhl(info, true);
234 break;
235 case MAX8997_ADC_JIG_USB_1:
236 case MAX8997_ADC_JIG_USB_2:
237 ret = max8997_muic_handle_usb(info, MAX8997_USB_DEVICE, true);
238 break;
239 case MAX8997_ADC_DESKDOCK:
240 case MAX8997_ADC_CARDOCK:
241 ret = max8997_muic_handle_dock(info, adc, true);
242 break;
243 case MAX8997_ADC_JIG_UART:
244 ret = max8997_muic_handle_jig_uart(info, true);
245 break;
246 case MAX8997_ADC_OPEN:
247 ret = max8997_muic_handle_adc_detach(info);
248 break;
249 default:
250 break;
251 }
252
253 info->pre_adc = adc;
254
255 return ret;
256}
257
258static int max8997_muic_handle_charger_type(struct max8997_muic_info *info,
259 enum max8997_muic_charger_type charger_type)
260{
261 struct max8997_muic_platform_data *mdata = info->muic_pdata;
262 u8 adc;
263 int ret;
264
265 ret = max8997_read_reg(info->muic, MAX8997_MUIC_REG_STATUS1, &adc);
266 if (ret) {
267 dev_err(info->dev, "failed to read muic register\n");
268 goto out;
269 }
270
271 switch (charger_type) {
272 case MAX8997_CHARGER_TYPE_NONE:
273 if (mdata->charger_callback)
274 mdata->charger_callback(false, charger_type);
275 if (info->pre_charger_type == MAX8997_CHARGER_TYPE_USB) {
276 max8997_muic_handle_usb(info,
277 MAX8997_USB_DEVICE, false);
278 }
279 break;
280 case MAX8997_CHARGER_TYPE_USB:
281 if ((adc & STATUS1_ADC_MASK) == MAX8997_ADC_OPEN) {
282 max8997_muic_handle_usb(info,
283 MAX8997_USB_DEVICE, true);
284 }
285 if (mdata->charger_callback)
286 mdata->charger_callback(true, charger_type);
287 break;
288 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
289 case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
290 case MAX8997_CHARGER_TYPE_500MA:
291 case MAX8997_CHARGER_TYPE_1A:
292 if (mdata->charger_callback)
293 mdata->charger_callback(true, charger_type);
294 break;
295 default:
296 break;
297 }
298
299 info->pre_charger_type = charger_type;
300out:
301 return ret;
302}
303
304static void max8997_muic_irq_work(struct work_struct *work)
305{
306 struct max8997_muic_info *info = container_of(work,
307 struct max8997_muic_info, irq_work);
308 struct max8997_platform_data *pdata =
309 dev_get_platdata(info->iodev->dev);
310 u8 status[3];
311 u8 adc, chg_type;
312
313 int irq_type = info->irq - pdata->irq_base;
314 int ret;
315
316 mutex_lock(&info->mutex);
317
318 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
319 3, status);
320 if (ret) {
321 dev_err(info->dev, "failed to read muic register\n");
322 mutex_unlock(&info->mutex);
323 return;
324 }
325
326 dev_dbg(info->dev, "%s: STATUS1:0x%x, 2:0x%x\n", __func__,
327 status[0], status[1]);
328
329 switch (irq_type) {
330 case MAX8997_MUICIRQ_ADC:
331 adc = status[0] & STATUS1_ADC_MASK;
332 adc >>= STATUS1_ADC_SHIFT;
333
334 max8997_muic_handle_adc(info, adc);
335 break;
336 case MAX8997_MUICIRQ_ChgTyp:
337 chg_type = status[1] & STATUS2_CHGTYP_MASK;
338 chg_type >>= STATUS2_CHGTYP_SHIFT;
339
340 max8997_muic_handle_charger_type(info, chg_type);
341 break;
342 default:
343 dev_info(info->dev, "misc interrupt: %s occurred\n",
344 muic_irqs[irq_type].name);
345 break;
346 }
347
348 mutex_unlock(&info->mutex);
349
350 return;
351}
352
353static irqreturn_t max8997_muic_irq_handler(int irq, void *data)
354{
355 struct max8997_muic_info *info = data;
356
357 dev_dbg(info->dev, "irq:%d\n", irq);
358 info->irq = irq;
359
360 schedule_work(&info->irq_work);
361
362 return IRQ_HANDLED;
363}
364
365static void max8997_muic_detect_dev(struct max8997_muic_info *info)
366{
367 int ret;
368 u8 status[2], adc, chg_type;
369
370 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
371 2, status);
372 if (ret) {
373 dev_err(info->dev, "failed to read muic register\n");
374 return;
375 }
376
377 dev_info(info->dev, "STATUS1:0x%x, STATUS2:0x%x\n",
378 status[0], status[1]);
379
380 adc = status[0] & STATUS1_ADC_MASK;
381 adc >>= STATUS1_ADC_SHIFT;
382
383 chg_type = status[1] & STATUS2_CHGTYP_MASK;
384 chg_type >>= STATUS2_CHGTYP_SHIFT;
385
386 max8997_muic_handle_adc(info, adc);
387 max8997_muic_handle_charger_type(info, chg_type);
388}
389
390static void max8997_initialize_device(struct max8997_muic_info *info)
391{
392 struct max8997_muic_platform_data *mdata = info->muic_pdata;
393 int i;
394
395 for (i = 0; i < mdata->num_init_data; i++) {
396 max8997_write_reg(info->muic, mdata->init_data[i].addr,
397 mdata->init_data[i].data);
398 }
399}
400
401static int __devinit max8997_muic_probe(struct platform_device *pdev)
402{
403 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
404 struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev);
405 struct max8997_muic_info *info;
406 int ret, i;
407
408 info = kzalloc(sizeof(struct max8997_muic_info), GFP_KERNEL);
409 if (!info) {
410 dev_err(&pdev->dev, "failed to allocate memory\n");
411 ret = -ENOMEM;
412 goto err_kfree;
413 }
414
415 if (!pdata->muic_pdata) {
416 dev_err(&pdev->dev, "failed to get platform_data\n");
417 ret = -EINVAL;
418 goto err_pdata;
419 }
420 info->muic_pdata = pdata->muic_pdata;
421
422 info->dev = &pdev->dev;
423 info->iodev = iodev;
424 info->muic = iodev->muic;
425
426 platform_set_drvdata(pdev, info);
427 mutex_init(&info->mutex);
428
429 INIT_WORK(&info->irq_work, max8997_muic_irq_work);
430
431 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
432 struct max8997_muic_irq *muic_irq = &muic_irqs[i];
433
434 ret = request_threaded_irq(pdata->irq_base + muic_irq->irq,
435 NULL, max8997_muic_irq_handler,
436 0, muic_irq->name,
437 info);
438 if (ret) {
439 dev_err(&pdev->dev,
440 "failed: irq request (IRQ: %d,"
441 " error :%d)\n",
442 muic_irq->irq, ret);
443
444 for (i = i - 1; i >= 0; i--)
445 free_irq(muic_irq->irq, info);
446
447 goto err_irq;
448 }
449 }
450
451 /* Initialize registers according to platform data */
452 max8997_initialize_device(info);
453
454 /* Initial device detection */
455 max8997_muic_detect_dev(info);
456
457 return ret;
458
459err_irq:
460err_pdata:
461 kfree(info);
462err_kfree:
463 return ret;
464}
465
466static int __devexit max8997_muic_remove(struct platform_device *pdev)
467{
468 struct max8997_muic_info *info = platform_get_drvdata(pdev);
469 struct max8997_platform_data *pdata =
470 dev_get_platdata(info->iodev->dev);
471 int i;
472
473 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
474 free_irq(pdata->irq_base + muic_irqs[i].irq, info);
475 cancel_work_sync(&info->irq_work);
476
477 kfree(info);
478
479 return 0;
480}
481
482static struct platform_driver max8997_muic_driver = {
483 .driver = {
484 .name = "max8997-muic",
485 .owner = THIS_MODULE,
486 },
487 .probe = max8997_muic_probe,
488 .remove = __devexit_p(max8997_muic_remove),
489};
490
491static int __init max8997_muic_init(void)
492{
493 return platform_driver_register(&max8997_muic_driver);
494}
495module_init(max8997_muic_init);
496
497static void __exit max8997_muic_exit(void)
498{
499 platform_driver_unregister(&max8997_muic_driver);
500}
501module_exit(max8997_muic_exit);
502
503MODULE_DESCRIPTION("Maxim MAX8997 MUIC driver");
504MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
505MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 12eef393e216..400756ec7c49 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -6,5 +6,4 @@ subdir-ccflags-$(CONFIG_MMC_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_MMC) += core/ 7obj-$(CONFIG_MMC) += core/
8obj-$(CONFIG_MMC) += card/ 8obj-$(CONFIG_MMC) += card/
9obj-$(CONFIG_MMC) += host/ 9obj-$(subst m,y,$(CONFIG_MMC)) += host/
10
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 1e0e27cbe987..0cad48a284a8 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -107,6 +107,8 @@ struct mmc_blk_data {
107 */ 107 */
108 unsigned int part_curr; 108 unsigned int part_curr;
109 struct device_attribute force_ro; 109 struct device_attribute force_ro;
110 struct device_attribute power_ro_lock;
111 int area_type;
110}; 112};
111 113
112static DEFINE_MUTEX(open_lock); 114static DEFINE_MUTEX(open_lock);
@@ -119,6 +121,7 @@ enum mmc_blk_status {
119 MMC_BLK_ABORT, 121 MMC_BLK_ABORT,
120 MMC_BLK_DATA_ERR, 122 MMC_BLK_DATA_ERR,
121 MMC_BLK_ECC_ERR, 123 MMC_BLK_ECC_ERR,
124 MMC_BLK_NOMEDIUM,
122}; 125};
123 126
124module_param(perdev_minors, int, 0444); 127module_param(perdev_minors, int, 0444);
@@ -165,6 +168,70 @@ static void mmc_blk_put(struct mmc_blk_data *md)
165 mutex_unlock(&open_lock); 168 mutex_unlock(&open_lock);
166} 169}
167 170
171static ssize_t power_ro_lock_show(struct device *dev,
172 struct device_attribute *attr, char *buf)
173{
174 int ret;
175 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
176 struct mmc_card *card = md->queue.card;
177 int locked = 0;
178
179 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PERM_WP_EN)
180 locked = 2;
181 else if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_EN)
182 locked = 1;
183
184 ret = snprintf(buf, PAGE_SIZE, "%d\n", locked);
185
186 return ret;
187}
188
189static ssize_t power_ro_lock_store(struct device *dev,
190 struct device_attribute *attr, const char *buf, size_t count)
191{
192 int ret;
193 struct mmc_blk_data *md, *part_md;
194 struct mmc_card *card;
195 unsigned long set;
196
197 if (kstrtoul(buf, 0, &set))
198 return -EINVAL;
199
200 if (set != 1)
201 return count;
202
203 md = mmc_blk_get(dev_to_disk(dev));
204 card = md->queue.card;
205
206 mmc_claim_host(card->host);
207
208 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP,
209 card->ext_csd.boot_ro_lock |
210 EXT_CSD_BOOT_WP_B_PWR_WP_EN,
211 card->ext_csd.part_time);
212 if (ret)
213 pr_err("%s: Locking boot partition ro until next power on failed: %d\n", md->disk->disk_name, ret);
214 else
215 card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN;
216
217 mmc_release_host(card->host);
218
219 if (!ret) {
220 pr_info("%s: Locking boot partition ro until next power on\n",
221 md->disk->disk_name);
222 set_disk_ro(md->disk, 1);
223
224 list_for_each_entry(part_md, &md->part, part)
225 if (part_md->area_type == MMC_BLK_DATA_AREA_BOOT) {
226 pr_info("%s: Locking boot partition ro until next power on\n", part_md->disk->disk_name);
227 set_disk_ro(part_md->disk, 1);
228 }
229 }
230
231 mmc_blk_put(md);
232 return count;
233}
234
168static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr, 235static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
169 char *buf) 236 char *buf)
170{ 237{
@@ -266,6 +333,9 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
266 goto idata_err; 333 goto idata_err;
267 } 334 }
268 335
336 if (!idata->buf_bytes)
337 return idata;
338
269 idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL); 339 idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL);
270 if (!idata->buf) { 340 if (!idata->buf) {
271 err = -ENOMEM; 341 err = -ENOMEM;
@@ -312,25 +382,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
312 if (IS_ERR(idata)) 382 if (IS_ERR(idata))
313 return PTR_ERR(idata); 383 return PTR_ERR(idata);
314 384
315 cmd.opcode = idata->ic.opcode;
316 cmd.arg = idata->ic.arg;
317 cmd.flags = idata->ic.flags;
318
319 data.sg = &sg;
320 data.sg_len = 1;
321 data.blksz = idata->ic.blksz;
322 data.blocks = idata->ic.blocks;
323
324 sg_init_one(data.sg, idata->buf, idata->buf_bytes);
325
326 if (idata->ic.write_flag)
327 data.flags = MMC_DATA_WRITE;
328 else
329 data.flags = MMC_DATA_READ;
330
331 mrq.cmd = &cmd;
332 mrq.data = &data;
333
334 md = mmc_blk_get(bdev->bd_disk); 385 md = mmc_blk_get(bdev->bd_disk);
335 if (!md) { 386 if (!md) {
336 err = -EINVAL; 387 err = -EINVAL;
@@ -343,6 +394,48 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
343 goto cmd_done; 394 goto cmd_done;
344 } 395 }
345 396
397 cmd.opcode = idata->ic.opcode;
398 cmd.arg = idata->ic.arg;
399 cmd.flags = idata->ic.flags;
400
401 if (idata->buf_bytes) {
402 data.sg = &sg;
403 data.sg_len = 1;
404 data.blksz = idata->ic.blksz;
405 data.blocks = idata->ic.blocks;
406
407 sg_init_one(data.sg, idata->buf, idata->buf_bytes);
408
409 if (idata->ic.write_flag)
410 data.flags = MMC_DATA_WRITE;
411 else
412 data.flags = MMC_DATA_READ;
413
414 /* data.flags must already be set before doing this. */
415 mmc_set_data_timeout(&data, card);
416
417 /* Allow overriding the timeout_ns for empirical tuning. */
418 if (idata->ic.data_timeout_ns)
419 data.timeout_ns = idata->ic.data_timeout_ns;
420
421 if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) {
422 /*
423 * Pretend this is a data transfer and rely on the
424 * host driver to compute timeout. When all host
425 * drivers support cmd.cmd_timeout for R1B, this
426 * can be changed to:
427 *
428 * mrq.data = NULL;
429 * cmd.cmd_timeout = idata->ic.cmd_timeout_ms;
430 */
431 data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000;
432 }
433
434 mrq.data = &data;
435 }
436
437 mrq.cmd = &cmd;
438
346 mmc_claim_host(card->host); 439 mmc_claim_host(card->host);
347 440
348 if (idata->ic.is_acmd) { 441 if (idata->ic.is_acmd) {
@@ -351,24 +444,6 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
351 goto cmd_rel_host; 444 goto cmd_rel_host;
352 } 445 }
353 446
354 /* data.flags must already be set before doing this. */
355 mmc_set_data_timeout(&data, card);
356 /* Allow overriding the timeout_ns for empirical tuning. */
357 if (idata->ic.data_timeout_ns)
358 data.timeout_ns = idata->ic.data_timeout_ns;
359
360 if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) {
361 /*
362 * Pretend this is a data transfer and rely on the host driver
363 * to compute timeout. When all host drivers support
364 * cmd.cmd_timeout for R1B, this can be changed to:
365 *
366 * mrq.data = NULL;
367 * cmd.cmd_timeout = idata->ic.cmd_timeout_ms;
368 */
369 data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000;
370 }
371
372 mmc_wait_for_req(card->host, &mrq); 447 mmc_wait_for_req(card->host, &mrq);
373 448
374 if (cmd.error) { 449 if (cmd.error) {
@@ -565,6 +640,7 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
565 return err; 640 return err;
566} 641}
567 642
643#define ERR_NOMEDIUM 3
568#define ERR_RETRY 2 644#define ERR_RETRY 2
569#define ERR_ABORT 1 645#define ERR_ABORT 1
570#define ERR_CONTINUE 0 646#define ERR_CONTINUE 0
@@ -632,6 +708,9 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
632 u32 status, stop_status = 0; 708 u32 status, stop_status = 0;
633 int err, retry; 709 int err, retry;
634 710
711 if (mmc_card_removed(card))
712 return ERR_NOMEDIUM;
713
635 /* 714 /*
636 * Try to get card status which indicates both the card state 715 * Try to get card status which indicates both the card state
637 * and why there was no response. If the first attempt fails, 716 * and why there was no response. If the first attempt fails,
@@ -648,8 +727,12 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
648 } 727 }
649 728
650 /* We couldn't get a response from the card. Give up. */ 729 /* We couldn't get a response from the card. Give up. */
651 if (err) 730 if (err) {
731 /* Check if the card is removed */
732 if (mmc_detect_card_removed(card->host))
733 return ERR_NOMEDIUM;
652 return ERR_ABORT; 734 return ERR_ABORT;
735 }
653 736
654 /* Flag ECC errors */ 737 /* Flag ECC errors */
655 if ((status & R1_CARD_ECC_FAILED) || 738 if ((status & R1_CARD_ECC_FAILED) ||
@@ -922,6 +1005,8 @@ static int mmc_blk_err_check(struct mmc_card *card,
922 return MMC_BLK_RETRY; 1005 return MMC_BLK_RETRY;
923 case ERR_ABORT: 1006 case ERR_ABORT:
924 return MMC_BLK_ABORT; 1007 return MMC_BLK_ABORT;
1008 case ERR_NOMEDIUM:
1009 return MMC_BLK_NOMEDIUM;
925 case ERR_CONTINUE: 1010 case ERR_CONTINUE:
926 break; 1011 break;
927 } 1012 }
@@ -1255,6 +1340,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1255 if (!ret) 1340 if (!ret)
1256 goto start_new_req; 1341 goto start_new_req;
1257 break; 1342 break;
1343 case MMC_BLK_NOMEDIUM:
1344 goto cmd_abort;
1258 } 1345 }
1259 1346
1260 if (ret) { 1347 if (ret) {
@@ -1271,6 +1358,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1271 1358
1272 cmd_abort: 1359 cmd_abort:
1273 spin_lock_irq(&md->lock); 1360 spin_lock_irq(&md->lock);
1361 if (mmc_card_removed(card))
1362 req->cmd_flags |= REQ_QUIET;
1274 while (ret) 1363 while (ret)
1275 ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); 1364 ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
1276 spin_unlock_irq(&md->lock); 1365 spin_unlock_irq(&md->lock);
@@ -1339,7 +1428,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
1339 struct device *parent, 1428 struct device *parent,
1340 sector_t size, 1429 sector_t size,
1341 bool default_ro, 1430 bool default_ro,
1342 const char *subname) 1431 const char *subname,
1432 int area_type)
1343{ 1433{
1344 struct mmc_blk_data *md; 1434 struct mmc_blk_data *md;
1345 int devidx, ret; 1435 int devidx, ret;
@@ -1364,11 +1454,12 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
1364 if (!subname) { 1454 if (!subname) {
1365 md->name_idx = find_first_zero_bit(name_use, max_devices); 1455 md->name_idx = find_first_zero_bit(name_use, max_devices);
1366 __set_bit(md->name_idx, name_use); 1456 __set_bit(md->name_idx, name_use);
1367 } 1457 } else
1368 else
1369 md->name_idx = ((struct mmc_blk_data *) 1458 md->name_idx = ((struct mmc_blk_data *)
1370 dev_to_disk(parent)->private_data)->name_idx; 1459 dev_to_disk(parent)->private_data)->name_idx;
1371 1460
1461 md->area_type = area_type;
1462
1372 /* 1463 /*
1373 * Set the read-only status based on the supported commands 1464 * Set the read-only status based on the supported commands
1374 * and the write protect switch. 1465 * and the write protect switch.
@@ -1462,7 +1553,8 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
1462 size = card->csd.capacity << (card->csd.read_blkbits - 9); 1553 size = card->csd.capacity << (card->csd.read_blkbits - 9);
1463 } 1554 }
1464 1555
1465 md = mmc_blk_alloc_req(card, &card->dev, size, false, NULL); 1556 md = mmc_blk_alloc_req(card, &card->dev, size, false, NULL,
1557 MMC_BLK_DATA_AREA_MAIN);
1466 return md; 1558 return md;
1467} 1559}
1468 1560
@@ -1471,13 +1563,14 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
1471 unsigned int part_type, 1563 unsigned int part_type,
1472 sector_t size, 1564 sector_t size,
1473 bool default_ro, 1565 bool default_ro,
1474 const char *subname) 1566 const char *subname,
1567 int area_type)
1475{ 1568{
1476 char cap_str[10]; 1569 char cap_str[10];
1477 struct mmc_blk_data *part_md; 1570 struct mmc_blk_data *part_md;
1478 1571
1479 part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro, 1572 part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro,
1480 subname); 1573 subname, area_type);
1481 if (IS_ERR(part_md)) 1574 if (IS_ERR(part_md))
1482 return PTR_ERR(part_md); 1575 return PTR_ERR(part_md);
1483 part_md->part_type = part_type; 1576 part_md->part_type = part_type;
@@ -1510,7 +1603,8 @@ static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
1510 card->part[idx].part_cfg, 1603 card->part[idx].part_cfg,
1511 card->part[idx].size >> 9, 1604 card->part[idx].size >> 9,
1512 card->part[idx].force_ro, 1605 card->part[idx].force_ro,
1513 card->part[idx].name); 1606 card->part[idx].name,
1607 card->part[idx].area_type);
1514 if (ret) 1608 if (ret)
1515 return ret; 1609 return ret;
1516 } 1610 }
@@ -1539,9 +1633,16 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
1539 1633
1540static void mmc_blk_remove_req(struct mmc_blk_data *md) 1634static void mmc_blk_remove_req(struct mmc_blk_data *md)
1541{ 1635{
1636 struct mmc_card *card;
1637
1542 if (md) { 1638 if (md) {
1639 card = md->queue.card;
1543 if (md->disk->flags & GENHD_FL_UP) { 1640 if (md->disk->flags & GENHD_FL_UP) {
1544 device_remove_file(disk_to_dev(md->disk), &md->force_ro); 1641 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
1642 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
1643 card->ext_csd.boot_ro_lockable)
1644 device_remove_file(disk_to_dev(md->disk),
1645 &md->power_ro_lock);
1545 1646
1546 /* Stop new requests from getting into the queue */ 1647 /* Stop new requests from getting into the queue */
1547 del_gendisk(md->disk); 1648 del_gendisk(md->disk);
@@ -1570,6 +1671,7 @@ static void mmc_blk_remove_parts(struct mmc_card *card,
1570static int mmc_add_disk(struct mmc_blk_data *md) 1671static int mmc_add_disk(struct mmc_blk_data *md)
1571{ 1672{
1572 int ret; 1673 int ret;
1674 struct mmc_card *card = md->queue.card;
1573 1675
1574 add_disk(md->disk); 1676 add_disk(md->disk);
1575 md->force_ro.show = force_ro_show; 1677 md->force_ro.show = force_ro_show;
@@ -1579,18 +1681,53 @@ static int mmc_add_disk(struct mmc_blk_data *md)
1579 md->force_ro.attr.mode = S_IRUGO | S_IWUSR; 1681 md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
1580 ret = device_create_file(disk_to_dev(md->disk), &md->force_ro); 1682 ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
1581 if (ret) 1683 if (ret)
1582 del_gendisk(md->disk); 1684 goto force_ro_fail;
1685
1686 if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
1687 card->ext_csd.boot_ro_lockable) {
1688 mode_t mode;
1689
1690 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS)
1691 mode = S_IRUGO;
1692 else
1693 mode = S_IRUGO | S_IWUSR;
1694
1695 md->power_ro_lock.show = power_ro_lock_show;
1696 md->power_ro_lock.store = power_ro_lock_store;
1697 md->power_ro_lock.attr.mode = mode;
1698 md->power_ro_lock.attr.name =
1699 "ro_lock_until_next_power_on";
1700 ret = device_create_file(disk_to_dev(md->disk),
1701 &md->power_ro_lock);
1702 if (ret)
1703 goto power_ro_lock_fail;
1704 }
1705 return ret;
1706
1707power_ro_lock_fail:
1708 device_remove_file(disk_to_dev(md->disk), &md->force_ro);
1709force_ro_fail:
1710 del_gendisk(md->disk);
1583 1711
1584 return ret; 1712 return ret;
1585} 1713}
1586 1714
1715#define CID_MANFID_SANDISK 0x2
1716#define CID_MANFID_TOSHIBA 0x11
1717#define CID_MANFID_MICRON 0x13
1718
1587static const struct mmc_fixup blk_fixups[] = 1719static const struct mmc_fixup blk_fixups[] =
1588{ 1720{
1589 MMC_FIXUP("SEM02G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), 1721 MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk,
1590 MMC_FIXUP("SEM04G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), 1722 MMC_QUIRK_INAND_CMD38),
1591 MMC_FIXUP("SEM08G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), 1723 MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk,
1592 MMC_FIXUP("SEM16G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), 1724 MMC_QUIRK_INAND_CMD38),
1593 MMC_FIXUP("SEM32G", 0x2, 0x100, add_quirk, MMC_QUIRK_INAND_CMD38), 1725 MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk,
1726 MMC_QUIRK_INAND_CMD38),
1727 MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk,
1728 MMC_QUIRK_INAND_CMD38),
1729 MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk,
1730 MMC_QUIRK_INAND_CMD38),
1594 1731
1595 /* 1732 /*
1596 * Some MMC cards experience performance degradation with CMD23 1733 * Some MMC cards experience performance degradation with CMD23
@@ -1600,18 +1737,18 @@ static const struct mmc_fixup blk_fixups[] =
1600 * 1737 *
1601 * N.B. This doesn't affect SD cards. 1738 * N.B. This doesn't affect SD cards.
1602 */ 1739 */
1603 MMC_FIXUP("MMC08G", 0x11, CID_OEMID_ANY, add_quirk_mmc, 1740 MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
1604 MMC_QUIRK_BLK_NO_CMD23), 1741 MMC_QUIRK_BLK_NO_CMD23),
1605 MMC_FIXUP("MMC16G", 0x11, CID_OEMID_ANY, add_quirk_mmc, 1742 MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
1606 MMC_QUIRK_BLK_NO_CMD23), 1743 MMC_QUIRK_BLK_NO_CMD23),
1607 MMC_FIXUP("MMC32G", 0x11, CID_OEMID_ANY, add_quirk_mmc, 1744 MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
1608 MMC_QUIRK_BLK_NO_CMD23), 1745 MMC_QUIRK_BLK_NO_CMD23),
1609 1746
1610 /* 1747 /*
1611 * Some Micron MMC cards needs longer data read timeout than 1748 * Some Micron MMC cards needs longer data read timeout than
1612 * indicated in CSD. 1749 * indicated in CSD.
1613 */ 1750 */
1614 MMC_FIXUP(CID_NAME_ANY, 0x13, 0x200, add_quirk_mmc, 1751 MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc,
1615 MMC_QUIRK_LONG_READ_TIME), 1752 MMC_QUIRK_LONG_READ_TIME),
1616 1753
1617 END_FIXUP 1754 END_FIXUP
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index e99bdc18002d..759714ed6bee 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -1581,6 +1581,7 @@ static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1581 1581
1582 t->max_segs = test->card->host->max_segs; 1582 t->max_segs = test->card->host->max_segs;
1583 t->max_seg_sz = test->card->host->max_seg_size; 1583 t->max_seg_sz = test->card->host->max_seg_size;
1584 t->max_seg_sz -= t->max_seg_sz % 512;
1584 1585
1585 t->max_tfr = t->max_sz; 1586 t->max_tfr = t->max_sz;
1586 if (t->max_tfr >> 9 > test->card->host->max_blk_count) 1587 if (t->max_tfr >> 9 > test->card->host->max_blk_count)
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index dcad59cbfef1..2517547b4366 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -29,6 +29,8 @@
29 */ 29 */
30static int mmc_prep_request(struct request_queue *q, struct request *req) 30static int mmc_prep_request(struct request_queue *q, struct request *req)
31{ 31{
32 struct mmc_queue *mq = q->queuedata;
33
32 /* 34 /*
33 * We only like normal block requests and discards. 35 * We only like normal block requests and discards.
34 */ 36 */
@@ -37,6 +39,9 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
37 return BLKPREP_KILL; 39 return BLKPREP_KILL;
38 } 40 }
39 41
42 if (mq && mmc_card_removed(mq->card))
43 return BLKPREP_KILL;
44
40 req->cmd_flags |= REQ_DONTPREP; 45 req->cmd_flags |= REQ_DONTPREP;
41 46
42 return BLKPREP_OK; 47 return BLKPREP_OK;
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 639501970b41..dca4428380f1 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -7,6 +7,6 @@ mmc_core-y := core.o bus.o host.o \
7 mmc.o mmc_ops.o sd.o sd_ops.o \ 7 mmc.o mmc_ops.o sd.o sd_ops.o \
8 sdio.o sdio_ops.o sdio_bus.o \ 8 sdio.o sdio_ops.o sdio_bus.o \
9 sdio_cis.o sdio_io.o sdio_irq.o \ 9 sdio_cis.o sdio_io.o sdio_irq.o \
10 quirks.o 10 quirks.o cd-gpio.o
11 11
12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o 12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 6be49249895a..5d011a39dfff 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -303,10 +303,11 @@ int mmc_add_card(struct mmc_card *card)
303 mmc_card_ddr_mode(card) ? "DDR " : "", 303 mmc_card_ddr_mode(card) ? "DDR " : "",
304 type); 304 type);
305 } else { 305 } else {
306 printk(KERN_INFO "%s: new %s%s%s card at address %04x\n", 306 pr_info("%s: new %s%s%s%s card at address %04x\n",
307 mmc_hostname(card->host), 307 mmc_hostname(card->host),
308 mmc_sd_card_uhs(card) ? "ultra high speed " : 308 mmc_card_uhs(card) ? "ultra high speed " :
309 (mmc_card_highspeed(card) ? "high speed " : ""), 309 (mmc_card_highspeed(card) ? "high speed " : ""),
310 (mmc_card_hs200(card) ? "HS200 " : ""),
310 mmc_card_ddr_mode(card) ? "DDR " : "", 311 mmc_card_ddr_mode(card) ? "DDR " : "",
311 type, card->rca); 312 type, card->rca);
312 } 313 }
diff --git a/drivers/mmc/core/cd-gpio.c b/drivers/mmc/core/cd-gpio.c
new file mode 100644
index 000000000000..082202ae4a03
--- /dev/null
+++ b/drivers/mmc/core/cd-gpio.c
@@ -0,0 +1,74 @@
1/*
2 * Generic GPIO card-detect helper
3 *
4 * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/err.h>
12#include <linux/gpio.h>
13#include <linux/interrupt.h>
14#include <linux/jiffies.h>
15#include <linux/mmc/host.h>
16#include <linux/module.h>
17#include <linux/slab.h>
18
19struct mmc_cd_gpio {
20 unsigned int gpio;
21 char label[0];
22};
23
24static irqreturn_t mmc_cd_gpio_irqt(int irq, void *dev_id)
25{
26 /* Schedule a card detection after a debounce timeout */
27 mmc_detect_change(dev_id, msecs_to_jiffies(100));
28 return IRQ_HANDLED;
29}
30
31int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio,
32 unsigned int irq, unsigned long flags)
33{
34 size_t len = strlen(dev_name(host->parent)) + 4;
35 struct mmc_cd_gpio *cd = kmalloc(sizeof(*cd) + len, GFP_KERNEL);
36 int ret;
37
38 if (!cd)
39 return -ENOMEM;
40
41 snprintf(cd->label, len, "%s cd", dev_name(host->parent));
42
43 ret = gpio_request_one(gpio, GPIOF_DIR_IN, cd->label);
44 if (ret < 0)
45 goto egpioreq;
46
47 ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt,
48 flags, cd->label, host);
49 if (ret < 0)
50 goto eirqreq;
51
52 cd->gpio = gpio;
53 host->hotplug.irq = irq;
54 host->hotplug.handler_priv = cd;
55
56 return 0;
57
58eirqreq:
59 gpio_free(gpio);
60egpioreq:
61 kfree(cd);
62 return ret;
63}
64EXPORT_SYMBOL(mmc_cd_gpio_request);
65
66void mmc_cd_gpio_free(struct mmc_host *host)
67{
68 struct mmc_cd_gpio *cd = host->hotplug.handler_priv;
69
70 free_irq(host->hotplug.irq, host);
71 gpio_free(cd->gpio);
72 kfree(cd);
73}
74EXPORT_SYMBOL(mmc_cd_gpio_free);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 75d7d7e17366..f545a3e6eb80 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -140,7 +140,7 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
140 cmd->retries = 0; 140 cmd->retries = 0;
141 } 141 }
142 142
143 if (err && cmd->retries) { 143 if (err && cmd->retries && !mmc_card_removed(host->card)) {
144 /* 144 /*
145 * Request starter must handle retries - see 145 * Request starter must handle retries - see
146 * mmc_wait_for_req_done(). 146 * mmc_wait_for_req_done().
@@ -247,6 +247,11 @@ static void __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
247{ 247{
248 init_completion(&mrq->completion); 248 init_completion(&mrq->completion);
249 mrq->done = mmc_wait_done; 249 mrq->done = mmc_wait_done;
250 if (mmc_card_removed(host->card)) {
251 mrq->cmd->error = -ENOMEDIUM;
252 complete(&mrq->completion);
253 return;
254 }
250 mmc_start_request(host, mrq); 255 mmc_start_request(host, mrq);
251} 256}
252 257
@@ -259,7 +264,8 @@ static void mmc_wait_for_req_done(struct mmc_host *host,
259 wait_for_completion(&mrq->completion); 264 wait_for_completion(&mrq->completion);
260 265
261 cmd = mrq->cmd; 266 cmd = mrq->cmd;
262 if (!cmd->error || !cmd->retries) 267 if (!cmd->error || !cmd->retries ||
268 mmc_card_removed(host->card))
263 break; 269 break;
264 270
265 pr_debug("%s: req failed (CMD%u): %d, retrying...\n", 271 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
@@ -1456,7 +1462,7 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1456 WARN_ON(host->removed); 1462 WARN_ON(host->removed);
1457 spin_unlock_irqrestore(&host->lock, flags); 1463 spin_unlock_irqrestore(&host->lock, flags);
1458#endif 1464#endif
1459 1465 host->detect_change = 1;
1460 mmc_schedule_delayed_work(&host->detect, delay); 1466 mmc_schedule_delayed_work(&host->detect, delay);
1461} 1467}
1462 1468
@@ -2049,6 +2055,43 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
2049 return -EIO; 2055 return -EIO;
2050} 2056}
2051 2057
2058int _mmc_detect_card_removed(struct mmc_host *host)
2059{
2060 int ret;
2061
2062 if ((host->caps & MMC_CAP_NONREMOVABLE) || !host->bus_ops->alive)
2063 return 0;
2064
2065 if (!host->card || mmc_card_removed(host->card))
2066 return 1;
2067
2068 ret = host->bus_ops->alive(host);
2069 if (ret) {
2070 mmc_card_set_removed(host->card);
2071 pr_debug("%s: card remove detected\n", mmc_hostname(host));
2072 }
2073
2074 return ret;
2075}
2076
2077int mmc_detect_card_removed(struct mmc_host *host)
2078{
2079 struct mmc_card *card = host->card;
2080
2081 WARN_ON(!host->claimed);
2082 /*
2083 * The card will be considered unchanged unless we have been asked to
2084 * detect a change or host requires polling to provide card detection.
2085 */
2086 if (card && !host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL))
2087 return mmc_card_removed(card);
2088
2089 host->detect_change = 0;
2090
2091 return _mmc_detect_card_removed(host);
2092}
2093EXPORT_SYMBOL(mmc_detect_card_removed);
2094
2052void mmc_rescan(struct work_struct *work) 2095void mmc_rescan(struct work_struct *work)
2053{ 2096{
2054 static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; 2097 static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
@@ -2069,6 +2112,8 @@ void mmc_rescan(struct work_struct *work)
2069 && !(host->caps & MMC_CAP_NONREMOVABLE)) 2112 && !(host->caps & MMC_CAP_NONREMOVABLE))
2070 host->bus_ops->detect(host); 2113 host->bus_ops->detect(host);
2071 2114
2115 host->detect_change = 0;
2116
2072 /* 2117 /*
2073 * Let mmc_bus_put() free the bus/bus_ops if we've found that 2118 * Let mmc_bus_put() free the bus/bus_ops if we've found that
2074 * the card is no longer present. 2119 * the card is no longer present.
@@ -2130,6 +2175,7 @@ void mmc_stop_host(struct mmc_host *host)
2130 2175
2131 mmc_bus_get(host); 2176 mmc_bus_get(host);
2132 if (host->bus_ops && !host->bus_dead) { 2177 if (host->bus_ops && !host->bus_dead) {
2178 /* Calling bus_ops->remove() with a claimed host can deadlock */
2133 if (host->bus_ops->remove) 2179 if (host->bus_ops->remove)
2134 host->bus_ops->remove(host); 2180 host->bus_ops->remove(host);
2135 2181
@@ -2201,6 +2247,9 @@ int mmc_card_awake(struct mmc_host *host)
2201{ 2247{
2202 int err = -ENOSYS; 2248 int err = -ENOSYS;
2203 2249
2250 if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD)
2251 return 0;
2252
2204 mmc_bus_get(host); 2253 mmc_bus_get(host);
2205 2254
2206 if (host->bus_ops && !host->bus_dead && host->bus_ops->awake) 2255 if (host->bus_ops && !host->bus_dead && host->bus_ops->awake)
@@ -2216,6 +2265,9 @@ int mmc_card_sleep(struct mmc_host *host)
2216{ 2265{
2217 int err = -ENOSYS; 2266 int err = -ENOSYS;
2218 2267
2268 if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD)
2269 return 0;
2270
2219 mmc_bus_get(host); 2271 mmc_bus_get(host);
2220 2272
2221 if (host->bus_ops && !host->bus_dead && host->bus_ops->sleep) 2273 if (host->bus_ops && !host->bus_dead && host->bus_ops->sleep)
@@ -2270,6 +2322,7 @@ EXPORT_SYMBOL(mmc_flush_cache);
2270int mmc_cache_ctrl(struct mmc_host *host, u8 enable) 2322int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2271{ 2323{
2272 struct mmc_card *card = host->card; 2324 struct mmc_card *card = host->card;
2325 unsigned int timeout;
2273 int err = 0; 2326 int err = 0;
2274 2327
2275 if (!(host->caps2 & MMC_CAP2_CACHE_CTRL) || 2328 if (!(host->caps2 & MMC_CAP2_CACHE_CTRL) ||
@@ -2280,16 +2333,18 @@ int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2280 (card->ext_csd.cache_size > 0)) { 2333 (card->ext_csd.cache_size > 0)) {
2281 enable = !!enable; 2334 enable = !!enable;
2282 2335
2283 if (card->ext_csd.cache_ctrl ^ enable) 2336 if (card->ext_csd.cache_ctrl ^ enable) {
2337 timeout = enable ? card->ext_csd.generic_cmd6_time : 0;
2284 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 2338 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
2285 EXT_CSD_CACHE_CTRL, enable, 0); 2339 EXT_CSD_CACHE_CTRL, enable, timeout);
2286 if (err) 2340 if (err)
2287 pr_err("%s: cache %s error %d\n", 2341 pr_err("%s: cache %s error %d\n",
2288 mmc_hostname(card->host), 2342 mmc_hostname(card->host),
2289 enable ? "on" : "off", 2343 enable ? "on" : "off",
2290 err); 2344 err);
2291 else 2345 else
2292 card->ext_csd.cache_ctrl = enable; 2346 card->ext_csd.cache_ctrl = enable;
2347 }
2293 } 2348 }
2294 2349
2295 return err; 2350 return err;
@@ -2310,7 +2365,13 @@ int mmc_suspend_host(struct mmc_host *host)
2310 cancel_delayed_work(&host->disable); 2365 cancel_delayed_work(&host->disable);
2311 cancel_delayed_work(&host->detect); 2366 cancel_delayed_work(&host->detect);
2312 mmc_flush_scheduled_work(); 2367 mmc_flush_scheduled_work();
2313 err = mmc_cache_ctrl(host, 0); 2368 if (mmc_try_claim_host(host)) {
2369 err = mmc_cache_ctrl(host, 0);
2370 mmc_do_release_host(host);
2371 } else {
2372 err = -EBUSY;
2373 }
2374
2314 if (err) 2375 if (err)
2315 goto out; 2376 goto out;
2316 2377
@@ -2338,7 +2399,9 @@ int mmc_suspend_host(struct mmc_host *host)
2338 if (err == -ENOSYS || !host->bus_ops->resume) { 2399 if (err == -ENOSYS || !host->bus_ops->resume) {
2339 /* 2400 /*
2340 * We simply "remove" the card in this case. 2401 * We simply "remove" the card in this case.
2341 * It will be redetected on resume. 2402 * It will be redetected on resume. (Calling
2403 * bus_ops->remove() with a claimed host can
2404 * deadlock.)
2342 */ 2405 */
2343 if (host->bus_ops->remove) 2406 if (host->bus_ops->remove)
2344 host->bus_ops->remove(host); 2407 host->bus_ops->remove(host);
@@ -2431,11 +2494,11 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2431 if (!host->bus_ops || host->bus_ops->suspend) 2494 if (!host->bus_ops || host->bus_ops->suspend)
2432 break; 2495 break;
2433 2496
2434 mmc_claim_host(host); 2497 /* Calling bus_ops->remove() with a claimed host can deadlock */
2435
2436 if (host->bus_ops->remove) 2498 if (host->bus_ops->remove)
2437 host->bus_ops->remove(host); 2499 host->bus_ops->remove(host);
2438 2500
2501 mmc_claim_host(host);
2439 mmc_detach_bus(host); 2502 mmc_detach_bus(host);
2440 mmc_power_off(host); 2503 mmc_power_off(host);
2441 mmc_release_host(host); 2504 mmc_release_host(host);
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index afa6bd2b7b70..3bdafbca354f 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -24,6 +24,7 @@ struct mmc_bus_ops {
24 int (*resume)(struct mmc_host *); 24 int (*resume)(struct mmc_host *);
25 int (*power_save)(struct mmc_host *); 25 int (*power_save)(struct mmc_host *);
26 int (*power_restore)(struct mmc_host *); 26 int (*power_restore)(struct mmc_host *);
27 int (*alive)(struct mmc_host *);
27}; 28};
28 29
29void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); 30void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
@@ -59,6 +60,8 @@ void mmc_rescan(struct work_struct *work);
59void mmc_start_host(struct mmc_host *host); 60void mmc_start_host(struct mmc_host *host);
60void mmc_stop_host(struct mmc_host *host); 61void mmc_stop_host(struct mmc_host *host);
61 62
63int _mmc_detect_card_removed(struct mmc_host *host);
64
62int mmc_attach_mmc(struct mmc_host *host); 65int mmc_attach_mmc(struct mmc_host *host);
63int mmc_attach_sd(struct mmc_host *host); 66int mmc_attach_sd(struct mmc_host *host);
64int mmc_attach_sdio(struct mmc_host *host); 67int mmc_attach_sdio(struct mmc_host *host);
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 3923880118b6..9ab5b17d488a 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -57,6 +57,8 @@ static int mmc_ios_show(struct seq_file *s, void *data)
57 const char *str; 57 const char *str;
58 58
59 seq_printf(s, "clock:\t\t%u Hz\n", ios->clock); 59 seq_printf(s, "clock:\t\t%u Hz\n", ios->clock);
60 if (host->actual_clock)
61 seq_printf(s, "actual clock:\t%u Hz\n", host->actual_clock);
60 seq_printf(s, "vdd:\t\t%u ", ios->vdd); 62 seq_printf(s, "vdd:\t\t%u ", ios->vdd);
61 if ((1 << ios->vdd) & MMC_VDD_165_195) 63 if ((1 << ios->vdd) & MMC_VDD_165_195)
62 seq_printf(s, "(1.65 - 1.95 V)\n"); 64 seq_printf(s, "(1.65 - 1.95 V)\n");
@@ -133,6 +135,9 @@ static int mmc_ios_show(struct seq_file *s, void *data)
133 case MMC_TIMING_UHS_DDR50: 135 case MMC_TIMING_UHS_DDR50:
134 str = "sd uhs DDR50"; 136 str = "sd uhs DDR50";
135 break; 137 break;
138 case MMC_TIMING_MMC_HS200:
139 str = "mmc high-speed SDR200";
140 break;
136 default: 141 default:
137 str = "invalid"; 142 str = "invalid";
138 break; 143 break;
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index d31c78b72b0f..30055f2b0d44 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -54,6 +54,27 @@ static DEFINE_IDR(mmc_host_idr);
54static DEFINE_SPINLOCK(mmc_host_lock); 54static DEFINE_SPINLOCK(mmc_host_lock);
55 55
56#ifdef CONFIG_MMC_CLKGATE 56#ifdef CONFIG_MMC_CLKGATE
57static ssize_t clkgate_delay_show(struct device *dev,
58 struct device_attribute *attr, char *buf)
59{
60 struct mmc_host *host = cls_dev_to_mmc_host(dev);
61 return snprintf(buf, PAGE_SIZE, "%lu\n", host->clkgate_delay);
62}
63
64static ssize_t clkgate_delay_store(struct device *dev,
65 struct device_attribute *attr, const char *buf, size_t count)
66{
67 struct mmc_host *host = cls_dev_to_mmc_host(dev);
68 unsigned long flags, value;
69
70 if (kstrtoul(buf, 0, &value))
71 return -EINVAL;
72
73 spin_lock_irqsave(&host->clk_lock, flags);
74 host->clkgate_delay = value;
75 spin_unlock_irqrestore(&host->clk_lock, flags);
76 return count;
77}
57 78
58/* 79/*
59 * Enabling clock gating will make the core call out to the host 80 * Enabling clock gating will make the core call out to the host
@@ -114,7 +135,7 @@ static void mmc_host_clk_gate_delayed(struct mmc_host *host)
114static void mmc_host_clk_gate_work(struct work_struct *work) 135static void mmc_host_clk_gate_work(struct work_struct *work)
115{ 136{
116 struct mmc_host *host = container_of(work, struct mmc_host, 137 struct mmc_host *host = container_of(work, struct mmc_host,
117 clk_gate_work); 138 clk_gate_work.work);
118 139
119 mmc_host_clk_gate_delayed(host); 140 mmc_host_clk_gate_delayed(host);
120} 141}
@@ -131,6 +152,8 @@ void mmc_host_clk_hold(struct mmc_host *host)
131{ 152{
132 unsigned long flags; 153 unsigned long flags;
133 154
155 /* cancel any clock gating work scheduled by mmc_host_clk_release() */
156 cancel_delayed_work_sync(&host->clk_gate_work);
134 mutex_lock(&host->clk_gate_mutex); 157 mutex_lock(&host->clk_gate_mutex);
135 spin_lock_irqsave(&host->clk_lock, flags); 158 spin_lock_irqsave(&host->clk_lock, flags);
136 if (host->clk_gated) { 159 if (host->clk_gated) {
@@ -180,7 +203,8 @@ void mmc_host_clk_release(struct mmc_host *host)
180 host->clk_requests--; 203 host->clk_requests--;
181 if (mmc_host_may_gate_card(host->card) && 204 if (mmc_host_may_gate_card(host->card) &&
182 !host->clk_requests) 205 !host->clk_requests)
183 queue_work(system_nrt_wq, &host->clk_gate_work); 206 queue_delayed_work(system_nrt_wq, &host->clk_gate_work,
207 msecs_to_jiffies(host->clkgate_delay));
184 spin_unlock_irqrestore(&host->clk_lock, flags); 208 spin_unlock_irqrestore(&host->clk_lock, flags);
185} 209}
186 210
@@ -213,8 +237,13 @@ static inline void mmc_host_clk_init(struct mmc_host *host)
213 host->clk_requests = 0; 237 host->clk_requests = 0;
214 /* Hold MCI clock for 8 cycles by default */ 238 /* Hold MCI clock for 8 cycles by default */
215 host->clk_delay = 8; 239 host->clk_delay = 8;
240 /*
241 * Default clock gating delay is 200ms.
242 * This value can be tuned by writing into sysfs entry.
243 */
244 host->clkgate_delay = 200;
216 host->clk_gated = false; 245 host->clk_gated = false;
217 INIT_WORK(&host->clk_gate_work, mmc_host_clk_gate_work); 246 INIT_DELAYED_WORK(&host->clk_gate_work, mmc_host_clk_gate_work);
218 spin_lock_init(&host->clk_lock); 247 spin_lock_init(&host->clk_lock);
219 mutex_init(&host->clk_gate_mutex); 248 mutex_init(&host->clk_gate_mutex);
220} 249}
@@ -229,7 +258,7 @@ static inline void mmc_host_clk_exit(struct mmc_host *host)
229 * Wait for any outstanding gate and then make sure we're 258 * Wait for any outstanding gate and then make sure we're
230 * ungated before exiting. 259 * ungated before exiting.
231 */ 260 */
232 if (cancel_work_sync(&host->clk_gate_work)) 261 if (cancel_delayed_work_sync(&host->clk_gate_work))
233 mmc_host_clk_gate_delayed(host); 262 mmc_host_clk_gate_delayed(host);
234 if (host->clk_gated) 263 if (host->clk_gated)
235 mmc_host_clk_hold(host); 264 mmc_host_clk_hold(host);
@@ -237,6 +266,17 @@ static inline void mmc_host_clk_exit(struct mmc_host *host)
237 WARN_ON(host->clk_requests > 1); 266 WARN_ON(host->clk_requests > 1);
238} 267}
239 268
269static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
270{
271 host->clkgate_delay_attr.show = clkgate_delay_show;
272 host->clkgate_delay_attr.store = clkgate_delay_store;
273 sysfs_attr_init(&host->clkgate_delay_attr.attr);
274 host->clkgate_delay_attr.attr.name = "clkgate_delay";
275 host->clkgate_delay_attr.attr.mode = S_IRUGO | S_IWUSR;
276 if (device_create_file(&host->class_dev, &host->clkgate_delay_attr))
277 pr_err("%s: Failed to create clkgate_delay sysfs entry\n",
278 mmc_hostname(host));
279}
240#else 280#else
241 281
242static inline void mmc_host_clk_init(struct mmc_host *host) 282static inline void mmc_host_clk_init(struct mmc_host *host)
@@ -247,6 +287,10 @@ static inline void mmc_host_clk_exit(struct mmc_host *host)
247{ 287{
248} 288}
249 289
290static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
291{
292}
293
250#endif 294#endif
251 295
252/** 296/**
@@ -335,6 +379,7 @@ int mmc_add_host(struct mmc_host *host)
335#ifdef CONFIG_DEBUG_FS 379#ifdef CONFIG_DEBUG_FS
336 mmc_add_host_debugfs(host); 380 mmc_add_host_debugfs(host);
337#endif 381#endif
382 mmc_host_clk_sysfs_init(host);
338 383
339 mmc_start_host(host); 384 mmc_start_host(host);
340 register_pm_notifier(&host->pm_notify); 385 register_pm_notifier(&host->pm_notify);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index d240427c1246..59b9ba52e66a 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -286,6 +286,27 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
286 } 286 }
287 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; 287 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE];
288 switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { 288 switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) {
289 case EXT_CSD_CARD_TYPE_SDR_ALL:
290 case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_8V:
291 case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_2V:
292 case EXT_CSD_CARD_TYPE_SDR_ALL_DDR_52:
293 card->ext_csd.hs_max_dtr = 200000000;
294 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_200;
295 break;
296 case EXT_CSD_CARD_TYPE_SDR_1_2V_ALL:
297 case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_8V:
298 case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_2V:
299 case EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_52:
300 card->ext_csd.hs_max_dtr = 200000000;
301 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_2V;
302 break;
303 case EXT_CSD_CARD_TYPE_SDR_1_8V_ALL:
304 case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_8V:
305 case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_2V:
306 case EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_52:
307 card->ext_csd.hs_max_dtr = 200000000;
308 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_SDR_1_8V;
309 break;
289 case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 | 310 case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 |
290 EXT_CSD_CARD_TYPE_26: 311 EXT_CSD_CARD_TYPE_26:
291 card->ext_csd.hs_max_dtr = 52000000; 312 card->ext_csd.hs_max_dtr = 52000000;
@@ -348,7 +369,8 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
348 part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; 369 part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
349 mmc_part_add(card, part_size, 370 mmc_part_add(card, part_size,
350 EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, 371 EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx,
351 "boot%d", idx, true); 372 "boot%d", idx, true,
373 MMC_BLK_DATA_AREA_BOOT);
352 } 374 }
353 } 375 }
354 } 376 }
@@ -435,7 +457,8 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
435 hc_wp_grp_sz); 457 hc_wp_grp_sz);
436 mmc_part_add(card, part_size << 19, 458 mmc_part_add(card, part_size << 19,
437 EXT_CSD_PART_CONFIG_ACC_GP0 + idx, 459 EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
438 "gp%d", idx, false); 460 "gp%d", idx, false,
461 MMC_BLK_DATA_AREA_GP);
439 } 462 }
440 } 463 }
441 card->ext_csd.sec_trim_mult = 464 card->ext_csd.sec_trim_mult =
@@ -446,6 +469,14 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
446 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; 469 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
447 card->ext_csd.trim_timeout = 300 * 470 card->ext_csd.trim_timeout = 300 *
448 ext_csd[EXT_CSD_TRIM_MULT]; 471 ext_csd[EXT_CSD_TRIM_MULT];
472
473 /*
474 * Note that the call to mmc_part_add above defaults to read
475 * only. If this default assumption is changed, the call must
476 * take into account the value of boot_locked below.
477 */
478 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP];
479 card->ext_csd.boot_ro_lockable = true;
449 } 480 }
450 481
451 if (card->ext_csd.rev >= 5) { 482 if (card->ext_csd.rev >= 5) {
@@ -690,6 +721,79 @@ static int mmc_select_powerclass(struct mmc_card *card,
690} 721}
691 722
692/* 723/*
724 * Selects the desired buswidth and switch to the HS200 mode
725 * if bus width set without error
726 */
727static int mmc_select_hs200(struct mmc_card *card)
728{
729 int idx, err = 0;
730 struct mmc_host *host;
731 static unsigned ext_csd_bits[] = {
732 EXT_CSD_BUS_WIDTH_4,
733 EXT_CSD_BUS_WIDTH_8,
734 };
735 static unsigned bus_widths[] = {
736 MMC_BUS_WIDTH_4,
737 MMC_BUS_WIDTH_8,
738 };
739
740 BUG_ON(!card);
741
742 host = card->host;
743
744 if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V &&
745 host->caps2 & MMC_CAP2_HS200_1_2V_SDR)
746 if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0))
747 err = mmc_set_signal_voltage(host,
748 MMC_SIGNAL_VOLTAGE_180, 0);
749
750 /* If fails try again during next card power cycle */
751 if (err)
752 goto err;
753
754 idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0;
755
756 /*
757 * Unlike SD, MMC cards dont have a configuration register to notify
758 * supported bus width. So bus test command should be run to identify
759 * the supported bus width or compare the ext csd values of current
760 * bus width and ext csd values of 1 bit mode read earlier.
761 */
762 for (; idx >= 0; idx--) {
763
764 /*
765 * Host is capable of 8bit transfer, then switch
766 * the device to work in 8bit transfer mode. If the
767 * mmc switch command returns error then switch to
768 * 4bit transfer mode. On success set the corresponding
769 * bus width on the host.
770 */
771 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
772 EXT_CSD_BUS_WIDTH,
773 ext_csd_bits[idx],
774 card->ext_csd.generic_cmd6_time);
775 if (err)
776 continue;
777
778 mmc_set_bus_width(card->host, bus_widths[idx]);
779
780 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST))
781 err = mmc_compare_ext_csds(card, bus_widths[idx]);
782 else
783 err = mmc_bus_test(card, bus_widths[idx]);
784 if (!err)
785 break;
786 }
787
788 /* switch to HS200 mode if bus width set successfully */
789 if (!err)
790 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
791 EXT_CSD_HS_TIMING, 2, 0);
792err:
793 return err;
794}
795
796/*
693 * Handle the detection and initialisation of a card. 797 * Handle the detection and initialisation of a card.
694 * 798 *
695 * In the case of a resume, "oldcard" will contain the card 799 * In the case of a resume, "oldcard" will contain the card
@@ -895,11 +999,15 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
895 /* 999 /*
896 * Activate high speed (if supported) 1000 * Activate high speed (if supported)
897 */ 1001 */
898 if ((card->ext_csd.hs_max_dtr != 0) && 1002 if (card->ext_csd.hs_max_dtr != 0) {
899 (host->caps & MMC_CAP_MMC_HIGHSPEED)) { 1003 err = 0;
900 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1004 if (card->ext_csd.hs_max_dtr > 52000000 &&
901 EXT_CSD_HS_TIMING, 1, 1005 host->caps2 & MMC_CAP2_HS200)
902 card->ext_csd.generic_cmd6_time); 1006 err = mmc_select_hs200(card);
1007 else if (host->caps & MMC_CAP_MMC_HIGHSPEED)
1008 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1009 EXT_CSD_HS_TIMING, 1, 0);
1010
903 if (err && err != -EBADMSG) 1011 if (err && err != -EBADMSG)
904 goto free_card; 1012 goto free_card;
905 1013
@@ -908,8 +1016,15 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
908 mmc_hostname(card->host)); 1016 mmc_hostname(card->host));
909 err = 0; 1017 err = 0;
910 } else { 1018 } else {
911 mmc_card_set_highspeed(card); 1019 if (card->ext_csd.hs_max_dtr > 52000000 &&
912 mmc_set_timing(card->host, MMC_TIMING_MMC_HS); 1020 host->caps2 & MMC_CAP2_HS200) {
1021 mmc_card_set_hs200(card);
1022 mmc_set_timing(card->host,
1023 MMC_TIMING_MMC_HS200);
1024 } else {
1025 mmc_card_set_highspeed(card);
1026 mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
1027 }
913 } 1028 }
914 } 1029 }
915 1030
@@ -934,7 +1049,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
934 */ 1049 */
935 max_dtr = (unsigned int)-1; 1050 max_dtr = (unsigned int)-1;
936 1051
937 if (mmc_card_highspeed(card)) { 1052 if (mmc_card_highspeed(card) || mmc_card_hs200(card)) {
938 if (max_dtr > card->ext_csd.hs_max_dtr) 1053 if (max_dtr > card->ext_csd.hs_max_dtr)
939 max_dtr = card->ext_csd.hs_max_dtr; 1054 max_dtr = card->ext_csd.hs_max_dtr;
940 } else if (max_dtr > card->csd.max_dtr) { 1055 } else if (max_dtr > card->csd.max_dtr) {
@@ -960,9 +1075,48 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
960 } 1075 }
961 1076
962 /* 1077 /*
1078 * Indicate HS200 SDR mode (if supported).
1079 */
1080 if (mmc_card_hs200(card)) {
1081 u32 ext_csd_bits;
1082 u32 bus_width = card->host->ios.bus_width;
1083
1084 /*
1085 * For devices supporting HS200 mode, the bus width has
1086 * to be set before executing the tuning function. If
1087 * set before tuning, then device will respond with CRC
1088 * errors for responses on CMD line. So for HS200 the
1089 * sequence will be
1090 * 1. set bus width 4bit / 8 bit (1 bit not supported)
1091 * 2. switch to HS200 mode
1092 * 3. set the clock to > 52Mhz <=200MHz and
1093 * 4. execute tuning for HS200
1094 */
1095 if ((host->caps2 & MMC_CAP2_HS200) &&
1096 card->host->ops->execute_tuning)
1097 err = card->host->ops->execute_tuning(card->host,
1098 MMC_SEND_TUNING_BLOCK_HS200);
1099 if (err) {
1100 pr_warning("%s: tuning execution failed\n",
1101 mmc_hostname(card->host));
1102 goto err;
1103 }
1104
1105 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ?
1106 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4;
1107 err = mmc_select_powerclass(card, ext_csd_bits, ext_csd);
1108 if (err) {
1109 pr_err("%s: power class selection to bus width %d failed\n",
1110 mmc_hostname(card->host), 1 << bus_width);
1111 goto err;
1112 }
1113 }
1114
1115 /*
963 * Activate wide bus and DDR (if supported). 1116 * Activate wide bus and DDR (if supported).
964 */ 1117 */
965 if ((card->csd.mmca_vsn >= CSD_SPEC_VER_4) && 1118 if (!mmc_card_hs200(card) &&
1119 (card->csd.mmca_vsn >= CSD_SPEC_VER_3) &&
966 (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { 1120 (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) {
967 static unsigned ext_csd_bits[][2] = { 1121 static unsigned ext_csd_bits[][2] = {
968 { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, 1122 { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 },
@@ -1048,7 +1202,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1048 * 1202 *
1049 * WARNING: eMMC rules are NOT the same as SD DDR 1203 * WARNING: eMMC rules are NOT the same as SD DDR
1050 */ 1204 */
1051 if (ddr == EXT_CSD_CARD_TYPE_DDR_1_2V) { 1205 if (ddr == MMC_1_2V_DDR_MODE) {
1052 err = mmc_set_signal_voltage(host, 1206 err = mmc_set_signal_voltage(host,
1053 MMC_SIGNAL_VOLTAGE_120, 0); 1207 MMC_SIGNAL_VOLTAGE_120, 0);
1054 if (err) 1208 if (err)
@@ -1067,14 +1221,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1067 if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && 1221 if ((host->caps2 & MMC_CAP2_CACHE_CTRL) &&
1068 card->ext_csd.cache_size > 0) { 1222 card->ext_csd.cache_size > 0) {
1069 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1223 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1070 EXT_CSD_CACHE_CTRL, 1, 0); 1224 EXT_CSD_CACHE_CTRL, 1,
1225 card->ext_csd.generic_cmd6_time);
1071 if (err && err != -EBADMSG) 1226 if (err && err != -EBADMSG)
1072 goto free_card; 1227 goto free_card;
1073 1228
1074 /* 1229 /*
1075 * Only if no error, cache is turned on successfully. 1230 * Only if no error, cache is turned on successfully.
1076 */ 1231 */
1077 card->ext_csd.cache_ctrl = err ? 0 : 1; 1232 if (err) {
1233 pr_warning("%s: Cache is supported, "
1234 "but failed to turn on (%d)\n",
1235 mmc_hostname(card->host), err);
1236 card->ext_csd.cache_ctrl = 0;
1237 err = 0;
1238 } else {
1239 card->ext_csd.cache_ctrl = 1;
1240 }
1078 } 1241 }
1079 1242
1080 if (!oldcard) 1243 if (!oldcard)
@@ -1105,6 +1268,14 @@ static void mmc_remove(struct mmc_host *host)
1105} 1268}
1106 1269
1107/* 1270/*
1271 * Card detection - card is alive.
1272 */
1273static int mmc_alive(struct mmc_host *host)
1274{
1275 return mmc_send_status(host->card, NULL);
1276}
1277
1278/*
1108 * Card detection callback from host. 1279 * Card detection callback from host.
1109 */ 1280 */
1110static void mmc_detect(struct mmc_host *host) 1281static void mmc_detect(struct mmc_host *host)
@@ -1119,7 +1290,7 @@ static void mmc_detect(struct mmc_host *host)
1119 /* 1290 /*
1120 * Just check if our card has been removed. 1291 * Just check if our card has been removed.
1121 */ 1292 */
1122 err = mmc_send_status(host->card, NULL); 1293 err = _mmc_detect_card_removed(host);
1123 1294
1124 mmc_release_host(host); 1295 mmc_release_host(host);
1125 1296
@@ -1224,6 +1395,7 @@ static const struct mmc_bus_ops mmc_ops = {
1224 .suspend = NULL, 1395 .suspend = NULL,
1225 .resume = NULL, 1396 .resume = NULL,
1226 .power_restore = mmc_power_restore, 1397 .power_restore = mmc_power_restore,
1398 .alive = mmc_alive,
1227}; 1399};
1228 1400
1229static const struct mmc_bus_ops mmc_ops_unsafe = { 1401static const struct mmc_bus_ops mmc_ops_unsafe = {
@@ -1234,6 +1406,7 @@ static const struct mmc_bus_ops mmc_ops_unsafe = {
1234 .suspend = mmc_suspend, 1406 .suspend = mmc_suspend,
1235 .resume = mmc_resume, 1407 .resume = mmc_resume,
1236 .power_restore = mmc_power_restore, 1408 .power_restore = mmc_power_restore,
1409 .alive = mmc_alive,
1237}; 1410};
1238 1411
1239static void mmc_attach_bus_ops(struct mmc_host *host) 1412static void mmc_attach_bus_ops(struct mmc_host *host)
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index f2a05ea40f2a..c63ad03c29c7 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -307,8 +307,8 @@ static int mmc_read_switch(struct mmc_card *card)
307 goto out; 307 goto out;
308 } 308 }
309 309
310 if (status[13] & UHS_SDR50_BUS_SPEED) 310 if (status[13] & SD_MODE_HIGH_SPEED)
311 card->sw_caps.hs_max_dtr = 50000000; 311 card->sw_caps.hs_max_dtr = HIGH_SPEED_MAX_DTR;
312 312
313 if (card->scr.sda_spec3) { 313 if (card->scr.sda_spec3) {
314 card->sw_caps.sd3_bus_mode = status[13]; 314 card->sw_caps.sd3_bus_mode = status[13];
@@ -661,7 +661,8 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
661 661
662 /* SPI mode doesn't define CMD19 */ 662 /* SPI mode doesn't define CMD19 */
663 if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning) 663 if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
664 err = card->host->ops->execute_tuning(card->host); 664 err = card->host->ops->execute_tuning(card->host,
665 MMC_SEND_TUNING_BLOCK);
665 666
666out: 667out:
667 kfree(status); 668 kfree(status);
@@ -960,7 +961,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
960 goto free_card; 961 goto free_card;
961 962
962 /* Card is an ultra-high-speed card */ 963 /* Card is an ultra-high-speed card */
963 mmc_sd_card_set_uhs(card); 964 mmc_card_set_uhs(card);
964 965
965 /* 966 /*
966 * Since initialization is now complete, enable preset 967 * Since initialization is now complete, enable preset
@@ -1019,6 +1020,14 @@ static void mmc_sd_remove(struct mmc_host *host)
1019} 1020}
1020 1021
1021/* 1022/*
1023 * Card detection - card is alive.
1024 */
1025static int mmc_sd_alive(struct mmc_host *host)
1026{
1027 return mmc_send_status(host->card, NULL);
1028}
1029
1030/*
1022 * Card detection callback from host. 1031 * Card detection callback from host.
1023 */ 1032 */
1024static void mmc_sd_detect(struct mmc_host *host) 1033static void mmc_sd_detect(struct mmc_host *host)
@@ -1033,7 +1042,7 @@ static void mmc_sd_detect(struct mmc_host *host)
1033 /* 1042 /*
1034 * Just check if our card has been removed. 1043 * Just check if our card has been removed.
1035 */ 1044 */
1036 err = mmc_send_status(host->card, NULL); 1045 err = _mmc_detect_card_removed(host);
1037 1046
1038 mmc_release_host(host); 1047 mmc_release_host(host);
1039 1048
@@ -1102,6 +1111,7 @@ static const struct mmc_bus_ops mmc_sd_ops = {
1102 .suspend = NULL, 1111 .suspend = NULL,
1103 .resume = NULL, 1112 .resume = NULL,
1104 .power_restore = mmc_sd_power_restore, 1113 .power_restore = mmc_sd_power_restore,
1114 .alive = mmc_sd_alive,
1105}; 1115};
1106 1116
1107static const struct mmc_bus_ops mmc_sd_ops_unsafe = { 1117static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
@@ -1110,6 +1120,7 @@ static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
1110 .suspend = mmc_sd_suspend, 1120 .suspend = mmc_sd_suspend,
1111 .resume = mmc_sd_resume, 1121 .resume = mmc_sd_resume,
1112 .power_restore = mmc_sd_power_restore, 1122 .power_restore = mmc_sd_power_restore,
1123 .alive = mmc_sd_alive,
1113}; 1124};
1114 1125
1115static void mmc_sd_attach_bus_ops(struct mmc_host *host) 1126static void mmc_sd_attach_bus_ops(struct mmc_host *host)
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 3ab565e32a6a..bd7bacc950dc 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/mmc/host.h> 15#include <linux/mmc/host.h>
16#include <linux/mmc/card.h> 16#include <linux/mmc/card.h>
17#include <linux/mmc/mmc.h>
17#include <linux/mmc/sdio.h> 18#include <linux/mmc/sdio.h>
18#include <linux/mmc/sdio_func.h> 19#include <linux/mmc/sdio_func.h>
19#include <linux/mmc/sdio_ids.h> 20#include <linux/mmc/sdio_ids.h>
@@ -102,6 +103,7 @@ static int sdio_read_cccr(struct mmc_card *card)
102 int ret; 103 int ret;
103 int cccr_vsn; 104 int cccr_vsn;
104 unsigned char data; 105 unsigned char data;
106 unsigned char speed;
105 107
106 memset(&card->cccr, 0, sizeof(struct sdio_cccr)); 108 memset(&card->cccr, 0, sizeof(struct sdio_cccr));
107 109
@@ -140,12 +142,60 @@ static int sdio_read_cccr(struct mmc_card *card)
140 } 142 }
141 143
142 if (cccr_vsn >= SDIO_CCCR_REV_1_20) { 144 if (cccr_vsn >= SDIO_CCCR_REV_1_20) {
143 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &data); 145 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed);
144 if (ret) 146 if (ret)
145 goto out; 147 goto out;
146 148
147 if (data & SDIO_SPEED_SHS) 149 card->scr.sda_spec3 = 0;
148 card->cccr.high_speed = 1; 150 card->sw_caps.sd3_bus_mode = 0;
151 card->sw_caps.sd3_drv_type = 0;
152 if (cccr_vsn >= SDIO_CCCR_REV_3_00) {
153 card->scr.sda_spec3 = 1;
154 ret = mmc_io_rw_direct(card, 0, 0,
155 SDIO_CCCR_UHS, 0, &data);
156 if (ret)
157 goto out;
158
159 if (card->host->caps &
160 (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
161 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |
162 MMC_CAP_UHS_DDR50)) {
163 if (data & SDIO_UHS_DDR50)
164 card->sw_caps.sd3_bus_mode
165 |= SD_MODE_UHS_DDR50;
166
167 if (data & SDIO_UHS_SDR50)
168 card->sw_caps.sd3_bus_mode
169 |= SD_MODE_UHS_SDR50;
170
171 if (data & SDIO_UHS_SDR104)
172 card->sw_caps.sd3_bus_mode
173 |= SD_MODE_UHS_SDR104;
174 }
175
176 ret = mmc_io_rw_direct(card, 0, 0,
177 SDIO_CCCR_DRIVE_STRENGTH, 0, &data);
178 if (ret)
179 goto out;
180
181 if (data & SDIO_DRIVE_SDTA)
182 card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_A;
183 if (data & SDIO_DRIVE_SDTC)
184 card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_C;
185 if (data & SDIO_DRIVE_SDTD)
186 card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_D;
187 }
188
189 /* if no uhs mode ensure we check for high speed */
190 if (!card->sw_caps.sd3_bus_mode) {
191 if (speed & SDIO_SPEED_SHS) {
192 card->cccr.high_speed = 1;
193 card->sw_caps.hs_max_dtr = 50000000;
194 } else {
195 card->cccr.high_speed = 0;
196 card->sw_caps.hs_max_dtr = 25000000;
197 }
198 }
149 } 199 }
150 200
151out: 201out:
@@ -327,6 +377,194 @@ static unsigned mmc_sdio_get_max_clock(struct mmc_card *card)
327 return max_dtr; 377 return max_dtr;
328} 378}
329 379
380static unsigned char host_drive_to_sdio_drive(int host_strength)
381{
382 switch (host_strength) {
383 case MMC_SET_DRIVER_TYPE_A:
384 return SDIO_DTSx_SET_TYPE_A;
385 case MMC_SET_DRIVER_TYPE_B:
386 return SDIO_DTSx_SET_TYPE_B;
387 case MMC_SET_DRIVER_TYPE_C:
388 return SDIO_DTSx_SET_TYPE_C;
389 case MMC_SET_DRIVER_TYPE_D:
390 return SDIO_DTSx_SET_TYPE_D;
391 default:
392 return SDIO_DTSx_SET_TYPE_B;
393 }
394}
395
396static void sdio_select_driver_type(struct mmc_card *card)
397{
398 int host_drv_type = SD_DRIVER_TYPE_B;
399 int card_drv_type = SD_DRIVER_TYPE_B;
400 int drive_strength;
401 unsigned char card_strength;
402 int err;
403
404 /*
405 * If the host doesn't support any of the Driver Types A,C or D,
406 * or there is no board specific handler then default Driver
407 * Type B is used.
408 */
409 if (!(card->host->caps &
410 (MMC_CAP_DRIVER_TYPE_A |
411 MMC_CAP_DRIVER_TYPE_C |
412 MMC_CAP_DRIVER_TYPE_D)))
413 return;
414
415 if (!card->host->ops->select_drive_strength)
416 return;
417
418 if (card->host->caps & MMC_CAP_DRIVER_TYPE_A)
419 host_drv_type |= SD_DRIVER_TYPE_A;
420
421 if (card->host->caps & MMC_CAP_DRIVER_TYPE_C)
422 host_drv_type |= SD_DRIVER_TYPE_C;
423
424 if (card->host->caps & MMC_CAP_DRIVER_TYPE_D)
425 host_drv_type |= SD_DRIVER_TYPE_D;
426
427 if (card->sw_caps.sd3_drv_type & SD_DRIVER_TYPE_A)
428 card_drv_type |= SD_DRIVER_TYPE_A;
429
430 if (card->sw_caps.sd3_drv_type & SD_DRIVER_TYPE_C)
431 card_drv_type |= SD_DRIVER_TYPE_C;
432
433 if (card->sw_caps.sd3_drv_type & SD_DRIVER_TYPE_D)
434 card_drv_type |= SD_DRIVER_TYPE_D;
435
436 /*
437 * The drive strength that the hardware can support
438 * depends on the board design. Pass the appropriate
439 * information and let the hardware specific code
440 * return what is possible given the options
441 */
442 drive_strength = card->host->ops->select_drive_strength(
443 card->sw_caps.uhs_max_dtr,
444 host_drv_type, card_drv_type);
445
446 /* if error just use default for drive strength B */
447 err = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_DRIVE_STRENGTH, 0,
448 &card_strength);
449 if (err)
450 return;
451
452 card_strength &= ~(SDIO_DRIVE_DTSx_MASK<<SDIO_DRIVE_DTSx_SHIFT);
453 card_strength |= host_drive_to_sdio_drive(drive_strength);
454
455 err = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_DRIVE_STRENGTH,
456 card_strength, NULL);
457
458 /* if error default to drive strength B */
459 if (!err)
460 mmc_set_driver_type(card->host, drive_strength);
461}
462
463
464static int sdio_set_bus_speed_mode(struct mmc_card *card)
465{
466 unsigned int bus_speed, timing;
467 int err;
468 unsigned char speed;
469
470 /*
471 * If the host doesn't support any of the UHS-I modes, fallback on
472 * default speed.
473 */
474 if (!(card->host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
475 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)))
476 return 0;
477
478 bus_speed = SDIO_SPEED_SDR12;
479 timing = MMC_TIMING_UHS_SDR12;
480 if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
481 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
482 bus_speed = SDIO_SPEED_SDR104;
483 timing = MMC_TIMING_UHS_SDR104;
484 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
485 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
486 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
487 bus_speed = SDIO_SPEED_DDR50;
488 timing = MMC_TIMING_UHS_DDR50;
489 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
490 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
491 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
492 SD_MODE_UHS_SDR50)) {
493 bus_speed = SDIO_SPEED_SDR50;
494 timing = MMC_TIMING_UHS_SDR50;
495 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
496 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
497 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
498 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
499 bus_speed = SDIO_SPEED_SDR25;
500 timing = MMC_TIMING_UHS_SDR25;
501 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
502 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
503 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
504 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
505 SD_MODE_UHS_SDR12)) {
506 bus_speed = SDIO_SPEED_SDR12;
507 timing = MMC_TIMING_UHS_SDR12;
508 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
509 }
510
511 err = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed);
512 if (err)
513 return err;
514
515 speed &= ~SDIO_SPEED_BSS_MASK;
516 speed |= bus_speed;
517 err = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL);
518 if (err)
519 return err;
520
521 if (bus_speed) {
522 mmc_set_timing(card->host, timing);
523 mmc_set_clock(card->host, card->sw_caps.uhs_max_dtr);
524 }
525
526 return 0;
527}
528
529/*
530 * UHS-I specific initialization procedure
531 */
532static int mmc_sdio_init_uhs_card(struct mmc_card *card)
533{
534 int err;
535
536 if (!card->scr.sda_spec3)
537 return 0;
538
539 /*
540 * Switch to wider bus (if supported).
541 */
542 if (card->host->caps & MMC_CAP_4_BIT_DATA) {
543 err = sdio_enable_4bit_bus(card);
544 if (err > 0) {
545 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
546 err = 0;
547 }
548 }
549
550 /* Set the driver strength for the card */
551 sdio_select_driver_type(card);
552
553 /* Set bus speed mode of the card */
554 err = sdio_set_bus_speed_mode(card);
555 if (err)
556 goto out;
557
558 /* Initialize and start re-tuning timer */
559 if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
560 err = card->host->ops->execute_tuning(card->host,
561 MMC_SEND_TUNING_BLOCK);
562
563out:
564
565 return err;
566}
567
330/* 568/*
331 * Handle the detection and initialisation of a card. 569 * Handle the detection and initialisation of a card.
332 * 570 *
@@ -394,6 +632,30 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
394 host->ops->init_card(host, card); 632 host->ops->init_card(host, card);
395 633
396 /* 634 /*
635 * If the host and card support UHS-I mode request the card
636 * to switch to 1.8V signaling level. No 1.8v signalling if
637 * UHS mode is not enabled to maintain compatibilty and some
638 * systems that claim 1.8v signalling in fact do not support
639 * it.
640 */
641 if ((ocr & R4_18V_PRESENT) &&
642 (host->caps &
643 (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
644 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |
645 MMC_CAP_UHS_DDR50))) {
646 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
647 true);
648 if (err) {
649 ocr &= ~R4_18V_PRESENT;
650 host->ocr &= ~R4_18V_PRESENT;
651 }
652 err = 0;
653 } else {
654 ocr &= ~R4_18V_PRESENT;
655 host->ocr &= ~R4_18V_PRESENT;
656 }
657
658 /*
397 * For native busses: set card RCA and quit open drain mode. 659 * For native busses: set card RCA and quit open drain mode.
398 */ 660 */
399 if (!powered_resume && !mmc_host_is_spi(host)) { 661 if (!powered_resume && !mmc_host_is_spi(host)) {
@@ -492,29 +754,39 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
492 if (err) 754 if (err)
493 goto remove; 755 goto remove;
494 756
495 /* 757 /* Initialization sequence for UHS-I cards */
496 * Switch to high-speed (if supported). 758 /* Only if card supports 1.8v and UHS signaling */
497 */ 759 if ((ocr & R4_18V_PRESENT) && card->sw_caps.sd3_bus_mode) {
498 err = sdio_enable_hs(card); 760 err = mmc_sdio_init_uhs_card(card);
499 if (err > 0) 761 if (err)
500 mmc_sd_go_highspeed(card); 762 goto remove;
501 else if (err)
502 goto remove;
503 763
504 /* 764 /* Card is an ultra-high-speed card */
505 * Change to the card's maximum speed. 765 mmc_card_set_uhs(card);
506 */ 766 } else {
507 mmc_set_clock(host, mmc_sdio_get_max_clock(card)); 767 /*
768 * Switch to high-speed (if supported).
769 */
770 err = sdio_enable_hs(card);
771 if (err > 0)
772 mmc_sd_go_highspeed(card);
773 else if (err)
774 goto remove;
508 775
509 /* 776 /*
510 * Switch to wider bus (if supported). 777 * Change to the card's maximum speed.
511 */ 778 */
512 err = sdio_enable_4bit_bus(card); 779 mmc_set_clock(host, mmc_sdio_get_max_clock(card));
513 if (err > 0)
514 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
515 else if (err)
516 goto remove;
517 780
781 /*
782 * Switch to wider bus (if supported).
783 */
784 err = sdio_enable_4bit_bus(card);
785 if (err > 0)
786 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
787 else if (err)
788 goto remove;
789 }
518finish: 790finish:
519 if (!oldcard) 791 if (!oldcard)
520 host->card = card; 792 host->card = card;
@@ -550,6 +822,14 @@ static void mmc_sdio_remove(struct mmc_host *host)
550} 822}
551 823
552/* 824/*
825 * Card detection - card is alive.
826 */
827static int mmc_sdio_alive(struct mmc_host *host)
828{
829 return mmc_select_card(host->card);
830}
831
832/*
553 * Card detection callback from host. 833 * Card detection callback from host.
554 */ 834 */
555static void mmc_sdio_detect(struct mmc_host *host) 835static void mmc_sdio_detect(struct mmc_host *host)
@@ -571,7 +851,7 @@ static void mmc_sdio_detect(struct mmc_host *host)
571 /* 851 /*
572 * Just check if our card has been removed. 852 * Just check if our card has been removed.
573 */ 853 */
574 err = mmc_select_card(host->card); 854 err = _mmc_detect_card_removed(host);
575 855
576 mmc_release_host(host); 856 mmc_release_host(host);
577 857
@@ -749,6 +1029,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = {
749 .suspend = mmc_sdio_suspend, 1029 .suspend = mmc_sdio_suspend,
750 .resume = mmc_sdio_resume, 1030 .resume = mmc_sdio_resume,
751 .power_restore = mmc_sdio_power_restore, 1031 .power_restore = mmc_sdio_power_restore,
1032 .alive = mmc_sdio_alive,
752}; 1033};
753 1034
754 1035
@@ -797,8 +1078,17 @@ int mmc_attach_sdio(struct mmc_host *host)
797 * Detect and init the card. 1078 * Detect and init the card.
798 */ 1079 */
799 err = mmc_sdio_init_card(host, host->ocr, NULL, 0); 1080 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
800 if (err) 1081 if (err) {
801 goto err; 1082 if (err == -EAGAIN) {
1083 /*
1084 * Retry initialization with S18R set to 0.
1085 */
1086 host->ocr &= ~R4_18V_PRESENT;
1087 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
1088 }
1089 if (err)
1090 goto err;
1091 }
802 card = host->card; 1092 card = host->card;
803 1093
804 /* 1094 /*
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c
index b1f3168f791b..8f6f5ac131fc 100644
--- a/drivers/mmc/core/sdio_io.c
+++ b/drivers/mmc/core/sdio_io.c
@@ -196,6 +196,9 @@ static inline unsigned int sdio_max_byte_size(struct sdio_func *func)
196 else 196 else
197 mval = min(mval, func->max_blksize); 197 mval = min(mval, func->max_blksize);
198 198
199 if (mmc_card_broken_byte_mode_512(func->card))
200 return min(mval, 511u);
201
199 return min(mval, 512u); /* maximum size for byte mode */ 202 return min(mval, 512u); /* maximum size for byte mode */
200} 203}
201 204
@@ -314,7 +317,7 @@ static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
314 func->card->host->max_seg_size / func->cur_blksize); 317 func->card->host->max_seg_size / func->cur_blksize);
315 max_blocks = min(max_blocks, 511u); 318 max_blocks = min(max_blocks, 511u);
316 319
317 while (remainder > func->cur_blksize) { 320 while (remainder >= func->cur_blksize) {
318 unsigned blocks; 321 unsigned blocks;
319 322
320 blocks = remainder / func->cur_blksize; 323 blocks = remainder / func->cur_blksize;
@@ -339,8 +342,9 @@ static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
339 while (remainder > 0) { 342 while (remainder > 0) {
340 size = min(remainder, sdio_max_byte_size(func)); 343 size = min(remainder, sdio_max_byte_size(func));
341 344
345 /* Indicate byte mode by setting "blocks" = 0 */
342 ret = mmc_io_rw_extended(func->card, write, func->num, addr, 346 ret = mmc_io_rw_extended(func->card, write, func->num, addr,
343 incr_addr, buf, 1, size); 347 incr_addr, buf, 0, size);
344 if (ret) 348 if (ret)
345 return ret; 349 return ret;
346 350
diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c
index b0517cc06200..d29e20630eed 100644
--- a/drivers/mmc/core/sdio_ops.c
+++ b/drivers/mmc/core/sdio_ops.c
@@ -128,8 +128,6 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
128 128
129 BUG_ON(!card); 129 BUG_ON(!card);
130 BUG_ON(fn > 7); 130 BUG_ON(fn > 7);
131 BUG_ON(blocks == 1 && blksz > 512);
132 WARN_ON(blocks == 0);
133 WARN_ON(blksz == 0); 131 WARN_ON(blksz == 0);
134 132
135 /* sanity check */ 133 /* sanity check */
@@ -144,22 +142,20 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
144 cmd.arg |= fn << 28; 142 cmd.arg |= fn << 28;
145 cmd.arg |= incr_addr ? 0x04000000 : 0x00000000; 143 cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
146 cmd.arg |= addr << 9; 144 cmd.arg |= addr << 9;
147 if (blocks == 1 && blksz < 512) 145 if (blocks == 0)
148 cmd.arg |= blksz; /* byte mode */ 146 cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */
149 else if (blocks == 1 && blksz == 512 &&
150 !(mmc_card_broken_byte_mode_512(card)))
151 cmd.arg |= 0; /* byte mode, 0==512 */
152 else 147 else
153 cmd.arg |= 0x08000000 | blocks; /* block mode */ 148 cmd.arg |= 0x08000000 | blocks; /* block mode */
154 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC; 149 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
155 150
156 data.blksz = blksz; 151 data.blksz = blksz;
157 data.blocks = blocks; 152 /* Code in host drivers/fwk assumes that "blocks" always is >=1 */
153 data.blocks = blocks ? blocks : 1;
158 data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; 154 data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
159 data.sg = &sg; 155 data.sg = &sg;
160 data.sg_len = 1; 156 data.sg_len = 1;
161 157
162 sg_init_one(&sg, buf, blksz * blocks); 158 sg_init_one(&sg, buf, data.blksz * data.blocks);
163 159
164 mmc_set_data_timeout(&data, card); 160 mmc_set_data_timeout(&data, card);
165 161
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index b4b83f302e32..745f8fce2519 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MMC_MXC) += mxcmmc.o
9obj-$(CONFIG_MMC_MXS) += mxs-mmc.o 9obj-$(CONFIG_MMC_MXS) += mxs-mmc.o
10obj-$(CONFIG_MMC_SDHCI) += sdhci.o 10obj-$(CONFIG_MMC_SDHCI) += sdhci.o
11obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o 11obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o
12obj-$(subst m,y,$(CONFIG_MMC_SDHCI_PCI)) += sdhci-pci-data.o
12obj-$(CONFIG_MMC_SDHCI_PXAV3) += sdhci-pxav3.o 13obj-$(CONFIG_MMC_SDHCI_PXAV3) += sdhci-pxav3.o
13obj-$(CONFIG_MMC_SDHCI_PXAV2) += sdhci-pxav2.o 14obj-$(CONFIG_MMC_SDHCI_PXAV2) += sdhci-pxav2.o
14obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o 15obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index f437c3e6f3aa..947faa5d2ce4 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -236,7 +236,7 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
236 236
237 sg = &data->sg[i]; 237 sg = &data->sg[i];
238 238
239 sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; 239 sgbuffer = kmap_atomic(sg_page(sg)) + sg->offset;
240 amount = min(size, sg->length); 240 amount = min(size, sg->length);
241 size -= amount; 241 size -= amount;
242 242
@@ -252,7 +252,7 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
252 dmabuf = (unsigned *)tmpv; 252 dmabuf = (unsigned *)tmpv;
253 } 253 }
254 254
255 kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); 255 kunmap_atomic(sgbuffer);
256 256
257 if (size == 0) 257 if (size == 0)
258 break; 258 break;
@@ -302,7 +302,7 @@ static void at91_mci_post_dma_read(struct at91mci_host *host)
302 302
303 sg = &data->sg[i]; 303 sg = &data->sg[i];
304 304
305 sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; 305 sgbuffer = kmap_atomic(sg_page(sg)) + sg->offset;
306 amount = min(size, sg->length); 306 amount = min(size, sg->length);
307 size -= amount; 307 size -= amount;
308 308
@@ -318,7 +318,7 @@ static void at91_mci_post_dma_read(struct at91mci_host *host)
318 } 318 }
319 319
320 flush_kernel_dcache_page(sg_page(sg)); 320 flush_kernel_dcache_page(sg_page(sg));
321 kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); 321 kunmap_atomic(sgbuffer);
322 data->bytes_xfered += amount; 322 data->bytes_xfered += amount;
323 if (size == 0) 323 if (size == 0)
324 break; 324 break;
diff --git a/drivers/mmc/host/bfin_sdh.c b/drivers/mmc/host/bfin_sdh.c
index 0371bf502249..03666174ca48 100644
--- a/drivers/mmc/host/bfin_sdh.c
+++ b/drivers/mmc/host/bfin_sdh.c
@@ -627,17 +627,7 @@ static struct platform_driver sdh_driver = {
627 }, 627 },
628}; 628};
629 629
630static int __init sdh_init(void) 630module_platform_driver(sdh_driver);
631{
632 return platform_driver_register(&sdh_driver);
633}
634module_init(sdh_init);
635
636static void __exit sdh_exit(void)
637{
638 platform_driver_unregister(&sdh_driver);
639}
640module_exit(sdh_exit);
641 631
642MODULE_DESCRIPTION("Blackfin Secure Digital Host Driver"); 632MODULE_DESCRIPTION("Blackfin Secure Digital Host Driver");
643MODULE_AUTHOR("Cliff Cai, Roy Huang"); 633MODULE_AUTHOR("Cliff Cai, Roy Huang");
diff --git a/drivers/mmc/host/cb710-mmc.c b/drivers/mmc/host/cb710-mmc.c
index ce2a47b71dd6..83693fd7c6b3 100644
--- a/drivers/mmc/host/cb710-mmc.c
+++ b/drivers/mmc/host/cb710-mmc.c
@@ -780,18 +780,7 @@ static struct platform_driver cb710_mmc_driver = {
780#endif 780#endif
781}; 781};
782 782
783static int __init cb710_mmc_init_module(void) 783module_platform_driver(cb710_mmc_driver);
784{
785 return platform_driver_register(&cb710_mmc_driver);
786}
787
788static void __exit cb710_mmc_cleanup_module(void)
789{
790 platform_driver_unregister(&cb710_mmc_driver);
791}
792
793module_init(cb710_mmc_init_module);
794module_exit(cb710_mmc_cleanup_module);
795 784
796MODULE_AUTHOR("Michał Mirosław <mirq-linux@rere.qmqm.pl>"); 785MODULE_AUTHOR("Michał Mirosław <mirq-linux@rere.qmqm.pl>");
797MODULE_DESCRIPTION("ENE CB710 memory card reader driver - MMC/SD part"); 786MODULE_DESCRIPTION("ENE CB710 memory card reader driver - MMC/SD part");
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 3aaeb0841914..0e342793ff14 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -588,11 +588,11 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot)
588 mci_writel(host, CTYPE, (slot->ctype << slot->id)); 588 mci_writel(host, CTYPE, (slot->ctype << slot->id));
589} 589}
590 590
591static void dw_mci_start_request(struct dw_mci *host, 591static void __dw_mci_start_request(struct dw_mci *host,
592 struct dw_mci_slot *slot) 592 struct dw_mci_slot *slot,
593 struct mmc_command *cmd)
593{ 594{
594 struct mmc_request *mrq; 595 struct mmc_request *mrq;
595 struct mmc_command *cmd;
596 struct mmc_data *data; 596 struct mmc_data *data;
597 u32 cmdflags; 597 u32 cmdflags;
598 598
@@ -610,14 +610,13 @@ static void dw_mci_start_request(struct dw_mci *host,
610 host->completed_events = 0; 610 host->completed_events = 0;
611 host->data_status = 0; 611 host->data_status = 0;
612 612
613 data = mrq->data; 613 data = cmd->data;
614 if (data) { 614 if (data) {
615 dw_mci_set_timeout(host); 615 dw_mci_set_timeout(host);
616 mci_writel(host, BYTCNT, data->blksz*data->blocks); 616 mci_writel(host, BYTCNT, data->blksz*data->blocks);
617 mci_writel(host, BLKSIZ, data->blksz); 617 mci_writel(host, BLKSIZ, data->blksz);
618 } 618 }
619 619
620 cmd = mrq->cmd;
621 cmdflags = dw_mci_prepare_command(slot->mmc, cmd); 620 cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
622 621
623 /* this is the first command, send the initialization clock */ 622 /* this is the first command, send the initialization clock */
@@ -635,6 +634,16 @@ static void dw_mci_start_request(struct dw_mci *host,
635 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop); 634 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
636} 635}
637 636
637static void dw_mci_start_request(struct dw_mci *host,
638 struct dw_mci_slot *slot)
639{
640 struct mmc_request *mrq = slot->mrq;
641 struct mmc_command *cmd;
642
643 cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
644 __dw_mci_start_request(host, slot, cmd);
645}
646
638/* must be called with host->lock held */ 647/* must be called with host->lock held */
639static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot, 648static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
640 struct mmc_request *mrq) 649 struct mmc_request *mrq)
@@ -698,12 +707,15 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
698 break; 707 break;
699 } 708 }
700 709
710 regs = mci_readl(slot->host, UHS_REG);
711
701 /* DDR mode set */ 712 /* DDR mode set */
702 if (ios->timing == MMC_TIMING_UHS_DDR50) { 713 if (ios->timing == MMC_TIMING_UHS_DDR50)
703 regs = mci_readl(slot->host, UHS_REG);
704 regs |= (0x1 << slot->id) << 16; 714 regs |= (0x1 << slot->id) << 16;
705 mci_writel(slot->host, UHS_REG, regs); 715 else
706 } 716 regs &= ~(0x1 << slot->id) << 16;
717
718 mci_writel(slot->host, UHS_REG, regs);
707 719
708 if (ios->clock) { 720 if (ios->clock) {
709 /* 721 /*
@@ -889,7 +901,14 @@ static void dw_mci_tasklet_func(unsigned long priv)
889 cmd = host->cmd; 901 cmd = host->cmd;
890 host->cmd = NULL; 902 host->cmd = NULL;
891 set_bit(EVENT_CMD_COMPLETE, &host->completed_events); 903 set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
892 dw_mci_command_complete(host, host->mrq->cmd); 904 dw_mci_command_complete(host, cmd);
905 if (cmd == host->mrq->sbc && !cmd->error) {
906 prev_state = state = STATE_SENDING_CMD;
907 __dw_mci_start_request(host, host->cur_slot,
908 host->mrq->cmd);
909 goto unlock;
910 }
911
893 if (!host->mrq->data || cmd->error) { 912 if (!host->mrq->data || cmd->error) {
894 dw_mci_request_end(host, host->mrq); 913 dw_mci_request_end(host, host->mrq);
895 goto unlock; 914 goto unlock;
@@ -967,6 +986,12 @@ static void dw_mci_tasklet_func(unsigned long priv)
967 goto unlock; 986 goto unlock;
968 } 987 }
969 988
989 if (host->mrq->sbc && !data->error) {
990 data->stop->error = 0;
991 dw_mci_request_end(host, host->mrq);
992 goto unlock;
993 }
994
970 prev_state = state = STATE_SENDING_STOP; 995 prev_state = state = STATE_SENDING_STOP;
971 if (!data->error) 996 if (!data->error)
972 send_stop_cmd(host, data); 997 send_stop_cmd(host, data);
@@ -1678,8 +1703,9 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1678 1703
1679 if (host->pdata->caps) 1704 if (host->pdata->caps)
1680 mmc->caps = host->pdata->caps; 1705 mmc->caps = host->pdata->caps;
1681 else 1706
1682 mmc->caps = 0; 1707 if (host->pdata->caps2)
1708 mmc->caps2 = host->pdata->caps2;
1683 1709
1684 if (host->pdata->get_bus_wd) 1710 if (host->pdata->get_bus_wd)
1685 if (host->pdata->get_bus_wd(slot->id) >= 4) 1711 if (host->pdata->get_bus_wd(slot->id) >= 4)
@@ -1923,7 +1949,7 @@ static int dw_mci_probe(struct platform_device *pdev)
1923 * should put it in the platform data. 1949 * should put it in the platform data.
1924 */ 1950 */
1925 fifo_size = mci_readl(host, FIFOTH); 1951 fifo_size = mci_readl(host, FIFOTH);
1926 fifo_size = 1 + ((fifo_size >> 16) & 0x7ff); 1952 fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
1927 } else { 1953 } else {
1928 fifo_size = host->pdata->fifo_depth; 1954 fifo_size = host->pdata->fifo_depth;
1929 } 1955 }
@@ -2062,14 +2088,14 @@ static int __exit dw_mci_remove(struct platform_device *pdev)
2062 return 0; 2088 return 0;
2063} 2089}
2064 2090
2065#ifdef CONFIG_PM 2091#ifdef CONFIG_PM_SLEEP
2066/* 2092/*
2067 * TODO: we should probably disable the clock to the card in the suspend path. 2093 * TODO: we should probably disable the clock to the card in the suspend path.
2068 */ 2094 */
2069static int dw_mci_suspend(struct platform_device *pdev, pm_message_t mesg) 2095static int dw_mci_suspend(struct device *dev)
2070{ 2096{
2071 int i, ret; 2097 int i, ret;
2072 struct dw_mci *host = platform_get_drvdata(pdev); 2098 struct dw_mci *host = dev_get_drvdata(dev);
2073 2099
2074 for (i = 0; i < host->num_slots; i++) { 2100 for (i = 0; i < host->num_slots; i++) {
2075 struct dw_mci_slot *slot = host->slot[i]; 2101 struct dw_mci_slot *slot = host->slot[i];
@@ -2092,10 +2118,10 @@ static int dw_mci_suspend(struct platform_device *pdev, pm_message_t mesg)
2092 return 0; 2118 return 0;
2093} 2119}
2094 2120
2095static int dw_mci_resume(struct platform_device *pdev) 2121static int dw_mci_resume(struct device *dev)
2096{ 2122{
2097 int i, ret; 2123 int i, ret;
2098 struct dw_mci *host = platform_get_drvdata(pdev); 2124 struct dw_mci *host = dev_get_drvdata(dev);
2099 2125
2100 if (host->vmmc) 2126 if (host->vmmc)
2101 regulator_enable(host->vmmc); 2127 regulator_enable(host->vmmc);
@@ -2103,7 +2129,7 @@ static int dw_mci_resume(struct platform_device *pdev)
2103 if (host->dma_ops->init) 2129 if (host->dma_ops->init)
2104 host->dma_ops->init(host); 2130 host->dma_ops->init(host);
2105 2131
2106 if (!mci_wait_reset(&pdev->dev, host)) { 2132 if (!mci_wait_reset(dev, host)) {
2107 ret = -ENODEV; 2133 ret = -ENODEV;
2108 return ret; 2134 return ret;
2109 } 2135 }
@@ -2131,14 +2157,15 @@ static int dw_mci_resume(struct platform_device *pdev)
2131#else 2157#else
2132#define dw_mci_suspend NULL 2158#define dw_mci_suspend NULL
2133#define dw_mci_resume NULL 2159#define dw_mci_resume NULL
2134#endif /* CONFIG_PM */ 2160#endif /* CONFIG_PM_SLEEP */
2161
2162static SIMPLE_DEV_PM_OPS(dw_mci_pmops, dw_mci_suspend, dw_mci_resume);
2135 2163
2136static struct platform_driver dw_mci_driver = { 2164static struct platform_driver dw_mci_driver = {
2137 .remove = __exit_p(dw_mci_remove), 2165 .remove = __exit_p(dw_mci_remove),
2138 .suspend = dw_mci_suspend,
2139 .resume = dw_mci_resume,
2140 .driver = { 2166 .driver = {
2141 .name = "dw_mmc", 2167 .name = "dw_mmc",
2168 .pm = &dw_mci_pmops,
2142 }, 2169 },
2143}; 2170};
2144 2171
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 72c071f6e001..df392a1143f2 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -126,7 +126,7 @@
126#define SDMMC_CMD_RESP_EXP BIT(6) 126#define SDMMC_CMD_RESP_EXP BIT(6)
127#define SDMMC_CMD_INDX(n) ((n) & 0x1F) 127#define SDMMC_CMD_INDX(n) ((n) & 0x1F)
128/* Status register defines */ 128/* Status register defines */
129#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FF) 129#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
130/* Internal DMAC interrupt defines */ 130/* Internal DMAC interrupt defines */
131#define SDMMC_IDMAC_INT_AI BIT(9) 131#define SDMMC_IDMAC_INT_AI BIT(9)
132#define SDMMC_IDMAC_INT_NI BIT(8) 132#define SDMMC_IDMAC_INT_NI BIT(8)
diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index 74218ad677e4..c8852a8128a9 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -1012,17 +1012,7 @@ static struct platform_driver jz4740_mmc_driver = {
1012 }, 1012 },
1013}; 1013};
1014 1014
1015static int __init jz4740_mmc_init(void) 1015module_platform_driver(jz4740_mmc_driver);
1016{
1017 return platform_driver_register(&jz4740_mmc_driver);
1018}
1019module_init(jz4740_mmc_init);
1020
1021static void __exit jz4740_mmc_exit(void)
1022{
1023 platform_driver_unregister(&jz4740_mmc_driver);
1024}
1025module_exit(jz4740_mmc_exit);
1026 1016
1027MODULE_DESCRIPTION("JZ4740 SD/MMC controller driver"); 1017MODULE_DESCRIPTION("JZ4740 SD/MMC controller driver");
1028MODULE_LICENSE("GPL"); 1018MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 92946b84e9fa..273306c68d58 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1525,7 +1525,6 @@ static struct of_device_id mmc_spi_of_match_table[] __devinitdata = {
1525static struct spi_driver mmc_spi_driver = { 1525static struct spi_driver mmc_spi_driver = {
1526 .driver = { 1526 .driver = {
1527 .name = "mmc_spi", 1527 .name = "mmc_spi",
1528 .bus = &spi_bus_type,
1529 .owner = THIS_MODULE, 1528 .owner = THIS_MODULE,
1530 .of_match_table = mmc_spi_of_match_table, 1529 .of_match_table = mmc_spi_of_match_table,
1531 }, 1530 },
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index fa8dd2fda4b2..ece03b491c7d 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1245,6 +1245,7 @@ static int __devinit mmci_probe(struct amba_device *dev,
1245 if (host->vcc == NULL) 1245 if (host->vcc == NULL)
1246 mmc->ocr_avail = plat->ocr_mask; 1246 mmc->ocr_avail = plat->ocr_mask;
1247 mmc->caps = plat->capabilities; 1247 mmc->caps = plat->capabilities;
1248 mmc->caps2 = plat->capabilities2;
1248 1249
1249 /* 1250 /*
1250 * We can do SGIO 1251 * We can do SGIO
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index 80d8eb143b48..1d14cda95e56 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -689,8 +689,8 @@ msmsdcc_pio_irq(int irq, void *dev_id)
689 689
690 /* Map the current scatter buffer */ 690 /* Map the current scatter buffer */
691 local_irq_save(flags); 691 local_irq_save(flags);
692 buffer = kmap_atomic(sg_page(host->pio.sg), 692 buffer = kmap_atomic(sg_page(host->pio.sg))
693 KM_BIO_SRC_IRQ) + host->pio.sg->offset; 693 + host->pio.sg->offset;
694 buffer += host->pio.sg_off; 694 buffer += host->pio.sg_off;
695 remain = host->pio.sg->length - host->pio.sg_off; 695 remain = host->pio.sg->length - host->pio.sg_off;
696 len = 0; 696 len = 0;
@@ -700,7 +700,7 @@ msmsdcc_pio_irq(int irq, void *dev_id)
700 len = msmsdcc_pio_write(host, buffer, remain, status); 700 len = msmsdcc_pio_write(host, buffer, remain, status);
701 701
702 /* Unmap the buffer */ 702 /* Unmap the buffer */
703 kunmap_atomic(buffer, KM_BIO_SRC_IRQ); 703 kunmap_atomic(buffer);
704 local_irq_restore(flags); 704 local_irq_restore(flags);
705 705
706 host->pio.sg_off += len; 706 host->pio.sg_off += len;
@@ -1480,18 +1480,7 @@ static struct platform_driver msmsdcc_driver = {
1480 }, 1480 },
1481}; 1481};
1482 1482
1483static int __init msmsdcc_init(void) 1483module_platform_driver(msmsdcc_driver);
1484{
1485 return platform_driver_register(&msmsdcc_driver);
1486}
1487
1488static void __exit msmsdcc_exit(void)
1489{
1490 platform_driver_unregister(&msmsdcc_driver);
1491}
1492
1493module_init(msmsdcc_init);
1494module_exit(msmsdcc_exit);
1495 1484
1496MODULE_DESCRIPTION("Qualcomm MSM 7X00A Multimedia Card Interface driver"); 1485MODULE_DESCRIPTION("Qualcomm MSM 7X00A Multimedia Card Interface driver");
1497MODULE_LICENSE("GPL"); 1486MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index 8e0fbe994047..7088b40f9579 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -1047,18 +1047,7 @@ static struct platform_driver mxcmci_driver = {
1047 } 1047 }
1048}; 1048};
1049 1049
1050static int __init mxcmci_init(void) 1050module_platform_driver(mxcmci_driver);
1051{
1052 return platform_driver_register(&mxcmci_driver);
1053}
1054
1055static void __exit mxcmci_exit(void)
1056{
1057 platform_driver_unregister(&mxcmci_driver);
1058}
1059
1060module_init(mxcmci_init);
1061module_exit(mxcmci_exit);
1062 1051
1063MODULE_DESCRIPTION("i.MX Multimedia Card Interface Driver"); 1052MODULE_DESCRIPTION("i.MX Multimedia Card Interface Driver");
1064MODULE_AUTHOR("Sascha Hauer, Pengutronix"); 1053MODULE_AUTHOR("Sascha Hauer, Pengutronix");
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index 973011f9a298..4e2e019dd5c9 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -855,18 +855,7 @@ static struct platform_driver mxs_mmc_driver = {
855 }, 855 },
856}; 856};
857 857
858static int __init mxs_mmc_init(void) 858module_platform_driver(mxs_mmc_driver);
859{
860 return platform_driver_register(&mxs_mmc_driver);
861}
862
863static void __exit mxs_mmc_exit(void)
864{
865 platform_driver_unregister(&mxs_mmc_driver);
866}
867
868module_init(mxs_mmc_init);
869module_exit(mxs_mmc_exit);
870 859
871MODULE_DESCRIPTION("FREESCALE MXS MMC peripheral"); 860MODULE_DESCRIPTION("FREESCALE MXS MMC peripheral");
872MODULE_AUTHOR("Freescale Semiconductor"); 861MODULE_AUTHOR("Freescale Semiconductor");
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index d1fb561e089d..fd0c661bbad3 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -24,7 +24,6 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/dma-mapping.h> 25#include <linux/dma-mapping.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/workqueue.h>
28#include <linux/timer.h> 27#include <linux/timer.h>
29#include <linux/clk.h> 28#include <linux/clk.h>
30#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
@@ -120,7 +119,6 @@
120 119
121#define MMC_AUTOSUSPEND_DELAY 100 120#define MMC_AUTOSUSPEND_DELAY 100
122#define MMC_TIMEOUT_MS 20 121#define MMC_TIMEOUT_MS 20
123#define OMAP_MMC_MASTER_CLOCK 96000000
124#define OMAP_MMC_MIN_CLOCK 400000 122#define OMAP_MMC_MIN_CLOCK 400000
125#define OMAP_MMC_MAX_CLOCK 52000000 123#define OMAP_MMC_MAX_CLOCK 52000000
126#define DRIVER_NAME "omap_hsmmc" 124#define DRIVER_NAME "omap_hsmmc"
@@ -163,7 +161,6 @@ struct omap_hsmmc_host {
163 */ 161 */
164 struct regulator *vcc; 162 struct regulator *vcc;
165 struct regulator *vcc_aux; 163 struct regulator *vcc_aux;
166 struct work_struct mmc_carddetect_work;
167 void __iomem *base; 164 void __iomem *base;
168 resource_size_t mapbase; 165 resource_size_t mapbase;
169 spinlock_t irq_lock; /* Prevent races with irq handler */ 166 spinlock_t irq_lock; /* Prevent races with irq handler */
@@ -598,12 +595,12 @@ static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host)
598} 595}
599 596
600/* Calculate divisor for the given clock frequency */ 597/* Calculate divisor for the given clock frequency */
601static u16 calc_divisor(struct mmc_ios *ios) 598static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios)
602{ 599{
603 u16 dsor = 0; 600 u16 dsor = 0;
604 601
605 if (ios->clock) { 602 if (ios->clock) {
606 dsor = DIV_ROUND_UP(OMAP_MMC_MASTER_CLOCK, ios->clock); 603 dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock);
607 if (dsor > 250) 604 if (dsor > 250)
608 dsor = 250; 605 dsor = 250;
609 } 606 }
@@ -623,7 +620,7 @@ static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
623 620
624 regval = OMAP_HSMMC_READ(host->base, SYSCTL); 621 regval = OMAP_HSMMC_READ(host->base, SYSCTL);
625 regval = regval & ~(CLKD_MASK | DTO_MASK); 622 regval = regval & ~(CLKD_MASK | DTO_MASK);
626 regval = regval | (calc_divisor(ios) << 6) | (DTO << 16); 623 regval = regval | (calc_divisor(host, ios) << 6) | (DTO << 16);
627 OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); 624 OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
628 OMAP_HSMMC_WRITE(host->base, SYSCTL, 625 OMAP_HSMMC_WRITE(host->base, SYSCTL,
629 OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); 626 OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
@@ -1280,17 +1277,16 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1280} 1277}
1281 1278
1282/* 1279/*
1283 * Work Item to notify the core about card insertion/removal 1280 * irq handler to notify the core about card insertion/removal
1284 */ 1281 */
1285static void omap_hsmmc_detect(struct work_struct *work) 1282static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)
1286{ 1283{
1287 struct omap_hsmmc_host *host = 1284 struct omap_hsmmc_host *host = dev_id;
1288 container_of(work, struct omap_hsmmc_host, mmc_carddetect_work);
1289 struct omap_mmc_slot_data *slot = &mmc_slot(host); 1285 struct omap_mmc_slot_data *slot = &mmc_slot(host);
1290 int carddetect; 1286 int carddetect;
1291 1287
1292 if (host->suspended) 1288 if (host->suspended)
1293 return; 1289 return IRQ_HANDLED;
1294 1290
1295 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); 1291 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
1296 1292
@@ -1305,19 +1301,6 @@ static void omap_hsmmc_detect(struct work_struct *work)
1305 mmc_detect_change(host->mmc, (HZ * 200) / 1000); 1301 mmc_detect_change(host->mmc, (HZ * 200) / 1000);
1306 else 1302 else
1307 mmc_detect_change(host->mmc, (HZ * 50) / 1000); 1303 mmc_detect_change(host->mmc, (HZ * 50) / 1000);
1308}
1309
1310/*
1311 * ISR for handling card insertion and removal
1312 */
1313static irqreturn_t omap_hsmmc_cd_handler(int irq, void *dev_id)
1314{
1315 struct omap_hsmmc_host *host = (struct omap_hsmmc_host *)dev_id;
1316
1317 if (host->suspended)
1318 return IRQ_HANDLED;
1319 schedule_work(&host->mmc_carddetect_work);
1320
1321 return IRQ_HANDLED; 1304 return IRQ_HANDLED;
1322} 1305}
1323 1306
@@ -1919,7 +1902,6 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
1919 host->next_data.cookie = 1; 1902 host->next_data.cookie = 1;
1920 1903
1921 platform_set_drvdata(pdev, host); 1904 platform_set_drvdata(pdev, host);
1922 INIT_WORK(&host->mmc_carddetect_work, omap_hsmmc_detect);
1923 1905
1924 mmc->ops = &omap_hsmmc_ops; 1906 mmc->ops = &omap_hsmmc_ops;
1925 1907
@@ -2049,10 +2031,11 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
2049 2031
2050 /* Request IRQ for card detect */ 2032 /* Request IRQ for card detect */
2051 if ((mmc_slot(host).card_detect_irq)) { 2033 if ((mmc_slot(host).card_detect_irq)) {
2052 ret = request_irq(mmc_slot(host).card_detect_irq, 2034 ret = request_threaded_irq(mmc_slot(host).card_detect_irq,
2053 omap_hsmmc_cd_handler, 2035 NULL,
2054 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 2036 omap_hsmmc_detect,
2055 mmc_hostname(mmc), host); 2037 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2038 mmc_hostname(mmc), host);
2056 if (ret) { 2039 if (ret) {
2057 dev_dbg(mmc_dev(host->mmc), 2040 dev_dbg(mmc_dev(host->mmc),
2058 "Unable to grab MMC CD IRQ\n"); 2041 "Unable to grab MMC CD IRQ\n");
@@ -2131,7 +2114,6 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2131 free_irq(host->irq, host); 2114 free_irq(host->irq, host);
2132 if (mmc_slot(host).card_detect_irq) 2115 if (mmc_slot(host).card_detect_irq)
2133 free_irq(mmc_slot(host).card_detect_irq, host); 2116 free_irq(mmc_slot(host).card_detect_irq, host);
2134 flush_work_sync(&host->mmc_carddetect_work);
2135 2117
2136 pm_runtime_put_sync(host->dev); 2118 pm_runtime_put_sync(host->dev);
2137 pm_runtime_disable(host->dev); 2119 pm_runtime_disable(host->dev);
@@ -2178,7 +2160,6 @@ static int omap_hsmmc_suspend(struct device *dev)
2178 return ret; 2160 return ret;
2179 } 2161 }
2180 } 2162 }
2181 cancel_work_sync(&host->mmc_carddetect_work);
2182 ret = mmc_suspend_host(host->mmc); 2163 ret = mmc_suspend_host(host->mmc);
2183 2164
2184 if (ret) { 2165 if (ret) {
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index fc4356e00d46..cb2dc0e75ba7 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -872,18 +872,7 @@ static struct platform_driver pxamci_driver = {
872 }, 872 },
873}; 873};
874 874
875static int __init pxamci_init(void) 875module_platform_driver(pxamci_driver);
876{
877 return platform_driver_register(&pxamci_driver);
878}
879
880static void __exit pxamci_exit(void)
881{
882 platform_driver_unregister(&pxamci_driver);
883}
884
885module_init(pxamci_init);
886module_exit(pxamci_exit);
887 876
888MODULE_DESCRIPTION("PXA Multimedia Card Interface Driver"); 877MODULE_DESCRIPTION("PXA Multimedia Card Interface Driver");
889MODULE_LICENSE("GPL"); 878MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index 720f99334a7f..1bcfd6dbb5cc 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -1914,18 +1914,7 @@ static struct platform_driver s3cmci_driver = {
1914 .shutdown = s3cmci_shutdown, 1914 .shutdown = s3cmci_shutdown,
1915}; 1915};
1916 1916
1917static int __init s3cmci_init(void) 1917module_platform_driver(s3cmci_driver);
1918{
1919 return platform_driver_register(&s3cmci_driver);
1920}
1921
1922static void __exit s3cmci_exit(void)
1923{
1924 platform_driver_unregister(&s3cmci_driver);
1925}
1926
1927module_init(s3cmci_init);
1928module_exit(s3cmci_exit);
1929 1918
1930MODULE_DESCRIPTION("Samsung S3C MMC/SD Card Interface driver"); 1919MODULE_DESCRIPTION("Samsung S3C MMC/SD Card Interface driver");
1931MODULE_LICENSE("GPL v2"); 1920MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/host/sdhci-cns3xxx.c b/drivers/mmc/host/sdhci-cns3xxx.c
index b4257e700617..28a870804f60 100644
--- a/drivers/mmc/host/sdhci-cns3xxx.c
+++ b/drivers/mmc/host/sdhci-cns3xxx.c
@@ -115,17 +115,7 @@ static struct platform_driver sdhci_cns3xxx_driver = {
115 .remove = __devexit_p(sdhci_cns3xxx_remove), 115 .remove = __devexit_p(sdhci_cns3xxx_remove),
116}; 116};
117 117
118static int __init sdhci_cns3xxx_init(void) 118module_platform_driver(sdhci_cns3xxx_driver);
119{
120 return platform_driver_register(&sdhci_cns3xxx_driver);
121}
122module_init(sdhci_cns3xxx_init);
123
124static void __exit sdhci_cns3xxx_exit(void)
125{
126 platform_driver_unregister(&sdhci_cns3xxx_driver);
127}
128module_exit(sdhci_cns3xxx_exit);
129 119
130MODULE_DESCRIPTION("SDHCI driver for CNS3xxx"); 120MODULE_DESCRIPTION("SDHCI driver for CNS3xxx");
131MODULE_AUTHOR("Scott Shu, " 121MODULE_AUTHOR("Scott Shu, "
diff --git a/drivers/mmc/host/sdhci-dove.c b/drivers/mmc/host/sdhci-dove.c
index a81312c91f70..46fd1fd1b605 100644
--- a/drivers/mmc/host/sdhci-dove.c
+++ b/drivers/mmc/host/sdhci-dove.c
@@ -88,17 +88,7 @@ static struct platform_driver sdhci_dove_driver = {
88 .remove = __devexit_p(sdhci_dove_remove), 88 .remove = __devexit_p(sdhci_dove_remove),
89}; 89};
90 90
91static int __init sdhci_dove_init(void) 91module_platform_driver(sdhci_dove_driver);
92{
93 return platform_driver_register(&sdhci_dove_driver);
94}
95module_init(sdhci_dove_init);
96
97static void __exit sdhci_dove_exit(void)
98{
99 platform_driver_unregister(&sdhci_dove_driver);
100}
101module_exit(sdhci_dove_exit);
102 92
103MODULE_DESCRIPTION("SDHCI driver for Dove"); 93MODULE_DESCRIPTION("SDHCI driver for Dove");
104MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, " 94MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, "
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 38ebc4ea259f..d601e41af282 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -606,17 +606,7 @@ static struct platform_driver sdhci_esdhc_imx_driver = {
606 .remove = __devexit_p(sdhci_esdhc_imx_remove), 606 .remove = __devexit_p(sdhci_esdhc_imx_remove),
607}; 607};
608 608
609static int __init sdhci_esdhc_imx_init(void) 609module_platform_driver(sdhci_esdhc_imx_driver);
610{
611 return platform_driver_register(&sdhci_esdhc_imx_driver);
612}
613module_init(sdhci_esdhc_imx_init);
614
615static void __exit sdhci_esdhc_imx_exit(void)
616{
617 platform_driver_unregister(&sdhci_esdhc_imx_driver);
618}
619module_exit(sdhci_esdhc_imx_exit);
620 610
621MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC"); 611MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC");
622MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>"); 612MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
diff --git a/drivers/mmc/host/sdhci-esdhc.h b/drivers/mmc/host/sdhci-esdhc.h
index c3b08f111942..b97b2f5dafdb 100644
--- a/drivers/mmc/host/sdhci-esdhc.h
+++ b/drivers/mmc/host/sdhci-esdhc.h
@@ -73,7 +73,7 @@ static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
73 | (div << ESDHC_DIVIDER_SHIFT) 73 | (div << ESDHC_DIVIDER_SHIFT)
74 | (pre_div << ESDHC_PREDIV_SHIFT)); 74 | (pre_div << ESDHC_PREDIV_SHIFT));
75 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 75 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
76 mdelay(100); 76 mdelay(1);
77out: 77out:
78 host->clock = clock; 78 host->clock = clock;
79} 79}
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index 01e5f627e0f0..ff4adc018041 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -131,17 +131,7 @@ static struct platform_driver sdhci_esdhc_driver = {
131 .remove = __devexit_p(sdhci_esdhc_remove), 131 .remove = __devexit_p(sdhci_esdhc_remove),
132}; 132};
133 133
134static int __init sdhci_esdhc_init(void) 134module_platform_driver(sdhci_esdhc_driver);
135{
136 return platform_driver_register(&sdhci_esdhc_driver);
137}
138module_init(sdhci_esdhc_init);
139
140static void __exit sdhci_esdhc_exit(void)
141{
142 platform_driver_unregister(&sdhci_esdhc_driver);
143}
144module_exit(sdhci_esdhc_exit);
145 135
146MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC"); 136MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
147MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, " 137MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
diff --git a/drivers/mmc/host/sdhci-of-hlwd.c b/drivers/mmc/host/sdhci-of-hlwd.c
index 3619adc7d9fc..0ce088ae0228 100644
--- a/drivers/mmc/host/sdhci-of-hlwd.c
+++ b/drivers/mmc/host/sdhci-of-hlwd.c
@@ -93,17 +93,7 @@ static struct platform_driver sdhci_hlwd_driver = {
93 .remove = __devexit_p(sdhci_hlwd_remove), 93 .remove = __devexit_p(sdhci_hlwd_remove),
94}; 94};
95 95
96static int __init sdhci_hlwd_init(void) 96module_platform_driver(sdhci_hlwd_driver);
97{
98 return platform_driver_register(&sdhci_hlwd_driver);
99}
100module_init(sdhci_hlwd_init);
101
102static void __exit sdhci_hlwd_exit(void)
103{
104 platform_driver_unregister(&sdhci_hlwd_driver);
105}
106module_exit(sdhci_hlwd_exit);
107 97
108MODULE_DESCRIPTION("Nintendo Wii SDHCI OF driver"); 98MODULE_DESCRIPTION("Nintendo Wii SDHCI OF driver");
109MODULE_AUTHOR("The GameCube Linux Team, Albert Herranz"); 99MODULE_AUTHOR("The GameCube Linux Team, Albert Herranz");
diff --git a/drivers/mmc/host/sdhci-pci-data.c b/drivers/mmc/host/sdhci-pci-data.c
new file mode 100644
index 000000000000..a611217769f5
--- /dev/null
+++ b/drivers/mmc/host/sdhci-pci-data.c
@@ -0,0 +1,5 @@
1#include <linux/module.h>
2#include <linux/mmc/sdhci-pci-data.h>
3
4struct sdhci_pci_data *(*sdhci_pci_get_data)(struct pci_dev *pdev, int slotno);
5EXPORT_SYMBOL_GPL(sdhci_pci_get_data);
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 6878a94626bc..7165e6a09274 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -23,8 +23,8 @@
23#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/sfi.h>
27#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
27#include <linux/mmc/sdhci-pci-data.h>
28 28
29#include "sdhci.h" 29#include "sdhci.h"
30 30
@@ -61,6 +61,7 @@ struct sdhci_pci_fixes {
61struct sdhci_pci_slot { 61struct sdhci_pci_slot {
62 struct sdhci_pci_chip *chip; 62 struct sdhci_pci_chip *chip;
63 struct sdhci_host *host; 63 struct sdhci_host *host;
64 struct sdhci_pci_data *data;
64 65
65 int pci_bar; 66 int pci_bar;
66 int rst_n_gpio; 67 int rst_n_gpio;
@@ -171,32 +172,9 @@ static int mrst_hc_probe(struct sdhci_pci_chip *chip)
171 return 0; 172 return 0;
172} 173}
173 174
174/* Medfield eMMC hardware reset GPIOs */
175static int mfd_emmc0_rst_gpio = -EINVAL;
176static int mfd_emmc1_rst_gpio = -EINVAL;
177
178static int mfd_emmc_gpio_parse(struct sfi_table_header *table)
179{
180 struct sfi_table_simple *sb = (struct sfi_table_simple *)table;
181 struct sfi_gpio_table_entry *entry;
182 int i, num;
183
184 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
185 entry = (struct sfi_gpio_table_entry *)sb->pentry;
186
187 for (i = 0; i < num; i++, entry++) {
188 if (!strncmp(entry->pin_name, "emmc0_rst", SFI_NAME_LEN))
189 mfd_emmc0_rst_gpio = entry->pin_no;
190 else if (!strncmp(entry->pin_name, "emmc1_rst", SFI_NAME_LEN))
191 mfd_emmc1_rst_gpio = entry->pin_no;
192 }
193
194 return 0;
195}
196
197#ifdef CONFIG_PM_RUNTIME 175#ifdef CONFIG_PM_RUNTIME
198 176
199static irqreturn_t mfd_sd_cd(int irq, void *dev_id) 177static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
200{ 178{
201 struct sdhci_pci_slot *slot = dev_id; 179 struct sdhci_pci_slot *slot = dev_id;
202 struct sdhci_host *host = slot->host; 180 struct sdhci_host *host = slot->host;
@@ -205,15 +183,16 @@ static irqreturn_t mfd_sd_cd(int irq, void *dev_id)
205 return IRQ_HANDLED; 183 return IRQ_HANDLED;
206} 184}
207 185
208#define MFLD_SD_CD_PIN 69 186static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
209
210static int mfd_sd_probe_slot(struct sdhci_pci_slot *slot)
211{ 187{
212 int err, irq, gpio = MFLD_SD_CD_PIN; 188 int err, irq, gpio = slot->cd_gpio;
213 189
214 slot->cd_gpio = -EINVAL; 190 slot->cd_gpio = -EINVAL;
215 slot->cd_irq = -EINVAL; 191 slot->cd_irq = -EINVAL;
216 192
193 if (!gpio_is_valid(gpio))
194 return;
195
217 err = gpio_request(gpio, "sd_cd"); 196 err = gpio_request(gpio, "sd_cd");
218 if (err < 0) 197 if (err < 0)
219 goto out; 198 goto out;
@@ -226,72 +205,53 @@ static int mfd_sd_probe_slot(struct sdhci_pci_slot *slot)
226 if (irq < 0) 205 if (irq < 0)
227 goto out_free; 206 goto out_free;
228 207
229 err = request_irq(irq, mfd_sd_cd, IRQF_TRIGGER_RISING | 208 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
230 IRQF_TRIGGER_FALLING, "sd_cd", slot); 209 IRQF_TRIGGER_FALLING, "sd_cd", slot);
231 if (err) 210 if (err)
232 goto out_free; 211 goto out_free;
233 212
234 slot->cd_gpio = gpio; 213 slot->cd_gpio = gpio;
235 slot->cd_irq = irq; 214 slot->cd_irq = irq;
236 slot->host->quirks2 |= SDHCI_QUIRK2_OWN_CARD_DETECTION;
237 215
238 return 0; 216 return;
239 217
240out_free: 218out_free:
241 gpio_free(gpio); 219 gpio_free(gpio);
242out: 220out:
243 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n"); 221 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
244 return 0;
245} 222}
246 223
247static void mfd_sd_remove_slot(struct sdhci_pci_slot *slot, int dead) 224static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
248{ 225{
249 if (slot->cd_irq >= 0) 226 if (slot->cd_irq >= 0)
250 free_irq(slot->cd_irq, slot); 227 free_irq(slot->cd_irq, slot);
251 gpio_free(slot->cd_gpio); 228 if (gpio_is_valid(slot->cd_gpio))
229 gpio_free(slot->cd_gpio);
252} 230}
253 231
254#else 232#else
255 233
256#define mfd_sd_probe_slot NULL 234static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
257#define mfd_sd_remove_slot NULL 235{
236}
237
238static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
239{
240}
258 241
259#endif 242#endif
260 243
261static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot) 244static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
262{ 245{
263 const char *name = NULL;
264 int gpio = -EINVAL;
265
266 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, mfd_emmc_gpio_parse);
267
268 switch (slot->chip->pdev->device) {
269 case PCI_DEVICE_ID_INTEL_MFD_EMMC0:
270 gpio = mfd_emmc0_rst_gpio;
271 name = "eMMC0_reset";
272 break;
273 case PCI_DEVICE_ID_INTEL_MFD_EMMC1:
274 gpio = mfd_emmc1_rst_gpio;
275 name = "eMMC1_reset";
276 break;
277 }
278
279 if (!gpio_request(gpio, name)) {
280 gpio_direction_output(gpio, 1);
281 slot->rst_n_gpio = gpio;
282 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
283 }
284
285 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE; 246 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
286
287 slot->host->mmc->caps2 = MMC_CAP2_BOOTPART_NOACC; 247 slot->host->mmc->caps2 = MMC_CAP2_BOOTPART_NOACC;
288
289 return 0; 248 return 0;
290} 249}
291 250
292static void mfd_emmc_remove_slot(struct sdhci_pci_slot *slot, int dead) 251static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
293{ 252{
294 gpio_free(slot->rst_n_gpio); 253 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD;
254 return 0;
295} 255}
296 256
297static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = { 257static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
@@ -307,20 +267,18 @@ static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
307static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = { 267static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
308 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 268 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
309 .allow_runtime_pm = true, 269 .allow_runtime_pm = true,
310 .probe_slot = mfd_sd_probe_slot,
311 .remove_slot = mfd_sd_remove_slot,
312}; 270};
313 271
314static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = { 272static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
315 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 273 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
316 .allow_runtime_pm = true, 274 .allow_runtime_pm = true,
275 .probe_slot = mfd_sdio_probe_slot,
317}; 276};
318 277
319static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = { 278static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
320 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 279 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
321 .allow_runtime_pm = true, 280 .allow_runtime_pm = true,
322 .probe_slot = mfd_emmc_probe_slot, 281 .probe_slot = mfd_emmc_probe_slot,
323 .remove_slot = mfd_emmc_remove_slot,
324}; 282};
325 283
326/* O2Micro extra registers */ 284/* O2Micro extra registers */
@@ -1012,11 +970,8 @@ static int sdhci_pci_suspend(struct device *dev)
1012 970
1013 ret = sdhci_suspend_host(slot->host); 971 ret = sdhci_suspend_host(slot->host);
1014 972
1015 if (ret) { 973 if (ret)
1016 for (i--; i >= 0; i--) 974 goto err_pci_suspend;
1017 sdhci_resume_host(chip->slots[i]->host);
1018 return ret;
1019 }
1020 975
1021 slot_pm_flags = slot->host->mmc->pm_flags; 976 slot_pm_flags = slot->host->mmc->pm_flags;
1022 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ) 977 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
@@ -1027,11 +982,8 @@ static int sdhci_pci_suspend(struct device *dev)
1027 982
1028 if (chip->fixes && chip->fixes->suspend) { 983 if (chip->fixes && chip->fixes->suspend) {
1029 ret = chip->fixes->suspend(chip); 984 ret = chip->fixes->suspend(chip);
1030 if (ret) { 985 if (ret)
1031 for (i = chip->num_slots - 1; i >= 0; i--) 986 goto err_pci_suspend;
1032 sdhci_resume_host(chip->slots[i]->host);
1033 return ret;
1034 }
1035 } 987 }
1036 988
1037 pci_save_state(pdev); 989 pci_save_state(pdev);
@@ -1048,6 +1000,11 @@ static int sdhci_pci_suspend(struct device *dev)
1048 } 1000 }
1049 1001
1050 return 0; 1002 return 0;
1003
1004err_pci_suspend:
1005 while (--i >= 0)
1006 sdhci_resume_host(chip->slots[i]->host);
1007 return ret;
1051} 1008}
1052 1009
1053static int sdhci_pci_resume(struct device *dev) 1010static int sdhci_pci_resume(struct device *dev)
@@ -1113,23 +1070,22 @@ static int sdhci_pci_runtime_suspend(struct device *dev)
1113 1070
1114 ret = sdhci_runtime_suspend_host(slot->host); 1071 ret = sdhci_runtime_suspend_host(slot->host);
1115 1072
1116 if (ret) { 1073 if (ret)
1117 for (i--; i >= 0; i--) 1074 goto err_pci_runtime_suspend;
1118 sdhci_runtime_resume_host(chip->slots[i]->host);
1119 return ret;
1120 }
1121 } 1075 }
1122 1076
1123 if (chip->fixes && chip->fixes->suspend) { 1077 if (chip->fixes && chip->fixes->suspend) {
1124 ret = chip->fixes->suspend(chip); 1078 ret = chip->fixes->suspend(chip);
1125 if (ret) { 1079 if (ret)
1126 for (i = chip->num_slots - 1; i >= 0; i--) 1080 goto err_pci_runtime_suspend;
1127 sdhci_runtime_resume_host(chip->slots[i]->host);
1128 return ret;
1129 }
1130 } 1081 }
1131 1082
1132 return 0; 1083 return 0;
1084
1085err_pci_runtime_suspend:
1086 while (--i >= 0)
1087 sdhci_runtime_resume_host(chip->slots[i]->host);
1088 return ret;
1133} 1089}
1134 1090
1135static int sdhci_pci_runtime_resume(struct device *dev) 1091static int sdhci_pci_runtime_resume(struct device *dev)
@@ -1190,11 +1146,12 @@ static const struct dev_pm_ops sdhci_pci_pm_ops = {
1190\*****************************************************************************/ 1146\*****************************************************************************/
1191 1147
1192static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot( 1148static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
1193 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar) 1149 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1150 int slotno)
1194{ 1151{
1195 struct sdhci_pci_slot *slot; 1152 struct sdhci_pci_slot *slot;
1196 struct sdhci_host *host; 1153 struct sdhci_host *host;
1197 int ret; 1154 int ret, bar = first_bar + slotno;
1198 1155
1199 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { 1156 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1200 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); 1157 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
@@ -1228,6 +1185,23 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
1228 slot->host = host; 1185 slot->host = host;
1229 slot->pci_bar = bar; 1186 slot->pci_bar = bar;
1230 slot->rst_n_gpio = -EINVAL; 1187 slot->rst_n_gpio = -EINVAL;
1188 slot->cd_gpio = -EINVAL;
1189
1190 /* Retrieve platform data if there is any */
1191 if (*sdhci_pci_get_data)
1192 slot->data = sdhci_pci_get_data(pdev, slotno);
1193
1194 if (slot->data) {
1195 if (slot->data->setup) {
1196 ret = slot->data->setup(slot->data);
1197 if (ret) {
1198 dev_err(&pdev->dev, "platform setup failed\n");
1199 goto free;
1200 }
1201 }
1202 slot->rst_n_gpio = slot->data->rst_n_gpio;
1203 slot->cd_gpio = slot->data->cd_gpio;
1204 }
1231 1205
1232 host->hw_name = "PCI"; 1206 host->hw_name = "PCI";
1233 host->ops = &sdhci_pci_ops; 1207 host->ops = &sdhci_pci_ops;
@@ -1238,7 +1212,7 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
1238 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc)); 1212 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1239 if (ret) { 1213 if (ret) {
1240 dev_err(&pdev->dev, "cannot request region\n"); 1214 dev_err(&pdev->dev, "cannot request region\n");
1241 goto free; 1215 goto cleanup;
1242 } 1216 }
1243 1217
1244 host->ioaddr = pci_ioremap_bar(pdev, bar); 1218 host->ioaddr = pci_ioremap_bar(pdev, bar);
@@ -1254,15 +1228,30 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
1254 goto unmap; 1228 goto unmap;
1255 } 1229 }
1256 1230
1231 if (gpio_is_valid(slot->rst_n_gpio)) {
1232 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1233 gpio_direction_output(slot->rst_n_gpio, 1);
1234 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
1235 } else {
1236 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1237 slot->rst_n_gpio = -EINVAL;
1238 }
1239 }
1240
1257 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; 1241 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
1258 1242
1259 ret = sdhci_add_host(host); 1243 ret = sdhci_add_host(host);
1260 if (ret) 1244 if (ret)
1261 goto remove; 1245 goto remove;
1262 1246
1247 sdhci_pci_add_own_cd(slot);
1248
1263 return slot; 1249 return slot;
1264 1250
1265remove: 1251remove:
1252 if (gpio_is_valid(slot->rst_n_gpio))
1253 gpio_free(slot->rst_n_gpio);
1254
1266 if (chip->fixes && chip->fixes->remove_slot) 1255 if (chip->fixes && chip->fixes->remove_slot)
1267 chip->fixes->remove_slot(slot, 0); 1256 chip->fixes->remove_slot(slot, 0);
1268 1257
@@ -1272,6 +1261,10 @@ unmap:
1272release: 1261release:
1273 pci_release_region(pdev, bar); 1262 pci_release_region(pdev, bar);
1274 1263
1264cleanup:
1265 if (slot->data && slot->data->cleanup)
1266 slot->data->cleanup(slot->data);
1267
1275free: 1268free:
1276 sdhci_free_host(host); 1269 sdhci_free_host(host);
1277 1270
@@ -1283,6 +1276,8 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1283 int dead; 1276 int dead;
1284 u32 scratch; 1277 u32 scratch;
1285 1278
1279 sdhci_pci_remove_own_cd(slot);
1280
1286 dead = 0; 1281 dead = 0;
1287 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS); 1282 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1288 if (scratch == (u32)-1) 1283 if (scratch == (u32)-1)
@@ -1290,9 +1285,15 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1290 1285
1291 sdhci_remove_host(slot->host, dead); 1286 sdhci_remove_host(slot->host, dead);
1292 1287
1288 if (gpio_is_valid(slot->rst_n_gpio))
1289 gpio_free(slot->rst_n_gpio);
1290
1293 if (slot->chip->fixes && slot->chip->fixes->remove_slot) 1291 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
1294 slot->chip->fixes->remove_slot(slot, dead); 1292 slot->chip->fixes->remove_slot(slot, dead);
1295 1293
1294 if (slot->data && slot->data->cleanup)
1295 slot->data->cleanup(slot->data);
1296
1296 pci_release_region(slot->chip->pdev, slot->pci_bar); 1297 pci_release_region(slot->chip->pdev, slot->pci_bar);
1297 1298
1298 sdhci_free_host(slot->host); 1299 sdhci_free_host(slot->host);
@@ -1379,7 +1380,7 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1379 slots = chip->num_slots; /* Quirk may have changed this */ 1380 slots = chip->num_slots; /* Quirk may have changed this */
1380 1381
1381 for (i = 0; i < slots; i++) { 1382 for (i = 0; i < slots; i++) {
1382 slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i); 1383 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
1383 if (IS_ERR(slot)) { 1384 if (IS_ERR(slot)) {
1384 for (i--; i >= 0; i--) 1385 for (i--; i >= 0; i--)
1385 sdhci_pci_remove_slot(chip->slots[i]); 1386 sdhci_pci_remove_slot(chip->slots[i]);
diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c
index 7a039c3cb1f1..dbb75bfbcffb 100644
--- a/drivers/mmc/host/sdhci-pxav2.c
+++ b/drivers/mmc/host/sdhci-pxav2.c
@@ -223,18 +223,8 @@ static struct platform_driver sdhci_pxav2_driver = {
223 .probe = sdhci_pxav2_probe, 223 .probe = sdhci_pxav2_probe,
224 .remove = __devexit_p(sdhci_pxav2_remove), 224 .remove = __devexit_p(sdhci_pxav2_remove),
225}; 225};
226static int __init sdhci_pxav2_init(void)
227{
228 return platform_driver_register(&sdhci_pxav2_driver);
229}
230
231static void __exit sdhci_pxav2_exit(void)
232{
233 platform_driver_unregister(&sdhci_pxav2_driver);
234}
235 226
236module_init(sdhci_pxav2_init); 227module_platform_driver(sdhci_pxav2_driver);
237module_exit(sdhci_pxav2_exit);
238 228
239MODULE_DESCRIPTION("SDHCI driver for pxav2"); 229MODULE_DESCRIPTION("SDHCI driver for pxav2");
240MODULE_AUTHOR("Marvell International Ltd."); 230MODULE_AUTHOR("Marvell International Ltd.");
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index 15673a7ee6a5..f29695683556 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -269,18 +269,8 @@ static struct platform_driver sdhci_pxav3_driver = {
269 .probe = sdhci_pxav3_probe, 269 .probe = sdhci_pxav3_probe,
270 .remove = __devexit_p(sdhci_pxav3_remove), 270 .remove = __devexit_p(sdhci_pxav3_remove),
271}; 271};
272static int __init sdhci_pxav3_init(void)
273{
274 return platform_driver_register(&sdhci_pxav3_driver);
275}
276
277static void __exit sdhci_pxav3_exit(void)
278{
279 platform_driver_unregister(&sdhci_pxav3_driver);
280}
281 272
282module_init(sdhci_pxav3_init); 273module_platform_driver(sdhci_pxav3_driver);
283module_exit(sdhci_pxav3_exit);
284 274
285MODULE_DESCRIPTION("SDHCI driver for pxav3"); 275MODULE_DESCRIPTION("SDHCI driver for pxav3");
286MODULE_AUTHOR("Marvell International Ltd."); 276MODULE_AUTHOR("Marvell International Ltd.");
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 9a20d1f55bb7..1af756ee0f9a 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -80,7 +80,7 @@ static void sdhci_s3c_check_sclk(struct sdhci_host *host)
80 80
81 tmp &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK; 81 tmp &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
82 tmp |= ourhost->cur_clk << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT; 82 tmp |= ourhost->cur_clk << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
83 writel(tmp, host->ioaddr + 0x80); 83 writel(tmp, host->ioaddr + S3C_SDHCI_CONTROL2);
84 } 84 }
85} 85}
86 86
@@ -521,6 +521,9 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
521 if (pdata->host_caps) 521 if (pdata->host_caps)
522 host->mmc->caps |= pdata->host_caps; 522 host->mmc->caps |= pdata->host_caps;
523 523
524 if (pdata->pm_caps)
525 host->mmc->pm_caps |= pdata->pm_caps;
526
524 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | 527 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
525 SDHCI_QUIRK_32BIT_DMA_SIZE); 528 SDHCI_QUIRK_32BIT_DMA_SIZE);
526 529
@@ -654,18 +657,7 @@ static struct platform_driver sdhci_s3c_driver = {
654 }, 657 },
655}; 658};
656 659
657static int __init sdhci_s3c_init(void) 660module_platform_driver(sdhci_s3c_driver);
658{
659 return platform_driver_register(&sdhci_s3c_driver);
660}
661
662static void __exit sdhci_s3c_exit(void)
663{
664 platform_driver_unregister(&sdhci_s3c_driver);
665}
666
667module_init(sdhci_s3c_init);
668module_exit(sdhci_s3c_exit);
669 661
670MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue"); 662MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");
671MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 663MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
index 63cc8b6a1c9e..b7f8b33c5f19 100644
--- a/drivers/mmc/host/sdhci-spear.c
+++ b/drivers/mmc/host/sdhci-spear.c
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/pm.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/mmc/host.h> 26#include <linux/mmc/host.h>
26#include <linux/mmc/sdhci-spear.h> 27#include <linux/mmc/sdhci-spear.h>
@@ -271,26 +272,54 @@ static int __devexit sdhci_remove(struct platform_device *pdev)
271 return 0; 272 return 0;
272} 273}
273 274
275#ifdef CONFIG_PM
276static int sdhci_suspend(struct device *dev)
277{
278 struct sdhci_host *host = dev_get_drvdata(dev);
279 struct spear_sdhci *sdhci = dev_get_platdata(dev);
280 int ret;
281
282 ret = sdhci_suspend_host(host);
283 if (!ret)
284 clk_disable(sdhci->clk);
285
286 return ret;
287}
288
289static int sdhci_resume(struct device *dev)
290{
291 struct sdhci_host *host = dev_get_drvdata(dev);
292 struct spear_sdhci *sdhci = dev_get_platdata(dev);
293 int ret;
294
295 ret = clk_enable(sdhci->clk);
296 if (ret) {
297 dev_dbg(dev, "Resume: Error enabling clock\n");
298 return ret;
299 }
300
301 return sdhci_resume_host(host);
302}
303
304const struct dev_pm_ops sdhci_pm_ops = {
305 .suspend = sdhci_suspend,
306 .resume = sdhci_resume,
307};
308#endif
309
274static struct platform_driver sdhci_driver = { 310static struct platform_driver sdhci_driver = {
275 .driver = { 311 .driver = {
276 .name = "sdhci", 312 .name = "sdhci",
277 .owner = THIS_MODULE, 313 .owner = THIS_MODULE,
314#ifdef CONFIG_PM
315 .pm = &sdhci_pm_ops,
316#endif
278 }, 317 },
279 .probe = sdhci_probe, 318 .probe = sdhci_probe,
280 .remove = __devexit_p(sdhci_remove), 319 .remove = __devexit_p(sdhci_remove),
281}; 320};
282 321
283static int __init sdhci_init(void) 322module_platform_driver(sdhci_driver);
284{
285 return platform_driver_register(&sdhci_driver);
286}
287module_init(sdhci_init);
288
289static void __exit sdhci_exit(void)
290{
291 platform_driver_unregister(&sdhci_driver);
292}
293module_exit(sdhci_exit);
294 323
295MODULE_DESCRIPTION("SPEAr Secure Digital Host Controller Interface driver"); 324MODULE_DESCRIPTION("SPEAr Secure Digital Host Controller Interface driver");
296MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>"); 325MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>");
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index e2e18d3f949c..78a36eba4df0 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -324,17 +324,7 @@ static struct platform_driver sdhci_tegra_driver = {
324 .remove = __devexit_p(sdhci_tegra_remove), 324 .remove = __devexit_p(sdhci_tegra_remove),
325}; 325};
326 326
327static int __init sdhci_tegra_init(void) 327module_platform_driver(sdhci_tegra_driver);
328{
329 return platform_driver_register(&sdhci_tegra_driver);
330}
331module_init(sdhci_tegra_init);
332
333static void __exit sdhci_tegra_exit(void)
334{
335 platform_driver_unregister(&sdhci_tegra_driver);
336}
337module_exit(sdhci_tegra_exit);
338 328
339MODULE_DESCRIPTION("SDHCI driver for Tegra"); 329MODULE_DESCRIPTION("SDHCI driver for Tegra");
340MODULE_AUTHOR(" Google, Inc."); 330MODULE_AUTHOR(" Google, Inc.");
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 19ed580f2cab..8d66706824a6 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -49,7 +49,7 @@ static void sdhci_finish_data(struct sdhci_host *);
49 49
50static void sdhci_send_command(struct sdhci_host *, struct mmc_command *); 50static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
51static void sdhci_finish_command(struct sdhci_host *); 51static void sdhci_finish_command(struct sdhci_host *);
52static int sdhci_execute_tuning(struct mmc_host *mmc); 52static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
53static void sdhci_tuning_timer(unsigned long data); 53static void sdhci_tuning_timer(unsigned long data);
54 54
55#ifdef CONFIG_PM_RUNTIME 55#ifdef CONFIG_PM_RUNTIME
@@ -146,10 +146,8 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
146{ 146{
147 u32 present, irqs; 147 u32 present, irqs;
148 148
149 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) 149 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
150 return; 150 !mmc_card_is_removable(host->mmc))
151
152 if (host->quirks2 & SDHCI_QUIRK2_OWN_CARD_DETECTION)
153 return; 151 return;
154 152
155 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & 153 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
@@ -214,6 +212,11 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
214 212
215 if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET) 213 if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET)
216 sdhci_clear_set_irqs(host, SDHCI_INT_ALL_MASK, ier); 214 sdhci_clear_set_irqs(host, SDHCI_INT_ALL_MASK, ier);
215
216 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
217 if ((host->ops->enable_dma) && (mask & SDHCI_RESET_ALL))
218 host->ops->enable_dma(host);
219 }
217} 220}
218 221
219static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios); 222static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios);
@@ -423,12 +426,12 @@ static void sdhci_transfer_pio(struct sdhci_host *host)
423static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags) 426static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
424{ 427{
425 local_irq_save(*flags); 428 local_irq_save(*flags);
426 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; 429 return kmap_atomic(sg_page(sg)) + sg->offset;
427} 430}
428 431
429static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags) 432static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
430{ 433{
431 kunmap_atomic(buffer, KM_BIO_SRC_IRQ); 434 kunmap_atomic(buffer);
432 local_irq_restore(*flags); 435 local_irq_restore(*flags);
433} 436}
434 437
@@ -1016,7 +1019,8 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
1016 flags |= SDHCI_CMD_INDEX; 1019 flags |= SDHCI_CMD_INDEX;
1017 1020
1018 /* CMD19 is special in that the Data Present Select should be set */ 1021 /* CMD19 is special in that the Data Present Select should be set */
1019 if (cmd->data || (cmd->opcode == MMC_SEND_TUNING_BLOCK)) 1022 if (cmd->data || cmd->opcode == MMC_SEND_TUNING_BLOCK ||
1023 cmd->opcode == MMC_SEND_TUNING_BLOCK_HS200)
1020 flags |= SDHCI_CMD_DATA; 1024 flags |= SDHCI_CMD_DATA;
1021 1025
1022 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); 1026 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
@@ -1066,12 +1070,15 @@ static void sdhci_finish_command(struct sdhci_host *host)
1066static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) 1070static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1067{ 1071{
1068 int div = 0; /* Initialized for compiler warning */ 1072 int div = 0; /* Initialized for compiler warning */
1073 int real_div = div, clk_mul = 1;
1069 u16 clk = 0; 1074 u16 clk = 0;
1070 unsigned long timeout; 1075 unsigned long timeout;
1071 1076
1072 if (clock == host->clock) 1077 if (clock && clock == host->clock)
1073 return; 1078 return;
1074 1079
1080 host->mmc->actual_clock = 0;
1081
1075 if (host->ops->set_clock) { 1082 if (host->ops->set_clock) {
1076 host->ops->set_clock(host, clock); 1083 host->ops->set_clock(host, clock);
1077 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) 1084 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK)
@@ -1109,6 +1116,8 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1109 * Control register. 1116 * Control register.
1110 */ 1117 */
1111 clk = SDHCI_PROG_CLOCK_MODE; 1118 clk = SDHCI_PROG_CLOCK_MODE;
1119 real_div = div;
1120 clk_mul = host->clk_mul;
1112 div--; 1121 div--;
1113 } 1122 }
1114 } else { 1123 } else {
@@ -1122,6 +1131,7 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1122 break; 1131 break;
1123 } 1132 }
1124 } 1133 }
1134 real_div = div;
1125 div >>= 1; 1135 div >>= 1;
1126 } 1136 }
1127 } else { 1137 } else {
@@ -1130,9 +1140,13 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1130 if ((host->max_clk / div) <= clock) 1140 if ((host->max_clk / div) <= clock)
1131 break; 1141 break;
1132 } 1142 }
1143 real_div = div;
1133 div >>= 1; 1144 div >>= 1;
1134 } 1145 }
1135 1146
1147 if (real_div)
1148 host->mmc->actual_clock = (host->max_clk * clk_mul) / real_div;
1149
1136 clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT; 1150 clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
1137 clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN) 1151 clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
1138 << SDHCI_DIVIDER_HI_SHIFT; 1152 << SDHCI_DIVIDER_HI_SHIFT;
@@ -1160,7 +1174,7 @@ out:
1160 host->clock = clock; 1174 host->clock = clock;
1161} 1175}
1162 1176
1163static void sdhci_set_power(struct sdhci_host *host, unsigned short power) 1177static int sdhci_set_power(struct sdhci_host *host, unsigned short power)
1164{ 1178{
1165 u8 pwr = 0; 1179 u8 pwr = 0;
1166 1180
@@ -1183,13 +1197,13 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
1183 } 1197 }
1184 1198
1185 if (host->pwr == pwr) 1199 if (host->pwr == pwr)
1186 return; 1200 return -1;
1187 1201
1188 host->pwr = pwr; 1202 host->pwr = pwr;
1189 1203
1190 if (pwr == 0) { 1204 if (pwr == 0) {
1191 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); 1205 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
1192 return; 1206 return 0;
1193 } 1207 }
1194 1208
1195 /* 1209 /*
@@ -1216,6 +1230,8 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
1216 */ 1230 */
1217 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) 1231 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER)
1218 mdelay(10); 1232 mdelay(10);
1233
1234 return power;
1219} 1235}
1220 1236
1221/*****************************************************************************\ 1237/*****************************************************************************\
@@ -1277,7 +1293,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1277 if ((host->flags & SDHCI_NEEDS_RETUNING) && 1293 if ((host->flags & SDHCI_NEEDS_RETUNING) &&
1278 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { 1294 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) {
1279 spin_unlock_irqrestore(&host->lock, flags); 1295 spin_unlock_irqrestore(&host->lock, flags);
1280 sdhci_execute_tuning(mmc); 1296 sdhci_execute_tuning(mmc, mrq->cmd->opcode);
1281 spin_lock_irqsave(&host->lock, flags); 1297 spin_lock_irqsave(&host->lock, flags);
1282 1298
1283 /* Restore original mmc_request structure */ 1299 /* Restore original mmc_request structure */
@@ -1297,12 +1313,17 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1297static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios) 1313static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1298{ 1314{
1299 unsigned long flags; 1315 unsigned long flags;
1316 int vdd_bit = -1;
1300 u8 ctrl; 1317 u8 ctrl;
1301 1318
1302 spin_lock_irqsave(&host->lock, flags); 1319 spin_lock_irqsave(&host->lock, flags);
1303 1320
1304 if (host->flags & SDHCI_DEVICE_DEAD) 1321 if (host->flags & SDHCI_DEVICE_DEAD) {
1305 goto out; 1322 spin_unlock_irqrestore(&host->lock, flags);
1323 if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
1324 mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
1325 return;
1326 }
1306 1327
1307 /* 1328 /*
1308 * Reset the chip on each power off. 1329 * Reset the chip on each power off.
@@ -1316,9 +1337,15 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1316 sdhci_set_clock(host, ios->clock); 1337 sdhci_set_clock(host, ios->clock);
1317 1338
1318 if (ios->power_mode == MMC_POWER_OFF) 1339 if (ios->power_mode == MMC_POWER_OFF)
1319 sdhci_set_power(host, -1); 1340 vdd_bit = sdhci_set_power(host, -1);
1320 else 1341 else
1321 sdhci_set_power(host, ios->vdd); 1342 vdd_bit = sdhci_set_power(host, ios->vdd);
1343
1344 if (host->vmmc && vdd_bit != -1) {
1345 spin_unlock_irqrestore(&host->lock, flags);
1346 mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
1347 spin_lock_irqsave(&host->lock, flags);
1348 }
1322 1349
1323 if (host->ops->platform_send_init_74_clocks) 1350 if (host->ops->platform_send_init_74_clocks)
1324 host->ops->platform_send_init_74_clocks(host, ios->power_mode); 1351 host->ops->platform_send_init_74_clocks(host, ios->power_mode);
@@ -1361,11 +1388,11 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1361 unsigned int clock; 1388 unsigned int clock;
1362 1389
1363 /* In case of UHS-I modes, set High Speed Enable */ 1390 /* In case of UHS-I modes, set High Speed Enable */
1364 if ((ios->timing == MMC_TIMING_UHS_SDR50) || 1391 if ((ios->timing == MMC_TIMING_MMC_HS200) ||
1392 (ios->timing == MMC_TIMING_UHS_SDR50) ||
1365 (ios->timing == MMC_TIMING_UHS_SDR104) || 1393 (ios->timing == MMC_TIMING_UHS_SDR104) ||
1366 (ios->timing == MMC_TIMING_UHS_DDR50) || 1394 (ios->timing == MMC_TIMING_UHS_DDR50) ||
1367 (ios->timing == MMC_TIMING_UHS_SDR25) || 1395 (ios->timing == MMC_TIMING_UHS_SDR25))
1368 (ios->timing == MMC_TIMING_UHS_SDR12))
1369 ctrl |= SDHCI_CTRL_HISPD; 1396 ctrl |= SDHCI_CTRL_HISPD;
1370 1397
1371 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1398 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
@@ -1415,7 +1442,9 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1415 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1442 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1416 /* Select Bus Speed Mode for host */ 1443 /* Select Bus Speed Mode for host */
1417 ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; 1444 ctrl_2 &= ~SDHCI_CTRL_UHS_MASK;
1418 if (ios->timing == MMC_TIMING_UHS_SDR12) 1445 if (ios->timing == MMC_TIMING_MMC_HS200)
1446 ctrl_2 |= SDHCI_CTRL_HS_SDR200;
1447 else if (ios->timing == MMC_TIMING_UHS_SDR12)
1419 ctrl_2 |= SDHCI_CTRL_UHS_SDR12; 1448 ctrl_2 |= SDHCI_CTRL_UHS_SDR12;
1420 else if (ios->timing == MMC_TIMING_UHS_SDR25) 1449 else if (ios->timing == MMC_TIMING_UHS_SDR25)
1421 ctrl_2 |= SDHCI_CTRL_UHS_SDR25; 1450 ctrl_2 |= SDHCI_CTRL_UHS_SDR25;
@@ -1443,7 +1472,6 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1443 if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS) 1472 if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
1444 sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); 1473 sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
1445 1474
1446out:
1447 mmiowb(); 1475 mmiowb();
1448 spin_unlock_irqrestore(&host->lock, flags); 1476 spin_unlock_irqrestore(&host->lock, flags);
1449} 1477}
@@ -1663,7 +1691,7 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1663 return err; 1691 return err;
1664} 1692}
1665 1693
1666static int sdhci_execute_tuning(struct mmc_host *mmc) 1694static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1667{ 1695{
1668 struct sdhci_host *host; 1696 struct sdhci_host *host;
1669 u16 ctrl; 1697 u16 ctrl;
@@ -1671,6 +1699,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1671 int tuning_loop_counter = MAX_TUNING_LOOP; 1699 int tuning_loop_counter = MAX_TUNING_LOOP;
1672 unsigned long timeout; 1700 unsigned long timeout;
1673 int err = 0; 1701 int err = 0;
1702 bool requires_tuning_nonuhs = false;
1674 1703
1675 host = mmc_priv(mmc); 1704 host = mmc_priv(mmc);
1676 1705
@@ -1681,13 +1710,19 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1681 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1710 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1682 1711
1683 /* 1712 /*
1684 * Host Controller needs tuning only in case of SDR104 mode 1713 * The Host Controller needs tuning only in case of SDR104 mode
1685 * and for SDR50 mode when Use Tuning for SDR50 is set in 1714 * and for SDR50 mode when Use Tuning for SDR50 is set in the
1686 * Capabilities register. 1715 * Capabilities register.
1716 * If the Host Controller supports the HS200 mode then the
1717 * tuning function has to be executed.
1687 */ 1718 */
1719 if (((ctrl & SDHCI_CTRL_UHS_MASK) == SDHCI_CTRL_UHS_SDR50) &&
1720 (host->flags & SDHCI_SDR50_NEEDS_TUNING ||
1721 host->flags & SDHCI_HS200_NEEDS_TUNING))
1722 requires_tuning_nonuhs = true;
1723
1688 if (((ctrl & SDHCI_CTRL_UHS_MASK) == SDHCI_CTRL_UHS_SDR104) || 1724 if (((ctrl & SDHCI_CTRL_UHS_MASK) == SDHCI_CTRL_UHS_SDR104) ||
1689 (((ctrl & SDHCI_CTRL_UHS_MASK) == SDHCI_CTRL_UHS_SDR50) && 1725 requires_tuning_nonuhs)
1690 (host->flags & SDHCI_SDR50_NEEDS_TUNING)))
1691 ctrl |= SDHCI_CTRL_EXEC_TUNING; 1726 ctrl |= SDHCI_CTRL_EXEC_TUNING;
1692 else { 1727 else {
1693 spin_unlock(&host->lock); 1728 spin_unlock(&host->lock);
@@ -1723,7 +1758,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1723 if (!tuning_loop_counter && !timeout) 1758 if (!tuning_loop_counter && !timeout)
1724 break; 1759 break;
1725 1760
1726 cmd.opcode = MMC_SEND_TUNING_BLOCK; 1761 cmd.opcode = opcode;
1727 cmd.arg = 0; 1762 cmd.arg = 0;
1728 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 1763 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
1729 cmd.retries = 0; 1764 cmd.retries = 0;
@@ -1738,7 +1773,17 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1738 * block to the Host Controller. So we set the block size 1773 * block to the Host Controller. So we set the block size
1739 * to 64 here. 1774 * to 64 here.
1740 */ 1775 */
1741 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64), SDHCI_BLOCK_SIZE); 1776 if (cmd.opcode == MMC_SEND_TUNING_BLOCK_HS200) {
1777 if (mmc->ios.bus_width == MMC_BUS_WIDTH_8)
1778 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 128),
1779 SDHCI_BLOCK_SIZE);
1780 else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4)
1781 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
1782 SDHCI_BLOCK_SIZE);
1783 } else {
1784 sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, 64),
1785 SDHCI_BLOCK_SIZE);
1786 }
1742 1787
1743 /* 1788 /*
1744 * The tuning block is sent by the card to the host controller. 1789 * The tuning block is sent by the card to the host controller.
@@ -2121,12 +2166,14 @@ static void sdhci_show_adma_error(struct sdhci_host *host) { }
2121 2166
2122static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) 2167static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2123{ 2168{
2169 u32 command;
2124 BUG_ON(intmask == 0); 2170 BUG_ON(intmask == 0);
2125 2171
2126 /* CMD19 generates _only_ Buffer Read Ready interrupt */ 2172 /* CMD19 generates _only_ Buffer Read Ready interrupt */
2127 if (intmask & SDHCI_INT_DATA_AVAIL) { 2173 if (intmask & SDHCI_INT_DATA_AVAIL) {
2128 if (SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) == 2174 command = SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND));
2129 MMC_SEND_TUNING_BLOCK) { 2175 if (command == MMC_SEND_TUNING_BLOCK ||
2176 command == MMC_SEND_TUNING_BLOCK_HS200) {
2130 host->tuning_done = 1; 2177 host->tuning_done = 1;
2131 wake_up(&host->buf_ready_int); 2178 wake_up(&host->buf_ready_int);
2132 return; 2179 return;
@@ -2330,26 +2377,33 @@ out:
2330int sdhci_suspend_host(struct sdhci_host *host) 2377int sdhci_suspend_host(struct sdhci_host *host)
2331{ 2378{
2332 int ret; 2379 int ret;
2380 bool has_tuning_timer;
2333 2381
2334 sdhci_disable_card_detection(host); 2382 sdhci_disable_card_detection(host);
2335 2383
2336 /* Disable tuning since we are suspending */ 2384 /* Disable tuning since we are suspending */
2337 if (host->version >= SDHCI_SPEC_300 && host->tuning_count && 2385 has_tuning_timer = host->version >= SDHCI_SPEC_300 &&
2338 host->tuning_mode == SDHCI_TUNING_MODE_1) { 2386 host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1;
2387 if (has_tuning_timer) {
2388 del_timer_sync(&host->tuning_timer);
2339 host->flags &= ~SDHCI_NEEDS_RETUNING; 2389 host->flags &= ~SDHCI_NEEDS_RETUNING;
2340 mod_timer(&host->tuning_timer, jiffies +
2341 host->tuning_count * HZ);
2342 } 2390 }
2343 2391
2344 ret = mmc_suspend_host(host->mmc); 2392 ret = mmc_suspend_host(host->mmc);
2345 if (ret) 2393 if (ret) {
2394 if (has_tuning_timer) {
2395 host->flags |= SDHCI_NEEDS_RETUNING;
2396 mod_timer(&host->tuning_timer, jiffies +
2397 host->tuning_count * HZ);
2398 }
2399
2400 sdhci_enable_card_detection(host);
2401
2346 return ret; 2402 return ret;
2403 }
2347 2404
2348 free_irq(host->irq, host); 2405 free_irq(host->irq, host);
2349 2406
2350 if (host->vmmc)
2351 ret = regulator_disable(host->vmmc);
2352
2353 return ret; 2407 return ret;
2354} 2408}
2355 2409
@@ -2359,12 +2413,6 @@ int sdhci_resume_host(struct sdhci_host *host)
2359{ 2413{
2360 int ret; 2414 int ret;
2361 2415
2362 if (host->vmmc) {
2363 int ret = regulator_enable(host->vmmc);
2364 if (ret)
2365 return ret;
2366 }
2367
2368 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 2416 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2369 if (host->ops->enable_dma) 2417 if (host->ops->enable_dma)
2370 host->ops->enable_dma(host); 2418 host->ops->enable_dma(host);
@@ -2727,10 +2775,14 @@ int sdhci_add_host(struct sdhci_host *host)
2727 if (caps[1] & SDHCI_SUPPORT_DDR50) 2775 if (caps[1] & SDHCI_SUPPORT_DDR50)
2728 mmc->caps |= MMC_CAP_UHS_DDR50; 2776 mmc->caps |= MMC_CAP_UHS_DDR50;
2729 2777
2730 /* Does the host needs tuning for SDR50? */ 2778 /* Does the host need tuning for SDR50? */
2731 if (caps[1] & SDHCI_USE_SDR50_TUNING) 2779 if (caps[1] & SDHCI_USE_SDR50_TUNING)
2732 host->flags |= SDHCI_SDR50_NEEDS_TUNING; 2780 host->flags |= SDHCI_SDR50_NEEDS_TUNING;
2733 2781
2782 /* Does the host need tuning for HS200? */
2783 if (mmc->caps2 & MMC_CAP2_HS200)
2784 host->flags |= SDHCI_HS200_NEEDS_TUNING;
2785
2734 /* Driver Type(s) (A, C, D) supported by the host */ 2786 /* Driver Type(s) (A, C, D) supported by the host */
2735 if (caps[1] & SDHCI_DRIVER_TYPE_A) 2787 if (caps[1] & SDHCI_DRIVER_TYPE_A)
2736 mmc->caps |= MMC_CAP_DRIVER_TYPE_A; 2788 mmc->caps |= MMC_CAP_DRIVER_TYPE_A;
@@ -2926,8 +2978,6 @@ int sdhci_add_host(struct sdhci_host *host)
2926 if (IS_ERR(host->vmmc)) { 2978 if (IS_ERR(host->vmmc)) {
2927 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); 2979 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
2928 host->vmmc = NULL; 2980 host->vmmc = NULL;
2929 } else {
2930 regulator_enable(host->vmmc);
2931 } 2981 }
2932 2982
2933 sdhci_init(host, 0); 2983 sdhci_init(host, 0);
@@ -3016,10 +3066,8 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3016 tasklet_kill(&host->card_tasklet); 3066 tasklet_kill(&host->card_tasklet);
3017 tasklet_kill(&host->finish_tasklet); 3067 tasklet_kill(&host->finish_tasklet);
3018 3068
3019 if (host->vmmc) { 3069 if (host->vmmc)
3020 regulator_disable(host->vmmc);
3021 regulator_put(host->vmmc); 3070 regulator_put(host->vmmc);
3022 }
3023 3071
3024 kfree(host->adma_desc); 3072 kfree(host->adma_desc);
3025 kfree(host->align_buffer); 3073 kfree(host->align_buffer);
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index a04d4d0c6fd2..ad265b96b75b 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -158,6 +158,7 @@
158#define SDHCI_CTRL_UHS_SDR50 0x0002 158#define SDHCI_CTRL_UHS_SDR50 0x0002
159#define SDHCI_CTRL_UHS_SDR104 0x0003 159#define SDHCI_CTRL_UHS_SDR104 0x0003
160#define SDHCI_CTRL_UHS_DDR50 0x0004 160#define SDHCI_CTRL_UHS_DDR50 0x0004
161#define SDHCI_CTRL_HS_SDR200 0x0005 /* reserved value in SDIO spec */
161#define SDHCI_CTRL_VDD_180 0x0008 162#define SDHCI_CTRL_VDD_180 0x0008
162#define SDHCI_CTRL_DRV_TYPE_MASK 0x0030 163#define SDHCI_CTRL_DRV_TYPE_MASK 0x0030
163#define SDHCI_CTRL_DRV_TYPE_B 0x0000 164#define SDHCI_CTRL_DRV_TYPE_B 0x0000
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index d5505f3fe2a1..4a2c5b2355f2 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -16,6 +16,33 @@
16 * 16 *
17 */ 17 */
18 18
19/*
20 * The MMCIF driver is now processing MMC requests asynchronously, according
21 * to the Linux MMC API requirement.
22 *
23 * The MMCIF driver processes MMC requests in up to 3 stages: command, optional
24 * data, and optional stop. To achieve asynchronous processing each of these
25 * stages is split into two halves: a top and a bottom half. The top half
26 * initialises the hardware, installs a timeout handler to handle completion
27 * timeouts, and returns. In case of the command stage this immediately returns
28 * control to the caller, leaving all further processing to run asynchronously.
29 * All further request processing is performed by the bottom halves.
30 *
31 * The bottom half further consists of a "hard" IRQ handler, an IRQ handler
32 * thread, a DMA completion callback, if DMA is used, a timeout work, and
33 * request- and stage-specific handler methods.
34 *
35 * Each bottom half run begins with either a hardware interrupt, a DMA callback
36 * invocation, or a timeout work run. In case of an error or a successful
37 * processing completion, the MMC core is informed and the request processing is
38 * finished. In case processing has to continue, i.e., if data has to be read
39 * from or written to the card, or if a stop command has to be sent, the next
40 * top half is called, which performs the necessary hardware handling and
41 * reschedules the timeout work. This returns the driver state machine into the
42 * bottom half waiting state.
43 */
44
45#include <linux/bitops.h>
19#include <linux/clk.h> 46#include <linux/clk.h>
20#include <linux/completion.h> 47#include <linux/completion.h>
21#include <linux/delay.h> 48#include <linux/delay.h>
@@ -123,6 +150,11 @@
123#define MASK_MRBSYTO (1 << 1) 150#define MASK_MRBSYTO (1 << 1)
124#define MASK_MRSPTO (1 << 0) 151#define MASK_MRSPTO (1 << 0)
125 152
153#define MASK_START_CMD (MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR | \
154 MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR | \
155 MASK_MCCSTO | MASK_MCRCSTO | MASK_MWDATTO | \
156 MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO)
157
126/* CE_HOST_STS1 */ 158/* CE_HOST_STS1 */
127#define STS1_CMDSEQ (1 << 31) 159#define STS1_CMDSEQ (1 << 31)
128 160
@@ -162,9 +194,21 @@ enum mmcif_state {
162 STATE_IOS, 194 STATE_IOS,
163}; 195};
164 196
197enum mmcif_wait_for {
198 MMCIF_WAIT_FOR_REQUEST,
199 MMCIF_WAIT_FOR_CMD,
200 MMCIF_WAIT_FOR_MREAD,
201 MMCIF_WAIT_FOR_MWRITE,
202 MMCIF_WAIT_FOR_READ,
203 MMCIF_WAIT_FOR_WRITE,
204 MMCIF_WAIT_FOR_READ_END,
205 MMCIF_WAIT_FOR_WRITE_END,
206 MMCIF_WAIT_FOR_STOP,
207};
208
165struct sh_mmcif_host { 209struct sh_mmcif_host {
166 struct mmc_host *mmc; 210 struct mmc_host *mmc;
167 struct mmc_data *data; 211 struct mmc_request *mrq;
168 struct platform_device *pd; 212 struct platform_device *pd;
169 struct sh_dmae_slave dma_slave_tx; 213 struct sh_dmae_slave dma_slave_tx;
170 struct sh_dmae_slave dma_slave_rx; 214 struct sh_dmae_slave dma_slave_rx;
@@ -172,11 +216,17 @@ struct sh_mmcif_host {
172 unsigned int clk; 216 unsigned int clk;
173 int bus_width; 217 int bus_width;
174 bool sd_error; 218 bool sd_error;
219 bool dying;
175 long timeout; 220 long timeout;
176 void __iomem *addr; 221 void __iomem *addr;
177 struct completion intr_wait; 222 u32 *pio_ptr;
223 spinlock_t lock; /* protect sh_mmcif_host::state */
178 enum mmcif_state state; 224 enum mmcif_state state;
179 spinlock_t lock; 225 enum mmcif_wait_for wait_for;
226 struct delayed_work timeout_work;
227 size_t blocksize;
228 int sg_idx;
229 int sg_blkidx;
180 bool power; 230 bool power;
181 bool card_present; 231 bool card_present;
182 232
@@ -202,19 +252,21 @@ static inline void sh_mmcif_bitclr(struct sh_mmcif_host *host,
202static void mmcif_dma_complete(void *arg) 252static void mmcif_dma_complete(void *arg)
203{ 253{
204 struct sh_mmcif_host *host = arg; 254 struct sh_mmcif_host *host = arg;
255 struct mmc_data *data = host->mrq->data;
256
205 dev_dbg(&host->pd->dev, "Command completed\n"); 257 dev_dbg(&host->pd->dev, "Command completed\n");
206 258
207 if (WARN(!host->data, "%s: NULL data in DMA completion!\n", 259 if (WARN(!data, "%s: NULL data in DMA completion!\n",
208 dev_name(&host->pd->dev))) 260 dev_name(&host->pd->dev)))
209 return; 261 return;
210 262
211 if (host->data->flags & MMC_DATA_READ) 263 if (data->flags & MMC_DATA_READ)
212 dma_unmap_sg(host->chan_rx->device->dev, 264 dma_unmap_sg(host->chan_rx->device->dev,
213 host->data->sg, host->data->sg_len, 265 data->sg, data->sg_len,
214 DMA_FROM_DEVICE); 266 DMA_FROM_DEVICE);
215 else 267 else
216 dma_unmap_sg(host->chan_tx->device->dev, 268 dma_unmap_sg(host->chan_tx->device->dev,
217 host->data->sg, host->data->sg_len, 269 data->sg, data->sg_len,
218 DMA_TO_DEVICE); 270 DMA_TO_DEVICE);
219 271
220 complete(&host->dma_complete); 272 complete(&host->dma_complete);
@@ -222,13 +274,14 @@ static void mmcif_dma_complete(void *arg)
222 274
223static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host) 275static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
224{ 276{
225 struct scatterlist *sg = host->data->sg; 277 struct mmc_data *data = host->mrq->data;
278 struct scatterlist *sg = data->sg;
226 struct dma_async_tx_descriptor *desc = NULL; 279 struct dma_async_tx_descriptor *desc = NULL;
227 struct dma_chan *chan = host->chan_rx; 280 struct dma_chan *chan = host->chan_rx;
228 dma_cookie_t cookie = -EINVAL; 281 dma_cookie_t cookie = -EINVAL;
229 int ret; 282 int ret;
230 283
231 ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len, 284 ret = dma_map_sg(chan->device->dev, sg, data->sg_len,
232 DMA_FROM_DEVICE); 285 DMA_FROM_DEVICE);
233 if (ret > 0) { 286 if (ret > 0) {
234 host->dma_active = true; 287 host->dma_active = true;
@@ -244,7 +297,7 @@ static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
244 dma_async_issue_pending(chan); 297 dma_async_issue_pending(chan);
245 } 298 }
246 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n", 299 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
247 __func__, host->data->sg_len, ret, cookie); 300 __func__, data->sg_len, ret, cookie);
248 301
249 if (!desc) { 302 if (!desc) {
250 /* DMA failed, fall back to PIO */ 303 /* DMA failed, fall back to PIO */
@@ -265,18 +318,19 @@ static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
265 } 318 }
266 319
267 dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__, 320 dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
268 desc, cookie, host->data->sg_len); 321 desc, cookie, data->sg_len);
269} 322}
270 323
271static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host) 324static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
272{ 325{
273 struct scatterlist *sg = host->data->sg; 326 struct mmc_data *data = host->mrq->data;
327 struct scatterlist *sg = data->sg;
274 struct dma_async_tx_descriptor *desc = NULL; 328 struct dma_async_tx_descriptor *desc = NULL;
275 struct dma_chan *chan = host->chan_tx; 329 struct dma_chan *chan = host->chan_tx;
276 dma_cookie_t cookie = -EINVAL; 330 dma_cookie_t cookie = -EINVAL;
277 int ret; 331 int ret;
278 332
279 ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len, 333 ret = dma_map_sg(chan->device->dev, sg, data->sg_len,
280 DMA_TO_DEVICE); 334 DMA_TO_DEVICE);
281 if (ret > 0) { 335 if (ret > 0) {
282 host->dma_active = true; 336 host->dma_active = true;
@@ -292,7 +346,7 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
292 dma_async_issue_pending(chan); 346 dma_async_issue_pending(chan);
293 } 347 }
294 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n", 348 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
295 __func__, host->data->sg_len, ret, cookie); 349 __func__, data->sg_len, ret, cookie);
296 350
297 if (!desc) { 351 if (!desc) {
298 /* DMA failed, fall back to PIO */ 352 /* DMA failed, fall back to PIO */
@@ -399,7 +453,7 @@ static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
399 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); 453 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
400 else 454 else
401 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & 455 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
402 (ilog2(__rounddown_pow_of_two(host->clk / clk)) << 16)); 456 ((fls(host->clk / clk) - 1) << 16));
403 457
404 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); 458 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
405} 459}
@@ -421,7 +475,7 @@ static void sh_mmcif_sync_reset(struct sh_mmcif_host *host)
421static int sh_mmcif_error_manage(struct sh_mmcif_host *host) 475static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
422{ 476{
423 u32 state1, state2; 477 u32 state1, state2;
424 int ret, timeout = 10000000; 478 int ret, timeout;
425 479
426 host->sd_error = false; 480 host->sd_error = false;
427 481
@@ -433,155 +487,212 @@ static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
433 if (state1 & STS1_CMDSEQ) { 487 if (state1 & STS1_CMDSEQ) {
434 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK); 488 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK);
435 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK); 489 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK);
436 while (1) { 490 for (timeout = 10000000; timeout; timeout--) {
437 timeout--;
438 if (timeout < 0) {
439 dev_err(&host->pd->dev,
440 "Forceed end of command sequence timeout err\n");
441 return -EIO;
442 }
443 if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1) 491 if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1)
444 & STS1_CMDSEQ)) 492 & STS1_CMDSEQ))
445 break; 493 break;
446 mdelay(1); 494 mdelay(1);
447 } 495 }
496 if (!timeout) {
497 dev_err(&host->pd->dev,
498 "Forced end of command sequence timeout err\n");
499 return -EIO;
500 }
448 sh_mmcif_sync_reset(host); 501 sh_mmcif_sync_reset(host);
449 dev_dbg(&host->pd->dev, "Forced end of command sequence\n"); 502 dev_dbg(&host->pd->dev, "Forced end of command sequence\n");
450 return -EIO; 503 return -EIO;
451 } 504 }
452 505
453 if (state2 & STS2_CRC_ERR) { 506 if (state2 & STS2_CRC_ERR) {
454 dev_dbg(&host->pd->dev, ": Happened CRC error\n"); 507 dev_dbg(&host->pd->dev, ": CRC error\n");
455 ret = -EIO; 508 ret = -EIO;
456 } else if (state2 & STS2_TIMEOUT_ERR) { 509 } else if (state2 & STS2_TIMEOUT_ERR) {
457 dev_dbg(&host->pd->dev, ": Happened Timeout error\n"); 510 dev_dbg(&host->pd->dev, ": Timeout\n");
458 ret = -ETIMEDOUT; 511 ret = -ETIMEDOUT;
459 } else { 512 } else {
460 dev_dbg(&host->pd->dev, ": Happened End/Index error\n"); 513 dev_dbg(&host->pd->dev, ": End/Index error\n");
461 ret = -EIO; 514 ret = -EIO;
462 } 515 }
463 return ret; 516 return ret;
464} 517}
465 518
466static int sh_mmcif_single_read(struct sh_mmcif_host *host, 519static bool sh_mmcif_next_block(struct sh_mmcif_host *host, u32 *p)
467 struct mmc_request *mrq)
468{ 520{
469 struct mmc_data *data = mrq->data; 521 struct mmc_data *data = host->mrq->data;
470 long time; 522
471 u32 blocksize, i, *p = sg_virt(data->sg); 523 host->sg_blkidx += host->blocksize;
524
525 /* data->sg->length must be a multiple of host->blocksize? */
526 BUG_ON(host->sg_blkidx > data->sg->length);
527
528 if (host->sg_blkidx == data->sg->length) {
529 host->sg_blkidx = 0;
530 if (++host->sg_idx < data->sg_len)
531 host->pio_ptr = sg_virt(++data->sg);
532 } else {
533 host->pio_ptr = p;
534 }
535
536 if (host->sg_idx == data->sg_len)
537 return false;
538
539 return true;
540}
541
542static void sh_mmcif_single_read(struct sh_mmcif_host *host,
543 struct mmc_request *mrq)
544{
545 host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
546 BLOCK_SIZE_MASK) + 3;
547
548 host->wait_for = MMCIF_WAIT_FOR_READ;
549 schedule_delayed_work(&host->timeout_work, host->timeout);
472 550
473 /* buf read enable */ 551 /* buf read enable */
474 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); 552 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
475 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 553}
476 host->timeout); 554
477 if (time <= 0 || host->sd_error) 555static bool sh_mmcif_read_block(struct sh_mmcif_host *host)
478 return sh_mmcif_error_manage(host); 556{
479 557 struct mmc_data *data = host->mrq->data;
480 blocksize = (BLOCK_SIZE_MASK & 558 u32 *p = sg_virt(data->sg);
481 sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3; 559 int i;
482 for (i = 0; i < blocksize / 4; i++) 560
561 if (host->sd_error) {
562 data->error = sh_mmcif_error_manage(host);
563 return false;
564 }
565
566 for (i = 0; i < host->blocksize / 4; i++)
483 *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA); 567 *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
484 568
485 /* buffer read end */ 569 /* buffer read end */
486 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE); 570 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
487 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 571 host->wait_for = MMCIF_WAIT_FOR_READ_END;
488 host->timeout);
489 if (time <= 0 || host->sd_error)
490 return sh_mmcif_error_manage(host);
491 572
492 return 0; 573 return true;
493} 574}
494 575
495static int sh_mmcif_multi_read(struct sh_mmcif_host *host, 576static void sh_mmcif_multi_read(struct sh_mmcif_host *host,
496 struct mmc_request *mrq) 577 struct mmc_request *mrq)
497{ 578{
498 struct mmc_data *data = mrq->data; 579 struct mmc_data *data = mrq->data;
499 long time; 580
500 u32 blocksize, i, j, sec, *p; 581 if (!data->sg_len || !data->sg->length)
501 582 return;
502 blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr, 583
503 MMCIF_CE_BLOCK_SET); 584 host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
504 for (j = 0; j < data->sg_len; j++) { 585 BLOCK_SIZE_MASK;
505 p = sg_virt(data->sg); 586
506 for (sec = 0; sec < data->sg->length / blocksize; sec++) { 587 host->wait_for = MMCIF_WAIT_FOR_MREAD;
507 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); 588 host->sg_idx = 0;
508 /* buf read enable */ 589 host->sg_blkidx = 0;
509 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 590 host->pio_ptr = sg_virt(data->sg);
510 host->timeout); 591 schedule_delayed_work(&host->timeout_work, host->timeout);
511 592 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
512 if (time <= 0 || host->sd_error) 593}
513 return sh_mmcif_error_manage(host); 594
514 595static bool sh_mmcif_mread_block(struct sh_mmcif_host *host)
515 for (i = 0; i < blocksize / 4; i++) 596{
516 *p++ = sh_mmcif_readl(host->addr, 597 struct mmc_data *data = host->mrq->data;
517 MMCIF_CE_DATA); 598 u32 *p = host->pio_ptr;
518 } 599 int i;
519 if (j < data->sg_len - 1) 600
520 data->sg++; 601 if (host->sd_error) {
602 data->error = sh_mmcif_error_manage(host);
603 return false;
521 } 604 }
522 return 0; 605
606 BUG_ON(!data->sg->length);
607
608 for (i = 0; i < host->blocksize / 4; i++)
609 *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
610
611 if (!sh_mmcif_next_block(host, p))
612 return false;
613
614 schedule_delayed_work(&host->timeout_work, host->timeout);
615 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
616
617 return true;
523} 618}
524 619
525static int sh_mmcif_single_write(struct sh_mmcif_host *host, 620static void sh_mmcif_single_write(struct sh_mmcif_host *host,
526 struct mmc_request *mrq) 621 struct mmc_request *mrq)
527{ 622{
528 struct mmc_data *data = mrq->data; 623 host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
529 long time; 624 BLOCK_SIZE_MASK) + 3;
530 u32 blocksize, i, *p = sg_virt(data->sg);
531 625
532 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN); 626 host->wait_for = MMCIF_WAIT_FOR_WRITE;
627 schedule_delayed_work(&host->timeout_work, host->timeout);
533 628
534 /* buf write enable */ 629 /* buf write enable */
535 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 630 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
536 host->timeout); 631}
537 if (time <= 0 || host->sd_error) 632
538 return sh_mmcif_error_manage(host); 633static bool sh_mmcif_write_block(struct sh_mmcif_host *host)
539 634{
540 blocksize = (BLOCK_SIZE_MASK & 635 struct mmc_data *data = host->mrq->data;
541 sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3; 636 u32 *p = sg_virt(data->sg);
542 for (i = 0; i < blocksize / 4; i++) 637 int i;
638
639 if (host->sd_error) {
640 data->error = sh_mmcif_error_manage(host);
641 return false;
642 }
643
644 for (i = 0; i < host->blocksize / 4; i++)
543 sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++); 645 sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
544 646
545 /* buffer write end */ 647 /* buffer write end */
546 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE); 648 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
649 host->wait_for = MMCIF_WAIT_FOR_WRITE_END;
547 650
548 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 651 return true;
549 host->timeout);
550 if (time <= 0 || host->sd_error)
551 return sh_mmcif_error_manage(host);
552
553 return 0;
554} 652}
555 653
556static int sh_mmcif_multi_write(struct sh_mmcif_host *host, 654static void sh_mmcif_multi_write(struct sh_mmcif_host *host,
557 struct mmc_request *mrq) 655 struct mmc_request *mrq)
558{ 656{
559 struct mmc_data *data = mrq->data; 657 struct mmc_data *data = mrq->data;
560 long time;
561 u32 i, sec, j, blocksize, *p;
562 658
563 blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr, 659 if (!data->sg_len || !data->sg->length)
564 MMCIF_CE_BLOCK_SET); 660 return;
565 661
566 for (j = 0; j < data->sg_len; j++) { 662 host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
567 p = sg_virt(data->sg); 663 BLOCK_SIZE_MASK;
568 for (sec = 0; sec < data->sg->length / blocksize; sec++) {
569 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
570 /* buf write enable*/
571 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
572 host->timeout);
573 664
574 if (time <= 0 || host->sd_error) 665 host->wait_for = MMCIF_WAIT_FOR_MWRITE;
575 return sh_mmcif_error_manage(host); 666 host->sg_idx = 0;
667 host->sg_blkidx = 0;
668 host->pio_ptr = sg_virt(data->sg);
669 schedule_delayed_work(&host->timeout_work, host->timeout);
670 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
671}
576 672
577 for (i = 0; i < blocksize / 4; i++) 673static bool sh_mmcif_mwrite_block(struct sh_mmcif_host *host)
578 sh_mmcif_writel(host->addr, 674{
579 MMCIF_CE_DATA, *p++); 675 struct mmc_data *data = host->mrq->data;
580 } 676 u32 *p = host->pio_ptr;
581 if (j < data->sg_len - 1) 677 int i;
582 data->sg++; 678
679 if (host->sd_error) {
680 data->error = sh_mmcif_error_manage(host);
681 return false;
583 } 682 }
584 return 0; 683
684 BUG_ON(!data->sg->length);
685
686 for (i = 0; i < host->blocksize / 4; i++)
687 sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
688
689 if (!sh_mmcif_next_block(host, p))
690 return false;
691
692 schedule_delayed_work(&host->timeout_work, host->timeout);
693 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
694
695 return true;
585} 696}
586 697
587static void sh_mmcif_get_response(struct sh_mmcif_host *host, 698static void sh_mmcif_get_response(struct sh_mmcif_host *host,
@@ -603,8 +714,11 @@ static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host,
603} 714}
604 715
605static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host, 716static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
606 struct mmc_request *mrq, struct mmc_command *cmd, u32 opc) 717 struct mmc_request *mrq)
607{ 718{
719 struct mmc_data *data = mrq->data;
720 struct mmc_command *cmd = mrq->cmd;
721 u32 opc = cmd->opcode;
608 u32 tmp = 0; 722 u32 tmp = 0;
609 723
610 /* Response Type check */ 724 /* Response Type check */
@@ -636,7 +750,7 @@ static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
636 break; 750 break;
637 } 751 }
638 /* WDAT / DATW */ 752 /* WDAT / DATW */
639 if (host->data) { 753 if (data) {
640 tmp |= CMD_SET_WDAT; 754 tmp |= CMD_SET_WDAT;
641 switch (host->bus_width) { 755 switch (host->bus_width) {
642 case MMC_BUS_WIDTH_1: 756 case MMC_BUS_WIDTH_1:
@@ -660,7 +774,7 @@ static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
660 if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) { 774 if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) {
661 tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN; 775 tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN;
662 sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET, 776 sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET,
663 mrq->data->blocks << 16); 777 data->blocks << 16);
664 } 778 }
665 /* RIDXC[1:0] check bits */ 779 /* RIDXC[1:0] check bits */
666 if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID || 780 if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID ||
@@ -674,68 +788,60 @@ static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
674 opc == MMC_SEND_CSD || opc == MMC_SEND_CID) 788 opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
675 tmp |= CMD_SET_CRC7C_INTERNAL; 789 tmp |= CMD_SET_CRC7C_INTERNAL;
676 790
677 return opc = ((opc << 24) | tmp); 791 return (opc << 24) | tmp;
678} 792}
679 793
680static int sh_mmcif_data_trans(struct sh_mmcif_host *host, 794static int sh_mmcif_data_trans(struct sh_mmcif_host *host,
681 struct mmc_request *mrq, u32 opc) 795 struct mmc_request *mrq, u32 opc)
682{ 796{
683 int ret;
684
685 switch (opc) { 797 switch (opc) {
686 case MMC_READ_MULTIPLE_BLOCK: 798 case MMC_READ_MULTIPLE_BLOCK:
687 ret = sh_mmcif_multi_read(host, mrq); 799 sh_mmcif_multi_read(host, mrq);
688 break; 800 return 0;
689 case MMC_WRITE_MULTIPLE_BLOCK: 801 case MMC_WRITE_MULTIPLE_BLOCK:
690 ret = sh_mmcif_multi_write(host, mrq); 802 sh_mmcif_multi_write(host, mrq);
691 break; 803 return 0;
692 case MMC_WRITE_BLOCK: 804 case MMC_WRITE_BLOCK:
693 ret = sh_mmcif_single_write(host, mrq); 805 sh_mmcif_single_write(host, mrq);
694 break; 806 return 0;
695 case MMC_READ_SINGLE_BLOCK: 807 case MMC_READ_SINGLE_BLOCK:
696 case MMC_SEND_EXT_CSD: 808 case MMC_SEND_EXT_CSD:
697 ret = sh_mmcif_single_read(host, mrq); 809 sh_mmcif_single_read(host, mrq);
698 break; 810 return 0;
699 default: 811 default:
700 dev_err(&host->pd->dev, "UNSUPPORTED CMD = d'%08d\n", opc); 812 dev_err(&host->pd->dev, "UNSUPPORTED CMD = d'%08d\n", opc);
701 ret = -EINVAL; 813 return -EINVAL;
702 break;
703 } 814 }
704 return ret;
705} 815}
706 816
707static void sh_mmcif_start_cmd(struct sh_mmcif_host *host, 817static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
708 struct mmc_request *mrq, struct mmc_command *cmd) 818 struct mmc_request *mrq)
709{ 819{
710 long time; 820 struct mmc_command *cmd = mrq->cmd;
711 int ret = 0, mask = 0;
712 u32 opc = cmd->opcode; 821 u32 opc = cmd->opcode;
822 u32 mask;
713 823
714 switch (opc) { 824 switch (opc) {
715 /* respons busy check */ 825 /* response busy check */
716 case MMC_SWITCH: 826 case MMC_SWITCH:
717 case MMC_STOP_TRANSMISSION: 827 case MMC_STOP_TRANSMISSION:
718 case MMC_SET_WRITE_PROT: 828 case MMC_SET_WRITE_PROT:
719 case MMC_CLR_WRITE_PROT: 829 case MMC_CLR_WRITE_PROT:
720 case MMC_ERASE: 830 case MMC_ERASE:
721 case MMC_GEN_CMD: 831 case MMC_GEN_CMD:
722 mask = MASK_MRBSYE; 832 mask = MASK_START_CMD | MASK_MRBSYE;
723 break; 833 break;
724 default: 834 default:
725 mask = MASK_MCRSPE; 835 mask = MASK_START_CMD | MASK_MCRSPE;
726 break; 836 break;
727 } 837 }
728 mask |= MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR |
729 MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR |
730 MASK_MCCSTO | MASK_MCRCSTO | MASK_MWDATTO |
731 MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO;
732 838
733 if (host->data) { 839 if (mrq->data) {
734 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0); 840 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0);
735 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 841 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET,
736 mrq->data->blksz); 842 mrq->data->blksz);
737 } 843 }
738 opc = sh_mmcif_set_cmd(host, mrq, cmd, opc); 844 opc = sh_mmcif_set_cmd(host, mrq);
739 845
740 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0); 846 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0);
741 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask); 847 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask);
@@ -744,80 +850,28 @@ static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
744 /* set cmd */ 850 /* set cmd */
745 sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc); 851 sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc);
746 852
747 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 853 host->wait_for = MMCIF_WAIT_FOR_CMD;
748 host->timeout); 854 schedule_delayed_work(&host->timeout_work, host->timeout);
749 if (time <= 0) {
750 cmd->error = sh_mmcif_error_manage(host);
751 return;
752 }
753 if (host->sd_error) {
754 switch (cmd->opcode) {
755 case MMC_ALL_SEND_CID:
756 case MMC_SELECT_CARD:
757 case MMC_APP_CMD:
758 cmd->error = -ETIMEDOUT;
759 break;
760 default:
761 dev_dbg(&host->pd->dev, "Cmd(d'%d) err\n",
762 cmd->opcode);
763 cmd->error = sh_mmcif_error_manage(host);
764 break;
765 }
766 host->sd_error = false;
767 return;
768 }
769 if (!(cmd->flags & MMC_RSP_PRESENT)) {
770 cmd->error = 0;
771 return;
772 }
773 sh_mmcif_get_response(host, cmd);
774 if (host->data) {
775 if (!host->dma_active) {
776 ret = sh_mmcif_data_trans(host, mrq, cmd->opcode);
777 } else {
778 long time =
779 wait_for_completion_interruptible_timeout(&host->dma_complete,
780 host->timeout);
781 if (!time)
782 ret = -ETIMEDOUT;
783 else if (time < 0)
784 ret = time;
785 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
786 BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
787 host->dma_active = false;
788 }
789 if (ret < 0)
790 mrq->data->bytes_xfered = 0;
791 else
792 mrq->data->bytes_xfered =
793 mrq->data->blocks * mrq->data->blksz;
794 }
795 cmd->error = ret;
796} 855}
797 856
798static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host, 857static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host,
799 struct mmc_request *mrq, struct mmc_command *cmd) 858 struct mmc_request *mrq)
800{ 859{
801 long time; 860 switch (mrq->cmd->opcode) {
802 861 case MMC_READ_MULTIPLE_BLOCK:
803 if (mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK)
804 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE); 862 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
805 else if (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK) 863 break;
864 case MMC_WRITE_MULTIPLE_BLOCK:
806 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE); 865 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
807 else { 866 break;
867 default:
808 dev_err(&host->pd->dev, "unsupported stop cmd\n"); 868 dev_err(&host->pd->dev, "unsupported stop cmd\n");
809 cmd->error = sh_mmcif_error_manage(host); 869 mrq->stop->error = sh_mmcif_error_manage(host);
810 return; 870 return;
811 } 871 }
812 872
813 time = wait_for_completion_interruptible_timeout(&host->intr_wait, 873 host->wait_for = MMCIF_WAIT_FOR_STOP;
814 host->timeout); 874 schedule_delayed_work(&host->timeout_work, host->timeout);
815 if (time <= 0 || host->sd_error) {
816 cmd->error = sh_mmcif_error_manage(host);
817 return;
818 }
819 sh_mmcif_get_cmd12response(host, cmd);
820 cmd->error = 0;
821} 875}
822 876
823static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) 877static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
@@ -856,23 +910,10 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
856 default: 910 default:
857 break; 911 break;
858 } 912 }
859 host->data = mrq->data;
860 if (mrq->data) {
861 if (mrq->data->flags & MMC_DATA_READ) {
862 if (host->chan_rx)
863 sh_mmcif_start_dma_rx(host);
864 } else {
865 if (host->chan_tx)
866 sh_mmcif_start_dma_tx(host);
867 }
868 }
869 sh_mmcif_start_cmd(host, mrq, mrq->cmd);
870 host->data = NULL;
871 913
872 if (!mrq->cmd->error && mrq->stop) 914 host->mrq = mrq;
873 sh_mmcif_stop_cmd(host, mrq, mrq->stop); 915
874 host->state = STATE_IDLE; 916 sh_mmcif_start_cmd(host, mrq);
875 mmc_request_done(mmc, mrq);
876} 917}
877 918
878static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 919static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
@@ -947,9 +988,156 @@ static struct mmc_host_ops sh_mmcif_ops = {
947 .get_cd = sh_mmcif_get_cd, 988 .get_cd = sh_mmcif_get_cd,
948}; 989};
949 990
950static void sh_mmcif_detect(struct mmc_host *mmc) 991static bool sh_mmcif_end_cmd(struct sh_mmcif_host *host)
951{ 992{
952 mmc_detect_change(mmc, 0); 993 struct mmc_command *cmd = host->mrq->cmd;
994 struct mmc_data *data = host->mrq->data;
995 long time;
996
997 if (host->sd_error) {
998 switch (cmd->opcode) {
999 case MMC_ALL_SEND_CID:
1000 case MMC_SELECT_CARD:
1001 case MMC_APP_CMD:
1002 cmd->error = -ETIMEDOUT;
1003 host->sd_error = false;
1004 break;
1005 default:
1006 cmd->error = sh_mmcif_error_manage(host);
1007 dev_dbg(&host->pd->dev, "Cmd(d'%d) error %d\n",
1008 cmd->opcode, cmd->error);
1009 break;
1010 }
1011 return false;
1012 }
1013 if (!(cmd->flags & MMC_RSP_PRESENT)) {
1014 cmd->error = 0;
1015 return false;
1016 }
1017
1018 sh_mmcif_get_response(host, cmd);
1019
1020 if (!data)
1021 return false;
1022
1023 if (data->flags & MMC_DATA_READ) {
1024 if (host->chan_rx)
1025 sh_mmcif_start_dma_rx(host);
1026 } else {
1027 if (host->chan_tx)
1028 sh_mmcif_start_dma_tx(host);
1029 }
1030
1031 if (!host->dma_active) {
1032 data->error = sh_mmcif_data_trans(host, host->mrq, cmd->opcode);
1033 if (!data->error)
1034 return true;
1035 return false;
1036 }
1037
1038 /* Running in the IRQ thread, can sleep */
1039 time = wait_for_completion_interruptible_timeout(&host->dma_complete,
1040 host->timeout);
1041 if (host->sd_error) {
1042 dev_err(host->mmc->parent,
1043 "Error IRQ while waiting for DMA completion!\n");
1044 /* Woken up by an error IRQ: abort DMA */
1045 if (data->flags & MMC_DATA_READ)
1046 dmaengine_terminate_all(host->chan_rx);
1047 else
1048 dmaengine_terminate_all(host->chan_tx);
1049 data->error = sh_mmcif_error_manage(host);
1050 } else if (!time) {
1051 data->error = -ETIMEDOUT;
1052 } else if (time < 0) {
1053 data->error = time;
1054 }
1055 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
1056 BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
1057 host->dma_active = false;
1058
1059 if (data->error)
1060 data->bytes_xfered = 0;
1061
1062 return false;
1063}
1064
1065static irqreturn_t sh_mmcif_irqt(int irq, void *dev_id)
1066{
1067 struct sh_mmcif_host *host = dev_id;
1068 struct mmc_request *mrq = host->mrq;
1069 struct mmc_data *data = mrq->data;
1070
1071 cancel_delayed_work_sync(&host->timeout_work);
1072
1073 /*
1074 * All handlers return true, if processing continues, and false, if the
1075 * request has to be completed - successfully or not
1076 */
1077 switch (host->wait_for) {
1078 case MMCIF_WAIT_FOR_REQUEST:
1079 /* We're too late, the timeout has already kicked in */
1080 return IRQ_HANDLED;
1081 case MMCIF_WAIT_FOR_CMD:
1082 if (sh_mmcif_end_cmd(host))
1083 /* Wait for data */
1084 return IRQ_HANDLED;
1085 break;
1086 case MMCIF_WAIT_FOR_MREAD:
1087 if (sh_mmcif_mread_block(host))
1088 /* Wait for more data */
1089 return IRQ_HANDLED;
1090 break;
1091 case MMCIF_WAIT_FOR_READ:
1092 if (sh_mmcif_read_block(host))
1093 /* Wait for data end */
1094 return IRQ_HANDLED;
1095 break;
1096 case MMCIF_WAIT_FOR_MWRITE:
1097 if (sh_mmcif_mwrite_block(host))
1098 /* Wait data to write */
1099 return IRQ_HANDLED;
1100 break;
1101 case MMCIF_WAIT_FOR_WRITE:
1102 if (sh_mmcif_write_block(host))
1103 /* Wait for data end */
1104 return IRQ_HANDLED;
1105 break;
1106 case MMCIF_WAIT_FOR_STOP:
1107 if (host->sd_error) {
1108 mrq->stop->error = sh_mmcif_error_manage(host);
1109 break;
1110 }
1111 sh_mmcif_get_cmd12response(host, mrq->stop);
1112 mrq->stop->error = 0;
1113 break;
1114 case MMCIF_WAIT_FOR_READ_END:
1115 case MMCIF_WAIT_FOR_WRITE_END:
1116 if (host->sd_error)
1117 data->error = sh_mmcif_error_manage(host);
1118 break;
1119 default:
1120 BUG();
1121 }
1122
1123 if (host->wait_for != MMCIF_WAIT_FOR_STOP) {
1124 if (!mrq->cmd->error && data && !data->error)
1125 data->bytes_xfered =
1126 data->blocks * data->blksz;
1127
1128 if (mrq->stop && !mrq->cmd->error && (!data || !data->error)) {
1129 sh_mmcif_stop_cmd(host, mrq);
1130 if (!mrq->stop->error)
1131 return IRQ_HANDLED;
1132 }
1133 }
1134
1135 host->wait_for = MMCIF_WAIT_FOR_REQUEST;
1136 host->state = STATE_IDLE;
1137 host->mrq = NULL;
1138 mmc_request_done(host->mmc, mrq);
1139
1140 return IRQ_HANDLED;
953} 1141}
954 1142
955static irqreturn_t sh_mmcif_intr(int irq, void *dev_id) 1143static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
@@ -960,7 +1148,12 @@ static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
960 1148
961 state = sh_mmcif_readl(host->addr, MMCIF_CE_INT); 1149 state = sh_mmcif_readl(host->addr, MMCIF_CE_INT);
962 1150
963 if (state & INT_RBSYE) { 1151 if (state & INT_ERR_STS) {
1152 /* error interrupts - process first */
1153 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
1154 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state);
1155 err = 1;
1156 } else if (state & INT_RBSYE) {
964 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 1157 sh_mmcif_writel(host->addr, MMCIF_CE_INT,
965 ~(INT_RBSYE | INT_CRSPE)); 1158 ~(INT_RBSYE | INT_CRSPE));
966 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MRBSYE); 1159 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MRBSYE);
@@ -988,11 +1181,6 @@ static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
988 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 1181 sh_mmcif_writel(host->addr, MMCIF_CE_INT,
989 ~(INT_CMD12RBE | INT_CMD12CRE)); 1182 ~(INT_CMD12RBE | INT_CMD12CRE));
990 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE); 1183 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
991 } else if (state & INT_ERR_STS) {
992 /* err interrupts */
993 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
994 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state);
995 err = 1;
996 } else { 1184 } else {
997 dev_dbg(&host->pd->dev, "Unsupported interrupt: 0x%x\n", state); 1185 dev_dbg(&host->pd->dev, "Unsupported interrupt: 0x%x\n", state);
998 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state); 1186 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
@@ -1003,14 +1191,57 @@ static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
1003 host->sd_error = true; 1191 host->sd_error = true;
1004 dev_dbg(&host->pd->dev, "int err state = %08x\n", state); 1192 dev_dbg(&host->pd->dev, "int err state = %08x\n", state);
1005 } 1193 }
1006 if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) 1194 if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) {
1007 complete(&host->intr_wait); 1195 if (!host->dma_active)
1008 else 1196 return IRQ_WAKE_THREAD;
1197 else if (host->sd_error)
1198 mmcif_dma_complete(host);
1199 } else {
1009 dev_dbg(&host->pd->dev, "Unexpected IRQ 0x%x\n", state); 1200 dev_dbg(&host->pd->dev, "Unexpected IRQ 0x%x\n", state);
1201 }
1010 1202
1011 return IRQ_HANDLED; 1203 return IRQ_HANDLED;
1012} 1204}
1013 1205
1206static void mmcif_timeout_work(struct work_struct *work)
1207{
1208 struct delayed_work *d = container_of(work, struct delayed_work, work);
1209 struct sh_mmcif_host *host = container_of(d, struct sh_mmcif_host, timeout_work);
1210 struct mmc_request *mrq = host->mrq;
1211
1212 if (host->dying)
1213 /* Don't run after mmc_remove_host() */
1214 return;
1215
1216 /*
1217 * Handle races with cancel_delayed_work(), unless
1218 * cancel_delayed_work_sync() is used
1219 */
1220 switch (host->wait_for) {
1221 case MMCIF_WAIT_FOR_CMD:
1222 mrq->cmd->error = sh_mmcif_error_manage(host);
1223 break;
1224 case MMCIF_WAIT_FOR_STOP:
1225 mrq->stop->error = sh_mmcif_error_manage(host);
1226 break;
1227 case MMCIF_WAIT_FOR_MREAD:
1228 case MMCIF_WAIT_FOR_MWRITE:
1229 case MMCIF_WAIT_FOR_READ:
1230 case MMCIF_WAIT_FOR_WRITE:
1231 case MMCIF_WAIT_FOR_READ_END:
1232 case MMCIF_WAIT_FOR_WRITE_END:
1233 mrq->data->error = sh_mmcif_error_manage(host);
1234 break;
1235 default:
1236 BUG();
1237 }
1238
1239 host->state = STATE_IDLE;
1240 host->wait_for = MMCIF_WAIT_FOR_REQUEST;
1241 host->mrq = NULL;
1242 mmc_request_done(host->mmc, mrq);
1243}
1244
1014static int __devinit sh_mmcif_probe(struct platform_device *pdev) 1245static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1015{ 1246{
1016 int ret = 0, irq[2]; 1247 int ret = 0, irq[2];
@@ -1064,7 +1295,6 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1064 host->clk = clk_get_rate(host->hclk); 1295 host->clk = clk_get_rate(host->hclk);
1065 host->pd = pdev; 1296 host->pd = pdev;
1066 1297
1067 init_completion(&host->intr_wait);
1068 spin_lock_init(&host->lock); 1298 spin_lock_init(&host->lock);
1069 1299
1070 mmc->ops = &sh_mmcif_ops; 1300 mmc->ops = &sh_mmcif_ops;
@@ -1101,19 +1331,21 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1101 1331
1102 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1332 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1103 1333
1104 ret = request_irq(irq[0], sh_mmcif_intr, 0, "sh_mmc:error", host); 1334 ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host);
1105 if (ret) { 1335 if (ret) {
1106 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n"); 1336 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n");
1107 goto clean_up3; 1337 goto clean_up3;
1108 } 1338 }
1109 ret = request_irq(irq[1], sh_mmcif_intr, 0, "sh_mmc:int", host); 1339 ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host);
1110 if (ret) { 1340 if (ret) {
1111 free_irq(irq[0], host); 1341 free_irq(irq[0], host);
1112 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n"); 1342 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
1113 goto clean_up3; 1343 goto clean_up3;
1114 } 1344 }
1115 1345
1116 sh_mmcif_detect(host->mmc); 1346 INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work);
1347
1348 mmc_detect_change(host->mmc, 0);
1117 1349
1118 dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION); 1350 dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION);
1119 dev_dbg(&pdev->dev, "chip ver H'%04x\n", 1351 dev_dbg(&pdev->dev, "chip ver H'%04x\n",
@@ -1139,11 +1371,19 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1139 struct sh_mmcif_host *host = platform_get_drvdata(pdev); 1371 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1140 int irq[2]; 1372 int irq[2];
1141 1373
1374 host->dying = true;
1142 pm_runtime_get_sync(&pdev->dev); 1375 pm_runtime_get_sync(&pdev->dev);
1143 1376
1144 mmc_remove_host(host->mmc); 1377 mmc_remove_host(host->mmc);
1145 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1378 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1146 1379
1380 /*
1381 * FIXME: cancel_delayed_work(_sync)() and free_irq() race with the
1382 * mmc_remove_host() call above. But swapping order doesn't help either
1383 * (a query on the linux-mmc mailing list didn't bring any replies).
1384 */
1385 cancel_delayed_work_sync(&host->timeout_work);
1386
1147 if (host->addr) 1387 if (host->addr)
1148 iounmap(host->addr); 1388 iounmap(host->addr);
1149 1389
@@ -1206,19 +1446,7 @@ static struct platform_driver sh_mmcif_driver = {
1206 }, 1446 },
1207}; 1447};
1208 1448
1209static int __init sh_mmcif_init(void) 1449module_platform_driver(sh_mmcif_driver);
1210{
1211 return platform_driver_register(&sh_mmcif_driver);
1212}
1213
1214static void __exit sh_mmcif_exit(void)
1215{
1216 platform_driver_unregister(&sh_mmcif_driver);
1217}
1218
1219module_init(sh_mmcif_init);
1220module_exit(sh_mmcif_exit);
1221
1222 1450
1223MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver"); 1451MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver");
1224MODULE_LICENSE("GPL"); 1452MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c
index 41ae6466bd83..58da3c44acc5 100644
--- a/drivers/mmc/host/sh_mobile_sdhi.c
+++ b/drivers/mmc/host/sh_mobile_sdhi.c
@@ -282,18 +282,7 @@ static struct platform_driver sh_mobile_sdhi_driver = {
282 .remove = __devexit_p(sh_mobile_sdhi_remove), 282 .remove = __devexit_p(sh_mobile_sdhi_remove),
283}; 283};
284 284
285static int __init sh_mobile_sdhi_init(void) 285module_platform_driver(sh_mobile_sdhi_driver);
286{
287 return platform_driver_register(&sh_mobile_sdhi_driver);
288}
289
290static void __exit sh_mobile_sdhi_exit(void)
291{
292 platform_driver_unregister(&sh_mobile_sdhi_driver);
293}
294
295module_init(sh_mobile_sdhi_init);
296module_exit(sh_mobile_sdhi_exit);
297 286
298MODULE_DESCRIPTION("SuperH Mobile SDHI driver"); 287MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
299MODULE_AUTHOR("Magnus Damm"); 288MODULE_AUTHOR("Magnus Damm");
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 69d249f51d6a..43d962829f8e 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -118,7 +118,7 @@ static void tifm_sd_read_fifo(struct tifm_sd *host, struct page *pg,
118 unsigned char *buf; 118 unsigned char *buf;
119 unsigned int pos = 0, val; 119 unsigned int pos = 0, val;
120 120
121 buf = kmap_atomic(pg, KM_BIO_DST_IRQ) + off; 121 buf = kmap_atomic(pg) + off;
122 if (host->cmd_flags & DATA_CARRY) { 122 if (host->cmd_flags & DATA_CARRY) {
123 buf[pos++] = host->bounce_buf_data[0]; 123 buf[pos++] = host->bounce_buf_data[0];
124 host->cmd_flags &= ~DATA_CARRY; 124 host->cmd_flags &= ~DATA_CARRY;
@@ -134,7 +134,7 @@ static void tifm_sd_read_fifo(struct tifm_sd *host, struct page *pg,
134 } 134 }
135 buf[pos++] = (val >> 8) & 0xff; 135 buf[pos++] = (val >> 8) & 0xff;
136 } 136 }
137 kunmap_atomic(buf - off, KM_BIO_DST_IRQ); 137 kunmap_atomic(buf - off);
138} 138}
139 139
140static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg, 140static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg,
@@ -144,7 +144,7 @@ static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg,
144 unsigned char *buf; 144 unsigned char *buf;
145 unsigned int pos = 0, val; 145 unsigned int pos = 0, val;
146 146
147 buf = kmap_atomic(pg, KM_BIO_SRC_IRQ) + off; 147 buf = kmap_atomic(pg) + off;
148 if (host->cmd_flags & DATA_CARRY) { 148 if (host->cmd_flags & DATA_CARRY) {
149 val = host->bounce_buf_data[0] | ((buf[pos++] << 8) & 0xff00); 149 val = host->bounce_buf_data[0] | ((buf[pos++] << 8) & 0xff00);
150 writel(val, sock->addr + SOCK_MMCSD_DATA); 150 writel(val, sock->addr + SOCK_MMCSD_DATA);
@@ -161,7 +161,7 @@ static void tifm_sd_write_fifo(struct tifm_sd *host, struct page *pg,
161 val |= (buf[pos++] << 8) & 0xff00; 161 val |= (buf[pos++] << 8) & 0xff00;
162 writel(val, sock->addr + SOCK_MMCSD_DATA); 162 writel(val, sock->addr + SOCK_MMCSD_DATA);
163 } 163 }
164 kunmap_atomic(buf - off, KM_BIO_SRC_IRQ); 164 kunmap_atomic(buf - off);
165} 165}
166 166
167static void tifm_sd_transfer_data(struct tifm_sd *host) 167static void tifm_sd_transfer_data(struct tifm_sd *host)
@@ -212,13 +212,13 @@ static void tifm_sd_copy_page(struct page *dst, unsigned int dst_off,
212 struct page *src, unsigned int src_off, 212 struct page *src, unsigned int src_off,
213 unsigned int count) 213 unsigned int count)
214{ 214{
215 unsigned char *src_buf = kmap_atomic(src, KM_BIO_SRC_IRQ) + src_off; 215 unsigned char *src_buf = kmap_atomic(src) + src_off;
216 unsigned char *dst_buf = kmap_atomic(dst, KM_BIO_DST_IRQ) + dst_off; 216 unsigned char *dst_buf = kmap_atomic(dst) + dst_off;
217 217
218 memcpy(dst_buf, src_buf, count); 218 memcpy(dst_buf, src_buf, count);
219 219
220 kunmap_atomic(dst_buf - dst_off, KM_BIO_DST_IRQ); 220 kunmap_atomic(dst_buf - dst_off);
221 kunmap_atomic(src_buf - src_off, KM_BIO_SRC_IRQ); 221 kunmap_atomic(src_buf - src_off);
222} 222}
223 223
224static void tifm_sd_bounce_block(struct tifm_sd *host, struct mmc_data *r_data) 224static void tifm_sd_bounce_block(struct tifm_sd *host, struct mmc_data *r_data)
diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c
index a4ea10242787..113ce6c9cf32 100644
--- a/drivers/mmc/host/tmio_mmc.c
+++ b/drivers/mmc/host/tmio_mmc.c
@@ -138,19 +138,7 @@ static struct platform_driver tmio_mmc_driver = {
138 .resume = tmio_mmc_resume, 138 .resume = tmio_mmc_resume,
139}; 139};
140 140
141 141module_platform_driver(tmio_mmc_driver);
142static int __init tmio_mmc_init(void)
143{
144 return platform_driver_register(&tmio_mmc_driver);
145}
146
147static void __exit tmio_mmc_exit(void)
148{
149 platform_driver_unregister(&tmio_mmc_driver);
150}
151
152module_init(tmio_mmc_init);
153module_exit(tmio_mmc_exit);
154 142
155MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver"); 143MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
156MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); 144MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index 3020f98218f0..a95e6d901726 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -105,13 +105,13 @@ static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
105 unsigned long *flags) 105 unsigned long *flags)
106{ 106{
107 local_irq_save(*flags); 107 local_irq_save(*flags);
108 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; 108 return kmap_atomic(sg_page(sg)) + sg->offset;
109} 109}
110 110
111static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg, 111static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg,
112 unsigned long *flags, void *virt) 112 unsigned long *flags, void *virt)
113{ 113{
114 kunmap_atomic(virt - sg->offset, KM_BIO_SRC_IRQ); 114 kunmap_atomic(virt - sg->offset);
115 local_irq_restore(*flags); 115 local_irq_restore(*flags);
116} 116}
117 117
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 4208b3958069..abad01b37cfb 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -800,8 +800,7 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
800 } else if (ios->power_mode != MMC_POWER_UP) { 800 } else if (ios->power_mode != MMC_POWER_UP) {
801 if (host->set_pwr && ios->power_mode == MMC_POWER_OFF) 801 if (host->set_pwr && ios->power_mode == MMC_POWER_OFF)
802 host->set_pwr(host->pdev, 0); 802 host->set_pwr(host->pdev, 0);
803 if ((pdata->flags & TMIO_MMC_HAS_COLD_CD) && 803 if (pdata->power) {
804 pdata->power) {
805 pdata->power = false; 804 pdata->power = false;
806 pm_runtime_put(&host->pdev->dev); 805 pm_runtime_put(&host->pdev->dev);
807 } 806 }
@@ -915,6 +914,23 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
915 if (ret < 0) 914 if (ret < 0)
916 goto pm_disable; 915 goto pm_disable;
917 916
917 /*
918 * There are 4 different scenarios for the card detection:
919 * 1) an external gpio irq handles the cd (best for power savings)
920 * 2) internal sdhi irq handles the cd
921 * 3) a worker thread polls the sdhi - indicated by MMC_CAP_NEEDS_POLL
922 * 4) the medium is non-removable - indicated by MMC_CAP_NONREMOVABLE
923 *
924 * While we increment the rtpm counter for all scenarios when the mmc
925 * core activates us by calling an appropriate set_ios(), we must
926 * additionally ensure that in case 2) the tmio mmc hardware stays
927 * powered on during runtime for the card detection to work.
928 */
929 if (!(pdata->flags & TMIO_MMC_HAS_COLD_CD
930 || mmc->caps & MMC_CAP_NEEDS_POLL
931 || mmc->caps & MMC_CAP_NONREMOVABLE))
932 pm_runtime_get_noresume(&pdev->dev);
933
918 tmio_mmc_clk_stop(_host); 934 tmio_mmc_clk_stop(_host);
919 tmio_mmc_reset(_host); 935 tmio_mmc_reset(_host);
920 936
@@ -933,12 +949,6 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
933 /* See if we also get DMA */ 949 /* See if we also get DMA */
934 tmio_mmc_request_dma(_host, pdata); 950 tmio_mmc_request_dma(_host, pdata);
935 951
936 /* We have to keep the device powered for its card detection to work */
937 if (!(pdata->flags & TMIO_MMC_HAS_COLD_CD)) {
938 pdata->power = true;
939 pm_runtime_get_noresume(&pdev->dev);
940 }
941
942 mmc_add_host(mmc); 952 mmc_add_host(mmc);
943 953
944 /* Unmask the IRQs we want to know about */ 954 /* Unmask the IRQs we want to know about */
@@ -974,7 +984,9 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
974 * the controller, the runtime PM is suspended and pdata->power == false, 984 * the controller, the runtime PM is suspended and pdata->power == false,
975 * so, our .runtime_resume() will not try to detect a card in the slot. 985 * so, our .runtime_resume() will not try to detect a card in the slot.
976 */ 986 */
977 if (host->pdata->flags & TMIO_MMC_HAS_COLD_CD) 987 if (host->pdata->flags & TMIO_MMC_HAS_COLD_CD
988 || host->mmc->caps & MMC_CAP_NEEDS_POLL
989 || host->mmc->caps & MMC_CAP_NONREMOVABLE)
978 pm_runtime_get_sync(&pdev->dev); 990 pm_runtime_get_sync(&pdev->dev);
979 991
980 mmc_remove_host(host->mmc); 992 mmc_remove_host(host->mmc);
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index db8e8272d69b..3ce99e00a49e 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -315,8 +315,7 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,
315 char *dst; 315 char *dst;
316 316
317 if (reason != KMSG_DUMP_OOPS && 317 if (reason != KMSG_DUMP_OOPS &&
318 reason != KMSG_DUMP_PANIC && 318 reason != KMSG_DUMP_PANIC)
319 reason != KMSG_DUMP_KEXEC)
320 return; 319 return;
321 320
322 /* Only dump oopses if dump_oops is set */ 321 /* Only dump oopses if dump_oops is set */
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index 64fbb0021825..ead2cd16ba75 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -43,7 +43,10 @@
43 pr_debug("UBI DBG " type ": " fmt "\n", ##__VA_ARGS__) 43 pr_debug("UBI DBG " type ": " fmt "\n", ##__VA_ARGS__)
44 44
45/* Just a debugging messages not related to any specific UBI subsystem */ 45/* Just a debugging messages not related to any specific UBI subsystem */
46#define dbg_msg(fmt, ...) ubi_dbg_msg("msg", fmt, ##__VA_ARGS__) 46#define dbg_msg(fmt, ...) \
47 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
48 current->pid, __func__, ##__VA_ARGS__)
49
47/* General debugging messages */ 50/* General debugging messages */
48#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) 51#define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__)
49/* Messages from the eraseblock association sub-system */ 52/* Messages from the eraseblock association sub-system */
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 9ad18da1891d..890754c9f327 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -306,7 +306,7 @@ static int create_vtbl(struct ubi_device *ubi, struct ubi_scan_info *si,
306 int copy, void *vtbl) 306 int copy, void *vtbl)
307{ 307{
308 int err, tries = 0; 308 int err, tries = 0;
309 static struct ubi_vid_hdr *vid_hdr; 309 struct ubi_vid_hdr *vid_hdr;
310 struct ubi_scan_leb *new_seb; 310 struct ubi_scan_leb *new_seb;
311 311
312 ubi_msg("create volume table (copy #%d)", copy + 1); 312 ubi_msg("create volume table (copy #%d)", copy + 1);
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 106b88a04738..342626f4bc46 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -99,16 +99,26 @@ static inline u8 _simple_hash(const u8 *hash_start, int hash_size)
99 99
100/*********************** tlb specific functions ***************************/ 100/*********************** tlb specific functions ***************************/
101 101
102static inline void _lock_tx_hashtbl(struct bonding *bond) 102static inline void _lock_tx_hashtbl_bh(struct bonding *bond)
103{ 103{
104 spin_lock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock)); 104 spin_lock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
105} 105}
106 106
107static inline void _unlock_tx_hashtbl(struct bonding *bond) 107static inline void _unlock_tx_hashtbl_bh(struct bonding *bond)
108{ 108{
109 spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock)); 109 spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
110} 110}
111 111
112static inline void _lock_tx_hashtbl(struct bonding *bond)
113{
114 spin_lock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
115}
116
117static inline void _unlock_tx_hashtbl(struct bonding *bond)
118{
119 spin_unlock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
120}
121
112/* Caller must hold tx_hashtbl lock */ 122/* Caller must hold tx_hashtbl lock */
113static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load) 123static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load)
114{ 124{
@@ -129,14 +139,13 @@ static inline void tlb_init_slave(struct slave *slave)
129 SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX; 139 SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX;
130} 140}
131 141
132/* Caller must hold bond lock for read */ 142/* Caller must hold bond lock for read, BH disabled */
133static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_load) 143static void __tlb_clear_slave(struct bonding *bond, struct slave *slave,
144 int save_load)
134{ 145{
135 struct tlb_client_info *tx_hash_table; 146 struct tlb_client_info *tx_hash_table;
136 u32 index; 147 u32 index;
137 148
138 _lock_tx_hashtbl(bond);
139
140 /* clear slave from tx_hashtbl */ 149 /* clear slave from tx_hashtbl */
141 tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl; 150 tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;
142 151
@@ -151,8 +160,15 @@ static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_
151 } 160 }
152 161
153 tlb_init_slave(slave); 162 tlb_init_slave(slave);
163}
154 164
155 _unlock_tx_hashtbl(bond); 165/* Caller must hold bond lock for read */
166static void tlb_clear_slave(struct bonding *bond, struct slave *slave,
167 int save_load)
168{
169 _lock_tx_hashtbl_bh(bond);
170 __tlb_clear_slave(bond, slave, save_load);
171 _unlock_tx_hashtbl_bh(bond);
156} 172}
157 173
158/* Must be called before starting the monitor timer */ 174/* Must be called before starting the monitor timer */
@@ -169,7 +185,7 @@ static int tlb_initialize(struct bonding *bond)
169 bond->dev->name); 185 bond->dev->name);
170 return -1; 186 return -1;
171 } 187 }
172 _lock_tx_hashtbl(bond); 188 _lock_tx_hashtbl_bh(bond);
173 189
174 bond_info->tx_hashtbl = new_hashtbl; 190 bond_info->tx_hashtbl = new_hashtbl;
175 191
@@ -177,7 +193,7 @@ static int tlb_initialize(struct bonding *bond)
177 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0); 193 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0);
178 } 194 }
179 195
180 _unlock_tx_hashtbl(bond); 196 _unlock_tx_hashtbl_bh(bond);
181 197
182 return 0; 198 return 0;
183} 199}
@@ -187,12 +203,12 @@ static void tlb_deinitialize(struct bonding *bond)
187{ 203{
188 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); 204 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
189 205
190 _lock_tx_hashtbl(bond); 206 _lock_tx_hashtbl_bh(bond);
191 207
192 kfree(bond_info->tx_hashtbl); 208 kfree(bond_info->tx_hashtbl);
193 bond_info->tx_hashtbl = NULL; 209 bond_info->tx_hashtbl = NULL;
194 210
195 _unlock_tx_hashtbl(bond); 211 _unlock_tx_hashtbl_bh(bond);
196} 212}
197 213
198static long long compute_gap(struct slave *slave) 214static long long compute_gap(struct slave *slave)
@@ -226,15 +242,13 @@ static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
226 return least_loaded; 242 return least_loaded;
227} 243}
228 244
229/* Caller must hold bond lock for read */ 245static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index,
230static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u32 skb_len) 246 u32 skb_len)
231{ 247{
232 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); 248 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
233 struct tlb_client_info *hash_table; 249 struct tlb_client_info *hash_table;
234 struct slave *assigned_slave; 250 struct slave *assigned_slave;
235 251
236 _lock_tx_hashtbl(bond);
237
238 hash_table = bond_info->tx_hashtbl; 252 hash_table = bond_info->tx_hashtbl;
239 assigned_slave = hash_table[hash_index].tx_slave; 253 assigned_slave = hash_table[hash_index].tx_slave;
240 if (!assigned_slave) { 254 if (!assigned_slave) {
@@ -263,22 +277,46 @@ static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u3
263 hash_table[hash_index].tx_bytes += skb_len; 277 hash_table[hash_index].tx_bytes += skb_len;
264 } 278 }
265 279
266 _unlock_tx_hashtbl(bond);
267
268 return assigned_slave; 280 return assigned_slave;
269} 281}
270 282
283/* Caller must hold bond lock for read */
284static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index,
285 u32 skb_len)
286{
287 struct slave *tx_slave;
288 /*
289 * We don't need to disable softirq here, becase
290 * tlb_choose_channel() is only called by bond_alb_xmit()
291 * which already has softirq disabled.
292 */
293 _lock_tx_hashtbl(bond);
294 tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
295 _unlock_tx_hashtbl(bond);
296 return tx_slave;
297}
298
271/*********************** rlb specific functions ***************************/ 299/*********************** rlb specific functions ***************************/
272static inline void _lock_rx_hashtbl(struct bonding *bond) 300static inline void _lock_rx_hashtbl_bh(struct bonding *bond)
273{ 301{
274 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock)); 302 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
275} 303}
276 304
277static inline void _unlock_rx_hashtbl(struct bonding *bond) 305static inline void _unlock_rx_hashtbl_bh(struct bonding *bond)
278{ 306{
279 spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock)); 307 spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
280} 308}
281 309
310static inline void _lock_rx_hashtbl(struct bonding *bond)
311{
312 spin_lock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
313}
314
315static inline void _unlock_rx_hashtbl(struct bonding *bond)
316{
317 spin_unlock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
318}
319
282/* when an ARP REPLY is received from a client update its info 320/* when an ARP REPLY is received from a client update its info
283 * in the rx_hashtbl 321 * in the rx_hashtbl
284 */ 322 */
@@ -288,7 +326,7 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
288 struct rlb_client_info *client_info; 326 struct rlb_client_info *client_info;
289 u32 hash_index; 327 u32 hash_index;
290 328
291 _lock_rx_hashtbl(bond); 329 _lock_rx_hashtbl_bh(bond);
292 330
293 hash_index = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src)); 331 hash_index = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src));
294 client_info = &(bond_info->rx_hashtbl[hash_index]); 332 client_info = &(bond_info->rx_hashtbl[hash_index]);
@@ -303,7 +341,7 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
303 bond_info->rx_ntt = 1; 341 bond_info->rx_ntt = 1;
304 } 342 }
305 343
306 _unlock_rx_hashtbl(bond); 344 _unlock_rx_hashtbl_bh(bond);
307} 345}
308 346
309static void rlb_arp_recv(struct sk_buff *skb, struct bonding *bond, 347static void rlb_arp_recv(struct sk_buff *skb, struct bonding *bond,
@@ -401,7 +439,7 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
401 u32 index, next_index; 439 u32 index, next_index;
402 440
403 /* clear slave from rx_hashtbl */ 441 /* clear slave from rx_hashtbl */
404 _lock_rx_hashtbl(bond); 442 _lock_rx_hashtbl_bh(bond);
405 443
406 rx_hash_table = bond_info->rx_hashtbl; 444 rx_hash_table = bond_info->rx_hashtbl;
407 index = bond_info->rx_hashtbl_head; 445 index = bond_info->rx_hashtbl_head;
@@ -432,7 +470,7 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
432 } 470 }
433 } 471 }
434 472
435 _unlock_rx_hashtbl(bond); 473 _unlock_rx_hashtbl_bh(bond);
436 474
437 write_lock_bh(&bond->curr_slave_lock); 475 write_lock_bh(&bond->curr_slave_lock);
438 476
@@ -489,7 +527,7 @@ static void rlb_update_rx_clients(struct bonding *bond)
489 struct rlb_client_info *client_info; 527 struct rlb_client_info *client_info;
490 u32 hash_index; 528 u32 hash_index;
491 529
492 _lock_rx_hashtbl(bond); 530 _lock_rx_hashtbl_bh(bond);
493 531
494 hash_index = bond_info->rx_hashtbl_head; 532 hash_index = bond_info->rx_hashtbl_head;
495 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) { 533 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
@@ -507,7 +545,7 @@ static void rlb_update_rx_clients(struct bonding *bond)
507 */ 545 */
508 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY; 546 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
509 547
510 _unlock_rx_hashtbl(bond); 548 _unlock_rx_hashtbl_bh(bond);
511} 549}
512 550
513/* The slave was assigned a new mac address - update the clients */ 551/* The slave was assigned a new mac address - update the clients */
@@ -518,7 +556,7 @@ static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *sla
518 int ntt = 0; 556 int ntt = 0;
519 u32 hash_index; 557 u32 hash_index;
520 558
521 _lock_rx_hashtbl(bond); 559 _lock_rx_hashtbl_bh(bond);
522 560
523 hash_index = bond_info->rx_hashtbl_head; 561 hash_index = bond_info->rx_hashtbl_head;
524 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) { 562 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
@@ -538,7 +576,7 @@ static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *sla
538 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY; 576 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
539 } 577 }
540 578
541 _unlock_rx_hashtbl(bond); 579 _unlock_rx_hashtbl_bh(bond);
542} 580}
543 581
544/* mark all clients using src_ip to be updated */ 582/* mark all clients using src_ip to be updated */
@@ -709,7 +747,7 @@ static void rlb_rebalance(struct bonding *bond)
709 int ntt; 747 int ntt;
710 u32 hash_index; 748 u32 hash_index;
711 749
712 _lock_rx_hashtbl(bond); 750 _lock_rx_hashtbl_bh(bond);
713 751
714 ntt = 0; 752 ntt = 0;
715 hash_index = bond_info->rx_hashtbl_head; 753 hash_index = bond_info->rx_hashtbl_head;
@@ -727,7 +765,7 @@ static void rlb_rebalance(struct bonding *bond)
727 if (ntt) { 765 if (ntt) {
728 bond_info->rx_ntt = 1; 766 bond_info->rx_ntt = 1;
729 } 767 }
730 _unlock_rx_hashtbl(bond); 768 _unlock_rx_hashtbl_bh(bond);
731} 769}
732 770
733/* Caller must hold rx_hashtbl lock */ 771/* Caller must hold rx_hashtbl lock */
@@ -751,7 +789,7 @@ static int rlb_initialize(struct bonding *bond)
751 bond->dev->name); 789 bond->dev->name);
752 return -1; 790 return -1;
753 } 791 }
754 _lock_rx_hashtbl(bond); 792 _lock_rx_hashtbl_bh(bond);
755 793
756 bond_info->rx_hashtbl = new_hashtbl; 794 bond_info->rx_hashtbl = new_hashtbl;
757 795
@@ -761,7 +799,7 @@ static int rlb_initialize(struct bonding *bond)
761 rlb_init_table_entry(bond_info->rx_hashtbl + i); 799 rlb_init_table_entry(bond_info->rx_hashtbl + i);
762 } 800 }
763 801
764 _unlock_rx_hashtbl(bond); 802 _unlock_rx_hashtbl_bh(bond);
765 803
766 /* register to receive ARPs */ 804 /* register to receive ARPs */
767 bond->recv_probe = rlb_arp_recv; 805 bond->recv_probe = rlb_arp_recv;
@@ -773,13 +811,13 @@ static void rlb_deinitialize(struct bonding *bond)
773{ 811{
774 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); 812 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
775 813
776 _lock_rx_hashtbl(bond); 814 _lock_rx_hashtbl_bh(bond);
777 815
778 kfree(bond_info->rx_hashtbl); 816 kfree(bond_info->rx_hashtbl);
779 bond_info->rx_hashtbl = NULL; 817 bond_info->rx_hashtbl = NULL;
780 bond_info->rx_hashtbl_head = RLB_NULL_INDEX; 818 bond_info->rx_hashtbl_head = RLB_NULL_INDEX;
781 819
782 _unlock_rx_hashtbl(bond); 820 _unlock_rx_hashtbl_bh(bond);
783} 821}
784 822
785static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id) 823static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
@@ -787,7 +825,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
787 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); 825 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
788 u32 curr_index; 826 u32 curr_index;
789 827
790 _lock_rx_hashtbl(bond); 828 _lock_rx_hashtbl_bh(bond);
791 829
792 curr_index = bond_info->rx_hashtbl_head; 830 curr_index = bond_info->rx_hashtbl_head;
793 while (curr_index != RLB_NULL_INDEX) { 831 while (curr_index != RLB_NULL_INDEX) {
@@ -812,7 +850,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
812 curr_index = next_index; 850 curr_index = next_index;
813 } 851 }
814 852
815 _unlock_rx_hashtbl(bond); 853 _unlock_rx_hashtbl_bh(bond);
816} 854}
817 855
818/*********************** tlb/rlb shared functions *********************/ 856/*********************** tlb/rlb shared functions *********************/
@@ -1320,7 +1358,9 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1320 res = bond_dev_queue_xmit(bond, skb, tx_slave->dev); 1358 res = bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1321 } else { 1359 } else {
1322 if (tx_slave) { 1360 if (tx_slave) {
1323 tlb_clear_slave(bond, tx_slave, 0); 1361 _lock_tx_hashtbl(bond);
1362 __tlb_clear_slave(bond, tx_slave, 0);
1363 _unlock_tx_hashtbl(bond);
1324 } 1364 }
1325 } 1365 }
1326 1366
diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
index 9e8ba4f5636b..0f92e3567f68 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -623,7 +623,8 @@ static int ax_mii_init(struct net_device *dev)
623 623
624 ax->mii_bus->name = "ax88796_mii_bus"; 624 ax->mii_bus->name = "ax88796_mii_bus";
625 ax->mii_bus->parent = dev->dev.parent; 625 ax->mii_bus->parent = dev->dev.parent;
626 snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id); 626 snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
627 pdev->name, pdev->id);
627 628
628 ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); 629 ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
629 if (!ax->mii_bus->irq) { 630 if (!ax->mii_bus->irq) {
diff --git a/drivers/net/ethernet/adi/bfin_mac.c b/drivers/net/ethernet/adi/bfin_mac.c
index b6d69c91db96..d812a103e032 100644
--- a/drivers/net/ethernet/adi/bfin_mac.c
+++ b/drivers/net/ethernet/adi/bfin_mac.c
@@ -1670,7 +1670,8 @@ static int __devinit bfin_mii_bus_probe(struct platform_device *pdev)
1670 miibus->name = "bfin_mii_bus"; 1670 miibus->name = "bfin_mii_bus";
1671 miibus->phy_mask = mii_bus_pd->phy_mask; 1671 miibus->phy_mask = mii_bus_pd->phy_mask;
1672 1672
1673 snprintf(miibus->id, MII_BUS_ID_SIZE, "0"); 1673 snprintf(miibus->id, MII_BUS_ID_SIZE, "%s-%x",
1674 pdev->name, pdev->id);
1674 miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 1675 miibus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
1675 if (!miibus->irq) 1676 if (!miibus->irq)
1676 goto out_err_irq_alloc; 1677 goto out_err_irq_alloc;
diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c
index cc9262be69c8..8b95dd314253 100644
--- a/drivers/net/ethernet/amd/au1000_eth.c
+++ b/drivers/net/ethernet/amd/au1000_eth.c
@@ -1171,7 +1171,8 @@ static int __devinit au1000_probe(struct platform_device *pdev)
1171 aup->mii_bus->write = au1000_mdiobus_write; 1171 aup->mii_bus->write = au1000_mdiobus_write;
1172 aup->mii_bus->reset = au1000_mdiobus_reset; 1172 aup->mii_bus->reset = au1000_mdiobus_reset;
1173 aup->mii_bus->name = "au1000_eth_mii"; 1173 aup->mii_bus->name = "au1000_eth_mii";
1174 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id); 1174 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1175 pdev->name, aup->mac_id);
1175 aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 1176 aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
1176 if (aup->mii_bus->irq == NULL) 1177 if (aup->mii_bus->irq == NULL)
1177 goto err_out; 1178 goto err_out;
diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index d44331eb07fe..986019b2c849 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -1727,7 +1727,7 @@ static int __devinit bcm_enet_probe(struct platform_device *pdev)
1727 bus->priv = priv; 1727 bus->priv = priv;
1728 bus->read = bcm_enet_mdio_read_phylib; 1728 bus->read = bcm_enet_mdio_read_phylib;
1729 bus->write = bcm_enet_mdio_write_phylib; 1729 bus->write = bcm_enet_mdio_write_phylib;
1730 sprintf(bus->id, "%d", priv->mac_id); 1730 sprintf(bus->id, "%s-%d", pdev->name, priv->mac_id);
1731 1731
1732 /* only probe bus where we think the PHY is, because 1732 /* only probe bus where we think the PHY is, because
1733 * the mdio read operation return 0 instead of 0xffff 1733 * the mdio read operation return 0 instead of 0xffff
diff --git a/drivers/net/ethernet/broadcom/sb1250-mac.c b/drivers/net/ethernet/broadcom/sb1250-mac.c
index 8fa7abc53ec6..084904ceaa30 100644
--- a/drivers/net/ethernet/broadcom/sb1250-mac.c
+++ b/drivers/net/ethernet/broadcom/sb1250-mac.c
@@ -2259,7 +2259,8 @@ static int sbmac_init(struct platform_device *pldev, long long base)
2259 } 2259 }
2260 2260
2261 sc->mii_bus->name = sbmac_mdio_string; 2261 sc->mii_bus->name = sbmac_mdio_string;
2262 snprintf(sc->mii_bus->id, MII_BUS_ID_SIZE, "%x", idx); 2262 snprintf(sc->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
2263 pldev->name, idx);
2263 sc->mii_bus->priv = sc; 2264 sc->mii_bus->priv = sc;
2264 sc->mii_bus->read = sbmac_mii_read; 2265 sc->mii_bus->read = sbmac_mii_read;
2265 sc->mii_bus->write = sbmac_mii_write; 2266 sc->mii_bus->write = sbmac_mii_write;
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index f3d5c65d99cf..23200680d4c1 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -243,7 +243,8 @@ static int macb_mii_init(struct macb *bp)
243 bp->mii_bus->read = &macb_mdio_read; 243 bp->mii_bus->read = &macb_mdio_read;
244 bp->mii_bus->write = &macb_mdio_write; 244 bp->mii_bus->write = &macb_mdio_write;
245 bp->mii_bus->reset = &macb_mdio_reset; 245 bp->mii_bus->reset = &macb_mdio_reset;
246 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%x", bp->pdev->id); 246 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
247 bp->pdev->name, bp->pdev->id);
247 bp->mii_bus->priv = bp; 248 bp->mii_bus->priv = bp;
248 bp->mii_bus->parent = &bp->dev->dev; 249 bp->mii_bus->parent = &bp->dev->dev;
249 pdata = bp->pdev->dev.platform_data; 250 pdata = bp->pdev->dev.platform_data;
diff --git a/drivers/net/ethernet/dnet.c b/drivers/net/ethernet/dnet.c
index ce88c0f399f6..925c9bafc9b9 100644
--- a/drivers/net/ethernet/dnet.c
+++ b/drivers/net/ethernet/dnet.c
@@ -325,7 +325,8 @@ static int dnet_mii_init(struct dnet *bp)
325 bp->mii_bus->write = &dnet_mdio_write; 325 bp->mii_bus->write = &dnet_mdio_write;
326 bp->mii_bus->reset = &dnet_mdio_reset; 326 bp->mii_bus->reset = &dnet_mdio_reset;
327 327
328 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%x", 0); 328 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
329 bp->pdev->name, bp->pdev->id);
329 330
330 bp->mii_bus->priv = bp; 331 bp->mii_bus->priv = bp;
331 332
diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index ddcbbb34d1b9..7b25e9cf13f6 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -476,6 +476,7 @@ fec_restart(struct net_device *ndev, int duplex)
476 } else { 476 } else {
477#ifdef FEC_MIIGSK_ENR 477#ifdef FEC_MIIGSK_ENR
478 if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) { 478 if (id_entry->driver_data & FEC_QUIRK_USE_GASKET) {
479 u32 cfgr;
479 /* disable the gasket and wait */ 480 /* disable the gasket and wait */
480 writel(0, fep->hwp + FEC_MIIGSK_ENR); 481 writel(0, fep->hwp + FEC_MIIGSK_ENR);
481 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4) 482 while (readl(fep->hwp + FEC_MIIGSK_ENR) & 4)
@@ -486,9 +487,11 @@ fec_restart(struct net_device *ndev, int duplex)
486 * RMII, 50 MHz, no loopback, no echo 487 * RMII, 50 MHz, no loopback, no echo
487 * MII, 25 MHz, no loopback, no echo 488 * MII, 25 MHz, no loopback, no echo
488 */ 489 */
489 writel((fep->phy_interface == PHY_INTERFACE_MODE_RMII) ? 490 cfgr = (fep->phy_interface == PHY_INTERFACE_MODE_RMII)
490 1 : 0, fep->hwp + FEC_MIIGSK_CFGR); 491 ? BM_MIIGSK_CFGR_RMII : BM_MIIGSK_CFGR_MII;
491 492 if (fep->phy_dev && fep->phy_dev->speed == SPEED_10)
493 cfgr |= BM_MIIGSK_CFGR_FRCONT_10M;
494 writel(cfgr, fep->hwp + FEC_MIIGSK_CFGR);
492 495
493 /* re-enable the gasket */ 496 /* re-enable the gasket */
494 writel(2, fep->hwp + FEC_MIIGSK_ENR); 497 writel(2, fep->hwp + FEC_MIIGSK_ENR);
@@ -1077,7 +1080,8 @@ static int fec_enet_mii_init(struct platform_device *pdev)
1077 fep->mii_bus->read = fec_enet_mdio_read; 1080 fep->mii_bus->read = fec_enet_mdio_read;
1078 fep->mii_bus->write = fec_enet_mdio_write; 1081 fep->mii_bus->write = fec_enet_mdio_write;
1079 fep->mii_bus->reset = fec_enet_mdio_reset; 1082 fep->mii_bus->reset = fec_enet_mdio_reset;
1080 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", fep->dev_id + 1); 1083 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1084 pdev->name, fep->dev_id + 1);
1081 fep->mii_bus->priv = fep; 1085 fep->mii_bus->priv = fep;
1082 fep->mii_bus->parent = &pdev->dev; 1086 fep->mii_bus->parent = &pdev->dev;
1083 1087
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 8b2c6d797e6d..8408c627b195 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -47,6 +47,10 @@
47#define FEC_MIIGSK_CFGR 0x300 /* MIIGSK Configuration reg */ 47#define FEC_MIIGSK_CFGR 0x300 /* MIIGSK Configuration reg */
48#define FEC_MIIGSK_ENR 0x308 /* MIIGSK Enable reg */ 48#define FEC_MIIGSK_ENR 0x308 /* MIIGSK Enable reg */
49 49
50#define BM_MIIGSK_CFGR_MII 0x00
51#define BM_MIIGSK_CFGR_RMII 0x01
52#define BM_MIIGSK_CFGR_FRCONT_10M 0x40
53
50#else 54#else
51 55
52#define FEC_ECNTRL 0x000 /* Ethernet control reg */ 56#define FEC_ECNTRL 0x000 /* Ethernet control reg */
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index e01cdaa722a9..39d160d353a4 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -1984,7 +1984,8 @@ static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
1984 return fcb; 1984 return fcb;
1985} 1985}
1986 1986
1987static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb) 1987static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb,
1988 int fcb_length)
1988{ 1989{
1989 u8 flags = 0; 1990 u8 flags = 0;
1990 1991
@@ -2006,7 +2007,7 @@ static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
2006 * frame (skb->data) and the start of the IP hdr. 2007 * frame (skb->data) and the start of the IP hdr.
2007 * l4os is the distance between the start of the 2008 * l4os is the distance between the start of the
2008 * l3 hdr and the l4 hdr */ 2009 * l3 hdr and the l4 hdr */
2009 fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN); 2010 fcb->l3os = (u16)(skb_network_offset(skb) - fcb_length);
2010 fcb->l4os = skb_network_header_len(skb); 2011 fcb->l4os = skb_network_header_len(skb);
2011 2012
2012 fcb->flags = flags; 2013 fcb->flags = flags;
@@ -2046,7 +2047,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2046 int i, rq = 0, do_tstamp = 0; 2047 int i, rq = 0, do_tstamp = 0;
2047 u32 bufaddr; 2048 u32 bufaddr;
2048 unsigned long flags; 2049 unsigned long flags;
2049 unsigned int nr_frags, nr_txbds, length; 2050 unsigned int nr_frags, nr_txbds, length, fcb_length = GMAC_FCB_LEN;
2050 2051
2051 /* 2052 /*
2052 * TOE=1 frames larger than 2500 bytes may see excess delays 2053 * TOE=1 frames larger than 2500 bytes may see excess delays
@@ -2070,22 +2071,28 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2070 2071
2071 /* check if time stamp should be generated */ 2072 /* check if time stamp should be generated */
2072 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && 2073 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
2073 priv->hwts_tx_en)) 2074 priv->hwts_tx_en)) {
2074 do_tstamp = 1; 2075 do_tstamp = 1;
2076 fcb_length = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
2077 }
2075 2078
2076 /* make space for additional header when fcb is needed */ 2079 /* make space for additional header when fcb is needed */
2077 if (((skb->ip_summed == CHECKSUM_PARTIAL) || 2080 if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
2078 vlan_tx_tag_present(skb) || 2081 vlan_tx_tag_present(skb) ||
2079 unlikely(do_tstamp)) && 2082 unlikely(do_tstamp)) &&
2080 (skb_headroom(skb) < GMAC_FCB_LEN)) { 2083 (skb_headroom(skb) < fcb_length)) {
2081 struct sk_buff *skb_new; 2084 struct sk_buff *skb_new;
2082 2085
2083 skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN); 2086 skb_new = skb_realloc_headroom(skb, fcb_length);
2084 if (!skb_new) { 2087 if (!skb_new) {
2085 dev->stats.tx_errors++; 2088 dev->stats.tx_errors++;
2086 kfree_skb(skb); 2089 kfree_skb(skb);
2087 return NETDEV_TX_OK; 2090 return NETDEV_TX_OK;
2088 } 2091 }
2092
2093 /* Steal sock reference for processing TX time stamps */
2094 swap(skb_new->sk, skb->sk);
2095 swap(skb_new->destructor, skb->destructor);
2089 kfree_skb(skb); 2096 kfree_skb(skb);
2090 skb = skb_new; 2097 skb = skb_new;
2091 } 2098 }
@@ -2154,6 +2161,12 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2154 lstatus = txbdp_start->lstatus; 2161 lstatus = txbdp_start->lstatus;
2155 } 2162 }
2156 2163
2164 /* Add TxPAL between FCB and frame if required */
2165 if (unlikely(do_tstamp)) {
2166 skb_push(skb, GMAC_TXPAL_LEN);
2167 memset(skb->data, 0, GMAC_TXPAL_LEN);
2168 }
2169
2157 /* Set up checksumming */ 2170 /* Set up checksumming */
2158 if (CHECKSUM_PARTIAL == skb->ip_summed) { 2171 if (CHECKSUM_PARTIAL == skb->ip_summed) {
2159 fcb = gfar_add_fcb(skb); 2172 fcb = gfar_add_fcb(skb);
@@ -2164,7 +2177,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2164 skb_checksum_help(skb); 2177 skb_checksum_help(skb);
2165 } else { 2178 } else {
2166 lstatus |= BD_LFLAG(TXBD_TOE); 2179 lstatus |= BD_LFLAG(TXBD_TOE);
2167 gfar_tx_checksum(skb, fcb); 2180 gfar_tx_checksum(skb, fcb, fcb_length);
2168 } 2181 }
2169 } 2182 }
2170 2183
@@ -2196,9 +2209,9 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2196 * the full frame length. 2209 * the full frame length.
2197 */ 2210 */
2198 if (unlikely(do_tstamp)) { 2211 if (unlikely(do_tstamp)) {
2199 txbdp_tstamp->bufPtr = txbdp_start->bufPtr + GMAC_FCB_LEN; 2212 txbdp_tstamp->bufPtr = txbdp_start->bufPtr + fcb_length;
2200 txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_READY) | 2213 txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_READY) |
2201 (skb_headlen(skb) - GMAC_FCB_LEN); 2214 (skb_headlen(skb) - fcb_length);
2202 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN; 2215 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN;
2203 } else { 2216 } else {
2204 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb); 2217 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
@@ -2490,7 +2503,7 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2490 2503
2491 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { 2504 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
2492 next = next_txbd(bdp, base, tx_ring_size); 2505 next = next_txbd(bdp, base, tx_ring_size);
2493 buflen = next->length + GMAC_FCB_LEN; 2506 buflen = next->length + GMAC_FCB_LEN + GMAC_TXPAL_LEN;
2494 } else 2507 } else
2495 buflen = bdp->length; 2508 buflen = bdp->length;
2496 2509
@@ -2502,6 +2515,7 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2502 u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7); 2515 u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7);
2503 memset(&shhwtstamps, 0, sizeof(shhwtstamps)); 2516 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
2504 shhwtstamps.hwtstamp = ns_to_ktime(*ns); 2517 shhwtstamps.hwtstamp = ns_to_ktime(*ns);
2518 skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN);
2505 skb_tstamp_tx(skb, &shhwtstamps); 2519 skb_tstamp_tx(skb, &shhwtstamps);
2506 bdp->lstatus &= BD_LFLAG(TXBD_WRAP); 2520 bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
2507 bdp = next; 2521 bdp = next;
diff --git a/drivers/net/ethernet/freescale/gianfar.h b/drivers/net/ethernet/freescale/gianfar.h
index fe7ac3a83194..40c33a7554c0 100644
--- a/drivers/net/ethernet/freescale/gianfar.h
+++ b/drivers/net/ethernet/freescale/gianfar.h
@@ -63,6 +63,9 @@ struct ethtool_rx_list {
63/* Length for FCB */ 63/* Length for FCB */
64#define GMAC_FCB_LEN 8 64#define GMAC_FCB_LEN 8
65 65
66/* Length for TxPAL */
67#define GMAC_TXPAL_LEN 16
68
66/* Default padding amount */ 69/* Default padding amount */
67#define DEFAULT_PADDING 2 70#define DEFAULT_PADDING 2
68 71
diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 0b3567ab8121..85e2c6cd9708 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -98,6 +98,7 @@ struct ltq_etop_chan {
98 98
99struct ltq_etop_priv { 99struct ltq_etop_priv {
100 struct net_device *netdev; 100 struct net_device *netdev;
101 struct platform_device *pdev;
101 struct ltq_eth_data *pldata; 102 struct ltq_eth_data *pldata;
102 struct resource *res; 103 struct resource *res;
103 104
@@ -436,7 +437,8 @@ ltq_etop_mdio_init(struct net_device *dev)
436 priv->mii_bus->read = ltq_etop_mdio_rd; 437 priv->mii_bus->read = ltq_etop_mdio_rd;
437 priv->mii_bus->write = ltq_etop_mdio_wr; 438 priv->mii_bus->write = ltq_etop_mdio_wr;
438 priv->mii_bus->name = "ltq_mii"; 439 priv->mii_bus->name = "ltq_mii";
439 snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%x", 0); 440 snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
441 priv->pdev->name, priv->pdev->id);
440 priv->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); 442 priv->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
441 if (!priv->mii_bus->irq) { 443 if (!priv->mii_bus->irq) {
442 err = -ENOMEM; 444 err = -ENOMEM;
@@ -734,6 +736,7 @@ ltq_etop_probe(struct platform_device *pdev)
734 dev->ethtool_ops = &ltq_etop_ethtool_ops; 736 dev->ethtool_ops = &ltq_etop_ethtool_ops;
735 priv = netdev_priv(dev); 737 priv = netdev_priv(dev);
736 priv->res = res; 738 priv->res = res;
739 priv->pdev = pdev;
737 priv->pldata = dev_get_platdata(&pdev->dev); 740 priv->pldata = dev_get_platdata(&pdev->dev);
738 priv->netdev = dev; 741 priv->netdev = dev;
739 spin_lock_init(&priv->lock); 742 spin_lock_init(&priv->lock);
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 80aab4e5d695..9c049d2cb97d 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -2613,7 +2613,8 @@ static int mv643xx_eth_shared_probe(struct platform_device *pdev)
2613 msp->smi_bus->name = "mv643xx_eth smi"; 2613 msp->smi_bus->name = "mv643xx_eth smi";
2614 msp->smi_bus->read = smi_bus_read; 2614 msp->smi_bus->read = smi_bus_read;
2615 msp->smi_bus->write = smi_bus_write, 2615 msp->smi_bus->write = smi_bus_write,
2616 snprintf(msp->smi_bus->id, MII_BUS_ID_SIZE, "%d", pdev->id); 2616 snprintf(msp->smi_bus->id, MII_BUS_ID_SIZE, "%s-%d",
2617 pdev->name, pdev->id);
2617 msp->smi_bus->parent = &pdev->dev; 2618 msp->smi_bus->parent = &pdev->dev;
2618 msp->smi_bus->phy_mask = 0xffffffff; 2619 msp->smi_bus->phy_mask = 0xffffffff;
2619 if (mdiobus_register(msp->smi_bus) < 0) 2620 if (mdiobus_register(msp->smi_bus) < 0)
diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c
index 5ec409e3da09..953ba5851f7b 100644
--- a/drivers/net/ethernet/marvell/pxa168_eth.c
+++ b/drivers/net/ethernet/marvell/pxa168_eth.c
@@ -1552,7 +1552,8 @@ static int pxa168_eth_probe(struct platform_device *pdev)
1552 pep->smi_bus->name = "pxa168_eth smi"; 1552 pep->smi_bus->name = "pxa168_eth smi";
1553 pep->smi_bus->read = pxa168_smi_read; 1553 pep->smi_bus->read = pxa168_smi_read;
1554 pep->smi_bus->write = pxa168_smi_write; 1554 pep->smi_bus->write = pxa168_smi_write;
1555 snprintf(pep->smi_bus->id, MII_BUS_ID_SIZE, "%d", pdev->id); 1555 snprintf(pep->smi_bus->id, MII_BUS_ID_SIZE, "%s-%d",
1556 pdev->name, pdev->id);
1556 pep->smi_bus->parent = &pdev->dev; 1557 pep->smi_bus->parent = &pdev->dev;
1557 pep->smi_bus->phy_mask = 0xffffffff; 1558 pep->smi_bus->phy_mask = 0xffffffff;
1558 err = mdiobus_register(pep->smi_bus); 1559 err = mdiobus_register(pep->smi_bus);
diff --git a/drivers/net/ethernet/micrel/ksz884x.c b/drivers/net/ethernet/micrel/ksz884x.c
index 6ed09a85f035..e52cd310ae76 100644
--- a/drivers/net/ethernet/micrel/ksz884x.c
+++ b/drivers/net/ethernet/micrel/ksz884x.c
@@ -746,7 +746,7 @@
746#define MAC_ADDR_ORDER(i) (ETH_ALEN - 1 - (i)) 746#define MAC_ADDR_ORDER(i) (ETH_ALEN - 1 - (i))
747 747
748#define MAX_ETHERNET_BODY_SIZE 1500 748#define MAX_ETHERNET_BODY_SIZE 1500
749#define ETHERNET_HEADER_SIZE 14 749#define ETHERNET_HEADER_SIZE (14 + VLAN_HLEN)
750 750
751#define MAX_ETHERNET_PACKET_SIZE \ 751#define MAX_ETHERNET_PACKET_SIZE \
752 (MAX_ETHERNET_BODY_SIZE + ETHERNET_HEADER_SIZE) 752 (MAX_ETHERNET_BODY_SIZE + ETHERNET_HEADER_SIZE)
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index fc9bda9bc36c..6ece4295d78f 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1702,7 +1702,8 @@ static int sh_mdio_init(struct net_device *ndev, int id,
1702 /* Hook up MII support for ethtool */ 1702 /* Hook up MII support for ethtool */
1703 mdp->mii_bus->name = "sh_mii"; 1703 mdp->mii_bus->name = "sh_mii";
1704 mdp->mii_bus->parent = &ndev->dev; 1704 mdp->mii_bus->parent = &ndev->dev;
1705 snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%x", id); 1705 snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1706 mdp->pdev->name, pdid);
1706 1707
1707 /* PHY IRQ */ 1708 /* PHY IRQ */
1708 mdp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 1709 mdp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
diff --git a/drivers/net/ethernet/s6gmac.c b/drivers/net/ethernet/s6gmac.c
index a7ff8ea342b4..22e9c0181ce8 100644
--- a/drivers/net/ethernet/s6gmac.c
+++ b/drivers/net/ethernet/s6gmac.c
@@ -1004,7 +1004,7 @@ static int __devinit s6gmac_probe(struct platform_device *pdev)
1004 mb->write = s6mii_write; 1004 mb->write = s6mii_write;
1005 mb->reset = s6mii_reset; 1005 mb->reset = s6mii_reset;
1006 mb->priv = pd; 1006 mb->priv = pd;
1007 snprintf(mb->id, MII_BUS_ID_SIZE, "0"); 1007 snprintf(mb->id, MII_BUS_ID_SIZE, "%s-%x", pdev->name, pdev->id);
1008 mb->phy_mask = ~(1 << 0); 1008 mb->phy_mask = ~(1 << 0);
1009 mb->irq = &pd->mii.irq[0]; 1009 mb->irq = &pd->mii.irq[0];
1010 for (i = 0; i < PHY_MAX_ADDR; i++) { 1010 for (i = 0; i < PHY_MAX_ADDR; i++) {
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 9d0b8ced0234..24d2df068d71 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -1044,7 +1044,8 @@ static int __devinit smsc911x_mii_init(struct platform_device *pdev,
1044 } 1044 }
1045 1045
1046 pdata->mii_bus->name = SMSC_MDIONAME; 1046 pdata->mii_bus->name = SMSC_MDIONAME;
1047 snprintf(pdata->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id); 1047 snprintf(pdata->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
1048 pdev->name, pdev->id);
1048 pdata->mii_bus->priv = pdata; 1049 pdata->mii_bus->priv = pdata;
1049 pdata->mii_bus->read = smsc911x_mii_read; 1050 pdata->mii_bus->read = smsc911x_mii_read;
1050 pdata->mii_bus->write = smsc911x_mii_write; 1051 pdata->mii_bus->write = smsc911x_mii_write;
diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
index 41e6b33e1b08..c07cfe989f6e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
@@ -22,6 +22,7 @@
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> 22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/ 23*******************************************************************************/
24 24
25#include <linux/kernel.h>
25#include <linux/io.h> 26#include <linux/io.h>
26#include "mmc.h" 27#include "mmc.h"
27 28
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 3738b4700548..96fa2da30763 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -307,7 +307,7 @@ static int stmmac_init_phy(struct net_device *dev)
307 priv->speed = 0; 307 priv->speed = 0;
308 priv->oldduplex = -1; 308 priv->oldduplex = -1;
309 309
310 snprintf(bus_id, MII_BUS_ID_SIZE, "%x", priv->plat->bus_id); 310 snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x", priv->plat->bus_id);
311 snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id, 311 snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
312 priv->plat->phy_addr); 312 priv->plat->phy_addr);
313 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id); 313 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id);
@@ -772,7 +772,7 @@ static void stmmac_mmc_setup(struct stmmac_priv *priv)
772 dwmac_mmc_ctrl(priv->ioaddr, mode); 772 dwmac_mmc_ctrl(priv->ioaddr, mode);
773 memset(&priv->mmc, 0, sizeof(struct stmmac_counters)); 773 memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
774 } else 774 } else
775 pr_info(" No MAC Management Counters available"); 775 pr_info(" No MAC Management Counters available\n");
776} 776}
777 777
778static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv) 778static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 51f441233962..da4a1042523a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -158,7 +158,8 @@ int stmmac_mdio_register(struct net_device *ndev)
158 new_bus->read = &stmmac_mdio_read; 158 new_bus->read = &stmmac_mdio_read;
159 new_bus->write = &stmmac_mdio_write; 159 new_bus->write = &stmmac_mdio_write;
160 new_bus->reset = &stmmac_mdio_reset; 160 new_bus->reset = &stmmac_mdio_reset;
161 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", mdio_bus_data->bus_id); 161 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%x",
162 new_bus->name, mdio_bus_data->bus_id);
162 new_bus->priv = ndev; 163 new_bus->priv = ndev;
163 new_bus->irq = irqlist; 164 new_bus->irq = irqlist;
164 new_bus->phy_mask = mdio_bus_data->phy_mask; 165 new_bus->phy_mask = mdio_bus_data->phy_mask;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 7b1594f4944e..1ac83243649a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -62,7 +62,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
62 priv = stmmac_dvr_probe(&(pdev->dev), plat_dat); 62 priv = stmmac_dvr_probe(&(pdev->dev), plat_dat);
63 if (!priv) { 63 if (!priv) {
64 pr_err("%s: main drivr probe failed", __func__); 64 pr_err("%s: main drivr probe failed", __func__);
65 goto out_release_region; 65 goto out_unmap;
66 } 66 }
67 67
68 priv->ioaddr = addr; 68 priv->ioaddr = addr;
diff --git a/drivers/net/ethernet/ti/cpmac.c b/drivers/net/ethernet/ti/cpmac.c
index aaac0c7ad111..4d9a28ffd3c3 100644
--- a/drivers/net/ethernet/ti/cpmac.c
+++ b/drivers/net/ethernet/ti/cpmac.c
@@ -1269,7 +1269,7 @@ int __devinit cpmac_init(void)
1269 } 1269 }
1270 1270
1271 cpmac_mii->phy_mask = ~(mask | 0x80000000); 1271 cpmac_mii->phy_mask = ~(mask | 0x80000000);
1272 snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "1"); 1272 snprintf(cpmac_mii->id, MII_BUS_ID_SIZE, "cpmac-1");
1273 1273
1274 res = mdiobus_register(cpmac_mii); 1274 res = mdiobus_register(cpmac_mii);
1275 if (res) 1275 if (res)
diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index 7615040df756..ef7c9c17bfff 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -313,7 +313,8 @@ static int __devinit davinci_mdio_probe(struct platform_device *pdev)
313 data->bus->reset = davinci_mdio_reset, 313 data->bus->reset = davinci_mdio_reset,
314 data->bus->parent = dev; 314 data->bus->parent = dev;
315 data->bus->priv = data; 315 data->bus->priv = data;
316 snprintf(data->bus->id, MII_BUS_ID_SIZE, "%x", pdev->id); 316 snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x",
317 pdev->name, pdev->id);
317 318
318 data->clk = clk_get(dev, NULL); 319 data->clk = clk_get(dev, NULL);
319 if (IS_ERR(data->clk)) { 320 if (IS_ERR(data->clk)) {
diff --git a/drivers/net/ethernet/tundra/tsi108_eth.c b/drivers/net/ethernet/tundra/tsi108_eth.c
index a9ce01bafd20..164fb775d7b3 100644
--- a/drivers/net/ethernet/tundra/tsi108_eth.c
+++ b/drivers/net/ethernet/tundra/tsi108_eth.c
@@ -1604,7 +1604,7 @@ tsi108_init_one(struct platform_device *pdev)
1604 data->phyregs = ioremap(einfo->phyregs, 0x400); 1604 data->phyregs = ioremap(einfo->phyregs, 0x400);
1605 if (NULL == data->phyregs) { 1605 if (NULL == data->phyregs) {
1606 err = -ENOMEM; 1606 err = -ENOMEM;
1607 goto regs_fail; 1607 goto phyregs_fail;
1608 } 1608 }
1609/* MII setup */ 1609/* MII setup */
1610 data->mii_if.dev = dev; 1610 data->mii_if.dev = dev;
@@ -1663,9 +1663,11 @@ tsi108_init_one(struct platform_device *pdev)
1663 return 0; 1663 return 0;
1664 1664
1665register_fail: 1665register_fail:
1666 iounmap(data->regs);
1667 iounmap(data->phyregs); 1666 iounmap(data->phyregs);
1668 1667
1668phyregs_fail:
1669 iounmap(data->regs);
1670
1669regs_fail: 1671regs_fail:
1670 free_netdev(dev); 1672 free_netdev(dev);
1671 return err; 1673 return err;
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 5c4983b2870a..10b18eb63d25 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -39,10 +39,9 @@
39 39
40/* A few user-configurable values. 40/* A few user-configurable values.
41 These may be modified when a driver module is loaded. */ 41 These may be modified when a driver module is loaded. */
42 42static int debug = 0;
43#define DEBUG 43#define RHINE_MSG_DEFAULT \
44static int debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */ 44 (0x0000)
45static int max_interrupt_work = 20;
46 45
47/* Set the copy breakpoint for the copy-only-tiny-frames scheme. 46/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
48 Setting to > 1518 effectively disables this feature. */ 47 Setting to > 1518 effectively disables this feature. */
@@ -128,12 +127,10 @@ MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
128MODULE_DESCRIPTION("VIA Rhine PCI Fast Ethernet driver"); 127MODULE_DESCRIPTION("VIA Rhine PCI Fast Ethernet driver");
129MODULE_LICENSE("GPL"); 128MODULE_LICENSE("GPL");
130 129
131module_param(max_interrupt_work, int, 0);
132module_param(debug, int, 0); 130module_param(debug, int, 0);
133module_param(rx_copybreak, int, 0); 131module_param(rx_copybreak, int, 0);
134module_param(avoid_D3, bool, 0); 132module_param(avoid_D3, bool, 0);
135MODULE_PARM_DESC(max_interrupt_work, "VIA Rhine maximum events handled per interrupt"); 133MODULE_PARM_DESC(debug, "VIA Rhine debug message flags");
136MODULE_PARM_DESC(debug, "VIA Rhine debug level (0-7)");
137MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames"); 134MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames");
138MODULE_PARM_DESC(avoid_D3, "Avoid power state D3 (work-around for broken BIOSes)"); 135MODULE_PARM_DESC(avoid_D3, "Avoid power state D3 (work-around for broken BIOSes)");
139 136
@@ -351,16 +348,25 @@ static const int mmio_verify_registers[] = {
351 348
352/* Bits in the interrupt status/mask registers. */ 349/* Bits in the interrupt status/mask registers. */
353enum intr_status_bits { 350enum intr_status_bits {
354 IntrRxDone=0x0001, IntrRxErr=0x0004, IntrRxEmpty=0x0020, 351 IntrRxDone = 0x0001,
355 IntrTxDone=0x0002, IntrTxError=0x0008, IntrTxUnderrun=0x0210, 352 IntrTxDone = 0x0002,
356 IntrPCIErr=0x0040, 353 IntrRxErr = 0x0004,
357 IntrStatsMax=0x0080, IntrRxEarly=0x0100, 354 IntrTxError = 0x0008,
358 IntrRxOverflow=0x0400, IntrRxDropped=0x0800, IntrRxNoBuf=0x1000, 355 IntrRxEmpty = 0x0020,
359 IntrTxAborted=0x2000, IntrLinkChange=0x4000, 356 IntrPCIErr = 0x0040,
360 IntrRxWakeUp=0x8000, 357 IntrStatsMax = 0x0080,
361 IntrNormalSummary=0x0003, IntrAbnormalSummary=0xC260, 358 IntrRxEarly = 0x0100,
362 IntrTxDescRace=0x080000, /* mapped from IntrStatus2 */ 359 IntrTxUnderrun = 0x0210,
363 IntrTxErrSummary=0x082218, 360 IntrRxOverflow = 0x0400,
361 IntrRxDropped = 0x0800,
362 IntrRxNoBuf = 0x1000,
363 IntrTxAborted = 0x2000,
364 IntrLinkChange = 0x4000,
365 IntrRxWakeUp = 0x8000,
366 IntrTxDescRace = 0x080000, /* mapped from IntrStatus2 */
367 IntrNormalSummary = IntrRxDone | IntrTxDone,
368 IntrTxErrSummary = IntrTxDescRace | IntrTxAborted | IntrTxError |
369 IntrTxUnderrun,
364}; 370};
365 371
366/* Bits in WOLcrSet/WOLcrClr and PwrcsrSet/PwrcsrClr */ 372/* Bits in WOLcrSet/WOLcrClr and PwrcsrSet/PwrcsrClr */
@@ -439,8 +445,13 @@ struct rhine_private {
439 struct net_device *dev; 445 struct net_device *dev;
440 struct napi_struct napi; 446 struct napi_struct napi;
441 spinlock_t lock; 447 spinlock_t lock;
448 struct mutex task_lock;
449 bool task_enable;
450 struct work_struct slow_event_task;
442 struct work_struct reset_task; 451 struct work_struct reset_task;
443 452
453 u32 msg_enable;
454
444 /* Frequently used values: keep some adjacent for cache effect. */ 455 /* Frequently used values: keep some adjacent for cache effect. */
445 u32 quirks; 456 u32 quirks;
446 struct rx_desc *rx_head_desc; 457 struct rx_desc *rx_head_desc;
@@ -476,41 +487,50 @@ static int mdio_read(struct net_device *dev, int phy_id, int location);
476static void mdio_write(struct net_device *dev, int phy_id, int location, int value); 487static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
477static int rhine_open(struct net_device *dev); 488static int rhine_open(struct net_device *dev);
478static void rhine_reset_task(struct work_struct *work); 489static void rhine_reset_task(struct work_struct *work);
490static void rhine_slow_event_task(struct work_struct *work);
479static void rhine_tx_timeout(struct net_device *dev); 491static void rhine_tx_timeout(struct net_device *dev);
480static netdev_tx_t rhine_start_tx(struct sk_buff *skb, 492static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
481 struct net_device *dev); 493 struct net_device *dev);
482static irqreturn_t rhine_interrupt(int irq, void *dev_instance); 494static irqreturn_t rhine_interrupt(int irq, void *dev_instance);
483static void rhine_tx(struct net_device *dev); 495static void rhine_tx(struct net_device *dev);
484static int rhine_rx(struct net_device *dev, int limit); 496static int rhine_rx(struct net_device *dev, int limit);
485static void rhine_error(struct net_device *dev, int intr_status);
486static void rhine_set_rx_mode(struct net_device *dev); 497static void rhine_set_rx_mode(struct net_device *dev);
487static struct net_device_stats *rhine_get_stats(struct net_device *dev); 498static struct net_device_stats *rhine_get_stats(struct net_device *dev);
488static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 499static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
489static const struct ethtool_ops netdev_ethtool_ops; 500static const struct ethtool_ops netdev_ethtool_ops;
490static int rhine_close(struct net_device *dev); 501static int rhine_close(struct net_device *dev);
491static void rhine_shutdown (struct pci_dev *pdev);
492static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid); 502static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid);
493static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid); 503static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid);
494static void rhine_set_cam(void __iomem *ioaddr, int idx, u8 *addr); 504static void rhine_restart_tx(struct net_device *dev);
495static void rhine_set_vlan_cam(void __iomem *ioaddr, int idx, u8 *addr); 505
496static void rhine_set_cam_mask(void __iomem *ioaddr, u32 mask); 506static void rhine_wait_bit(struct rhine_private *rp, u8 reg, u8 mask, bool high)
497static void rhine_set_vlan_cam_mask(void __iomem *ioaddr, u32 mask); 507{
498static void rhine_init_cam_filter(struct net_device *dev); 508 void __iomem *ioaddr = rp->base;
499static void rhine_update_vcam(struct net_device *dev); 509 int i;
500 510
501#define RHINE_WAIT_FOR(condition) \ 511 for (i = 0; i < 1024; i++) {
502do { \ 512 if (high ^ !!(ioread8(ioaddr + reg) & mask))
503 int i = 1024; \ 513 break;
504 while (!(condition) && --i) \ 514 udelay(10);
505 ; \ 515 }
506 if (debug > 1 && i < 512) \ 516 if (i > 64) {
507 pr_info("%4d cycles used @ %s:%d\n", \ 517 netif_dbg(rp, hw, rp->dev, "%s bit wait (%02x/%02x) cycle "
508 1024 - i, __func__, __LINE__); \ 518 "count: %04d\n", high ? "high" : "low", reg, mask, i);
509} while (0) 519 }
510 520}
511static inline u32 get_intr_status(struct net_device *dev) 521
522static void rhine_wait_bit_high(struct rhine_private *rp, u8 reg, u8 mask)
523{
524 rhine_wait_bit(rp, reg, mask, true);
525}
526
527static void rhine_wait_bit_low(struct rhine_private *rp, u8 reg, u8 mask)
528{
529 rhine_wait_bit(rp, reg, mask, false);
530}
531
532static u32 rhine_get_events(struct rhine_private *rp)
512{ 533{
513 struct rhine_private *rp = netdev_priv(dev);
514 void __iomem *ioaddr = rp->base; 534 void __iomem *ioaddr = rp->base;
515 u32 intr_status; 535 u32 intr_status;
516 536
@@ -521,6 +541,16 @@ static inline u32 get_intr_status(struct net_device *dev)
521 return intr_status; 541 return intr_status;
522} 542}
523 543
544static void rhine_ack_events(struct rhine_private *rp, u32 mask)
545{
546 void __iomem *ioaddr = rp->base;
547
548 if (rp->quirks & rqStatusWBRace)
549 iowrite8(mask >> 16, ioaddr + IntrStatus2);
550 iowrite16(mask, ioaddr + IntrStatus);
551 mmiowb();
552}
553
524/* 554/*
525 * Get power related registers into sane state. 555 * Get power related registers into sane state.
526 * Notify user about past WOL event. 556 * Notify user about past WOL event.
@@ -585,6 +615,7 @@ static void rhine_chip_reset(struct net_device *dev)
585{ 615{
586 struct rhine_private *rp = netdev_priv(dev); 616 struct rhine_private *rp = netdev_priv(dev);
587 void __iomem *ioaddr = rp->base; 617 void __iomem *ioaddr = rp->base;
618 u8 cmd1;
588 619
589 iowrite8(Cmd1Reset, ioaddr + ChipCmd1); 620 iowrite8(Cmd1Reset, ioaddr + ChipCmd1);
590 IOSYNC; 621 IOSYNC;
@@ -597,13 +628,12 @@ static void rhine_chip_reset(struct net_device *dev)
597 iowrite8(0x40, ioaddr + MiscCmd); 628 iowrite8(0x40, ioaddr + MiscCmd);
598 629
599 /* Reset can take somewhat longer (rare) */ 630 /* Reset can take somewhat longer (rare) */
600 RHINE_WAIT_FOR(!(ioread8(ioaddr + ChipCmd1) & Cmd1Reset)); 631 rhine_wait_bit_low(rp, ChipCmd1, Cmd1Reset);
601 } 632 }
602 633
603 if (debug > 1) 634 cmd1 = ioread8(ioaddr + ChipCmd1);
604 netdev_info(dev, "Reset %s\n", 635 netif_info(rp, hw, dev, "Reset %s\n", (cmd1 & Cmd1Reset) ?
605 (ioread8(ioaddr + ChipCmd1) & Cmd1Reset) ? 636 "failed" : "succeeded");
606 "failed" : "succeeded");
607} 637}
608 638
609#ifdef USE_MMIO 639#ifdef USE_MMIO
@@ -629,9 +659,15 @@ static void __devinit rhine_reload_eeprom(long pioaddr, struct net_device *dev)
629{ 659{
630 struct rhine_private *rp = netdev_priv(dev); 660 struct rhine_private *rp = netdev_priv(dev);
631 void __iomem *ioaddr = rp->base; 661 void __iomem *ioaddr = rp->base;
662 int i;
632 663
633 outb(0x20, pioaddr + MACRegEEcsr); 664 outb(0x20, pioaddr + MACRegEEcsr);
634 RHINE_WAIT_FOR(!(inb(pioaddr + MACRegEEcsr) & 0x20)); 665 for (i = 0; i < 1024; i++) {
666 if (!(inb(pioaddr + MACRegEEcsr) & 0x20))
667 break;
668 }
669 if (i > 512)
670 pr_info("%4d cycles used @ %s:%d\n", i, __func__, __LINE__);
635 671
636#ifdef USE_MMIO 672#ifdef USE_MMIO
637 /* 673 /*
@@ -657,23 +693,127 @@ static void rhine_poll(struct net_device *dev)
657} 693}
658#endif 694#endif
659 695
696static void rhine_kick_tx_threshold(struct rhine_private *rp)
697{
698 if (rp->tx_thresh < 0xe0) {
699 void __iomem *ioaddr = rp->base;
700
701 rp->tx_thresh += 0x20;
702 BYTE_REG_BITS_SET(rp->tx_thresh, 0x80, ioaddr + TxConfig);
703 }
704}
705
706static void rhine_tx_err(struct rhine_private *rp, u32 status)
707{
708 struct net_device *dev = rp->dev;
709
710 if (status & IntrTxAborted) {
711 netif_info(rp, tx_err, dev,
712 "Abort %08x, frame dropped\n", status);
713 }
714
715 if (status & IntrTxUnderrun) {
716 rhine_kick_tx_threshold(rp);
717 netif_info(rp, tx_err ,dev, "Transmitter underrun, "
718 "Tx threshold now %02x\n", rp->tx_thresh);
719 }
720
721 if (status & IntrTxDescRace)
722 netif_info(rp, tx_err, dev, "Tx descriptor write-back race\n");
723
724 if ((status & IntrTxError) &&
725 (status & (IntrTxAborted | IntrTxUnderrun | IntrTxDescRace)) == 0) {
726 rhine_kick_tx_threshold(rp);
727 netif_info(rp, tx_err, dev, "Unspecified error. "
728 "Tx threshold now %02x\n", rp->tx_thresh);
729 }
730
731 rhine_restart_tx(dev);
732}
733
734static void rhine_update_rx_crc_and_missed_errord(struct rhine_private *rp)
735{
736 void __iomem *ioaddr = rp->base;
737 struct net_device_stats *stats = &rp->dev->stats;
738
739 stats->rx_crc_errors += ioread16(ioaddr + RxCRCErrs);
740 stats->rx_missed_errors += ioread16(ioaddr + RxMissed);
741
742 /*
743 * Clears the "tally counters" for CRC errors and missed frames(?).
744 * It has been reported that some chips need a write of 0 to clear
745 * these, for others the counters are set to 1 when written to and
746 * instead cleared when read. So we clear them both ways ...
747 */
748 iowrite32(0, ioaddr + RxMissed);
749 ioread16(ioaddr + RxCRCErrs);
750 ioread16(ioaddr + RxMissed);
751}
752
753#define RHINE_EVENT_NAPI_RX (IntrRxDone | \
754 IntrRxErr | \
755 IntrRxEmpty | \
756 IntrRxOverflow | \
757 IntrRxDropped | \
758 IntrRxNoBuf | \
759 IntrRxWakeUp)
760
761#define RHINE_EVENT_NAPI_TX_ERR (IntrTxError | \
762 IntrTxAborted | \
763 IntrTxUnderrun | \
764 IntrTxDescRace)
765#define RHINE_EVENT_NAPI_TX (IntrTxDone | RHINE_EVENT_NAPI_TX_ERR)
766
767#define RHINE_EVENT_NAPI (RHINE_EVENT_NAPI_RX | \
768 RHINE_EVENT_NAPI_TX | \
769 IntrStatsMax)
770#define RHINE_EVENT_SLOW (IntrPCIErr | IntrLinkChange)
771#define RHINE_EVENT (RHINE_EVENT_NAPI | RHINE_EVENT_SLOW)
772
660static int rhine_napipoll(struct napi_struct *napi, int budget) 773static int rhine_napipoll(struct napi_struct *napi, int budget)
661{ 774{
662 struct rhine_private *rp = container_of(napi, struct rhine_private, napi); 775 struct rhine_private *rp = container_of(napi, struct rhine_private, napi);
663 struct net_device *dev = rp->dev; 776 struct net_device *dev = rp->dev;
664 void __iomem *ioaddr = rp->base; 777 void __iomem *ioaddr = rp->base;
665 int work_done; 778 u16 enable_mask = RHINE_EVENT & 0xffff;
779 int work_done = 0;
780 u32 status;
781
782 status = rhine_get_events(rp);
783 rhine_ack_events(rp, status & ~RHINE_EVENT_SLOW);
784
785 if (status & RHINE_EVENT_NAPI_RX)
786 work_done += rhine_rx(dev, budget);
787
788 if (status & RHINE_EVENT_NAPI_TX) {
789 if (status & RHINE_EVENT_NAPI_TX_ERR) {
790 /* Avoid scavenging before Tx engine turned off */
791 rhine_wait_bit_low(rp, ChipCmd, CmdTxOn);
792 if (ioread8(ioaddr + ChipCmd) & CmdTxOn)
793 netif_warn(rp, tx_err, dev, "Tx still on\n");
794 }
666 795
667 work_done = rhine_rx(dev, budget); 796 rhine_tx(dev);
797
798 if (status & RHINE_EVENT_NAPI_TX_ERR)
799 rhine_tx_err(rp, status);
800 }
801
802 if (status & IntrStatsMax) {
803 spin_lock(&rp->lock);
804 rhine_update_rx_crc_and_missed_errord(rp);
805 spin_unlock(&rp->lock);
806 }
807
808 if (status & RHINE_EVENT_SLOW) {
809 enable_mask &= ~RHINE_EVENT_SLOW;
810 schedule_work(&rp->slow_event_task);
811 }
668 812
669 if (work_done < budget) { 813 if (work_done < budget) {
670 napi_complete(napi); 814 napi_complete(napi);
671 815 iowrite16(enable_mask, ioaddr + IntrEnable);
672 iowrite16(IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow | 816 mmiowb();
673 IntrRxDropped | IntrRxNoBuf | IntrTxAborted |
674 IntrTxDone | IntrTxError | IntrTxUnderrun |
675 IntrPCIErr | IntrStatsMax | IntrLinkChange,
676 ioaddr + IntrEnable);
677 } 817 }
678 return work_done; 818 return work_done;
679} 819}
@@ -797,6 +937,7 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
797 rp->quirks = quirks; 937 rp->quirks = quirks;
798 rp->pioaddr = pioaddr; 938 rp->pioaddr = pioaddr;
799 rp->pdev = pdev; 939 rp->pdev = pdev;
940 rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT);
800 941
801 rc = pci_request_regions(pdev, DRV_NAME); 942 rc = pci_request_regions(pdev, DRV_NAME);
802 if (rc) 943 if (rc)
@@ -856,7 +997,9 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
856 dev->irq = pdev->irq; 997 dev->irq = pdev->irq;
857 998
858 spin_lock_init(&rp->lock); 999 spin_lock_init(&rp->lock);
1000 mutex_init(&rp->task_lock);
859 INIT_WORK(&rp->reset_task, rhine_reset_task); 1001 INIT_WORK(&rp->reset_task, rhine_reset_task);
1002 INIT_WORK(&rp->slow_event_task, rhine_slow_event_task);
860 1003
861 rp->mii_if.dev = dev; 1004 rp->mii_if.dev = dev;
862 rp->mii_if.mdio_read = mdio_read; 1005 rp->mii_if.mdio_read = mdio_read;
@@ -916,8 +1059,8 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
916 } 1059 }
917 } 1060 }
918 rp->mii_if.phy_id = phy_id; 1061 rp->mii_if.phy_id = phy_id;
919 if (debug > 1 && avoid_D3) 1062 if (avoid_D3)
920 netdev_info(dev, "No D3 power state at shutdown\n"); 1063 netif_info(rp, probe, dev, "No D3 power state at shutdown\n");
921 1064
922 return 0; 1065 return 0;
923 1066
@@ -1093,7 +1236,7 @@ static void rhine_check_media(struct net_device *dev, unsigned int init_media)
1093 struct rhine_private *rp = netdev_priv(dev); 1236 struct rhine_private *rp = netdev_priv(dev);
1094 void __iomem *ioaddr = rp->base; 1237 void __iomem *ioaddr = rp->base;
1095 1238
1096 mii_check_media(&rp->mii_if, debug, init_media); 1239 mii_check_media(&rp->mii_if, netif_msg_link(rp), init_media);
1097 1240
1098 if (rp->mii_if.full_duplex) 1241 if (rp->mii_if.full_duplex)
1099 iowrite8(ioread8(ioaddr + ChipCmd1) | Cmd1FDuplex, 1242 iowrite8(ioread8(ioaddr + ChipCmd1) | Cmd1FDuplex,
@@ -1101,24 +1244,26 @@ static void rhine_check_media(struct net_device *dev, unsigned int init_media)
1101 else 1244 else
1102 iowrite8(ioread8(ioaddr + ChipCmd1) & ~Cmd1FDuplex, 1245 iowrite8(ioread8(ioaddr + ChipCmd1) & ~Cmd1FDuplex,
1103 ioaddr + ChipCmd1); 1246 ioaddr + ChipCmd1);
1104 if (debug > 1) 1247
1105 netdev_info(dev, "force_media %d, carrier %d\n", 1248 netif_info(rp, link, dev, "force_media %d, carrier %d\n",
1106 rp->mii_if.force_media, netif_carrier_ok(dev)); 1249 rp->mii_if.force_media, netif_carrier_ok(dev));
1107} 1250}
1108 1251
1109/* Called after status of force_media possibly changed */ 1252/* Called after status of force_media possibly changed */
1110static void rhine_set_carrier(struct mii_if_info *mii) 1253static void rhine_set_carrier(struct mii_if_info *mii)
1111{ 1254{
1255 struct net_device *dev = mii->dev;
1256 struct rhine_private *rp = netdev_priv(dev);
1257
1112 if (mii->force_media) { 1258 if (mii->force_media) {
1113 /* autoneg is off: Link is always assumed to be up */ 1259 /* autoneg is off: Link is always assumed to be up */
1114 if (!netif_carrier_ok(mii->dev)) 1260 if (!netif_carrier_ok(dev))
1115 netif_carrier_on(mii->dev); 1261 netif_carrier_on(dev);
1116 } 1262 } else /* Let MMI library update carrier status */
1117 else /* Let MMI library update carrier status */ 1263 rhine_check_media(dev, 0);
1118 rhine_check_media(mii->dev, 0); 1264
1119 if (debug > 1) 1265 netif_info(rp, link, dev, "force_media %d, carrier %d\n",
1120 netdev_info(mii->dev, "force_media %d, carrier %d\n", 1266 mii->force_media, netif_carrier_ok(dev));
1121 mii->force_media, netif_carrier_ok(mii->dev));
1122} 1267}
1123 1268
1124/** 1269/**
@@ -1266,10 +1411,10 @@ static int rhine_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1266{ 1411{
1267 struct rhine_private *rp = netdev_priv(dev); 1412 struct rhine_private *rp = netdev_priv(dev);
1268 1413
1269 spin_lock_irq(&rp->lock); 1414 spin_lock_bh(&rp->lock);
1270 set_bit(vid, rp->active_vlans); 1415 set_bit(vid, rp->active_vlans);
1271 rhine_update_vcam(dev); 1416 rhine_update_vcam(dev);
1272 spin_unlock_irq(&rp->lock); 1417 spin_unlock_bh(&rp->lock);
1273 return 0; 1418 return 0;
1274} 1419}
1275 1420
@@ -1277,10 +1422,10 @@ static int rhine_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1277{ 1422{
1278 struct rhine_private *rp = netdev_priv(dev); 1423 struct rhine_private *rp = netdev_priv(dev);
1279 1424
1280 spin_lock_irq(&rp->lock); 1425 spin_lock_bh(&rp->lock);
1281 clear_bit(vid, rp->active_vlans); 1426 clear_bit(vid, rp->active_vlans);
1282 rhine_update_vcam(dev); 1427 rhine_update_vcam(dev);
1283 spin_unlock_irq(&rp->lock); 1428 spin_unlock_bh(&rp->lock);
1284 return 0; 1429 return 0;
1285} 1430}
1286 1431
@@ -1310,12 +1455,7 @@ static void init_registers(struct net_device *dev)
1310 1455
1311 napi_enable(&rp->napi); 1456 napi_enable(&rp->napi);
1312 1457
1313 /* Enable interrupts by setting the interrupt mask. */ 1458 iowrite16(RHINE_EVENT & 0xffff, ioaddr + IntrEnable);
1314 iowrite16(IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow |
1315 IntrRxDropped | IntrRxNoBuf | IntrTxAborted |
1316 IntrTxDone | IntrTxError | IntrTxUnderrun |
1317 IntrPCIErr | IntrStatsMax | IntrLinkChange,
1318 ioaddr + IntrEnable);
1319 1459
1320 iowrite16(CmdStart | CmdTxOn | CmdRxOn | (Cmd1NoTxPoll << 8), 1460 iowrite16(CmdStart | CmdTxOn | CmdRxOn | (Cmd1NoTxPoll << 8),
1321 ioaddr + ChipCmd); 1461 ioaddr + ChipCmd);
@@ -1323,23 +1463,27 @@ static void init_registers(struct net_device *dev)
1323} 1463}
1324 1464
1325/* Enable MII link status auto-polling (required for IntrLinkChange) */ 1465/* Enable MII link status auto-polling (required for IntrLinkChange) */
1326static void rhine_enable_linkmon(void __iomem *ioaddr) 1466static void rhine_enable_linkmon(struct rhine_private *rp)
1327{ 1467{
1468 void __iomem *ioaddr = rp->base;
1469
1328 iowrite8(0, ioaddr + MIICmd); 1470 iowrite8(0, ioaddr + MIICmd);
1329 iowrite8(MII_BMSR, ioaddr + MIIRegAddr); 1471 iowrite8(MII_BMSR, ioaddr + MIIRegAddr);
1330 iowrite8(0x80, ioaddr + MIICmd); 1472 iowrite8(0x80, ioaddr + MIICmd);
1331 1473
1332 RHINE_WAIT_FOR((ioread8(ioaddr + MIIRegAddr) & 0x20)); 1474 rhine_wait_bit_high(rp, MIIRegAddr, 0x20);
1333 1475
1334 iowrite8(MII_BMSR | 0x40, ioaddr + MIIRegAddr); 1476 iowrite8(MII_BMSR | 0x40, ioaddr + MIIRegAddr);
1335} 1477}
1336 1478
1337/* Disable MII link status auto-polling (required for MDIO access) */ 1479/* Disable MII link status auto-polling (required for MDIO access) */
1338static void rhine_disable_linkmon(void __iomem *ioaddr, u32 quirks) 1480static void rhine_disable_linkmon(struct rhine_private *rp)
1339{ 1481{
1482 void __iomem *ioaddr = rp->base;
1483
1340 iowrite8(0, ioaddr + MIICmd); 1484 iowrite8(0, ioaddr + MIICmd);
1341 1485
1342 if (quirks & rqRhineI) { 1486 if (rp->quirks & rqRhineI) {
1343 iowrite8(0x01, ioaddr + MIIRegAddr); // MII_BMSR 1487 iowrite8(0x01, ioaddr + MIIRegAddr); // MII_BMSR
1344 1488
1345 /* Can be called from ISR. Evil. */ 1489 /* Can be called from ISR. Evil. */
@@ -1348,13 +1492,13 @@ static void rhine_disable_linkmon(void __iomem *ioaddr, u32 quirks)
1348 /* 0x80 must be set immediately before turning it off */ 1492 /* 0x80 must be set immediately before turning it off */
1349 iowrite8(0x80, ioaddr + MIICmd); 1493 iowrite8(0x80, ioaddr + MIICmd);
1350 1494
1351 RHINE_WAIT_FOR(ioread8(ioaddr + MIIRegAddr) & 0x20); 1495 rhine_wait_bit_high(rp, MIIRegAddr, 0x20);
1352 1496
1353 /* Heh. Now clear 0x80 again. */ 1497 /* Heh. Now clear 0x80 again. */
1354 iowrite8(0, ioaddr + MIICmd); 1498 iowrite8(0, ioaddr + MIICmd);
1355 } 1499 }
1356 else 1500 else
1357 RHINE_WAIT_FOR(ioread8(ioaddr + MIIRegAddr) & 0x80); 1501 rhine_wait_bit_high(rp, MIIRegAddr, 0x80);
1358} 1502}
1359 1503
1360/* Read and write over the MII Management Data I/O (MDIO) interface. */ 1504/* Read and write over the MII Management Data I/O (MDIO) interface. */
@@ -1365,16 +1509,16 @@ static int mdio_read(struct net_device *dev, int phy_id, int regnum)
1365 void __iomem *ioaddr = rp->base; 1509 void __iomem *ioaddr = rp->base;
1366 int result; 1510 int result;
1367 1511
1368 rhine_disable_linkmon(ioaddr, rp->quirks); 1512 rhine_disable_linkmon(rp);
1369 1513
1370 /* rhine_disable_linkmon already cleared MIICmd */ 1514 /* rhine_disable_linkmon already cleared MIICmd */
1371 iowrite8(phy_id, ioaddr + MIIPhyAddr); 1515 iowrite8(phy_id, ioaddr + MIIPhyAddr);
1372 iowrite8(regnum, ioaddr + MIIRegAddr); 1516 iowrite8(regnum, ioaddr + MIIRegAddr);
1373 iowrite8(0x40, ioaddr + MIICmd); /* Trigger read */ 1517 iowrite8(0x40, ioaddr + MIICmd); /* Trigger read */
1374 RHINE_WAIT_FOR(!(ioread8(ioaddr + MIICmd) & 0x40)); 1518 rhine_wait_bit_low(rp, MIICmd, 0x40);
1375 result = ioread16(ioaddr + MIIData); 1519 result = ioread16(ioaddr + MIIData);
1376 1520
1377 rhine_enable_linkmon(ioaddr); 1521 rhine_enable_linkmon(rp);
1378 return result; 1522 return result;
1379} 1523}
1380 1524
@@ -1383,16 +1527,33 @@ static void mdio_write(struct net_device *dev, int phy_id, int regnum, int value
1383 struct rhine_private *rp = netdev_priv(dev); 1527 struct rhine_private *rp = netdev_priv(dev);
1384 void __iomem *ioaddr = rp->base; 1528 void __iomem *ioaddr = rp->base;
1385 1529
1386 rhine_disable_linkmon(ioaddr, rp->quirks); 1530 rhine_disable_linkmon(rp);
1387 1531
1388 /* rhine_disable_linkmon already cleared MIICmd */ 1532 /* rhine_disable_linkmon already cleared MIICmd */
1389 iowrite8(phy_id, ioaddr + MIIPhyAddr); 1533 iowrite8(phy_id, ioaddr + MIIPhyAddr);
1390 iowrite8(regnum, ioaddr + MIIRegAddr); 1534 iowrite8(regnum, ioaddr + MIIRegAddr);
1391 iowrite16(value, ioaddr + MIIData); 1535 iowrite16(value, ioaddr + MIIData);
1392 iowrite8(0x20, ioaddr + MIICmd); /* Trigger write */ 1536 iowrite8(0x20, ioaddr + MIICmd); /* Trigger write */
1393 RHINE_WAIT_FOR(!(ioread8(ioaddr + MIICmd) & 0x20)); 1537 rhine_wait_bit_low(rp, MIICmd, 0x20);
1394 1538
1395 rhine_enable_linkmon(ioaddr); 1539 rhine_enable_linkmon(rp);
1540}
1541
1542static void rhine_task_disable(struct rhine_private *rp)
1543{
1544 mutex_lock(&rp->task_lock);
1545 rp->task_enable = false;
1546 mutex_unlock(&rp->task_lock);
1547
1548 cancel_work_sync(&rp->slow_event_task);
1549 cancel_work_sync(&rp->reset_task);
1550}
1551
1552static void rhine_task_enable(struct rhine_private *rp)
1553{
1554 mutex_lock(&rp->task_lock);
1555 rp->task_enable = true;
1556 mutex_unlock(&rp->task_lock);
1396} 1557}
1397 1558
1398static int rhine_open(struct net_device *dev) 1559static int rhine_open(struct net_device *dev)
@@ -1406,8 +1567,7 @@ static int rhine_open(struct net_device *dev)
1406 if (rc) 1567 if (rc)
1407 return rc; 1568 return rc;
1408 1569
1409 if (debug > 1) 1570 netif_dbg(rp, ifup, dev, "%s() irq %d\n", __func__, rp->pdev->irq);
1410 netdev_dbg(dev, "%s() irq %d\n", __func__, rp->pdev->irq);
1411 1571
1412 rc = alloc_ring(dev); 1572 rc = alloc_ring(dev);
1413 if (rc) { 1573 if (rc) {
@@ -1417,11 +1577,12 @@ static int rhine_open(struct net_device *dev)
1417 alloc_rbufs(dev); 1577 alloc_rbufs(dev);
1418 alloc_tbufs(dev); 1578 alloc_tbufs(dev);
1419 rhine_chip_reset(dev); 1579 rhine_chip_reset(dev);
1580 rhine_task_enable(rp);
1420 init_registers(dev); 1581 init_registers(dev);
1421 if (debug > 2) 1582
1422 netdev_dbg(dev, "%s() Done - status %04x MII status: %04x\n", 1583 netif_dbg(rp, ifup, dev, "%s() Done - status %04x MII status: %04x\n",
1423 __func__, ioread16(ioaddr + ChipCmd), 1584 __func__, ioread16(ioaddr + ChipCmd),
1424 mdio_read(dev, rp->mii_if.phy_id, MII_BMSR)); 1585 mdio_read(dev, rp->mii_if.phy_id, MII_BMSR));
1425 1586
1426 netif_start_queue(dev); 1587 netif_start_queue(dev);
1427 1588
@@ -1434,11 +1595,12 @@ static void rhine_reset_task(struct work_struct *work)
1434 reset_task); 1595 reset_task);
1435 struct net_device *dev = rp->dev; 1596 struct net_device *dev = rp->dev;
1436 1597
1437 /* protect against concurrent rx interrupts */ 1598 mutex_lock(&rp->task_lock);
1438 disable_irq(rp->pdev->irq);
1439 1599
1440 napi_disable(&rp->napi); 1600 if (!rp->task_enable)
1601 goto out_unlock;
1441 1602
1603 napi_disable(&rp->napi);
1442 spin_lock_bh(&rp->lock); 1604 spin_lock_bh(&rp->lock);
1443 1605
1444 /* clear all descriptors */ 1606 /* clear all descriptors */
@@ -1452,11 +1614,13 @@ static void rhine_reset_task(struct work_struct *work)
1452 init_registers(dev); 1614 init_registers(dev);
1453 1615
1454 spin_unlock_bh(&rp->lock); 1616 spin_unlock_bh(&rp->lock);
1455 enable_irq(rp->pdev->irq);
1456 1617
1457 dev->trans_start = jiffies; /* prevent tx timeout */ 1618 dev->trans_start = jiffies; /* prevent tx timeout */
1458 dev->stats.tx_errors++; 1619 dev->stats.tx_errors++;
1459 netif_wake_queue(dev); 1620 netif_wake_queue(dev);
1621
1622out_unlock:
1623 mutex_unlock(&rp->task_lock);
1460} 1624}
1461 1625
1462static void rhine_tx_timeout(struct net_device *dev) 1626static void rhine_tx_timeout(struct net_device *dev)
@@ -1477,7 +1641,6 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
1477 struct rhine_private *rp = netdev_priv(dev); 1641 struct rhine_private *rp = netdev_priv(dev);
1478 void __iomem *ioaddr = rp->base; 1642 void __iomem *ioaddr = rp->base;
1479 unsigned entry; 1643 unsigned entry;
1480 unsigned long flags;
1481 1644
1482 /* Caution: the write order is important here, set the field 1645 /* Caution: the write order is important here, set the field
1483 with the "ownership" bits last. */ 1646 with the "ownership" bits last. */
@@ -1529,7 +1692,6 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
1529 rp->tx_ring[entry].tx_status = 0; 1692 rp->tx_ring[entry].tx_status = 0;
1530 1693
1531 /* lock eth irq */ 1694 /* lock eth irq */
1532 spin_lock_irqsave(&rp->lock, flags);
1533 wmb(); 1695 wmb();
1534 rp->tx_ring[entry].tx_status |= cpu_to_le32(DescOwn); 1696 rp->tx_ring[entry].tx_status |= cpu_to_le32(DescOwn);
1535 wmb(); 1697 wmb();
@@ -1550,78 +1712,43 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
1550 if (rp->cur_tx == rp->dirty_tx + TX_QUEUE_LEN) 1712 if (rp->cur_tx == rp->dirty_tx + TX_QUEUE_LEN)
1551 netif_stop_queue(dev); 1713 netif_stop_queue(dev);
1552 1714
1553 spin_unlock_irqrestore(&rp->lock, flags); 1715 netif_dbg(rp, tx_queued, dev, "Transmit frame #%d queued in slot %d\n",
1716 rp->cur_tx - 1, entry);
1554 1717
1555 if (debug > 4) {
1556 netdev_dbg(dev, "Transmit frame #%d queued in slot %d\n",
1557 rp->cur_tx-1, entry);
1558 }
1559 return NETDEV_TX_OK; 1718 return NETDEV_TX_OK;
1560} 1719}
1561 1720
1721static void rhine_irq_disable(struct rhine_private *rp)
1722{
1723 iowrite16(0x0000, rp->base + IntrEnable);
1724 mmiowb();
1725}
1726
1562/* The interrupt handler does all of the Rx thread work and cleans up 1727/* The interrupt handler does all of the Rx thread work and cleans up
1563 after the Tx thread. */ 1728 after the Tx thread. */
1564static irqreturn_t rhine_interrupt(int irq, void *dev_instance) 1729static irqreturn_t rhine_interrupt(int irq, void *dev_instance)
1565{ 1730{
1566 struct net_device *dev = dev_instance; 1731 struct net_device *dev = dev_instance;
1567 struct rhine_private *rp = netdev_priv(dev); 1732 struct rhine_private *rp = netdev_priv(dev);
1568 void __iomem *ioaddr = rp->base; 1733 u32 status;
1569 u32 intr_status;
1570 int boguscnt = max_interrupt_work;
1571 int handled = 0; 1734 int handled = 0;
1572 1735
1573 while ((intr_status = get_intr_status(dev))) { 1736 status = rhine_get_events(rp);
1574 handled = 1;
1575
1576 /* Acknowledge all of the current interrupt sources ASAP. */
1577 if (intr_status & IntrTxDescRace)
1578 iowrite8(0x08, ioaddr + IntrStatus2);
1579 iowrite16(intr_status & 0xffff, ioaddr + IntrStatus);
1580 IOSYNC;
1581 1737
1582 if (debug > 4) 1738 netif_dbg(rp, intr, dev, "Interrupt, status %08x\n", status);
1583 netdev_dbg(dev, "Interrupt, status %08x\n",
1584 intr_status);
1585
1586 if (intr_status & (IntrRxDone | IntrRxErr | IntrRxDropped |
1587 IntrRxWakeUp | IntrRxEmpty | IntrRxNoBuf)) {
1588 iowrite16(IntrTxAborted |
1589 IntrTxDone | IntrTxError | IntrTxUnderrun |
1590 IntrPCIErr | IntrStatsMax | IntrLinkChange,
1591 ioaddr + IntrEnable);
1592
1593 napi_schedule(&rp->napi);
1594 }
1595 1739
1596 if (intr_status & (IntrTxErrSummary | IntrTxDone)) { 1740 if (status & RHINE_EVENT) {
1597 if (intr_status & IntrTxErrSummary) { 1741 handled = 1;
1598 /* Avoid scavenging before Tx engine turned off */
1599 RHINE_WAIT_FOR(!(ioread8(ioaddr+ChipCmd) & CmdTxOn));
1600 if (debug > 2 &&
1601 ioread8(ioaddr+ChipCmd) & CmdTxOn)
1602 netdev_warn(dev,
1603 "%s: Tx engine still on\n",
1604 __func__);
1605 }
1606 rhine_tx(dev);
1607 }
1608 1742
1609 /* Abnormal error summary/uncommon events handlers. */ 1743 rhine_irq_disable(rp);
1610 if (intr_status & (IntrPCIErr | IntrLinkChange | 1744 napi_schedule(&rp->napi);
1611 IntrStatsMax | IntrTxError | IntrTxAborted | 1745 }
1612 IntrTxUnderrun | IntrTxDescRace))
1613 rhine_error(dev, intr_status);
1614 1746
1615 if (--boguscnt < 0) { 1747 if (status & ~(IntrLinkChange | IntrStatsMax | RHINE_EVENT_NAPI)) {
1616 netdev_warn(dev, "Too much work at interrupt, status=%#08x\n", 1748 netif_err(rp, intr, dev, "Something Wicked happened! %08x\n",
1617 intr_status); 1749 status);
1618 break;
1619 }
1620 } 1750 }
1621 1751
1622 if (debug > 3)
1623 netdev_dbg(dev, "exiting interrupt, status=%08x\n",
1624 ioread16(ioaddr + IntrStatus));
1625 return IRQ_RETVAL(handled); 1752 return IRQ_RETVAL(handled);
1626} 1753}
1627 1754
@@ -1632,20 +1759,16 @@ static void rhine_tx(struct net_device *dev)
1632 struct rhine_private *rp = netdev_priv(dev); 1759 struct rhine_private *rp = netdev_priv(dev);
1633 int txstatus = 0, entry = rp->dirty_tx % TX_RING_SIZE; 1760 int txstatus = 0, entry = rp->dirty_tx % TX_RING_SIZE;
1634 1761
1635 spin_lock(&rp->lock);
1636
1637 /* find and cleanup dirty tx descriptors */ 1762 /* find and cleanup dirty tx descriptors */
1638 while (rp->dirty_tx != rp->cur_tx) { 1763 while (rp->dirty_tx != rp->cur_tx) {
1639 txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status); 1764 txstatus = le32_to_cpu(rp->tx_ring[entry].tx_status);
1640 if (debug > 6) 1765 netif_dbg(rp, tx_done, dev, "Tx scavenge %d status %08x\n",
1641 netdev_dbg(dev, "Tx scavenge %d status %08x\n", 1766 entry, txstatus);
1642 entry, txstatus);
1643 if (txstatus & DescOwn) 1767 if (txstatus & DescOwn)
1644 break; 1768 break;
1645 if (txstatus & 0x8000) { 1769 if (txstatus & 0x8000) {
1646 if (debug > 1) 1770 netif_dbg(rp, tx_done, dev,
1647 netdev_dbg(dev, "Transmit error, Tx status %08x\n", 1771 "Transmit error, Tx status %08x\n", txstatus);
1648 txstatus);
1649 dev->stats.tx_errors++; 1772 dev->stats.tx_errors++;
1650 if (txstatus & 0x0400) 1773 if (txstatus & 0x0400)
1651 dev->stats.tx_carrier_errors++; 1774 dev->stats.tx_carrier_errors++;
@@ -1667,10 +1790,8 @@ static void rhine_tx(struct net_device *dev)
1667 dev->stats.collisions += (txstatus >> 3) & 0x0F; 1790 dev->stats.collisions += (txstatus >> 3) & 0x0F;
1668 else 1791 else
1669 dev->stats.collisions += txstatus & 0x0F; 1792 dev->stats.collisions += txstatus & 0x0F;
1670 if (debug > 6) 1793 netif_dbg(rp, tx_done, dev, "collisions: %1.1x:%1.1x\n",
1671 netdev_dbg(dev, "collisions: %1.1x:%1.1x\n", 1794 (txstatus >> 3) & 0xF, txstatus & 0xF);
1672 (txstatus >> 3) & 0xF,
1673 txstatus & 0xF);
1674 dev->stats.tx_bytes += rp->tx_skbuff[entry]->len; 1795 dev->stats.tx_bytes += rp->tx_skbuff[entry]->len;
1675 dev->stats.tx_packets++; 1796 dev->stats.tx_packets++;
1676 } 1797 }
@@ -1687,8 +1808,6 @@ static void rhine_tx(struct net_device *dev)
1687 } 1808 }
1688 if ((rp->cur_tx - rp->dirty_tx) < TX_QUEUE_LEN - 4) 1809 if ((rp->cur_tx - rp->dirty_tx) < TX_QUEUE_LEN - 4)
1689 netif_wake_queue(dev); 1810 netif_wake_queue(dev);
1690
1691 spin_unlock(&rp->lock);
1692} 1811}
1693 1812
1694/** 1813/**
@@ -1713,11 +1832,8 @@ static int rhine_rx(struct net_device *dev, int limit)
1713 int count; 1832 int count;
1714 int entry = rp->cur_rx % RX_RING_SIZE; 1833 int entry = rp->cur_rx % RX_RING_SIZE;
1715 1834
1716 if (debug > 4) { 1835 netif_dbg(rp, rx_status, dev, "%s(), entry %d status %08x\n", __func__,
1717 netdev_dbg(dev, "%s(), entry %d status %08x\n", 1836 entry, le32_to_cpu(rp->rx_head_desc->rx_status));
1718 __func__, entry,
1719 le32_to_cpu(rp->rx_head_desc->rx_status));
1720 }
1721 1837
1722 /* If EOP is set on the next entry, it's a new packet. Send it up. */ 1838 /* If EOP is set on the next entry, it's a new packet. Send it up. */
1723 for (count = 0; count < limit; ++count) { 1839 for (count = 0; count < limit; ++count) {
@@ -1729,9 +1845,8 @@ static int rhine_rx(struct net_device *dev, int limit)
1729 if (desc_status & DescOwn) 1845 if (desc_status & DescOwn)
1730 break; 1846 break;
1731 1847
1732 if (debug > 4) 1848 netif_dbg(rp, rx_status, dev, "%s() status %08x\n", __func__,
1733 netdev_dbg(dev, "%s() status is %08x\n", 1849 desc_status);
1734 __func__, desc_status);
1735 1850
1736 if ((desc_status & (RxWholePkt | RxErr)) != RxWholePkt) { 1851 if ((desc_status & (RxWholePkt | RxErr)) != RxWholePkt) {
1737 if ((desc_status & RxWholePkt) != RxWholePkt) { 1852 if ((desc_status & RxWholePkt) != RxWholePkt) {
@@ -1747,9 +1862,9 @@ static int rhine_rx(struct net_device *dev, int limit)
1747 dev->stats.rx_length_errors++; 1862 dev->stats.rx_length_errors++;
1748 } else if (desc_status & RxErr) { 1863 } else if (desc_status & RxErr) {
1749 /* There was a error. */ 1864 /* There was a error. */
1750 if (debug > 2) 1865 netif_dbg(rp, rx_err, dev,
1751 netdev_dbg(dev, "%s() Rx error was %08x\n", 1866 "%s() Rx error %08x\n", __func__,
1752 __func__, desc_status); 1867 desc_status);
1753 dev->stats.rx_errors++; 1868 dev->stats.rx_errors++;
1754 if (desc_status & 0x0030) 1869 if (desc_status & 0x0030)
1755 dev->stats.rx_length_errors++; 1870 dev->stats.rx_length_errors++;
@@ -1839,19 +1954,6 @@ static int rhine_rx(struct net_device *dev, int limit)
1839 return count; 1954 return count;
1840} 1955}
1841 1956
1842/*
1843 * Clears the "tally counters" for CRC errors and missed frames(?).
1844 * It has been reported that some chips need a write of 0 to clear
1845 * these, for others the counters are set to 1 when written to and
1846 * instead cleared when read. So we clear them both ways ...
1847 */
1848static inline void clear_tally_counters(void __iomem *ioaddr)
1849{
1850 iowrite32(0, ioaddr + RxMissed);
1851 ioread16(ioaddr + RxCRCErrs);
1852 ioread16(ioaddr + RxMissed);
1853}
1854
1855static void rhine_restart_tx(struct net_device *dev) { 1957static void rhine_restart_tx(struct net_device *dev) {
1856 struct rhine_private *rp = netdev_priv(dev); 1958 struct rhine_private *rp = netdev_priv(dev);
1857 void __iomem *ioaddr = rp->base; 1959 void __iomem *ioaddr = rp->base;
@@ -1862,7 +1964,7 @@ static void rhine_restart_tx(struct net_device *dev) {
1862 * If new errors occurred, we need to sort them out before doing Tx. 1964 * If new errors occurred, we need to sort them out before doing Tx.
1863 * In that case the ISR will be back here RSN anyway. 1965 * In that case the ISR will be back here RSN anyway.
1864 */ 1966 */
1865 intr_status = get_intr_status(dev); 1967 intr_status = rhine_get_events(rp);
1866 1968
1867 if ((intr_status & IntrTxErrSummary) == 0) { 1969 if ((intr_status & IntrTxErrSummary) == 0) {
1868 1970
@@ -1883,79 +1985,50 @@ static void rhine_restart_tx(struct net_device *dev) {
1883 } 1985 }
1884 else { 1986 else {
1885 /* This should never happen */ 1987 /* This should never happen */
1886 if (debug > 1) 1988 netif_warn(rp, tx_err, dev, "another error occurred %08x\n",
1887 netdev_warn(dev, "%s() Another error occurred %08x\n", 1989 intr_status);
1888 __func__, intr_status);
1889 } 1990 }
1890 1991
1891} 1992}
1892 1993
1893static void rhine_error(struct net_device *dev, int intr_status) 1994static void rhine_slow_event_task(struct work_struct *work)
1894{ 1995{
1895 struct rhine_private *rp = netdev_priv(dev); 1996 struct rhine_private *rp =
1896 void __iomem *ioaddr = rp->base; 1997 container_of(work, struct rhine_private, slow_event_task);
1998 struct net_device *dev = rp->dev;
1999 u32 intr_status;
1897 2000
1898 spin_lock(&rp->lock); 2001 mutex_lock(&rp->task_lock);
2002
2003 if (!rp->task_enable)
2004 goto out_unlock;
2005
2006 intr_status = rhine_get_events(rp);
2007 rhine_ack_events(rp, intr_status & RHINE_EVENT_SLOW);
1899 2008
1900 if (intr_status & IntrLinkChange) 2009 if (intr_status & IntrLinkChange)
1901 rhine_check_media(dev, 0); 2010 rhine_check_media(dev, 0);
1902 if (intr_status & IntrStatsMax) {
1903 dev->stats.rx_crc_errors += ioread16(ioaddr + RxCRCErrs);
1904 dev->stats.rx_missed_errors += ioread16(ioaddr + RxMissed);
1905 clear_tally_counters(ioaddr);
1906 }
1907 if (intr_status & IntrTxAborted) {
1908 if (debug > 1)
1909 netdev_info(dev, "Abort %08x, frame dropped\n",
1910 intr_status);
1911 }
1912 if (intr_status & IntrTxUnderrun) {
1913 if (rp->tx_thresh < 0xE0)
1914 BYTE_REG_BITS_SET((rp->tx_thresh += 0x20), 0x80, ioaddr + TxConfig);
1915 if (debug > 1)
1916 netdev_info(dev, "Transmitter underrun, Tx threshold now %02x\n",
1917 rp->tx_thresh);
1918 }
1919 if (intr_status & IntrTxDescRace) {
1920 if (debug > 2)
1921 netdev_info(dev, "Tx descriptor write-back race\n");
1922 }
1923 if ((intr_status & IntrTxError) &&
1924 (intr_status & (IntrTxAborted |
1925 IntrTxUnderrun | IntrTxDescRace)) == 0) {
1926 if (rp->tx_thresh < 0xE0) {
1927 BYTE_REG_BITS_SET((rp->tx_thresh += 0x20), 0x80, ioaddr + TxConfig);
1928 }
1929 if (debug > 1)
1930 netdev_info(dev, "Unspecified error. Tx threshold now %02x\n",
1931 rp->tx_thresh);
1932 }
1933 if (intr_status & (IntrTxAborted | IntrTxUnderrun | IntrTxDescRace |
1934 IntrTxError))
1935 rhine_restart_tx(dev);
1936
1937 if (intr_status & ~(IntrLinkChange | IntrStatsMax | IntrTxUnderrun |
1938 IntrTxError | IntrTxAborted | IntrNormalSummary |
1939 IntrTxDescRace)) {
1940 if (debug > 1)
1941 netdev_err(dev, "Something Wicked happened! %08x\n",
1942 intr_status);
1943 }
1944 2011
1945 spin_unlock(&rp->lock); 2012 if (intr_status & IntrPCIErr)
2013 netif_warn(rp, hw, dev, "PCI error\n");
2014
2015 napi_disable(&rp->napi);
2016 rhine_irq_disable(rp);
2017 /* Slow and safe. Consider __napi_schedule as a replacement ? */
2018 napi_enable(&rp->napi);
2019 napi_schedule(&rp->napi);
2020
2021out_unlock:
2022 mutex_unlock(&rp->task_lock);
1946} 2023}
1947 2024
1948static struct net_device_stats *rhine_get_stats(struct net_device *dev) 2025static struct net_device_stats *rhine_get_stats(struct net_device *dev)
1949{ 2026{
1950 struct rhine_private *rp = netdev_priv(dev); 2027 struct rhine_private *rp = netdev_priv(dev);
1951 void __iomem *ioaddr = rp->base;
1952 unsigned long flags;
1953 2028
1954 spin_lock_irqsave(&rp->lock, flags); 2029 spin_lock_bh(&rp->lock);
1955 dev->stats.rx_crc_errors += ioread16(ioaddr + RxCRCErrs); 2030 rhine_update_rx_crc_and_missed_errord(rp);
1956 dev->stats.rx_missed_errors += ioread16(ioaddr + RxMissed); 2031 spin_unlock_bh(&rp->lock);
1957 clear_tally_counters(ioaddr);
1958 spin_unlock_irqrestore(&rp->lock, flags);
1959 2032
1960 return &dev->stats; 2033 return &dev->stats;
1961} 2034}
@@ -2022,9 +2095,9 @@ static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2022 struct rhine_private *rp = netdev_priv(dev); 2095 struct rhine_private *rp = netdev_priv(dev);
2023 int rc; 2096 int rc;
2024 2097
2025 spin_lock_irq(&rp->lock); 2098 mutex_lock(&rp->task_lock);
2026 rc = mii_ethtool_gset(&rp->mii_if, cmd); 2099 rc = mii_ethtool_gset(&rp->mii_if, cmd);
2027 spin_unlock_irq(&rp->lock); 2100 mutex_unlock(&rp->task_lock);
2028 2101
2029 return rc; 2102 return rc;
2030} 2103}
@@ -2034,10 +2107,10 @@ static int netdev_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
2034 struct rhine_private *rp = netdev_priv(dev); 2107 struct rhine_private *rp = netdev_priv(dev);
2035 int rc; 2108 int rc;
2036 2109
2037 spin_lock_irq(&rp->lock); 2110 mutex_lock(&rp->task_lock);
2038 rc = mii_ethtool_sset(&rp->mii_if, cmd); 2111 rc = mii_ethtool_sset(&rp->mii_if, cmd);
2039 spin_unlock_irq(&rp->lock);
2040 rhine_set_carrier(&rp->mii_if); 2112 rhine_set_carrier(&rp->mii_if);
2113 mutex_unlock(&rp->task_lock);
2041 2114
2042 return rc; 2115 return rc;
2043} 2116}
@@ -2058,12 +2131,16 @@ static u32 netdev_get_link(struct net_device *dev)
2058 2131
2059static u32 netdev_get_msglevel(struct net_device *dev) 2132static u32 netdev_get_msglevel(struct net_device *dev)
2060{ 2133{
2061 return debug; 2134 struct rhine_private *rp = netdev_priv(dev);
2135
2136 return rp->msg_enable;
2062} 2137}
2063 2138
2064static void netdev_set_msglevel(struct net_device *dev, u32 value) 2139static void netdev_set_msglevel(struct net_device *dev, u32 value)
2065{ 2140{
2066 debug = value; 2141 struct rhine_private *rp = netdev_priv(dev);
2142
2143 rp->msg_enable = value;
2067} 2144}
2068 2145
2069static void rhine_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2146static void rhine_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
@@ -2119,10 +2196,10 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2119 if (!netif_running(dev)) 2196 if (!netif_running(dev))
2120 return -EINVAL; 2197 return -EINVAL;
2121 2198
2122 spin_lock_irq(&rp->lock); 2199 mutex_lock(&rp->task_lock);
2123 rc = generic_mii_ioctl(&rp->mii_if, if_mii(rq), cmd, NULL); 2200 rc = generic_mii_ioctl(&rp->mii_if, if_mii(rq), cmd, NULL);
2124 spin_unlock_irq(&rp->lock);
2125 rhine_set_carrier(&rp->mii_if); 2201 rhine_set_carrier(&rp->mii_if);
2202 mutex_unlock(&rp->task_lock);
2126 2203
2127 return rc; 2204 return rc;
2128} 2205}
@@ -2132,27 +2209,21 @@ static int rhine_close(struct net_device *dev)
2132 struct rhine_private *rp = netdev_priv(dev); 2209 struct rhine_private *rp = netdev_priv(dev);
2133 void __iomem *ioaddr = rp->base; 2210 void __iomem *ioaddr = rp->base;
2134 2211
2212 rhine_task_disable(rp);
2135 napi_disable(&rp->napi); 2213 napi_disable(&rp->napi);
2136 cancel_work_sync(&rp->reset_task);
2137 netif_stop_queue(dev); 2214 netif_stop_queue(dev);
2138 2215
2139 spin_lock_irq(&rp->lock); 2216 netif_dbg(rp, ifdown, dev, "Shutting down ethercard, status was %04x\n",
2140 2217 ioread16(ioaddr + ChipCmd));
2141 if (debug > 1)
2142 netdev_dbg(dev, "Shutting down ethercard, status was %04x\n",
2143 ioread16(ioaddr + ChipCmd));
2144 2218
2145 /* Switch to loopback mode to avoid hardware races. */ 2219 /* Switch to loopback mode to avoid hardware races. */
2146 iowrite8(rp->tx_thresh | 0x02, ioaddr + TxConfig); 2220 iowrite8(rp->tx_thresh | 0x02, ioaddr + TxConfig);
2147 2221
2148 /* Disable interrupts by clearing the interrupt mask. */ 2222 rhine_irq_disable(rp);
2149 iowrite16(0x0000, ioaddr + IntrEnable);
2150 2223
2151 /* Stop the chip's Tx and Rx processes. */ 2224 /* Stop the chip's Tx and Rx processes. */
2152 iowrite16(CmdStop, ioaddr + ChipCmd); 2225 iowrite16(CmdStop, ioaddr + ChipCmd);
2153 2226
2154 spin_unlock_irq(&rp->lock);
2155
2156 free_irq(rp->pdev->irq, dev); 2227 free_irq(rp->pdev->irq, dev);
2157 free_rbufs(dev); 2228 free_rbufs(dev);
2158 free_tbufs(dev); 2229 free_tbufs(dev);
@@ -2192,6 +2263,8 @@ static void rhine_shutdown (struct pci_dev *pdev)
2192 if (rp->quirks & rq6patterns) 2263 if (rp->quirks & rq6patterns)
2193 iowrite8(0x04, ioaddr + WOLcgClr); 2264 iowrite8(0x04, ioaddr + WOLcgClr);
2194 2265
2266 spin_lock(&rp->lock);
2267
2195 if (rp->wolopts & WAKE_MAGIC) { 2268 if (rp->wolopts & WAKE_MAGIC) {
2196 iowrite8(WOLmagic, ioaddr + WOLcrSet); 2269 iowrite8(WOLmagic, ioaddr + WOLcrSet);
2197 /* 2270 /*
@@ -2216,58 +2289,46 @@ static void rhine_shutdown (struct pci_dev *pdev)
2216 iowrite8(ioread8(ioaddr + StickyHW) | 0x04, ioaddr + StickyHW); 2289 iowrite8(ioread8(ioaddr + StickyHW) | 0x04, ioaddr + StickyHW);
2217 } 2290 }
2218 2291
2219 /* Hit power state D3 (sleep) */ 2292 spin_unlock(&rp->lock);
2220 if (!avoid_D3)
2221 iowrite8(ioread8(ioaddr + StickyHW) | 0x03, ioaddr + StickyHW);
2222 2293
2223 /* TODO: Check use of pci_enable_wake() */ 2294 if (system_state == SYSTEM_POWER_OFF && !avoid_D3) {
2295 iowrite8(ioread8(ioaddr + StickyHW) | 0x03, ioaddr + StickyHW);
2224 2296
2297 pci_wake_from_d3(pdev, true);
2298 pci_set_power_state(pdev, PCI_D3hot);
2299 }
2225} 2300}
2226 2301
2227#ifdef CONFIG_PM 2302#ifdef CONFIG_PM_SLEEP
2228static int rhine_suspend(struct pci_dev *pdev, pm_message_t state) 2303static int rhine_suspend(struct device *device)
2229{ 2304{
2305 struct pci_dev *pdev = to_pci_dev(device);
2230 struct net_device *dev = pci_get_drvdata(pdev); 2306 struct net_device *dev = pci_get_drvdata(pdev);
2231 struct rhine_private *rp = netdev_priv(dev); 2307 struct rhine_private *rp = netdev_priv(dev);
2232 unsigned long flags;
2233 2308
2234 if (!netif_running(dev)) 2309 if (!netif_running(dev))
2235 return 0; 2310 return 0;
2236 2311
2312 rhine_task_disable(rp);
2313 rhine_irq_disable(rp);
2237 napi_disable(&rp->napi); 2314 napi_disable(&rp->napi);
2238 2315
2239 netif_device_detach(dev); 2316 netif_device_detach(dev);
2240 pci_save_state(pdev);
2241 2317
2242 spin_lock_irqsave(&rp->lock, flags);
2243 rhine_shutdown(pdev); 2318 rhine_shutdown(pdev);
2244 spin_unlock_irqrestore(&rp->lock, flags);
2245 2319
2246 free_irq(dev->irq, dev);
2247 return 0; 2320 return 0;
2248} 2321}
2249 2322
2250static int rhine_resume(struct pci_dev *pdev) 2323static int rhine_resume(struct device *device)
2251{ 2324{
2325 struct pci_dev *pdev = to_pci_dev(device);
2252 struct net_device *dev = pci_get_drvdata(pdev); 2326 struct net_device *dev = pci_get_drvdata(pdev);
2253 struct rhine_private *rp = netdev_priv(dev); 2327 struct rhine_private *rp = netdev_priv(dev);
2254 unsigned long flags;
2255 int ret;
2256 2328
2257 if (!netif_running(dev)) 2329 if (!netif_running(dev))
2258 return 0; 2330 return 0;
2259 2331
2260 if (request_irq(dev->irq, rhine_interrupt, IRQF_SHARED, dev->name, dev))
2261 netdev_err(dev, "request_irq failed\n");
2262
2263 ret = pci_set_power_state(pdev, PCI_D0);
2264 if (debug > 1)
2265 netdev_info(dev, "Entering power state D0 %s (%d)\n",
2266 ret ? "failed" : "succeeded", ret);
2267
2268 pci_restore_state(pdev);
2269
2270 spin_lock_irqsave(&rp->lock, flags);
2271#ifdef USE_MMIO 2332#ifdef USE_MMIO
2272 enable_mmio(rp->pioaddr, rp->quirks); 2333 enable_mmio(rp->pioaddr, rp->quirks);
2273#endif 2334#endif
@@ -2276,25 +2337,32 @@ static int rhine_resume(struct pci_dev *pdev)
2276 free_rbufs(dev); 2337 free_rbufs(dev);
2277 alloc_tbufs(dev); 2338 alloc_tbufs(dev);
2278 alloc_rbufs(dev); 2339 alloc_rbufs(dev);
2340 rhine_task_enable(rp);
2341 spin_lock_bh(&rp->lock);
2279 init_registers(dev); 2342 init_registers(dev);
2280 spin_unlock_irqrestore(&rp->lock, flags); 2343 spin_unlock_bh(&rp->lock);
2281 2344
2282 netif_device_attach(dev); 2345 netif_device_attach(dev);
2283 2346
2284 return 0; 2347 return 0;
2285} 2348}
2286#endif /* CONFIG_PM */ 2349
2350static SIMPLE_DEV_PM_OPS(rhine_pm_ops, rhine_suspend, rhine_resume);
2351#define RHINE_PM_OPS (&rhine_pm_ops)
2352
2353#else
2354
2355#define RHINE_PM_OPS NULL
2356
2357#endif /* !CONFIG_PM_SLEEP */
2287 2358
2288static struct pci_driver rhine_driver = { 2359static struct pci_driver rhine_driver = {
2289 .name = DRV_NAME, 2360 .name = DRV_NAME,
2290 .id_table = rhine_pci_tbl, 2361 .id_table = rhine_pci_tbl,
2291 .probe = rhine_init_one, 2362 .probe = rhine_init_one,
2292 .remove = __devexit_p(rhine_remove_one), 2363 .remove = __devexit_p(rhine_remove_one),
2293#ifdef CONFIG_PM 2364 .shutdown = rhine_shutdown,
2294 .suspend = rhine_suspend, 2365 .driver.pm = RHINE_PM_OPS,
2295 .resume = rhine_resume,
2296#endif /* CONFIG_PM */
2297 .shutdown = rhine_shutdown,
2298}; 2366};
2299 2367
2300static struct dmi_system_id __initdata rhine_dmi_table[] = { 2368static struct dmi_system_id __initdata rhine_dmi_table[] = {
diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index f45c85a84261..72a854f05bb8 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -529,7 +529,7 @@ static int ixp4xx_mdio_register(void)
529 mdio_bus->name = "IXP4xx MII Bus"; 529 mdio_bus->name = "IXP4xx MII Bus";
530 mdio_bus->read = &ixp4xx_mdio_read; 530 mdio_bus->read = &ixp4xx_mdio_read;
531 mdio_bus->write = &ixp4xx_mdio_write; 531 mdio_bus->write = &ixp4xx_mdio_write;
532 strcpy(mdio_bus->id, "0"); 532 snprintf(mdio_bus->id, MII_BUS_ID_SIZE, "ixp4xx-eth-0");
533 533
534 if ((err = mdiobus_register(mdio_bus))) 534 if ((err = mdiobus_register(mdio_bus)))
535 mdiobus_free(mdio_bus); 535 mdiobus_free(mdio_bus);
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 9663e0ba6003..ba3c59147aa7 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1159,7 +1159,7 @@ static void rx_timestamp_work(struct work_struct *work)
1159 } 1159 }
1160 } 1160 }
1161 spin_unlock_irqrestore(&dp83640->rx_lock, flags); 1161 spin_unlock_irqrestore(&dp83640->rx_lock, flags);
1162 netif_rx(skb); 1162 netif_rx_ni(skb);
1163 } 1163 }
1164 1164
1165 /* Clear out expired time stamps. */ 1165 /* Clear out expired time stamps. */
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 1fa4d73c3cca..633680d0828e 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -220,7 +220,7 @@ static int __init fixed_mdio_bus_init(void)
220 goto err_mdiobus_reg; 220 goto err_mdiobus_reg;
221 } 221 }
222 222
223 snprintf(fmb->mii_bus->id, MII_BUS_ID_SIZE, "0"); 223 snprintf(fmb->mii_bus->id, MII_BUS_ID_SIZE, "fixed-0");
224 fmb->mii_bus->name = "Fixed MDIO Bus"; 224 fmb->mii_bus->name = "Fixed MDIO Bus";
225 fmb->mii_bus->priv = fmb; 225 fmb->mii_bus->priv = fmb;
226 fmb->mii_bus->parent = &pdev->dev; 226 fmb->mii_bus->parent = &pdev->dev;
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 89c5a3eccc12..50e8e5e74465 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -116,7 +116,7 @@ static struct mii_bus * __devinit mdio_gpio_bus_init(struct device *dev,
116 if (!new_bus->irq[i]) 116 if (!new_bus->irq[i])
117 new_bus->irq[i] = PHY_POLL; 117 new_bus->irq[i] = PHY_POLL;
118 118
119 snprintf(new_bus->id, MII_BUS_ID_SIZE, "%x", bus_id); 119 snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id);
120 120
121 if (gpio_request(bitbang->mdc, "mdc")) 121 if (gpio_request(bitbang->mdc, "mdc"))
122 goto out_free_bus; 122 goto out_free_bus;
diff --git a/drivers/net/phy/mdio-octeon.c b/drivers/net/phy/mdio-octeon.c
index bd12ba941be5..826d961f39f7 100644
--- a/drivers/net/phy/mdio-octeon.c
+++ b/drivers/net/phy/mdio-octeon.c
@@ -118,7 +118,8 @@ static int __devinit octeon_mdiobus_probe(struct platform_device *pdev)
118 bus->mii_bus->priv = bus; 118 bus->mii_bus->priv = bus;
119 bus->mii_bus->irq = bus->phy_irq; 119 bus->mii_bus->irq = bus->phy_irq;
120 bus->mii_bus->name = "mdio-octeon"; 120 bus->mii_bus->name = "mdio-octeon";
121 snprintf(bus->mii_bus->id, MII_BUS_ID_SIZE, "%x", bus->unit); 121 snprintf(bus->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
122 bus->mii_bus->name, bus->unit);
122 bus->mii_bus->parent = &pdev->dev; 123 bus->mii_bus->parent = &pdev->dev;
123 124
124 bus->mii_bus->read = octeon_mdiobus_read; 125 bus->mii_bus->read = octeon_mdiobus_read;
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6c58da2b882c..88cc5db9affd 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -37,22 +37,36 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38 38
39/** 39/**
40 * mdiobus_alloc - allocate a mii_bus structure 40 * mdiobus_alloc_size - allocate a mii_bus structure
41 * 41 *
42 * Description: called by a bus driver to allocate an mii_bus 42 * Description: called by a bus driver to allocate an mii_bus
43 * structure to fill in. 43 * structure to fill in.
44 *
45 * 'size' is an an extra amount of memory to allocate for private storage.
46 * If non-zero, then bus->priv is points to that memory.
44 */ 47 */
45struct mii_bus *mdiobus_alloc(void) 48struct mii_bus *mdiobus_alloc_size(size_t size)
46{ 49{
47 struct mii_bus *bus; 50 struct mii_bus *bus;
51 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
52 size_t alloc_size;
53
54 /* If we alloc extra space, it should be aligned */
55 if (size)
56 alloc_size = aligned_size + size;
57 else
58 alloc_size = sizeof(*bus);
48 59
49 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 60 bus = kzalloc(alloc_size, GFP_KERNEL);
50 if (bus != NULL) 61 if (bus) {
51 bus->state = MDIOBUS_ALLOCATED; 62 bus->state = MDIOBUS_ALLOCATED;
63 if (size)
64 bus->priv = (void *)bus + aligned_size;
65 }
52 66
53 return bus; 67 return bus;
54} 68}
55EXPORT_SYMBOL(mdiobus_alloc); 69EXPORT_SYMBOL(mdiobus_alloc_size);
56 70
57/** 71/**
58 * mdiobus_release - mii_bus device release callback 72 * mdiobus_release - mii_bus device release callback
diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
index c1c9293c2bbf..df884dde2a51 100644
--- a/drivers/net/ppp/pptp.c
+++ b/drivers/net/ppp/pptp.c
@@ -585,8 +585,8 @@ static int pptp_create(struct net *net, struct socket *sock)
585 po = pppox_sk(sk); 585 po = pppox_sk(sk);
586 opt = &po->proto.pptp; 586 opt = &po->proto.pptp;
587 587
588 opt->seq_sent = 0; opt->seq_recv = 0; 588 opt->seq_sent = 0; opt->seq_recv = 0xffffffff;
589 opt->ack_recv = 0; opt->ack_sent = 0; 589 opt->ack_recv = 0; opt->ack_sent = 0xffffffff;
590 590
591 error = 0; 591 error = 0;
592out: 592out:
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index d0937c4634c9..8e84f5bdd6ca 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -978,6 +978,7 @@ static int ax88772_link_reset(struct usbnet *dev)
978 978
979static int ax88772_reset(struct usbnet *dev) 979static int ax88772_reset(struct usbnet *dev)
980{ 980{
981 struct asix_data *data = (struct asix_data *)&dev->data;
981 int ret, embd_phy; 982 int ret, embd_phy;
982 u16 rx_ctl; 983 u16 rx_ctl;
983 984
@@ -1055,6 +1056,13 @@ static int ax88772_reset(struct usbnet *dev)
1055 goto out; 1056 goto out;
1056 } 1057 }
1057 1058
1059 /* Rewrite MAC address */
1060 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
1061 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
1062 data->mac_addr);
1063 if (ret < 0)
1064 goto out;
1065
1058 /* Set RX_CTL to default values with 2k buffer, and enable cactus */ 1066 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
1059 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL); 1067 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
1060 if (ret < 0) 1068 if (ret < 0)
@@ -1320,6 +1328,13 @@ static int ax88178_reset(struct usbnet *dev)
1320 if (ret < 0) 1328 if (ret < 0)
1321 return ret; 1329 return ret;
1322 1330
1331 /* Rewrite MAC address */
1332 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
1333 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
1334 data->mac_addr);
1335 if (ret < 0)
1336 return ret;
1337
1323 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL); 1338 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
1324 if (ret < 0) 1339 if (ret < 0)
1325 return ret; 1340 return ret;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index 2589b38b689a..2b0bfb8cca02 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -46,7 +46,7 @@ static const int m2ThreshExt_off = 127;
46 * @chan: 46 * @chan:
47 * 47 *
48 * This is the function to change channel on single-chip devices, that is 48 * This is the function to change channel on single-chip devices, that is
49 * all devices after ar9280. 49 * for AR9300 family of chipsets.
50 * 50 *
51 * This function takes the channel value in MHz and sets 51 * This function takes the channel value in MHz and sets
52 * hardware channel value. Assumes writes have been enabled to analog bus. 52 * hardware channel value. Assumes writes have been enabled to analog bus.
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index b30e9fc6433f..171ccf7c972f 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -679,7 +679,6 @@ void ath9k_deinit_device(struct ath_softc *sc);
679void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw); 679void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw);
680void ath9k_reload_chainmask_settings(struct ath_softc *sc); 680void ath9k_reload_chainmask_settings(struct ath_softc *sc);
681 681
682void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw);
683bool ath9k_uses_beacons(int type); 682bool ath9k_uses_beacons(int type);
684 683
685#ifdef CONFIG_ATH9K_PCI 684#ifdef CONFIG_ATH9K_PCI
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 172e33db7f4c..2f4b48e6fb03 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -400,6 +400,7 @@ bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan)
400 ah->noise = ath9k_hw_getchan_noise(ah, chan); 400 ah->noise = ath9k_hw_getchan_noise(ah, chan);
401 return true; 401 return true;
402} 402}
403EXPORT_SYMBOL(ath9k_hw_getnf);
403 404
404void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah, 405void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
405 struct ath9k_channel *chan) 406 struct ath9k_channel *chan)
diff --git a/drivers/net/wireless/ath/ath9k/calib.h b/drivers/net/wireless/ath/ath9k/calib.h
index 05b9dbf81850..3b33996d97df 100644
--- a/drivers/net/wireless/ath/ath9k/calib.h
+++ b/drivers/net/wireless/ath/ath9k/calib.h
@@ -19,7 +19,6 @@
19 19
20#include "hw.h" 20#include "hw.h"
21 21
22#define AR_PHY_CCA_FILTERWINDOW_LENGTH_INIT 3
23#define AR_PHY_CCA_FILTERWINDOW_LENGTH 5 22#define AR_PHY_CCA_FILTERWINDOW_LENGTH 5
24 23
25#define NUM_NF_READINGS 6 24#define NUM_NF_READINGS 6
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index e267c92dbfb8..4a00806e2852 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -1629,7 +1629,6 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1629 1629
1630 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 1630 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1631 struct ieee80211_channel *curchan = hw->conf.channel; 1631 struct ieee80211_channel *curchan = hw->conf.channel;
1632 struct ath9k_channel old_chan;
1633 int pos = curchan->hw_value; 1632 int pos = curchan->hw_value;
1634 int old_pos = -1; 1633 int old_pos = -1;
1635 unsigned long flags; 1634 unsigned long flags;
@@ -1654,11 +1653,8 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1654 * Preserve the current channel values, before updating 1653 * Preserve the current channel values, before updating
1655 * the same channel 1654 * the same channel
1656 */ 1655 */
1657 if (old_pos == pos) { 1656 if (ah->curchan && (old_pos == pos))
1658 memcpy(&old_chan, &sc->sc_ah->channels[pos], 1657 ath9k_hw_getnf(ah, ah->curchan);
1659 sizeof(struct ath9k_channel));
1660 ah->curchan = &old_chan;
1661 }
1662 1658
1663 ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos], 1659 ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
1664 curchan, conf->channel_type); 1660 curchan, conf->channel_type);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 5a002a21f108..f7eeee1dcdb6 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -3119,8 +3119,10 @@ static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
3119 /* Verify NVRAM bytes */ 3119 /* Verify NVRAM bytes */
3120 brcmf_dbg(INFO, "Compare NVRAM dl & ul; varsize=%d\n", varsize); 3120 brcmf_dbg(INFO, "Compare NVRAM dl & ul; varsize=%d\n", varsize);
3121 nvram_ularray = kmalloc(varsize, GFP_ATOMIC); 3121 nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
3122 if (!nvram_ularray) 3122 if (!nvram_ularray) {
3123 kfree(vbuffer);
3123 return -ENOMEM; 3124 return -ENOMEM;
3125 }
3124 3126
3125 /* Upload image to verify downloaded contents. */ 3127 /* Upload image to verify downloaded contents. */
3126 memset(nvram_ularray, 0xaa, varsize); 3128 memset(nvram_ularray, 0xaa, varsize);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/fw.c b/drivers/net/wireless/rtlwifi/rtl8192se/fw.c
index 6f91a148c222..3fda6b1dcf46 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/fw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/fw.c
@@ -196,6 +196,8 @@ static bool _rtl92s_firmware_downloadcode(struct ieee80211_hw *hw,
196 /* Allocate skb buffer to contain firmware */ 196 /* Allocate skb buffer to contain firmware */
197 /* info and tx descriptor info. */ 197 /* info and tx descriptor info. */
198 skb = dev_alloc_skb(frag_length); 198 skb = dev_alloc_skb(frag_length);
199 if (!skb)
200 return false;
199 skb_reserve(skb, extra_descoffset); 201 skb_reserve(skb, extra_descoffset);
200 seg_ptr = (u8 *)skb_put(skb, (u32)(frag_length - 202 seg_ptr = (u8 *)skb_put(skb, (u32)(frag_length -
201 extra_descoffset)); 203 extra_descoffset));
@@ -573,6 +575,8 @@ static bool _rtl92s_firmware_set_h2c_cmd(struct ieee80211_hw *hw, u8 h2c_cmd,
573 575
574 len = _rtl92s_get_h2c_cmdlen(MAX_TRANSMIT_BUFFER_SIZE, 1, &cmd_len); 576 len = _rtl92s_get_h2c_cmdlen(MAX_TRANSMIT_BUFFER_SIZE, 1, &cmd_len);
575 skb = dev_alloc_skb(len); 577 skb = dev_alloc_skb(len);
578 if (!skb)
579 return false;
576 cb_desc = (struct rtl_tcb_desc *)(skb->cb); 580 cb_desc = (struct rtl_tcb_desc *)(skb->cb);
577 cb_desc->queue_index = TXCMD_QUEUE; 581 cb_desc->queue_index = TXCMD_QUEUE;
578 cb_desc->cmd_or_init = DESC_PACKET_TYPE_NORMAL; 582 cb_desc->cmd_or_init = DESC_PACKET_TYPE_NORMAL;
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index d0b597b50398..0cb64f50cecd 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -3404,8 +3404,8 @@ static int __init parport_init_mode_setup(char *str)
3404#endif 3404#endif
3405 3405
3406#ifdef MODULE 3406#ifdef MODULE
3407static const char *irq[PARPORT_PC_MAX_PORTS]; 3407static char *irq[PARPORT_PC_MAX_PORTS];
3408static const char *dma[PARPORT_PC_MAX_PORTS]; 3408static char *dma[PARPORT_PC_MAX_PORTS];
3409 3409
3410MODULE_PARM_DESC(io, "Base I/O address (SPP regs)"); 3410MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
3411module_param_array(io, int, NULL, 0); 3411module_param_array(io, int, NULL, 0);
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index e91b8ddc2793..c9b92531ae60 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -16,8 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/mfd/ab8500.h>
20#include <linux/mfd/abx500.h> 19#include <linux/mfd/abx500.h>
20#include <linux/mfd/abx500/ab8500.h>
21#include <linux/regulator/driver.h> 21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h> 22#include <linux/regulator/machine.h>
23#include <linux/regulator/ab8500.h> 23#include <linux/regulator/ab8500.h>
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index a0a9810adf0b..4bcf9ca2818a 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -15,7 +15,7 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/rtc.h> 16#include <linux/rtc.h>
17#include <linux/mfd/abx500.h> 17#include <linux/mfd/abx500.h>
18#include <linux/mfd/ab8500.h> 18#include <linux/mfd/abx500/ab8500.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20 20
21#define AB8500_RTC_SOFF_STAT_REG 0x00 21#define AB8500_RTC_SOFF_STAT_REG 0x00
diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
index 4a5529346b47..2d71943bc436 100644
--- a/drivers/rtc/rtc-max8925.c
+++ b/drivers/rtc/rtc-max8925.c
@@ -261,6 +261,8 @@ static int __devinit max8925_rtc_probe(struct platform_device *pdev)
261 /* XXX - isn't this redundant? */ 261 /* XXX - isn't this redundant? */
262 platform_set_drvdata(pdev, info); 262 platform_set_drvdata(pdev, info);
263 263
264 device_init_wakeup(&pdev->dev, 1);
265
264 info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev, 266 info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev,
265 &max8925_rtc_ops, THIS_MODULE); 267 &max8925_rtc_ops, THIS_MODULE);
266 ret = PTR_ERR(info->rtc_dev); 268 ret = PTR_ERR(info->rtc_dev);
@@ -290,10 +292,34 @@ static int __devexit max8925_rtc_remove(struct platform_device *pdev)
290 return 0; 292 return 0;
291} 293}
292 294
295#ifdef CONFIG_PM_SLEEP
296static int max8925_rtc_suspend(struct device *dev)
297{
298 struct platform_device *pdev = to_platform_device(dev);
299 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
300
301 if (device_may_wakeup(dev))
302 chip->wakeup_flag |= 1 << MAX8925_IRQ_RTC_ALARM0;
303 return 0;
304}
305static int max8925_rtc_resume(struct device *dev)
306{
307 struct platform_device *pdev = to_platform_device(dev);
308 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
309
310 if (device_may_wakeup(dev))
311 chip->wakeup_flag &= ~(1 << MAX8925_IRQ_RTC_ALARM0);
312 return 0;
313}
314#endif
315
316static SIMPLE_DEV_PM_OPS(max8925_rtc_pm_ops, max8925_rtc_suspend, max8925_rtc_resume);
317
293static struct platform_driver max8925_rtc_driver = { 318static struct platform_driver max8925_rtc_driver = {
294 .driver = { 319 .driver = {
295 .name = "max8925-rtc", 320 .name = "max8925-rtc",
296 .owner = THIS_MODULE, 321 .owner = THIS_MODULE,
322 .pm = &max8925_rtc_pm_ops,
297 }, 323 },
298 .probe = max8925_rtc_probe, 324 .probe = max8925_rtc_probe,
299 .remove = __devexit_p(max8925_rtc_remove), 325 .remove = __devexit_p(max8925_rtc_remove),
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
index 07ccea9ada40..74fe6e62e0f7 100644
--- a/drivers/usb/otg/ab8500-usb.c
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -30,7 +30,7 @@
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/mfd/abx500.h> 32#include <linux/mfd/abx500.h>
33#include <linux/mfd/ab8500.h> 33#include <linux/mfd/abx500/ab8500.h>
34 34
35#define AB8500_MAIN_WD_CTRL_REG 0x01 35#define AB8500_MAIN_WD_CTRL_REG 0x01
36#define AB8500_USB_LINE_STAT_REG 0x80 36#define AB8500_USB_LINE_STAT_REG 0x80
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index 081dc4745274..fe13ac567d54 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -81,7 +81,7 @@ static int vram __devinitdata = 0;
81static int bpp __devinitdata = 8; 81static int bpp __devinitdata = 8;
82static int reverse_i2c __devinitdata; 82static int reverse_i2c __devinitdata;
83#ifdef CONFIG_MTRR 83#ifdef CONFIG_MTRR
84static int nomtrr __devinitdata = 0; 84static bool nomtrr __devinitdata = false;
85#endif 85#endif
86#ifdef CONFIG_PMAC_BACKLIGHT 86#ifdef CONFIG_PMAC_BACKLIGHT
87static int backlight __devinitdata = 1; 87static int backlight __devinitdata = 1;
@@ -1509,7 +1509,7 @@ static int __devinit nvidiafb_setup(char *options)
1509 backlight = simple_strtoul(this_opt+10, NULL, 0); 1509 backlight = simple_strtoul(this_opt+10, NULL, 0);
1510#ifdef CONFIG_MTRR 1510#ifdef CONFIG_MTRR
1511 } else if (!strncmp(this_opt, "nomtrr", 6)) { 1511 } else if (!strncmp(this_opt, "nomtrr", 6)) {
1512 nomtrr = 1; 1512 nomtrr = true;
1513#endif 1513#endif
1514 } else if (!strncmp(this_opt, "fpdither:", 9)) { 1514 } else if (!strncmp(this_opt, "fpdither:", 9)) {
1515 fpdither = simple_strtol(this_opt+9, NULL, 0); 1515 fpdither = simple_strtol(this_opt+9, NULL, 0);
@@ -1599,7 +1599,7 @@ MODULE_PARM_DESC(bpp, "pixel width in bits"
1599module_param(reverse_i2c, int, 0); 1599module_param(reverse_i2c, int, 0);
1600MODULE_PARM_DESC(reverse_i2c, "reverse port assignment of the i2c bus"); 1600MODULE_PARM_DESC(reverse_i2c, "reverse port assignment of the i2c bus");
1601#ifdef CONFIG_MTRR 1601#ifdef CONFIG_MTRR
1602module_param(nomtrr, bool, 0); 1602module_param(nomtrr, bool, false);
1603MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) " 1603MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) "
1604 "(default=0)"); 1604 "(default=0)");
1605#endif 1605#endif
diff --git a/fs/aio.c b/fs/aio.c
index 78c514cfd212..969beb0e2231 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -476,14 +476,21 @@ static void kiocb_batch_init(struct kiocb_batch *batch, long total)
476 batch->count = total; 476 batch->count = total;
477} 477}
478 478
479static void kiocb_batch_free(struct kiocb_batch *batch) 479static void kiocb_batch_free(struct kioctx *ctx, struct kiocb_batch *batch)
480{ 480{
481 struct kiocb *req, *n; 481 struct kiocb *req, *n;
482 482
483 if (list_empty(&batch->head))
484 return;
485
486 spin_lock_irq(&ctx->ctx_lock);
483 list_for_each_entry_safe(req, n, &batch->head, ki_batch) { 487 list_for_each_entry_safe(req, n, &batch->head, ki_batch) {
484 list_del(&req->ki_batch); 488 list_del(&req->ki_batch);
489 list_del(&req->ki_list);
485 kmem_cache_free(kiocb_cachep, req); 490 kmem_cache_free(kiocb_cachep, req);
491 ctx->reqs_active--;
486 } 492 }
493 spin_unlock_irq(&ctx->ctx_lock);
487} 494}
488 495
489/* 496/*
@@ -1742,7 +1749,7 @@ long do_io_submit(aio_context_t ctx_id, long nr,
1742 } 1749 }
1743 blk_finish_plug(&plug); 1750 blk_finish_plug(&plug);
1744 1751
1745 kiocb_batch_free(&batch); 1752 kiocb_batch_free(ctx, &batch);
1746 put_ioctx(ctx); 1753 put_ioctx(ctx);
1747 return i ? i : ret; 1754 return i ? i : ret;
1748} 1755}
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 9ef5b2914407..da8876d38a7b 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -76,7 +76,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
76 data += wr; 76 data += wr;
77 bytes -= wr; 77 bytes -= wr;
78 } 78 }
79 mutex_lock(&sbi->pipe_mutex); 79 mutex_unlock(&sbi->pipe_mutex);
80 80
81 set_fs(fs); 81 set_fs(fs);
82 82
diff --git a/fs/block_dev.c b/fs/block_dev.c
index afe74dda632b..0e575d1304b4 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1139,6 +1139,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1139 mutex_lock_nested(&bdev->bd_mutex, for_part); 1139 mutex_lock_nested(&bdev->bd_mutex, for_part);
1140 if (!bdev->bd_openers) { 1140 if (!bdev->bd_openers) {
1141 bdev->bd_disk = disk; 1141 bdev->bd_disk = disk;
1142 bdev->bd_queue = disk->queue;
1142 bdev->bd_contains = bdev; 1143 bdev->bd_contains = bdev;
1143 if (!partno) { 1144 if (!partno) {
1144 struct backing_dev_info *bdi; 1145 struct backing_dev_info *bdi;
@@ -1159,6 +1160,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1159 disk_put_part(bdev->bd_part); 1160 disk_put_part(bdev->bd_part);
1160 bdev->bd_part = NULL; 1161 bdev->bd_part = NULL;
1161 bdev->bd_disk = NULL; 1162 bdev->bd_disk = NULL;
1163 bdev->bd_queue = NULL;
1162 mutex_unlock(&bdev->bd_mutex); 1164 mutex_unlock(&bdev->bd_mutex);
1163 disk_unblock_events(disk); 1165 disk_unblock_events(disk);
1164 put_disk(disk); 1166 put_disk(disk);
@@ -1232,6 +1234,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1232 disk_put_part(bdev->bd_part); 1234 disk_put_part(bdev->bd_part);
1233 bdev->bd_disk = NULL; 1235 bdev->bd_disk = NULL;
1234 bdev->bd_part = NULL; 1236 bdev->bd_part = NULL;
1237 bdev->bd_queue = NULL;
1235 bdev_inode_switch_bdi(bdev->bd_inode, &default_backing_dev_info); 1238 bdev_inode_switch_bdi(bdev->bd_inode, &default_backing_dev_info);
1236 if (bdev != bdev->bd_contains) 1239 if (bdev != bdev->bd_contains)
1237 __blkdev_put(bdev->bd_contains, mode, 1); 1240 __blkdev_put(bdev->bd_contains, mode, 1);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index f99a099a7747..d8525662ca7a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -872,7 +872,8 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
872 872
873#ifdef CONFIG_MIGRATION 873#ifdef CONFIG_MIGRATION
874static int btree_migratepage(struct address_space *mapping, 874static int btree_migratepage(struct address_space *mapping,
875 struct page *newpage, struct page *page) 875 struct page *newpage, struct page *page,
876 enum migrate_mode mode)
876{ 877{
877 /* 878 /*
878 * we can't safely write a btree page from here, 879 * we can't safely write a btree page from here,
@@ -887,7 +888,7 @@ static int btree_migratepage(struct address_space *mapping,
887 if (page_has_private(page) && 888 if (page_has_private(page) &&
888 !try_to_release_page(page, GFP_KERNEL)) 889 !try_to_release_page(page, GFP_KERNEL))
889 return -EAGAIN; 890 return -EAGAIN;
890 return migrate_page(mapping, newpage, page); 891 return migrate_page(mapping, newpage, page, mode);
891} 892}
892#endif 893#endif
893 894
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 74fd74719dc2..618246bc2196 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -973,7 +973,7 @@ static int dentry_lease_is_valid(struct dentry *dentry)
973 973
974 spin_lock(&dentry->d_lock); 974 spin_lock(&dentry->d_lock);
975 di = ceph_dentry(dentry); 975 di = ceph_dentry(dentry);
976 if (di && di->lease_session) { 976 if (di->lease_session) {
977 s = di->lease_session; 977 s = di->lease_session;
978 spin_lock(&s->s_cap_lock); 978 spin_lock(&s->s_cap_lock);
979 gen = s->s_cap_gen; 979 gen = s->s_cap_gen;
@@ -1072,13 +1072,11 @@ static void ceph_d_release(struct dentry *dentry)
1072 struct ceph_dentry_info *di = ceph_dentry(dentry); 1072 struct ceph_dentry_info *di = ceph_dentry(dentry);
1073 1073
1074 dout("d_release %p\n", dentry); 1074 dout("d_release %p\n", dentry);
1075 if (di) { 1075 ceph_dentry_lru_del(dentry);
1076 ceph_dentry_lru_del(dentry); 1076 if (di->lease_session)
1077 if (di->lease_session) 1077 ceph_put_mds_session(di->lease_session);
1078 ceph_put_mds_session(di->lease_session); 1078 kmem_cache_free(ceph_dentry_cachep, di);
1079 kmem_cache_free(ceph_dentry_cachep, di); 1079 dentry->d_fsdata = NULL;
1080 dentry->d_fsdata = NULL;
1081 }
1082} 1080}
1083 1081
1084static int ceph_snapdir_d_revalidate(struct dentry *dentry, 1082static int ceph_snapdir_d_revalidate(struct dentry *dentry,
@@ -1096,17 +1094,36 @@ static int ceph_snapdir_d_revalidate(struct dentry *dentry,
1096 */ 1094 */
1097void ceph_dir_set_complete(struct inode *inode) 1095void ceph_dir_set_complete(struct inode *inode)
1098{ 1096{
1099 /* not yet implemented */ 1097 struct dentry *dentry = d_find_any_alias(inode);
1098
1099 if (dentry && ceph_dentry(dentry) &&
1100 ceph_test_mount_opt(ceph_sb_to_client(dentry->d_sb), DCACHE)) {
1101 dout(" marking %p (%p) complete\n", inode, dentry);
1102 set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
1103 }
1104 dput(dentry);
1100} 1105}
1101 1106
1102void ceph_dir_clear_complete(struct inode *inode) 1107void ceph_dir_clear_complete(struct inode *inode)
1103{ 1108{
1104 /* not yet implemented */ 1109 struct dentry *dentry = d_find_any_alias(inode);
1110
1111 if (dentry && ceph_dentry(dentry)) {
1112 dout(" marking %p (%p) complete\n", inode, dentry);
1113 set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
1114 }
1115 dput(dentry);
1105} 1116}
1106 1117
1107bool ceph_dir_test_complete(struct inode *inode) 1118bool ceph_dir_test_complete(struct inode *inode)
1108{ 1119{
1109 /* not yet implemented */ 1120 struct dentry *dentry = d_find_any_alias(inode);
1121
1122 if (dentry && ceph_dentry(dentry)) {
1123 dout(" marking %p (%p) NOT complete\n", inode, dentry);
1124 clear_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
1125 }
1126 dput(dentry);
1110 return false; 1127 return false;
1111} 1128}
1112 1129
@@ -1220,6 +1237,7 @@ static int ceph_dir_fsync(struct file *file, loff_t start, loff_t end,
1220 do { 1237 do {
1221 ceph_mdsc_get_request(req); 1238 ceph_mdsc_get_request(req);
1222 spin_unlock(&ci->i_unsafe_lock); 1239 spin_unlock(&ci->i_unsafe_lock);
1240
1223 dout("dir_fsync %p wait on tid %llu (until %llu)\n", 1241 dout("dir_fsync %p wait on tid %llu (until %llu)\n",
1224 inode, req->r_tid, last_tid); 1242 inode, req->r_tid, last_tid);
1225 if (req->r_timeout) { 1243 if (req->r_timeout) {
@@ -1232,9 +1250,9 @@ static int ceph_dir_fsync(struct file *file, loff_t start, loff_t end,
1232 } else { 1250 } else {
1233 wait_for_completion(&req->r_safe_completion); 1251 wait_for_completion(&req->r_safe_completion);
1234 } 1252 }
1235 spin_lock(&ci->i_unsafe_lock);
1236 ceph_mdsc_put_request(req); 1253 ceph_mdsc_put_request(req);
1237 1254
1255 spin_lock(&ci->i_unsafe_lock);
1238 if (ret || list_empty(head)) 1256 if (ret || list_empty(head))
1239 break; 1257 break;
1240 req = list_entry(head->next, 1258 req = list_entry(head->next,
@@ -1259,13 +1277,11 @@ void ceph_dentry_lru_add(struct dentry *dn)
1259 1277
1260 dout("dentry_lru_add %p %p '%.*s'\n", di, dn, 1278 dout("dentry_lru_add %p %p '%.*s'\n", di, dn,
1261 dn->d_name.len, dn->d_name.name); 1279 dn->d_name.len, dn->d_name.name);
1262 if (di) { 1280 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
1263 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc; 1281 spin_lock(&mdsc->dentry_lru_lock);
1264 spin_lock(&mdsc->dentry_lru_lock); 1282 list_add_tail(&di->lru, &mdsc->dentry_lru);
1265 list_add_tail(&di->lru, &mdsc->dentry_lru); 1283 mdsc->num_dentry++;
1266 mdsc->num_dentry++; 1284 spin_unlock(&mdsc->dentry_lru_lock);
1267 spin_unlock(&mdsc->dentry_lru_lock);
1268 }
1269} 1285}
1270 1286
1271void ceph_dentry_lru_touch(struct dentry *dn) 1287void ceph_dentry_lru_touch(struct dentry *dn)
@@ -1275,12 +1291,10 @@ void ceph_dentry_lru_touch(struct dentry *dn)
1275 1291
1276 dout("dentry_lru_touch %p %p '%.*s' (offset %lld)\n", di, dn, 1292 dout("dentry_lru_touch %p %p '%.*s' (offset %lld)\n", di, dn,
1277 dn->d_name.len, dn->d_name.name, di->offset); 1293 dn->d_name.len, dn->d_name.name, di->offset);
1278 if (di) { 1294 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
1279 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc; 1295 spin_lock(&mdsc->dentry_lru_lock);
1280 spin_lock(&mdsc->dentry_lru_lock); 1296 list_move_tail(&di->lru, &mdsc->dentry_lru);
1281 list_move_tail(&di->lru, &mdsc->dentry_lru); 1297 spin_unlock(&mdsc->dentry_lru_lock);
1282 spin_unlock(&mdsc->dentry_lru_lock);
1283 }
1284} 1298}
1285 1299
1286void ceph_dentry_lru_del(struct dentry *dn) 1300void ceph_dentry_lru_del(struct dentry *dn)
@@ -1290,13 +1304,11 @@ void ceph_dentry_lru_del(struct dentry *dn)
1290 1304
1291 dout("dentry_lru_del %p %p '%.*s'\n", di, dn, 1305 dout("dentry_lru_del %p %p '%.*s'\n", di, dn,
1292 dn->d_name.len, dn->d_name.name); 1306 dn->d_name.len, dn->d_name.name);
1293 if (di) { 1307 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
1294 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc; 1308 spin_lock(&mdsc->dentry_lru_lock);
1295 spin_lock(&mdsc->dentry_lru_lock); 1309 list_del_init(&di->lru);
1296 list_del_init(&di->lru); 1310 mdsc->num_dentry--;
1297 mdsc->num_dentry--; 1311 spin_unlock(&mdsc->dentry_lru_lock);
1298 spin_unlock(&mdsc->dentry_lru_lock);
1299 }
1300} 1312}
1301 1313
1302/* 1314/*
diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index 9fbcdecaaccd..fbb2a643ef10 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -56,9 +56,7 @@ static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
56 return -EINVAL; 56 return -EINVAL;
57 57
58 spin_lock(&dentry->d_lock); 58 spin_lock(&dentry->d_lock);
59 parent = dget(dentry->d_parent); 59 parent = dentry->d_parent;
60 spin_unlock(&dentry->d_lock);
61
62 if (*max_len >= connected_handle_length) { 60 if (*max_len >= connected_handle_length) {
63 dout("encode_fh %p connectable\n", dentry); 61 dout("encode_fh %p connectable\n", dentry);
64 cfh->ino = ceph_ino(dentry->d_inode); 62 cfh->ino = ceph_ino(dentry->d_inode);
@@ -81,7 +79,7 @@ static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
81 *max_len = handle_length; 79 *max_len = handle_length;
82 type = 255; 80 type = 255;
83 } 81 }
84 dput(parent); 82 spin_unlock(&dentry->d_lock);
85 return type; 83 return type;
86} 84}
87 85
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 25283e7a37f8..2c489378b4cd 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -850,11 +850,12 @@ static void ceph_set_dentry_offset(struct dentry *dn)
850{ 850{
851 struct dentry *dir = dn->d_parent; 851 struct dentry *dir = dn->d_parent;
852 struct inode *inode = dir->d_inode; 852 struct inode *inode = dir->d_inode;
853 struct ceph_inode_info *ci = ceph_inode(inode); 853 struct ceph_inode_info *ci;
854 struct ceph_dentry_info *di; 854 struct ceph_dentry_info *di;
855 855
856 BUG_ON(!inode); 856 BUG_ON(!inode);
857 857
858 ci = ceph_inode(inode);
858 di = ceph_dentry(dn); 859 di = ceph_dentry(dn);
859 860
860 spin_lock(&ci->i_ceph_lock); 861 spin_lock(&ci->i_ceph_lock);
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 6203d805eb45..23ab6a3f1825 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2772,7 +2772,7 @@ static void handle_lease(struct ceph_mds_client *mdsc,
2772 di = ceph_dentry(dentry); 2772 di = ceph_dentry(dentry);
2773 switch (h->action) { 2773 switch (h->action) {
2774 case CEPH_MDS_LEASE_REVOKE: 2774 case CEPH_MDS_LEASE_REVOKE:
2775 if (di && di->lease_session == session) { 2775 if (di->lease_session == session) {
2776 if (ceph_seq_cmp(di->lease_seq, seq) > 0) 2776 if (ceph_seq_cmp(di->lease_seq, seq) > 0)
2777 h->seq = cpu_to_le32(di->lease_seq); 2777 h->seq = cpu_to_le32(di->lease_seq);
2778 __ceph_mdsc_drop_dentry_lease(dentry); 2778 __ceph_mdsc_drop_dentry_lease(dentry);
@@ -2781,7 +2781,7 @@ static void handle_lease(struct ceph_mds_client *mdsc,
2781 break; 2781 break;
2782 2782
2783 case CEPH_MDS_LEASE_RENEW: 2783 case CEPH_MDS_LEASE_RENEW:
2784 if (di && di->lease_session == session && 2784 if (di->lease_session == session &&
2785 di->lease_gen == session->s_cap_gen && 2785 di->lease_gen == session->s_cap_gen &&
2786 di->lease_renew_from && 2786 di->lease_renew_from &&
2787 di->lease_renew_after == 0) { 2787 di->lease_renew_after == 0) {
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 48f61a12af66..00de2c9568cd 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -131,6 +131,8 @@ enum {
131 Opt_rbytes, 131 Opt_rbytes,
132 Opt_norbytes, 132 Opt_norbytes,
133 Opt_noasyncreaddir, 133 Opt_noasyncreaddir,
134 Opt_dcache,
135 Opt_nodcache,
134 Opt_ino32, 136 Opt_ino32,
135}; 137};
136 138
@@ -152,6 +154,8 @@ static match_table_t fsopt_tokens = {
152 {Opt_rbytes, "rbytes"}, 154 {Opt_rbytes, "rbytes"},
153 {Opt_norbytes, "norbytes"}, 155 {Opt_norbytes, "norbytes"},
154 {Opt_noasyncreaddir, "noasyncreaddir"}, 156 {Opt_noasyncreaddir, "noasyncreaddir"},
157 {Opt_dcache, "dcache"},
158 {Opt_nodcache, "nodcache"},
155 {Opt_ino32, "ino32"}, 159 {Opt_ino32, "ino32"},
156 {-1, NULL} 160 {-1, NULL}
157}; 161};
@@ -231,6 +235,12 @@ static int parse_fsopt_token(char *c, void *private)
231 case Opt_noasyncreaddir: 235 case Opt_noasyncreaddir:
232 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR; 236 fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
233 break; 237 break;
238 case Opt_dcache:
239 fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
240 break;
241 case Opt_nodcache:
242 fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
243 break;
234 case Opt_ino32: 244 case Opt_ino32:
235 fsopt->flags |= CEPH_MOUNT_OPT_INO32; 245 fsopt->flags |= CEPH_MOUNT_OPT_INO32;
236 break; 246 break;
@@ -377,6 +387,10 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)
377 seq_puts(m, ",norbytes"); 387 seq_puts(m, ",norbytes");
378 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR) 388 if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
379 seq_puts(m, ",noasyncreaddir"); 389 seq_puts(m, ",noasyncreaddir");
390 if (fsopt->flags & CEPH_MOUNT_OPT_DCACHE)
391 seq_puts(m, ",dcache");
392 else
393 seq_puts(m, ",nodcache");
380 394
381 if (fsopt->wsize) 395 if (fsopt->wsize)
382 seq_printf(m, ",wsize=%d", fsopt->wsize); 396 seq_printf(m, ",wsize=%d", fsopt->wsize);
@@ -647,10 +661,10 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
647 root = ERR_PTR(-ENOMEM); 661 root = ERR_PTR(-ENOMEM);
648 goto out; 662 goto out;
649 } 663 }
650 ceph_init_dentry(root);
651 } else { 664 } else {
652 root = d_obtain_alias(inode); 665 root = d_obtain_alias(inode);
653 } 666 }
667 ceph_init_dentry(root);
654 dout("open_root_inode success, root dentry is %p\n", root); 668 dout("open_root_inode success, root dentry is %p\n", root);
655 } else { 669 } else {
656 root = ERR_PTR(err); 670 root = ERR_PTR(err);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index cb3652b37271..1421f3d875a2 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -28,6 +28,7 @@
28#define CEPH_MOUNT_OPT_RBYTES (1<<5) /* dir st_bytes = rbytes */ 28#define CEPH_MOUNT_OPT_RBYTES (1<<5) /* dir st_bytes = rbytes */
29#define CEPH_MOUNT_OPT_NOASYNCREADDIR (1<<7) /* no dcache readdir */ 29#define CEPH_MOUNT_OPT_NOASYNCREADDIR (1<<7) /* no dcache readdir */
30#define CEPH_MOUNT_OPT_INO32 (1<<8) /* 32 bit inos */ 30#define CEPH_MOUNT_OPT_INO32 (1<<8) /* 32 bit inos */
31#define CEPH_MOUNT_OPT_DCACHE (1<<9) /* use dcache for readdir etc */
31 32
32#define CEPH_MOUNT_OPT_DEFAULT (CEPH_MOUNT_OPT_RBYTES) 33#define CEPH_MOUNT_OPT_DEFAULT (CEPH_MOUNT_OPT_RBYTES)
33 34
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index a5e36e4488a7..857214ae8c08 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -818,6 +818,7 @@ int ceph_removexattr(struct dentry *dentry, const char *name)
818 struct ceph_vxattr_cb *vxattrs = ceph_inode_vxattrs(inode); 818 struct ceph_vxattr_cb *vxattrs = ceph_inode_vxattrs(inode);
819 int issued; 819 int issued;
820 int err; 820 int err;
821 int required_blob_size;
821 int dirty; 822 int dirty;
822 823
823 if (ceph_snap(inode) != CEPH_NOSNAP) 824 if (ceph_snap(inode) != CEPH_NOSNAP)
@@ -833,14 +834,34 @@ int ceph_removexattr(struct dentry *dentry, const char *name)
833 return -EOPNOTSUPP; 834 return -EOPNOTSUPP;
834 } 835 }
835 836
837 err = -ENOMEM;
836 spin_lock(&ci->i_ceph_lock); 838 spin_lock(&ci->i_ceph_lock);
837 __build_xattrs(inode); 839 __build_xattrs(inode);
840retry:
838 issued = __ceph_caps_issued(ci, NULL); 841 issued = __ceph_caps_issued(ci, NULL);
839 dout("removexattr %p issued %s\n", inode, ceph_cap_string(issued)); 842 dout("removexattr %p issued %s\n", inode, ceph_cap_string(issued));
840 843
841 if (!(issued & CEPH_CAP_XATTR_EXCL)) 844 if (!(issued & CEPH_CAP_XATTR_EXCL))
842 goto do_sync; 845 goto do_sync;
843 846
847 required_blob_size = __get_required_blob_size(ci, 0, 0);
848
849 if (!ci->i_xattrs.prealloc_blob ||
850 required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
851 struct ceph_buffer *blob;
852
853 spin_unlock(&ci->i_ceph_lock);
854 dout(" preaallocating new blob size=%d\n", required_blob_size);
855 blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
856 if (!blob)
857 goto out;
858 spin_lock(&ci->i_ceph_lock);
859 if (ci->i_xattrs.prealloc_blob)
860 ceph_buffer_put(ci->i_xattrs.prealloc_blob);
861 ci->i_xattrs.prealloc_blob = blob;
862 goto retry;
863 }
864
844 err = __remove_xattr_by_name(ceph_inode(inode), name); 865 err = __remove_xattr_by_name(ceph_inode(inode), name);
845 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL); 866 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
846 ci->i_xattrs.dirty = true; 867 ci->i_xattrs.dirty = true;
@@ -853,6 +874,7 @@ int ceph_removexattr(struct dentry *dentry, const char *name)
853do_sync: 874do_sync:
854 spin_unlock(&ci->i_ceph_lock); 875 spin_unlock(&ci->i_ceph_lock);
855 err = ceph_send_removexattr(dentry, name); 876 err = ceph_send_removexattr(dentry, name);
877out:
856 return err; 878 return err;
857} 879}
858 880
diff --git a/fs/dcache.c b/fs/dcache.c
index 616fedff011a..16a53cc2cc02 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1475,7 +1475,14 @@ static struct dentry * __d_find_any_alias(struct inode *inode)
1475 return alias; 1475 return alias;
1476} 1476}
1477 1477
1478static struct dentry * d_find_any_alias(struct inode *inode) 1478/**
1479 * d_find_any_alias - find any alias for a given inode
1480 * @inode: inode to find an alias for
1481 *
1482 * If any aliases exist for the given inode, take and return a
1483 * reference for one of them. If no aliases exist, return %NULL.
1484 */
1485struct dentry *d_find_any_alias(struct inode *inode)
1479{ 1486{
1480 struct dentry *de; 1487 struct dentry *de;
1481 1488
@@ -1484,7 +1491,7 @@ static struct dentry * d_find_any_alias(struct inode *inode)
1484 spin_unlock(&inode->i_lock); 1491 spin_unlock(&inode->i_lock);
1485 return de; 1492 return de;
1486} 1493}
1487 1494EXPORT_SYMBOL(d_find_any_alias);
1488 1495
1489/** 1496/**
1490 * d_obtain_alias - find or allocate a dentry for a given inode 1497 * d_obtain_alias - find or allocate a dentry for a given inode
diff --git a/fs/direct-io.c b/fs/direct-io.c
index d740ab67ff6e..4a588dbd11bf 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -36,6 +36,7 @@
36#include <linux/rwsem.h> 36#include <linux/rwsem.h>
37#include <linux/uio.h> 37#include <linux/uio.h>
38#include <linux/atomic.h> 38#include <linux/atomic.h>
39#include <linux/prefetch.h>
39 40
40/* 41/*
41 * How many user pages to map in one call to get_user_pages(). This determines 42 * How many user pages to map in one call to get_user_pages(). This determines
@@ -580,9 +581,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
580{ 581{
581 int ret; 582 int ret;
582 sector_t fs_startblk; /* Into file, in filesystem-sized blocks */ 583 sector_t fs_startblk; /* Into file, in filesystem-sized blocks */
584 sector_t fs_endblk; /* Into file, in filesystem-sized blocks */
583 unsigned long fs_count; /* Number of filesystem-sized blocks */ 585 unsigned long fs_count; /* Number of filesystem-sized blocks */
584 unsigned long dio_count;/* Number of dio_block-sized blocks */
585 unsigned long blkmask;
586 int create; 586 int create;
587 587
588 /* 588 /*
@@ -593,11 +593,9 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
593 if (ret == 0) { 593 if (ret == 0) {
594 BUG_ON(sdio->block_in_file >= sdio->final_block_in_request); 594 BUG_ON(sdio->block_in_file >= sdio->final_block_in_request);
595 fs_startblk = sdio->block_in_file >> sdio->blkfactor; 595 fs_startblk = sdio->block_in_file >> sdio->blkfactor;
596 dio_count = sdio->final_block_in_request - sdio->block_in_file; 596 fs_endblk = (sdio->final_block_in_request - 1) >>
597 fs_count = dio_count >> sdio->blkfactor; 597 sdio->blkfactor;
598 blkmask = (1 << sdio->blkfactor) - 1; 598 fs_count = fs_endblk - fs_startblk + 1;
599 if (dio_count & blkmask)
600 fs_count++;
601 599
602 map_bh->b_state = 0; 600 map_bh->b_state = 0;
603 map_bh->b_size = fs_count << dio->inode->i_blkbits; 601 map_bh->b_size = fs_count << dio->inode->i_blkbits;
@@ -1090,8 +1088,8 @@ static inline int drop_refcount(struct dio *dio)
1090 * individual fields and will generate much worse code. This is important 1088 * individual fields and will generate much worse code. This is important
1091 * for the whole file. 1089 * for the whole file.
1092 */ 1090 */
1093ssize_t 1091static inline ssize_t
1094__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, 1092do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1095 struct block_device *bdev, const struct iovec *iov, loff_t offset, 1093 struct block_device *bdev, const struct iovec *iov, loff_t offset,
1096 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, 1094 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
1097 dio_submit_t submit_io, int flags) 1095 dio_submit_t submit_io, int flags)
@@ -1100,7 +1098,6 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1100 size_t size; 1098 size_t size;
1101 unsigned long addr; 1099 unsigned long addr;
1102 unsigned blkbits = inode->i_blkbits; 1100 unsigned blkbits = inode->i_blkbits;
1103 unsigned bdev_blkbits = 0;
1104 unsigned blocksize_mask = (1 << blkbits) - 1; 1101 unsigned blocksize_mask = (1 << blkbits) - 1;
1105 ssize_t retval = -EINVAL; 1102 ssize_t retval = -EINVAL;
1106 loff_t end = offset; 1103 loff_t end = offset;
@@ -1113,12 +1110,14 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1113 if (rw & WRITE) 1110 if (rw & WRITE)
1114 rw = WRITE_ODIRECT; 1111 rw = WRITE_ODIRECT;
1115 1112
1116 if (bdev) 1113 /*
1117 bdev_blkbits = blksize_bits(bdev_logical_block_size(bdev)); 1114 * Avoid references to bdev if not absolutely needed to give
1115 * the early prefetch in the caller enough time.
1116 */
1118 1117
1119 if (offset & blocksize_mask) { 1118 if (offset & blocksize_mask) {
1120 if (bdev) 1119 if (bdev)
1121 blkbits = bdev_blkbits; 1120 blkbits = blksize_bits(bdev_logical_block_size(bdev));
1122 blocksize_mask = (1 << blkbits) - 1; 1121 blocksize_mask = (1 << blkbits) - 1;
1123 if (offset & blocksize_mask) 1122 if (offset & blocksize_mask)
1124 goto out; 1123 goto out;
@@ -1129,11 +1128,13 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1129 addr = (unsigned long)iov[seg].iov_base; 1128 addr = (unsigned long)iov[seg].iov_base;
1130 size = iov[seg].iov_len; 1129 size = iov[seg].iov_len;
1131 end += size; 1130 end += size;
1132 if ((addr & blocksize_mask) || (size & blocksize_mask)) { 1131 if (unlikely((addr & blocksize_mask) ||
1132 (size & blocksize_mask))) {
1133 if (bdev) 1133 if (bdev)
1134 blkbits = bdev_blkbits; 1134 blkbits = blksize_bits(
1135 bdev_logical_block_size(bdev));
1135 blocksize_mask = (1 << blkbits) - 1; 1136 blocksize_mask = (1 << blkbits) - 1;
1136 if ((addr & blocksize_mask) || (size & blocksize_mask)) 1137 if ((addr & blocksize_mask) || (size & blocksize_mask))
1137 goto out; 1138 goto out;
1138 } 1139 }
1139 } 1140 }
@@ -1316,6 +1317,30 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1316out: 1317out:
1317 return retval; 1318 return retval;
1318} 1319}
1320
1321ssize_t
1322__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1323 struct block_device *bdev, const struct iovec *iov, loff_t offset,
1324 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
1325 dio_submit_t submit_io, int flags)
1326{
1327 /*
1328 * The block device state is needed in the end to finally
1329 * submit everything. Since it's likely to be cache cold
1330 * prefetch it here as first thing to hide some of the
1331 * latency.
1332 *
1333 * Attempt to prefetch the pieces we likely need later.
1334 */
1335 prefetch(&bdev->bd_disk->part_tbl);
1336 prefetch(bdev->bd_queue);
1337 prefetch((char *)bdev->bd_queue + SMP_CACHE_BYTES);
1338
1339 return do_blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1340 nr_segs, get_block, end_io,
1341 submit_io, flags);
1342}
1343
1319EXPORT_SYMBOL(__blockdev_direct_IO); 1344EXPORT_SYMBOL(__blockdev_direct_IO);
1320 1345
1321static __init int dio_init(void) 1346static __init int dio_init(void)
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 828e750af23a..aabdfc38cf24 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -197,6 +197,12 @@ struct eventpoll {
197 197
198 /* The user that created the eventpoll descriptor */ 198 /* The user that created the eventpoll descriptor */
199 struct user_struct *user; 199 struct user_struct *user;
200
201 struct file *file;
202
203 /* used to optimize loop detection check */
204 int visited;
205 struct list_head visited_list_link;
200}; 206};
201 207
202/* Wait structure used by the poll hooks */ 208/* Wait structure used by the poll hooks */
@@ -255,6 +261,15 @@ static struct kmem_cache *epi_cache __read_mostly;
255/* Slab cache used to allocate "struct eppoll_entry" */ 261/* Slab cache used to allocate "struct eppoll_entry" */
256static struct kmem_cache *pwq_cache __read_mostly; 262static struct kmem_cache *pwq_cache __read_mostly;
257 263
264/* Visited nodes during ep_loop_check(), so we can unset them when we finish */
265static LIST_HEAD(visited_list);
266
267/*
268 * List of files with newly added links, where we may need to limit the number
269 * of emanating paths. Protected by the epmutex.
270 */
271static LIST_HEAD(tfile_check_list);
272
258#ifdef CONFIG_SYSCTL 273#ifdef CONFIG_SYSCTL
259 274
260#include <linux/sysctl.h> 275#include <linux/sysctl.h>
@@ -276,6 +291,12 @@ ctl_table epoll_table[] = {
276}; 291};
277#endif /* CONFIG_SYSCTL */ 292#endif /* CONFIG_SYSCTL */
278 293
294static const struct file_operations eventpoll_fops;
295
296static inline int is_file_epoll(struct file *f)
297{
298 return f->f_op == &eventpoll_fops;
299}
279 300
280/* Setup the structure that is used as key for the RB tree */ 301/* Setup the structure that is used as key for the RB tree */
281static inline void ep_set_ffd(struct epoll_filefd *ffd, 302static inline void ep_set_ffd(struct epoll_filefd *ffd,
@@ -711,12 +732,6 @@ static const struct file_operations eventpoll_fops = {
711 .llseek = noop_llseek, 732 .llseek = noop_llseek,
712}; 733};
713 734
714/* Fast test to see if the file is an eventpoll file */
715static inline int is_file_epoll(struct file *f)
716{
717 return f->f_op == &eventpoll_fops;
718}
719
720/* 735/*
721 * This is called from eventpoll_release() to unlink files from the eventpoll 736 * This is called from eventpoll_release() to unlink files from the eventpoll
722 * interface. We need to have this facility to cleanup correctly files that are 737 * interface. We need to have this facility to cleanup correctly files that are
@@ -926,6 +941,99 @@ static void ep_rbtree_insert(struct eventpoll *ep, struct epitem *epi)
926 rb_insert_color(&epi->rbn, &ep->rbr); 941 rb_insert_color(&epi->rbn, &ep->rbr);
927} 942}
928 943
944
945
946#define PATH_ARR_SIZE 5
947/*
948 * These are the number paths of length 1 to 5, that we are allowing to emanate
949 * from a single file of interest. For example, we allow 1000 paths of length
950 * 1, to emanate from each file of interest. This essentially represents the
951 * potential wakeup paths, which need to be limited in order to avoid massive
952 * uncontrolled wakeup storms. The common use case should be a single ep which
953 * is connected to n file sources. In this case each file source has 1 path
954 * of length 1. Thus, the numbers below should be more than sufficient. These
955 * path limits are enforced during an EPOLL_CTL_ADD operation, since a modify
956 * and delete can't add additional paths. Protected by the epmutex.
957 */
958static const int path_limits[PATH_ARR_SIZE] = { 1000, 500, 100, 50, 10 };
959static int path_count[PATH_ARR_SIZE];
960
961static int path_count_inc(int nests)
962{
963 if (++path_count[nests] > path_limits[nests])
964 return -1;
965 return 0;
966}
967
968static void path_count_init(void)
969{
970 int i;
971
972 for (i = 0; i < PATH_ARR_SIZE; i++)
973 path_count[i] = 0;
974}
975
976static int reverse_path_check_proc(void *priv, void *cookie, int call_nests)
977{
978 int error = 0;
979 struct file *file = priv;
980 struct file *child_file;
981 struct epitem *epi;
982
983 list_for_each_entry(epi, &file->f_ep_links, fllink) {
984 child_file = epi->ep->file;
985 if (is_file_epoll(child_file)) {
986 if (list_empty(&child_file->f_ep_links)) {
987 if (path_count_inc(call_nests)) {
988 error = -1;
989 break;
990 }
991 } else {
992 error = ep_call_nested(&poll_loop_ncalls,
993 EP_MAX_NESTS,
994 reverse_path_check_proc,
995 child_file, child_file,
996 current);
997 }
998 if (error != 0)
999 break;
1000 } else {
1001 printk(KERN_ERR "reverse_path_check_proc: "
1002 "file is not an ep!\n");
1003 }
1004 }
1005 return error;
1006}
1007
1008/**
1009 * reverse_path_check - The tfile_check_list is list of file *, which have
1010 * links that are proposed to be newly added. We need to
1011 * make sure that those added links don't add too many
1012 * paths such that we will spend all our time waking up
1013 * eventpoll objects.
1014 *
1015 * Returns: Returns zero if the proposed links don't create too many paths,
1016 * -1 otherwise.
1017 */
1018static int reverse_path_check(void)
1019{
1020 int length = 0;
1021 int error = 0;
1022 struct file *current_file;
1023
1024 /* let's call this for all tfiles */
1025 list_for_each_entry(current_file, &tfile_check_list, f_tfile_llink) {
1026 length++;
1027 path_count_init();
1028 error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS,
1029 reverse_path_check_proc, current_file,
1030 current_file, current);
1031 if (error)
1032 break;
1033 }
1034 return error;
1035}
1036
929/* 1037/*
930 * Must be called with "mtx" held. 1038 * Must be called with "mtx" held.
931 */ 1039 */
@@ -987,6 +1095,11 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
987 */ 1095 */
988 ep_rbtree_insert(ep, epi); 1096 ep_rbtree_insert(ep, epi);
989 1097
1098 /* now check if we've created too many backpaths */
1099 error = -EINVAL;
1100 if (reverse_path_check())
1101 goto error_remove_epi;
1102
990 /* We have to drop the new item inside our item list to keep track of it */ 1103 /* We have to drop the new item inside our item list to keep track of it */
991 spin_lock_irqsave(&ep->lock, flags); 1104 spin_lock_irqsave(&ep->lock, flags);
992 1105
@@ -1011,6 +1124,14 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
1011 1124
1012 return 0; 1125 return 0;
1013 1126
1127error_remove_epi:
1128 spin_lock(&tfile->f_lock);
1129 if (ep_is_linked(&epi->fllink))
1130 list_del_init(&epi->fllink);
1131 spin_unlock(&tfile->f_lock);
1132
1133 rb_erase(&epi->rbn, &ep->rbr);
1134
1014error_unregister: 1135error_unregister:
1015 ep_unregister_pollwait(ep, epi); 1136 ep_unregister_pollwait(ep, epi);
1016 1137
@@ -1275,18 +1396,36 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
1275 int error = 0; 1396 int error = 0;
1276 struct file *file = priv; 1397 struct file *file = priv;
1277 struct eventpoll *ep = file->private_data; 1398 struct eventpoll *ep = file->private_data;
1399 struct eventpoll *ep_tovisit;
1278 struct rb_node *rbp; 1400 struct rb_node *rbp;
1279 struct epitem *epi; 1401 struct epitem *epi;
1280 1402
1281 mutex_lock_nested(&ep->mtx, call_nests + 1); 1403 mutex_lock_nested(&ep->mtx, call_nests + 1);
1404 ep->visited = 1;
1405 list_add(&ep->visited_list_link, &visited_list);
1282 for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) { 1406 for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) {
1283 epi = rb_entry(rbp, struct epitem, rbn); 1407 epi = rb_entry(rbp, struct epitem, rbn);
1284 if (unlikely(is_file_epoll(epi->ffd.file))) { 1408 if (unlikely(is_file_epoll(epi->ffd.file))) {
1409 ep_tovisit = epi->ffd.file->private_data;
1410 if (ep_tovisit->visited)
1411 continue;
1285 error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS, 1412 error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS,
1286 ep_loop_check_proc, epi->ffd.file, 1413 ep_loop_check_proc, epi->ffd.file,
1287 epi->ffd.file->private_data, current); 1414 ep_tovisit, current);
1288 if (error != 0) 1415 if (error != 0)
1289 break; 1416 break;
1417 } else {
1418 /*
1419 * If we've reached a file that is not associated with
1420 * an ep, then we need to check if the newly added
1421 * links are going to add too many wakeup paths. We do
1422 * this by adding it to the tfile_check_list, if it's
1423 * not already there, and calling reverse_path_check()
1424 * during ep_insert().
1425 */
1426 if (list_empty(&epi->ffd.file->f_tfile_llink))
1427 list_add(&epi->ffd.file->f_tfile_llink,
1428 &tfile_check_list);
1290 } 1429 }
1291 } 1430 }
1292 mutex_unlock(&ep->mtx); 1431 mutex_unlock(&ep->mtx);
@@ -1307,8 +1446,31 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
1307 */ 1446 */
1308static int ep_loop_check(struct eventpoll *ep, struct file *file) 1447static int ep_loop_check(struct eventpoll *ep, struct file *file)
1309{ 1448{
1310 return ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS, 1449 int ret;
1450 struct eventpoll *ep_cur, *ep_next;
1451
1452 ret = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS,
1311 ep_loop_check_proc, file, ep, current); 1453 ep_loop_check_proc, file, ep, current);
1454 /* clear visited list */
1455 list_for_each_entry_safe(ep_cur, ep_next, &visited_list,
1456 visited_list_link) {
1457 ep_cur->visited = 0;
1458 list_del(&ep_cur->visited_list_link);
1459 }
1460 return ret;
1461}
1462
1463static void clear_tfile_check_list(void)
1464{
1465 struct file *file;
1466
1467 /* first clear the tfile_check_list */
1468 while (!list_empty(&tfile_check_list)) {
1469 file = list_first_entry(&tfile_check_list, struct file,
1470 f_tfile_llink);
1471 list_del_init(&file->f_tfile_llink);
1472 }
1473 INIT_LIST_HEAD(&tfile_check_list);
1312} 1474}
1313 1475
1314/* 1476/*
@@ -1316,8 +1478,9 @@ static int ep_loop_check(struct eventpoll *ep, struct file *file)
1316 */ 1478 */
1317SYSCALL_DEFINE1(epoll_create1, int, flags) 1479SYSCALL_DEFINE1(epoll_create1, int, flags)
1318{ 1480{
1319 int error; 1481 int error, fd;
1320 struct eventpoll *ep = NULL; 1482 struct eventpoll *ep = NULL;
1483 struct file *file;
1321 1484
1322 /* Check the EPOLL_* constant for consistency. */ 1485 /* Check the EPOLL_* constant for consistency. */
1323 BUILD_BUG_ON(EPOLL_CLOEXEC != O_CLOEXEC); 1486 BUILD_BUG_ON(EPOLL_CLOEXEC != O_CLOEXEC);
@@ -1334,11 +1497,25 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
1334 * Creates all the items needed to setup an eventpoll file. That is, 1497 * Creates all the items needed to setup an eventpoll file. That is,
1335 * a file structure and a free file descriptor. 1498 * a file structure and a free file descriptor.
1336 */ 1499 */
1337 error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep, 1500 fd = get_unused_fd_flags(O_RDWR | (flags & O_CLOEXEC));
1501 if (fd < 0) {
1502 error = fd;
1503 goto out_free_ep;
1504 }
1505 file = anon_inode_getfile("[eventpoll]", &eventpoll_fops, ep,
1338 O_RDWR | (flags & O_CLOEXEC)); 1506 O_RDWR | (flags & O_CLOEXEC));
1339 if (error < 0) 1507 if (IS_ERR(file)) {
1340 ep_free(ep); 1508 error = PTR_ERR(file);
1341 1509 goto out_free_fd;
1510 }
1511 fd_install(fd, file);
1512 ep->file = file;
1513 return fd;
1514
1515out_free_fd:
1516 put_unused_fd(fd);
1517out_free_ep:
1518 ep_free(ep);
1342 return error; 1519 return error;
1343} 1520}
1344 1521
@@ -1404,21 +1581,27 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1404 /* 1581 /*
1405 * When we insert an epoll file descriptor, inside another epoll file 1582 * When we insert an epoll file descriptor, inside another epoll file
1406 * descriptor, there is the change of creating closed loops, which are 1583 * descriptor, there is the change of creating closed loops, which are
1407 * better be handled here, than in more critical paths. 1584 * better be handled here, than in more critical paths. While we are
1585 * checking for loops we also determine the list of files reachable
1586 * and hang them on the tfile_check_list, so we can check that we
1587 * haven't created too many possible wakeup paths.
1408 * 1588 *
1409 * We hold epmutex across the loop check and the insert in this case, in 1589 * We need to hold the epmutex across both ep_insert and ep_remove
1410 * order to prevent two separate inserts from racing and each doing the 1590 * b/c we want to make sure we are looking at a coherent view of
1411 * insert "at the same time" such that ep_loop_check passes on both 1591 * epoll network.
1412 * before either one does the insert, thereby creating a cycle.
1413 */ 1592 */
1414 if (unlikely(is_file_epoll(tfile) && op == EPOLL_CTL_ADD)) { 1593 if (op == EPOLL_CTL_ADD || op == EPOLL_CTL_DEL) {
1415 mutex_lock(&epmutex); 1594 mutex_lock(&epmutex);
1416 did_lock_epmutex = 1; 1595 did_lock_epmutex = 1;
1417 error = -ELOOP;
1418 if (ep_loop_check(ep, tfile) != 0)
1419 goto error_tgt_fput;
1420 } 1596 }
1421 1597 if (op == EPOLL_CTL_ADD) {
1598 if (is_file_epoll(tfile)) {
1599 error = -ELOOP;
1600 if (ep_loop_check(ep, tfile) != 0)
1601 goto error_tgt_fput;
1602 } else
1603 list_add(&tfile->f_tfile_llink, &tfile_check_list);
1604 }
1422 1605
1423 mutex_lock_nested(&ep->mtx, 0); 1606 mutex_lock_nested(&ep->mtx, 0);
1424 1607
@@ -1437,6 +1620,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1437 error = ep_insert(ep, &epds, tfile, fd); 1620 error = ep_insert(ep, &epds, tfile, fd);
1438 } else 1621 } else
1439 error = -EEXIST; 1622 error = -EEXIST;
1623 clear_tfile_check_list();
1440 break; 1624 break;
1441 case EPOLL_CTL_DEL: 1625 case EPOLL_CTL_DEL:
1442 if (epi) 1626 if (epi)
@@ -1455,7 +1639,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1455 mutex_unlock(&ep->mtx); 1639 mutex_unlock(&ep->mtx);
1456 1640
1457error_tgt_fput: 1641error_tgt_fput:
1458 if (unlikely(did_lock_epmutex)) 1642 if (did_lock_epmutex)
1459 mutex_unlock(&epmutex); 1643 mutex_unlock(&epmutex);
1460 1644
1461 fput(tfile); 1645 fput(tfile);
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 88e8a23d0026..376816fcd040 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1353,7 +1353,7 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
1353 spin_lock(&gl->gl_spin); 1353 spin_lock(&gl->gl_spin);
1354 gl->gl_reply = ret; 1354 gl->gl_reply = ret;
1355 1355
1356 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))) { 1356 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))) {
1357 if (gfs2_should_freeze(gl)) { 1357 if (gfs2_should_freeze(gl)) {
1358 set_bit(GLF_FROZEN, &gl->gl_flags); 1358 set_bit(GLF_FROZEN, &gl->gl_flags);
1359 spin_unlock(&gl->gl_spin); 1359 spin_unlock(&gl->gl_spin);
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 2553b858a72e..307ac31df781 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -121,8 +121,11 @@ enum {
121 121
122struct lm_lockops { 122struct lm_lockops {
123 const char *lm_proto_name; 123 const char *lm_proto_name;
124 int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname); 124 int (*lm_mount) (struct gfs2_sbd *sdp, const char *table);
125 void (*lm_unmount) (struct gfs2_sbd *sdp); 125 void (*lm_first_done) (struct gfs2_sbd *sdp);
126 void (*lm_recovery_result) (struct gfs2_sbd *sdp, unsigned int jid,
127 unsigned int result);
128 void (*lm_unmount) (struct gfs2_sbd *sdp);
126 void (*lm_withdraw) (struct gfs2_sbd *sdp); 129 void (*lm_withdraw) (struct gfs2_sbd *sdp);
127 void (*lm_put_lock) (struct gfs2_glock *gl); 130 void (*lm_put_lock) (struct gfs2_glock *gl);
128 int (*lm_lock) (struct gfs2_glock *gl, unsigned int req_state, 131 int (*lm_lock) (struct gfs2_glock *gl, unsigned int req_state,
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index e1d3bb59945c..97742a7ea9cc 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -139,8 +139,45 @@ struct gfs2_bufdata {
139#define GDLM_STRNAME_BYTES 25 139#define GDLM_STRNAME_BYTES 25
140#define GDLM_LVB_SIZE 32 140#define GDLM_LVB_SIZE 32
141 141
142/*
143 * ls_recover_flags:
144 *
145 * DFL_BLOCK_LOCKS: dlm is in recovery and will grant locks that had been
146 * held by failed nodes whose journals need recovery. Those locks should
147 * only be used for journal recovery until the journal recovery is done.
148 * This is set by the dlm recover_prep callback and cleared by the
149 * gfs2_control thread when journal recovery is complete. To avoid
150 * races between recover_prep setting and gfs2_control clearing, recover_spin
151 * is held while changing this bit and reading/writing recover_block
152 * and recover_start.
153 *
154 * DFL_NO_DLM_OPS: dlm lockspace ops/callbacks are not being used.
155 *
156 * DFL_FIRST_MOUNT: this node is the first to mount this fs and is doing
157 * recovery of all journals before allowing other nodes to mount the fs.
158 * This is cleared when FIRST_MOUNT_DONE is set.
159 *
160 * DFL_FIRST_MOUNT_DONE: this node was the first mounter, and has finished
161 * recovery of all journals, and now allows other nodes to mount the fs.
162 *
163 * DFL_MOUNT_DONE: gdlm_mount has completed successfully and cleared
164 * BLOCK_LOCKS for the first time. The gfs2_control thread should now
165 * control clearing BLOCK_LOCKS for further recoveries.
166 *
167 * DFL_UNMOUNT: gdlm_unmount sets to keep sdp off gfs2_control_wq.
168 *
169 * DFL_DLM_RECOVERY: set while dlm is in recovery, between recover_prep()
170 * and recover_done(), i.e. set while recover_block == recover_start.
171 */
172
142enum { 173enum {
143 DFL_BLOCK_LOCKS = 0, 174 DFL_BLOCK_LOCKS = 0,
175 DFL_NO_DLM_OPS = 1,
176 DFL_FIRST_MOUNT = 2,
177 DFL_FIRST_MOUNT_DONE = 3,
178 DFL_MOUNT_DONE = 4,
179 DFL_UNMOUNT = 5,
180 DFL_DLM_RECOVERY = 6,
144}; 181};
145 182
146struct lm_lockname { 183struct lm_lockname {
@@ -392,6 +429,7 @@ struct gfs2_jdesc {
392#define JDF_RECOVERY 1 429#define JDF_RECOVERY 1
393 unsigned int jd_jid; 430 unsigned int jd_jid;
394 unsigned int jd_blocks; 431 unsigned int jd_blocks;
432 int jd_recover_error;
395}; 433};
396 434
397struct gfs2_statfs_change_host { 435struct gfs2_statfs_change_host {
@@ -461,6 +499,7 @@ enum {
461 SDF_NORECOVERY = 4, 499 SDF_NORECOVERY = 4,
462 SDF_DEMOTE = 5, 500 SDF_DEMOTE = 5,
463 SDF_NOJOURNALID = 6, 501 SDF_NOJOURNALID = 6,
502 SDF_RORECOVERY = 7, /* read only recovery */
464}; 503};
465 504
466#define GFS2_FSNAME_LEN 256 505#define GFS2_FSNAME_LEN 256
@@ -499,14 +538,26 @@ struct gfs2_sb_host {
499struct lm_lockstruct { 538struct lm_lockstruct {
500 int ls_jid; 539 int ls_jid;
501 unsigned int ls_first; 540 unsigned int ls_first;
502 unsigned int ls_first_done;
503 unsigned int ls_nodir; 541 unsigned int ls_nodir;
504 const struct lm_lockops *ls_ops; 542 const struct lm_lockops *ls_ops;
505 unsigned long ls_flags;
506 dlm_lockspace_t *ls_dlm; 543 dlm_lockspace_t *ls_dlm;
507 544
508 int ls_recover_jid_done; 545 int ls_recover_jid_done; /* These two are deprecated, */
509 int ls_recover_jid_status; 546 int ls_recover_jid_status; /* used previously by gfs_controld */
547
548 struct dlm_lksb ls_mounted_lksb; /* mounted_lock */
549 struct dlm_lksb ls_control_lksb; /* control_lock */
550 char ls_control_lvb[GDLM_LVB_SIZE]; /* control_lock lvb */
551 struct completion ls_sync_wait; /* {control,mounted}_{lock,unlock} */
552
553 spinlock_t ls_recover_spin; /* protects following fields */
554 unsigned long ls_recover_flags; /* DFL_ */
555 uint32_t ls_recover_mount; /* gen in first recover_done cb */
556 uint32_t ls_recover_start; /* gen in last recover_done cb */
557 uint32_t ls_recover_block; /* copy recover_start in last recover_prep */
558 uint32_t ls_recover_size; /* size of recover_submit, recover_result */
559 uint32_t *ls_recover_submit; /* gen in last recover_slot cb per jid */
560 uint32_t *ls_recover_result; /* result of last jid recovery */
510}; 561};
511 562
512struct gfs2_sbd { 563struct gfs2_sbd {
@@ -544,6 +595,7 @@ struct gfs2_sbd {
544 wait_queue_head_t sd_glock_wait; 595 wait_queue_head_t sd_glock_wait;
545 atomic_t sd_glock_disposal; 596 atomic_t sd_glock_disposal;
546 struct completion sd_locking_init; 597 struct completion sd_locking_init;
598 struct delayed_work sd_control_work;
547 599
548 /* Inode Stuff */ 600 /* Inode Stuff */
549 601
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 017960cf1d7a..a7d611b93f0f 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -599,9 +599,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
599 error = gfs2_meta_inode_buffer(ip, &dibh); 599 error = gfs2_meta_inode_buffer(ip, &dibh);
600 if (error) 600 if (error)
601 goto fail_end_trans; 601 goto fail_end_trans;
602 inc_nlink(&ip->i_inode); 602 set_nlink(&ip->i_inode, S_ISDIR(ip->i_inode.i_mode) ? 2 : 1);
603 if (S_ISDIR(ip->i_inode.i_mode))
604 inc_nlink(&ip->i_inode);
605 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 603 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
606 gfs2_dinode_out(ip, dibh->b_data); 604 gfs2_dinode_out(ip, dibh->b_data);
607 brelse(dibh); 605 brelse(dibh);
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c
index ce85b62bc0a2..8944d1e32ab5 100644
--- a/fs/gfs2/lock_dlm.c
+++ b/fs/gfs2/lock_dlm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. 3 * Copyright 2004-2011 Red Hat, Inc.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -11,12 +11,15 @@
11#include <linux/dlm.h> 11#include <linux/dlm.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/delay.h>
14#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
15 16
16#include "incore.h" 17#include "incore.h"
17#include "glock.h" 18#include "glock.h"
18#include "util.h" 19#include "util.h"
20#include "sys.h"
19 21
22extern struct workqueue_struct *gfs2_control_wq;
20 23
21static void gdlm_ast(void *arg) 24static void gdlm_ast(void *arg)
22{ 25{
@@ -185,34 +188,1002 @@ static void gdlm_cancel(struct gfs2_glock *gl)
185 dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl); 188 dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl);
186} 189}
187 190
188static int gdlm_mount(struct gfs2_sbd *sdp, const char *fsname) 191/*
192 * dlm/gfs2 recovery coordination using dlm_recover callbacks
193 *
194 * 1. dlm_controld sees lockspace members change
195 * 2. dlm_controld blocks dlm-kernel locking activity
196 * 3. dlm_controld within dlm-kernel notifies gfs2 (recover_prep)
197 * 4. dlm_controld starts and finishes its own user level recovery
198 * 5. dlm_controld starts dlm-kernel dlm_recoverd to do kernel recovery
199 * 6. dlm_recoverd notifies gfs2 of failed nodes (recover_slot)
200 * 7. dlm_recoverd does its own lock recovery
201 * 8. dlm_recoverd unblocks dlm-kernel locking activity
202 * 9. dlm_recoverd notifies gfs2 when done (recover_done with new generation)
203 * 10. gfs2_control updates control_lock lvb with new generation and jid bits
204 * 11. gfs2_control enqueues journals for gfs2_recover to recover (maybe none)
205 * 12. gfs2_recover dequeues and recovers journals of failed nodes
206 * 13. gfs2_recover provides recovery results to gfs2_control (recovery_result)
207 * 14. gfs2_control updates control_lock lvb jid bits for recovered journals
208 * 15. gfs2_control unblocks normal locking when all journals are recovered
209 *
210 * - failures during recovery
211 *
212 * recover_prep() may set BLOCK_LOCKS (step 3) again before gfs2_control
213 * clears BLOCK_LOCKS (step 15), e.g. another node fails while still
214 * recovering for a prior failure. gfs2_control needs a way to detect
215 * this so it can leave BLOCK_LOCKS set in step 15. This is managed using
216 * the recover_block and recover_start values.
217 *
218 * recover_done() provides a new lockspace generation number each time it
219 * is called (step 9). This generation number is saved as recover_start.
220 * When recover_prep() is called, it sets BLOCK_LOCKS and sets
221 * recover_block = recover_start. So, while recover_block is equal to
222 * recover_start, BLOCK_LOCKS should remain set. (recover_spin must
223 * be held around the BLOCK_LOCKS/recover_block/recover_start logic.)
224 *
225 * - more specific gfs2 steps in sequence above
226 *
227 * 3. recover_prep sets BLOCK_LOCKS and sets recover_block = recover_start
228 * 6. recover_slot records any failed jids (maybe none)
229 * 9. recover_done sets recover_start = new generation number
230 * 10. gfs2_control sets control_lock lvb = new gen + bits for failed jids
231 * 12. gfs2_recover does journal recoveries for failed jids identified above
232 * 14. gfs2_control clears control_lock lvb bits for recovered jids
233 * 15. gfs2_control checks if recover_block == recover_start (step 3 occured
234 * again) then do nothing, otherwise if recover_start > recover_block
235 * then clear BLOCK_LOCKS.
236 *
237 * - parallel recovery steps across all nodes
238 *
239 * All nodes attempt to update the control_lock lvb with the new generation
240 * number and jid bits, but only the first to get the control_lock EX will
241 * do so; others will see that it's already done (lvb already contains new
242 * generation number.)
243 *
244 * . All nodes get the same recover_prep/recover_slot/recover_done callbacks
245 * . All nodes attempt to set control_lock lvb gen + bits for the new gen
246 * . One node gets control_lock first and writes the lvb, others see it's done
247 * . All nodes attempt to recover jids for which they see control_lock bits set
248 * . One node succeeds for a jid, and that one clears the jid bit in the lvb
249 * . All nodes will eventually see all lvb bits clear and unblock locks
250 *
251 * - is there a problem with clearing an lvb bit that should be set
252 * and missing a journal recovery?
253 *
254 * 1. jid fails
255 * 2. lvb bit set for step 1
256 * 3. jid recovered for step 1
257 * 4. jid taken again (new mount)
258 * 5. jid fails (for step 4)
259 * 6. lvb bit set for step 5 (will already be set)
260 * 7. lvb bit cleared for step 3
261 *
262 * This is not a problem because the failure in step 5 does not
263 * require recovery, because the mount in step 4 could not have
264 * progressed far enough to unblock locks and access the fs. The
265 * control_mount() function waits for all recoveries to be complete
266 * for the latest lockspace generation before ever unblocking locks
267 * and returning. The mount in step 4 waits until the recovery in
268 * step 1 is done.
269 *
270 * - special case of first mounter: first node to mount the fs
271 *
272 * The first node to mount a gfs2 fs needs to check all the journals
273 * and recover any that need recovery before other nodes are allowed
274 * to mount the fs. (Others may begin mounting, but they must wait
275 * for the first mounter to be done before taking locks on the fs
276 * or accessing the fs.) This has two parts:
277 *
278 * 1. The mounted_lock tells a node it's the first to mount the fs.
279 * Each node holds the mounted_lock in PR while it's mounted.
280 * Each node tries to acquire the mounted_lock in EX when it mounts.
281 * If a node is granted the mounted_lock EX it means there are no
282 * other mounted nodes (no PR locks exist), and it is the first mounter.
283 * The mounted_lock is demoted to PR when first recovery is done, so
284 * others will fail to get an EX lock, but will get a PR lock.
285 *
286 * 2. The control_lock blocks others in control_mount() while the first
287 * mounter is doing first mount recovery of all journals.
288 * A mounting node needs to acquire control_lock in EX mode before
289 * it can proceed. The first mounter holds control_lock in EX while doing
290 * the first mount recovery, blocking mounts from other nodes, then demotes
291 * control_lock to NL when it's done (others_may_mount/first_done),
292 * allowing other nodes to continue mounting.
293 *
294 * first mounter:
295 * control_lock EX/NOQUEUE success
296 * mounted_lock EX/NOQUEUE success (no other PR, so no other mounters)
297 * set first=1
298 * do first mounter recovery
299 * mounted_lock EX->PR
300 * control_lock EX->NL, write lvb generation
301 *
302 * other mounter:
303 * control_lock EX/NOQUEUE success (if fail -EAGAIN, retry)
304 * mounted_lock EX/NOQUEUE fail -EAGAIN (expected due to other mounters PR)
305 * mounted_lock PR/NOQUEUE success
306 * read lvb generation
307 * control_lock EX->NL
308 * set first=0
309 *
310 * - mount during recovery
311 *
312 * If a node mounts while others are doing recovery (not first mounter),
313 * the mounting node will get its initial recover_done() callback without
314 * having seen any previous failures/callbacks.
315 *
316 * It must wait for all recoveries preceding its mount to be finished
317 * before it unblocks locks. It does this by repeating the "other mounter"
318 * steps above until the lvb generation number is >= its mount generation
319 * number (from initial recover_done) and all lvb bits are clear.
320 *
321 * - control_lock lvb format
322 *
323 * 4 bytes generation number: the latest dlm lockspace generation number
324 * from recover_done callback. Indicates the jid bitmap has been updated
325 * to reflect all slot failures through that generation.
326 * 4 bytes unused.
327 * GDLM_LVB_SIZE-8 bytes of jid bit map. If bit N is set, it indicates
328 * that jid N needs recovery.
329 */
330
331#define JID_BITMAP_OFFSET 8 /* 4 byte generation number + 4 byte unused */
332
333static void control_lvb_read(struct lm_lockstruct *ls, uint32_t *lvb_gen,
334 char *lvb_bits)
335{
336 uint32_t gen;
337 memcpy(lvb_bits, ls->ls_control_lvb, GDLM_LVB_SIZE);
338 memcpy(&gen, lvb_bits, sizeof(uint32_t));
339 *lvb_gen = le32_to_cpu(gen);
340}
341
342static void control_lvb_write(struct lm_lockstruct *ls, uint32_t lvb_gen,
343 char *lvb_bits)
344{
345 uint32_t gen;
346 memcpy(ls->ls_control_lvb, lvb_bits, GDLM_LVB_SIZE);
347 gen = cpu_to_le32(lvb_gen);
348 memcpy(ls->ls_control_lvb, &gen, sizeof(uint32_t));
349}
350
351static int all_jid_bits_clear(char *lvb)
352{
353 int i;
354 for (i = JID_BITMAP_OFFSET; i < GDLM_LVB_SIZE; i++) {
355 if (lvb[i])
356 return 0;
357 }
358 return 1;
359}
360
361static void sync_wait_cb(void *arg)
362{
363 struct lm_lockstruct *ls = arg;
364 complete(&ls->ls_sync_wait);
365}
366
367static int sync_unlock(struct gfs2_sbd *sdp, struct dlm_lksb *lksb, char *name)
189{ 368{
190 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 369 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
191 int error; 370 int error;
192 371
193 if (fsname == NULL) { 372 error = dlm_unlock(ls->ls_dlm, lksb->sb_lkid, 0, lksb, ls);
194 fs_info(sdp, "no fsname found\n"); 373 if (error) {
195 return -EINVAL; 374 fs_err(sdp, "%s lkid %x error %d\n",
375 name, lksb->sb_lkid, error);
376 return error;
377 }
378
379 wait_for_completion(&ls->ls_sync_wait);
380
381 if (lksb->sb_status != -DLM_EUNLOCK) {
382 fs_err(sdp, "%s lkid %x status %d\n",
383 name, lksb->sb_lkid, lksb->sb_status);
384 return -1;
385 }
386 return 0;
387}
388
389static int sync_lock(struct gfs2_sbd *sdp, int mode, uint32_t flags,
390 unsigned int num, struct dlm_lksb *lksb, char *name)
391{
392 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
393 char strname[GDLM_STRNAME_BYTES];
394 int error, status;
395
396 memset(strname, 0, GDLM_STRNAME_BYTES);
397 snprintf(strname, GDLM_STRNAME_BYTES, "%8x%16x", LM_TYPE_NONDISK, num);
398
399 error = dlm_lock(ls->ls_dlm, mode, lksb, flags,
400 strname, GDLM_STRNAME_BYTES - 1,
401 0, sync_wait_cb, ls, NULL);
402 if (error) {
403 fs_err(sdp, "%s lkid %x flags %x mode %d error %d\n",
404 name, lksb->sb_lkid, flags, mode, error);
405 return error;
406 }
407
408 wait_for_completion(&ls->ls_sync_wait);
409
410 status = lksb->sb_status;
411
412 if (status && status != -EAGAIN) {
413 fs_err(sdp, "%s lkid %x flags %x mode %d status %d\n",
414 name, lksb->sb_lkid, flags, mode, status);
415 }
416
417 return status;
418}
419
420static int mounted_unlock(struct gfs2_sbd *sdp)
421{
422 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
423 return sync_unlock(sdp, &ls->ls_mounted_lksb, "mounted_lock");
424}
425
426static int mounted_lock(struct gfs2_sbd *sdp, int mode, uint32_t flags)
427{
428 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
429 return sync_lock(sdp, mode, flags, GFS2_MOUNTED_LOCK,
430 &ls->ls_mounted_lksb, "mounted_lock");
431}
432
433static int control_unlock(struct gfs2_sbd *sdp)
434{
435 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
436 return sync_unlock(sdp, &ls->ls_control_lksb, "control_lock");
437}
438
439static int control_lock(struct gfs2_sbd *sdp, int mode, uint32_t flags)
440{
441 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
442 return sync_lock(sdp, mode, flags, GFS2_CONTROL_LOCK,
443 &ls->ls_control_lksb, "control_lock");
444}
445
446static void gfs2_control_func(struct work_struct *work)
447{
448 struct gfs2_sbd *sdp = container_of(work, struct gfs2_sbd, sd_control_work.work);
449 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
450 char lvb_bits[GDLM_LVB_SIZE];
451 uint32_t block_gen, start_gen, lvb_gen, flags;
452 int recover_set = 0;
453 int write_lvb = 0;
454 int recover_size;
455 int i, error;
456
457 spin_lock(&ls->ls_recover_spin);
458 /*
459 * No MOUNT_DONE means we're still mounting; control_mount()
460 * will set this flag, after which this thread will take over
461 * all further clearing of BLOCK_LOCKS.
462 *
463 * FIRST_MOUNT means this node is doing first mounter recovery,
464 * for which recovery control is handled by
465 * control_mount()/control_first_done(), not this thread.
466 */
467 if (!test_bit(DFL_MOUNT_DONE, &ls->ls_recover_flags) ||
468 test_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags)) {
469 spin_unlock(&ls->ls_recover_spin);
470 return;
471 }
472 block_gen = ls->ls_recover_block;
473 start_gen = ls->ls_recover_start;
474 spin_unlock(&ls->ls_recover_spin);
475
476 /*
477 * Equal block_gen and start_gen implies we are between
478 * recover_prep and recover_done callbacks, which means
479 * dlm recovery is in progress and dlm locking is blocked.
480 * There's no point trying to do any work until recover_done.
481 */
482
483 if (block_gen == start_gen)
484 return;
485
486 /*
487 * Propagate recover_submit[] and recover_result[] to lvb:
488 * dlm_recoverd adds to recover_submit[] jids needing recovery
489 * gfs2_recover adds to recover_result[] journal recovery results
490 *
491 * set lvb bit for jids in recover_submit[] if the lvb has not
492 * yet been updated for the generation of the failure
493 *
494 * clear lvb bit for jids in recover_result[] if the result of
495 * the journal recovery is SUCCESS
496 */
497
498 error = control_lock(sdp, DLM_LOCK_EX, DLM_LKF_CONVERT|DLM_LKF_VALBLK);
499 if (error) {
500 fs_err(sdp, "control lock EX error %d\n", error);
501 return;
502 }
503
504 control_lvb_read(ls, &lvb_gen, lvb_bits);
505
506 spin_lock(&ls->ls_recover_spin);
507 if (block_gen != ls->ls_recover_block ||
508 start_gen != ls->ls_recover_start) {
509 fs_info(sdp, "recover generation %u block1 %u %u\n",
510 start_gen, block_gen, ls->ls_recover_block);
511 spin_unlock(&ls->ls_recover_spin);
512 control_lock(sdp, DLM_LOCK_NL, DLM_LKF_CONVERT);
513 return;
514 }
515
516 recover_size = ls->ls_recover_size;
517
518 if (lvb_gen <= start_gen) {
519 /*
520 * Clear lvb bits for jids we've successfully recovered.
521 * Because all nodes attempt to recover failed journals,
522 * a journal can be recovered multiple times successfully
523 * in succession. Only the first will really do recovery,
524 * the others find it clean, but still report a successful
525 * recovery. So, another node may have already recovered
526 * the jid and cleared the lvb bit for it.
527 */
528 for (i = 0; i < recover_size; i++) {
529 if (ls->ls_recover_result[i] != LM_RD_SUCCESS)
530 continue;
531
532 ls->ls_recover_result[i] = 0;
533
534 if (!test_bit_le(i, lvb_bits + JID_BITMAP_OFFSET))
535 continue;
536
537 __clear_bit_le(i, lvb_bits + JID_BITMAP_OFFSET);
538 write_lvb = 1;
539 }
540 }
541
542 if (lvb_gen == start_gen) {
543 /*
544 * Failed slots before start_gen are already set in lvb.
545 */
546 for (i = 0; i < recover_size; i++) {
547 if (!ls->ls_recover_submit[i])
548 continue;
549 if (ls->ls_recover_submit[i] < lvb_gen)
550 ls->ls_recover_submit[i] = 0;
551 }
552 } else if (lvb_gen < start_gen) {
553 /*
554 * Failed slots before start_gen are not yet set in lvb.
555 */
556 for (i = 0; i < recover_size; i++) {
557 if (!ls->ls_recover_submit[i])
558 continue;
559 if (ls->ls_recover_submit[i] < start_gen) {
560 ls->ls_recover_submit[i] = 0;
561 __set_bit_le(i, lvb_bits + JID_BITMAP_OFFSET);
562 }
563 }
564 /* even if there are no bits to set, we need to write the
565 latest generation to the lvb */
566 write_lvb = 1;
567 } else {
568 /*
569 * we should be getting a recover_done() for lvb_gen soon
570 */
571 }
572 spin_unlock(&ls->ls_recover_spin);
573
574 if (write_lvb) {
575 control_lvb_write(ls, start_gen, lvb_bits);
576 flags = DLM_LKF_CONVERT | DLM_LKF_VALBLK;
577 } else {
578 flags = DLM_LKF_CONVERT;
579 }
580
581 error = control_lock(sdp, DLM_LOCK_NL, flags);
582 if (error) {
583 fs_err(sdp, "control lock NL error %d\n", error);
584 return;
585 }
586
587 /*
588 * Everyone will see jid bits set in the lvb, run gfs2_recover_set(),
589 * and clear a jid bit in the lvb if the recovery is a success.
590 * Eventually all journals will be recovered, all jid bits will
591 * be cleared in the lvb, and everyone will clear BLOCK_LOCKS.
592 */
593
594 for (i = 0; i < recover_size; i++) {
595 if (test_bit_le(i, lvb_bits + JID_BITMAP_OFFSET)) {
596 fs_info(sdp, "recover generation %u jid %d\n",
597 start_gen, i);
598 gfs2_recover_set(sdp, i);
599 recover_set++;
600 }
601 }
602 if (recover_set)
603 return;
604
605 /*
606 * No more jid bits set in lvb, all recovery is done, unblock locks
607 * (unless a new recover_prep callback has occured blocking locks
608 * again while working above)
609 */
610
611 spin_lock(&ls->ls_recover_spin);
612 if (ls->ls_recover_block == block_gen &&
613 ls->ls_recover_start == start_gen) {
614 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
615 spin_unlock(&ls->ls_recover_spin);
616 fs_info(sdp, "recover generation %u done\n", start_gen);
617 gfs2_glock_thaw(sdp);
618 } else {
619 fs_info(sdp, "recover generation %u block2 %u %u\n",
620 start_gen, block_gen, ls->ls_recover_block);
621 spin_unlock(&ls->ls_recover_spin);
622 }
623}
624
625static int control_mount(struct gfs2_sbd *sdp)
626{
627 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
628 char lvb_bits[GDLM_LVB_SIZE];
629 uint32_t start_gen, block_gen, mount_gen, lvb_gen;
630 int mounted_mode;
631 int retries = 0;
632 int error;
633
634 memset(&ls->ls_mounted_lksb, 0, sizeof(struct dlm_lksb));
635 memset(&ls->ls_control_lksb, 0, sizeof(struct dlm_lksb));
636 memset(&ls->ls_control_lvb, 0, GDLM_LVB_SIZE);
637 ls->ls_control_lksb.sb_lvbptr = ls->ls_control_lvb;
638 init_completion(&ls->ls_sync_wait);
639
640 set_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
641
642 error = control_lock(sdp, DLM_LOCK_NL, DLM_LKF_VALBLK);
643 if (error) {
644 fs_err(sdp, "control_mount control_lock NL error %d\n", error);
645 return error;
646 }
647
648 error = mounted_lock(sdp, DLM_LOCK_NL, 0);
649 if (error) {
650 fs_err(sdp, "control_mount mounted_lock NL error %d\n", error);
651 control_unlock(sdp);
652 return error;
653 }
654 mounted_mode = DLM_LOCK_NL;
655
656restart:
657 if (retries++ && signal_pending(current)) {
658 error = -EINTR;
659 goto fail;
660 }
661
662 /*
663 * We always start with both locks in NL. control_lock is
664 * demoted to NL below so we don't need to do it here.
665 */
666
667 if (mounted_mode != DLM_LOCK_NL) {
668 error = mounted_lock(sdp, DLM_LOCK_NL, DLM_LKF_CONVERT);
669 if (error)
670 goto fail;
671 mounted_mode = DLM_LOCK_NL;
672 }
673
674 /*
675 * Other nodes need to do some work in dlm recovery and gfs2_control
676 * before the recover_done and control_lock will be ready for us below.
677 * A delay here is not required but often avoids having to retry.
678 */
679
680 msleep_interruptible(500);
681
682 /*
683 * Acquire control_lock in EX and mounted_lock in either EX or PR.
684 * control_lock lvb keeps track of any pending journal recoveries.
685 * mounted_lock indicates if any other nodes have the fs mounted.
686 */
687
688 error = control_lock(sdp, DLM_LOCK_EX, DLM_LKF_CONVERT|DLM_LKF_NOQUEUE|DLM_LKF_VALBLK);
689 if (error == -EAGAIN) {
690 goto restart;
691 } else if (error) {
692 fs_err(sdp, "control_mount control_lock EX error %d\n", error);
693 goto fail;
694 }
695
696 error = mounted_lock(sdp, DLM_LOCK_EX, DLM_LKF_CONVERT|DLM_LKF_NOQUEUE);
697 if (!error) {
698 mounted_mode = DLM_LOCK_EX;
699 goto locks_done;
700 } else if (error != -EAGAIN) {
701 fs_err(sdp, "control_mount mounted_lock EX error %d\n", error);
702 goto fail;
703 }
704
705 error = mounted_lock(sdp, DLM_LOCK_PR, DLM_LKF_CONVERT|DLM_LKF_NOQUEUE);
706 if (!error) {
707 mounted_mode = DLM_LOCK_PR;
708 goto locks_done;
709 } else {
710 /* not even -EAGAIN should happen here */
711 fs_err(sdp, "control_mount mounted_lock PR error %d\n", error);
712 goto fail;
713 }
714
715locks_done:
716 /*
717 * If we got both locks above in EX, then we're the first mounter.
718 * If not, then we need to wait for the control_lock lvb to be
719 * updated by other mounted nodes to reflect our mount generation.
720 *
721 * In simple first mounter cases, first mounter will see zero lvb_gen,
722 * but in cases where all existing nodes leave/fail before mounting
723 * nodes finish control_mount, then all nodes will be mounting and
724 * lvb_gen will be non-zero.
725 */
726
727 control_lvb_read(ls, &lvb_gen, lvb_bits);
728
729 if (lvb_gen == 0xFFFFFFFF) {
730 /* special value to force mount attempts to fail */
731 fs_err(sdp, "control_mount control_lock disabled\n");
732 error = -EINVAL;
733 goto fail;
734 }
735
736 if (mounted_mode == DLM_LOCK_EX) {
737 /* first mounter, keep both EX while doing first recovery */
738 spin_lock(&ls->ls_recover_spin);
739 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
740 set_bit(DFL_MOUNT_DONE, &ls->ls_recover_flags);
741 set_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags);
742 spin_unlock(&ls->ls_recover_spin);
743 fs_info(sdp, "first mounter control generation %u\n", lvb_gen);
744 return 0;
745 }
746
747 error = control_lock(sdp, DLM_LOCK_NL, DLM_LKF_CONVERT);
748 if (error)
749 goto fail;
750
751 /*
752 * We are not first mounter, now we need to wait for the control_lock
753 * lvb generation to be >= the generation from our first recover_done
754 * and all lvb bits to be clear (no pending journal recoveries.)
755 */
756
757 if (!all_jid_bits_clear(lvb_bits)) {
758 /* journals need recovery, wait until all are clear */
759 fs_info(sdp, "control_mount wait for journal recovery\n");
760 goto restart;
761 }
762
763 spin_lock(&ls->ls_recover_spin);
764 block_gen = ls->ls_recover_block;
765 start_gen = ls->ls_recover_start;
766 mount_gen = ls->ls_recover_mount;
767
768 if (lvb_gen < mount_gen) {
769 /* wait for mounted nodes to update control_lock lvb to our
770 generation, which might include new recovery bits set */
771 fs_info(sdp, "control_mount wait1 block %u start %u mount %u "
772 "lvb %u flags %lx\n", block_gen, start_gen, mount_gen,
773 lvb_gen, ls->ls_recover_flags);
774 spin_unlock(&ls->ls_recover_spin);
775 goto restart;
776 }
777
778 if (lvb_gen != start_gen) {
779 /* wait for mounted nodes to update control_lock lvb to the
780 latest recovery generation */
781 fs_info(sdp, "control_mount wait2 block %u start %u mount %u "
782 "lvb %u flags %lx\n", block_gen, start_gen, mount_gen,
783 lvb_gen, ls->ls_recover_flags);
784 spin_unlock(&ls->ls_recover_spin);
785 goto restart;
786 }
787
788 if (block_gen == start_gen) {
789 /* dlm recovery in progress, wait for it to finish */
790 fs_info(sdp, "control_mount wait3 block %u start %u mount %u "
791 "lvb %u flags %lx\n", block_gen, start_gen, mount_gen,
792 lvb_gen, ls->ls_recover_flags);
793 spin_unlock(&ls->ls_recover_spin);
794 goto restart;
196 } 795 }
197 796
198 error = dlm_new_lockspace(fsname, NULL, 797 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
199 DLM_LSFL_FS | DLM_LSFL_NEWEXCL | 798 set_bit(DFL_MOUNT_DONE, &ls->ls_recover_flags);
200 (ls->ls_nodir ? DLM_LSFL_NODIR : 0), 799 memset(ls->ls_recover_submit, 0, ls->ls_recover_size*sizeof(uint32_t));
201 GDLM_LVB_SIZE, NULL, NULL, NULL, &ls->ls_dlm); 800 memset(ls->ls_recover_result, 0, ls->ls_recover_size*sizeof(uint32_t));
801 spin_unlock(&ls->ls_recover_spin);
802 return 0;
803
804fail:
805 mounted_unlock(sdp);
806 control_unlock(sdp);
807 return error;
808}
809
810static int dlm_recovery_wait(void *word)
811{
812 schedule();
813 return 0;
814}
815
816static int control_first_done(struct gfs2_sbd *sdp)
817{
818 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
819 char lvb_bits[GDLM_LVB_SIZE];
820 uint32_t start_gen, block_gen;
821 int error;
822
823restart:
824 spin_lock(&ls->ls_recover_spin);
825 start_gen = ls->ls_recover_start;
826 block_gen = ls->ls_recover_block;
827
828 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags) ||
829 !test_bit(DFL_MOUNT_DONE, &ls->ls_recover_flags) ||
830 !test_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags)) {
831 /* sanity check, should not happen */
832 fs_err(sdp, "control_first_done start %u block %u flags %lx\n",
833 start_gen, block_gen, ls->ls_recover_flags);
834 spin_unlock(&ls->ls_recover_spin);
835 control_unlock(sdp);
836 return -1;
837 }
838
839 if (start_gen == block_gen) {
840 /*
841 * Wait for the end of a dlm recovery cycle to switch from
842 * first mounter recovery. We can ignore any recover_slot
843 * callbacks between the recover_prep and next recover_done
844 * because we are still the first mounter and any failed nodes
845 * have not fully mounted, so they don't need recovery.
846 */
847 spin_unlock(&ls->ls_recover_spin);
848 fs_info(sdp, "control_first_done wait gen %u\n", start_gen);
849
850 wait_on_bit(&ls->ls_recover_flags, DFL_DLM_RECOVERY,
851 dlm_recovery_wait, TASK_UNINTERRUPTIBLE);
852 goto restart;
853 }
854
855 clear_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags);
856 set_bit(DFL_FIRST_MOUNT_DONE, &ls->ls_recover_flags);
857 memset(ls->ls_recover_submit, 0, ls->ls_recover_size*sizeof(uint32_t));
858 memset(ls->ls_recover_result, 0, ls->ls_recover_size*sizeof(uint32_t));
859 spin_unlock(&ls->ls_recover_spin);
860
861 memset(lvb_bits, 0, sizeof(lvb_bits));
862 control_lvb_write(ls, start_gen, lvb_bits);
863
864 error = mounted_lock(sdp, DLM_LOCK_PR, DLM_LKF_CONVERT);
865 if (error)
866 fs_err(sdp, "control_first_done mounted PR error %d\n", error);
867
868 error = control_lock(sdp, DLM_LOCK_NL, DLM_LKF_CONVERT|DLM_LKF_VALBLK);
202 if (error) 869 if (error)
203 printk(KERN_ERR "dlm_new_lockspace error %d", error); 870 fs_err(sdp, "control_first_done control NL error %d\n", error);
204 871
205 return error; 872 return error;
206} 873}
207 874
875/*
876 * Expand static jid arrays if necessary (by increments of RECOVER_SIZE_INC)
877 * to accomodate the largest slot number. (NB dlm slot numbers start at 1,
878 * gfs2 jids start at 0, so jid = slot - 1)
879 */
880
881#define RECOVER_SIZE_INC 16
882
883static int set_recover_size(struct gfs2_sbd *sdp, struct dlm_slot *slots,
884 int num_slots)
885{
886 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
887 uint32_t *submit = NULL;
888 uint32_t *result = NULL;
889 uint32_t old_size, new_size;
890 int i, max_jid;
891
892 max_jid = 0;
893 for (i = 0; i < num_slots; i++) {
894 if (max_jid < slots[i].slot - 1)
895 max_jid = slots[i].slot - 1;
896 }
897
898 old_size = ls->ls_recover_size;
899
900 if (old_size >= max_jid + 1)
901 return 0;
902
903 new_size = old_size + RECOVER_SIZE_INC;
904
905 submit = kzalloc(new_size * sizeof(uint32_t), GFP_NOFS);
906 result = kzalloc(new_size * sizeof(uint32_t), GFP_NOFS);
907 if (!submit || !result) {
908 kfree(submit);
909 kfree(result);
910 return -ENOMEM;
911 }
912
913 spin_lock(&ls->ls_recover_spin);
914 memcpy(submit, ls->ls_recover_submit, old_size * sizeof(uint32_t));
915 memcpy(result, ls->ls_recover_result, old_size * sizeof(uint32_t));
916 kfree(ls->ls_recover_submit);
917 kfree(ls->ls_recover_result);
918 ls->ls_recover_submit = submit;
919 ls->ls_recover_result = result;
920 ls->ls_recover_size = new_size;
921 spin_unlock(&ls->ls_recover_spin);
922 return 0;
923}
924
925static void free_recover_size(struct lm_lockstruct *ls)
926{
927 kfree(ls->ls_recover_submit);
928 kfree(ls->ls_recover_result);
929 ls->ls_recover_submit = NULL;
930 ls->ls_recover_result = NULL;
931 ls->ls_recover_size = 0;
932}
933
934/* dlm calls before it does lock recovery */
935
936static void gdlm_recover_prep(void *arg)
937{
938 struct gfs2_sbd *sdp = arg;
939 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
940
941 spin_lock(&ls->ls_recover_spin);
942 ls->ls_recover_block = ls->ls_recover_start;
943 set_bit(DFL_DLM_RECOVERY, &ls->ls_recover_flags);
944
945 if (!test_bit(DFL_MOUNT_DONE, &ls->ls_recover_flags) ||
946 test_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags)) {
947 spin_unlock(&ls->ls_recover_spin);
948 return;
949 }
950 set_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
951 spin_unlock(&ls->ls_recover_spin);
952}
953
954/* dlm calls after recover_prep has been completed on all lockspace members;
955 identifies slot/jid of failed member */
956
957static void gdlm_recover_slot(void *arg, struct dlm_slot *slot)
958{
959 struct gfs2_sbd *sdp = arg;
960 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
961 int jid = slot->slot - 1;
962
963 spin_lock(&ls->ls_recover_spin);
964 if (ls->ls_recover_size < jid + 1) {
965 fs_err(sdp, "recover_slot jid %d gen %u short size %d",
966 jid, ls->ls_recover_block, ls->ls_recover_size);
967 spin_unlock(&ls->ls_recover_spin);
968 return;
969 }
970
971 if (ls->ls_recover_submit[jid]) {
972 fs_info(sdp, "recover_slot jid %d gen %u prev %u",
973 jid, ls->ls_recover_block, ls->ls_recover_submit[jid]);
974 }
975 ls->ls_recover_submit[jid] = ls->ls_recover_block;
976 spin_unlock(&ls->ls_recover_spin);
977}
978
979/* dlm calls after recover_slot and after it completes lock recovery */
980
981static void gdlm_recover_done(void *arg, struct dlm_slot *slots, int num_slots,
982 int our_slot, uint32_t generation)
983{
984 struct gfs2_sbd *sdp = arg;
985 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
986
987 /* ensure the ls jid arrays are large enough */
988 set_recover_size(sdp, slots, num_slots);
989
990 spin_lock(&ls->ls_recover_spin);
991 ls->ls_recover_start = generation;
992
993 if (!ls->ls_recover_mount) {
994 ls->ls_recover_mount = generation;
995 ls->ls_jid = our_slot - 1;
996 }
997
998 if (!test_bit(DFL_UNMOUNT, &ls->ls_recover_flags))
999 queue_delayed_work(gfs2_control_wq, &sdp->sd_control_work, 0);
1000
1001 clear_bit(DFL_DLM_RECOVERY, &ls->ls_recover_flags);
1002 smp_mb__after_clear_bit();
1003 wake_up_bit(&ls->ls_recover_flags, DFL_DLM_RECOVERY);
1004 spin_unlock(&ls->ls_recover_spin);
1005}
1006
1007/* gfs2_recover thread has a journal recovery result */
1008
1009static void gdlm_recovery_result(struct gfs2_sbd *sdp, unsigned int jid,
1010 unsigned int result)
1011{
1012 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1013
1014 if (test_bit(DFL_NO_DLM_OPS, &ls->ls_recover_flags))
1015 return;
1016
1017 /* don't care about the recovery of own journal during mount */
1018 if (jid == ls->ls_jid)
1019 return;
1020
1021 spin_lock(&ls->ls_recover_spin);
1022 if (test_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags)) {
1023 spin_unlock(&ls->ls_recover_spin);
1024 return;
1025 }
1026 if (ls->ls_recover_size < jid + 1) {
1027 fs_err(sdp, "recovery_result jid %d short size %d",
1028 jid, ls->ls_recover_size);
1029 spin_unlock(&ls->ls_recover_spin);
1030 return;
1031 }
1032
1033 fs_info(sdp, "recover jid %d result %s\n", jid,
1034 result == LM_RD_GAVEUP ? "busy" : "success");
1035
1036 ls->ls_recover_result[jid] = result;
1037
1038 /* GAVEUP means another node is recovering the journal; delay our
1039 next attempt to recover it, to give the other node a chance to
1040 finish before trying again */
1041
1042 if (!test_bit(DFL_UNMOUNT, &ls->ls_recover_flags))
1043 queue_delayed_work(gfs2_control_wq, &sdp->sd_control_work,
1044 result == LM_RD_GAVEUP ? HZ : 0);
1045 spin_unlock(&ls->ls_recover_spin);
1046}
1047
1048const struct dlm_lockspace_ops gdlm_lockspace_ops = {
1049 .recover_prep = gdlm_recover_prep,
1050 .recover_slot = gdlm_recover_slot,
1051 .recover_done = gdlm_recover_done,
1052};
1053
1054static int gdlm_mount(struct gfs2_sbd *sdp, const char *table)
1055{
1056 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1057 char cluster[GFS2_LOCKNAME_LEN];
1058 const char *fsname;
1059 uint32_t flags;
1060 int error, ops_result;
1061
1062 /*
1063 * initialize everything
1064 */
1065
1066 INIT_DELAYED_WORK(&sdp->sd_control_work, gfs2_control_func);
1067 spin_lock_init(&ls->ls_recover_spin);
1068 ls->ls_recover_flags = 0;
1069 ls->ls_recover_mount = 0;
1070 ls->ls_recover_start = 0;
1071 ls->ls_recover_block = 0;
1072 ls->ls_recover_size = 0;
1073 ls->ls_recover_submit = NULL;
1074 ls->ls_recover_result = NULL;
1075
1076 error = set_recover_size(sdp, NULL, 0);
1077 if (error)
1078 goto fail;
1079
1080 /*
1081 * prepare dlm_new_lockspace args
1082 */
1083
1084 fsname = strchr(table, ':');
1085 if (!fsname) {
1086 fs_info(sdp, "no fsname found\n");
1087 error = -EINVAL;
1088 goto fail_free;
1089 }
1090 memset(cluster, 0, sizeof(cluster));
1091 memcpy(cluster, table, strlen(table) - strlen(fsname));
1092 fsname++;
1093
1094 flags = DLM_LSFL_FS | DLM_LSFL_NEWEXCL;
1095 if (ls->ls_nodir)
1096 flags |= DLM_LSFL_NODIR;
1097
1098 /*
1099 * create/join lockspace
1100 */
1101
1102 error = dlm_new_lockspace(fsname, cluster, flags, GDLM_LVB_SIZE,
1103 &gdlm_lockspace_ops, sdp, &ops_result,
1104 &ls->ls_dlm);
1105 if (error) {
1106 fs_err(sdp, "dlm_new_lockspace error %d\n", error);
1107 goto fail_free;
1108 }
1109
1110 if (ops_result < 0) {
1111 /*
1112 * dlm does not support ops callbacks,
1113 * old dlm_controld/gfs_controld are used, try without ops.
1114 */
1115 fs_info(sdp, "dlm lockspace ops not used\n");
1116 free_recover_size(ls);
1117 set_bit(DFL_NO_DLM_OPS, &ls->ls_recover_flags);
1118 return 0;
1119 }
1120
1121 if (!test_bit(SDF_NOJOURNALID, &sdp->sd_flags)) {
1122 fs_err(sdp, "dlm lockspace ops disallow jid preset\n");
1123 error = -EINVAL;
1124 goto fail_release;
1125 }
1126
1127 /*
1128 * control_mount() uses control_lock to determine first mounter,
1129 * and for later mounts, waits for any recoveries to be cleared.
1130 */
1131
1132 error = control_mount(sdp);
1133 if (error) {
1134 fs_err(sdp, "mount control error %d\n", error);
1135 goto fail_release;
1136 }
1137
1138 ls->ls_first = !!test_bit(DFL_FIRST_MOUNT, &ls->ls_recover_flags);
1139 clear_bit(SDF_NOJOURNALID, &sdp->sd_flags);
1140 smp_mb__after_clear_bit();
1141 wake_up_bit(&sdp->sd_flags, SDF_NOJOURNALID);
1142 return 0;
1143
1144fail_release:
1145 dlm_release_lockspace(ls->ls_dlm, 2);
1146fail_free:
1147 free_recover_size(ls);
1148fail:
1149 return error;
1150}
1151
1152static void gdlm_first_done(struct gfs2_sbd *sdp)
1153{
1154 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1155 int error;
1156
1157 if (test_bit(DFL_NO_DLM_OPS, &ls->ls_recover_flags))
1158 return;
1159
1160 error = control_first_done(sdp);
1161 if (error)
1162 fs_err(sdp, "mount first_done error %d\n", error);
1163}
1164
208static void gdlm_unmount(struct gfs2_sbd *sdp) 1165static void gdlm_unmount(struct gfs2_sbd *sdp)
209{ 1166{
210 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 1167 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
211 1168
1169 if (test_bit(DFL_NO_DLM_OPS, &ls->ls_recover_flags))
1170 goto release;
1171
1172 /* wait for gfs2_control_wq to be done with this mount */
1173
1174 spin_lock(&ls->ls_recover_spin);
1175 set_bit(DFL_UNMOUNT, &ls->ls_recover_flags);
1176 spin_unlock(&ls->ls_recover_spin);
1177 flush_delayed_work_sync(&sdp->sd_control_work);
1178
1179 /* mounted_lock and control_lock will be purged in dlm recovery */
1180release:
212 if (ls->ls_dlm) { 1181 if (ls->ls_dlm) {
213 dlm_release_lockspace(ls->ls_dlm, 2); 1182 dlm_release_lockspace(ls->ls_dlm, 2);
214 ls->ls_dlm = NULL; 1183 ls->ls_dlm = NULL;
215 } 1184 }
1185
1186 free_recover_size(ls);
216} 1187}
217 1188
218static const match_table_t dlm_tokens = { 1189static const match_table_t dlm_tokens = {
@@ -226,6 +1197,8 @@ static const match_table_t dlm_tokens = {
226const struct lm_lockops gfs2_dlm_ops = { 1197const struct lm_lockops gfs2_dlm_ops = {
227 .lm_proto_name = "lock_dlm", 1198 .lm_proto_name = "lock_dlm",
228 .lm_mount = gdlm_mount, 1199 .lm_mount = gdlm_mount,
1200 .lm_first_done = gdlm_first_done,
1201 .lm_recovery_result = gdlm_recovery_result,
229 .lm_unmount = gdlm_unmount, 1202 .lm_unmount = gdlm_unmount,
230 .lm_put_lock = gdlm_put_lock, 1203 .lm_put_lock = gdlm_put_lock,
231 .lm_lock = gdlm_lock, 1204 .lm_lock = gdlm_lock,
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index c150298e2d8e..a8d9bcd0e19c 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -28,6 +28,8 @@
28#include "recovery.h" 28#include "recovery.h"
29#include "dir.h" 29#include "dir.h"
30 30
31struct workqueue_struct *gfs2_control_wq;
32
31static struct shrinker qd_shrinker = { 33static struct shrinker qd_shrinker = {
32 .shrink = gfs2_shrink_qd_memory, 34 .shrink = gfs2_shrink_qd_memory,
33 .seeks = DEFAULT_SEEKS, 35 .seeks = DEFAULT_SEEKS,
@@ -146,12 +148,19 @@ static int __init init_gfs2_fs(void)
146 if (!gfs_recovery_wq) 148 if (!gfs_recovery_wq)
147 goto fail_wq; 149 goto fail_wq;
148 150
151 gfs2_control_wq = alloc_workqueue("gfs2_control",
152 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_FREEZABLE, 0);
153 if (!gfs2_control_wq)
154 goto fail_control;
155
149 gfs2_register_debugfs(); 156 gfs2_register_debugfs();
150 157
151 printk("GFS2 installed\n"); 158 printk("GFS2 installed\n");
152 159
153 return 0; 160 return 0;
154 161
162fail_control:
163 destroy_workqueue(gfs_recovery_wq);
155fail_wq: 164fail_wq:
156 unregister_filesystem(&gfs2meta_fs_type); 165 unregister_filesystem(&gfs2meta_fs_type);
157fail_unregister: 166fail_unregister:
@@ -195,6 +204,7 @@ static void __exit exit_gfs2_fs(void)
195 unregister_filesystem(&gfs2_fs_type); 204 unregister_filesystem(&gfs2_fs_type);
196 unregister_filesystem(&gfs2meta_fs_type); 205 unregister_filesystem(&gfs2meta_fs_type);
197 destroy_workqueue(gfs_recovery_wq); 206 destroy_workqueue(gfs_recovery_wq);
207 destroy_workqueue(gfs2_control_wq);
198 208
199 rcu_barrier(); 209 rcu_barrier();
200 210
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index fe72e79e6ff9..6aacf3f230a2 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -562,8 +562,12 @@ static void gfs2_others_may_mount(struct gfs2_sbd *sdp)
562{ 562{
563 char *message = "FIRSTMOUNT=Done"; 563 char *message = "FIRSTMOUNT=Done";
564 char *envp[] = { message, NULL }; 564 char *envp[] = { message, NULL };
565 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 565
566 ls->ls_first_done = 1; 566 fs_info(sdp, "first mount done, others may mount\n");
567
568 if (sdp->sd_lockstruct.ls_ops->lm_first_done)
569 sdp->sd_lockstruct.ls_ops->lm_first_done(sdp);
570
567 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp); 571 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
568} 572}
569 573
@@ -944,7 +948,6 @@ static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
944 struct gfs2_args *args = &sdp->sd_args; 948 struct gfs2_args *args = &sdp->sd_args;
945 const char *proto = sdp->sd_proto_name; 949 const char *proto = sdp->sd_proto_name;
946 const char *table = sdp->sd_table_name; 950 const char *table = sdp->sd_table_name;
947 const char *fsname;
948 char *o, *options; 951 char *o, *options;
949 int ret; 952 int ret;
950 953
@@ -1004,21 +1007,12 @@ hostdata_error:
1004 } 1007 }
1005 } 1008 }
1006 1009
1007 if (sdp->sd_args.ar_spectator)
1008 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
1009 else
1010 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
1011 sdp->sd_lockstruct.ls_jid);
1012
1013 fsname = strchr(table, ':');
1014 if (fsname)
1015 fsname++;
1016 if (lm->lm_mount == NULL) { 1010 if (lm->lm_mount == NULL) {
1017 fs_info(sdp, "Now mounting FS...\n"); 1011 fs_info(sdp, "Now mounting FS...\n");
1018 complete_all(&sdp->sd_locking_init); 1012 complete_all(&sdp->sd_locking_init);
1019 return 0; 1013 return 0;
1020 } 1014 }
1021 ret = lm->lm_mount(sdp, fsname); 1015 ret = lm->lm_mount(sdp, table);
1022 if (ret == 0) 1016 if (ret == 0)
1023 fs_info(sdp, "Joined cluster. Now mounting FS...\n"); 1017 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
1024 complete_all(&sdp->sd_locking_init); 1018 complete_all(&sdp->sd_locking_init);
@@ -1084,7 +1078,7 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1084 1078
1085 if (sdp->sd_args.ar_spectator) { 1079 if (sdp->sd_args.ar_spectator) {
1086 sb->s_flags |= MS_RDONLY; 1080 sb->s_flags |= MS_RDONLY;
1087 set_bit(SDF_NORECOVERY, &sdp->sd_flags); 1081 set_bit(SDF_RORECOVERY, &sdp->sd_flags);
1088 } 1082 }
1089 if (sdp->sd_args.ar_posix_acl) 1083 if (sdp->sd_args.ar_posix_acl)
1090 sb->s_flags |= MS_POSIXACL; 1084 sb->s_flags |= MS_POSIXACL;
@@ -1124,6 +1118,8 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1124 if (error) 1118 if (error)
1125 goto fail; 1119 goto fail;
1126 1120
1121 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s", sdp->sd_table_name);
1122
1127 gfs2_create_debugfs_file(sdp); 1123 gfs2_create_debugfs_file(sdp);
1128 1124
1129 error = gfs2_sys_fs_add(sdp); 1125 error = gfs2_sys_fs_add(sdp);
@@ -1160,6 +1156,13 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1160 goto fail_sb; 1156 goto fail_sb;
1161 } 1157 }
1162 1158
1159 if (sdp->sd_args.ar_spectator)
1160 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s",
1161 sdp->sd_table_name);
1162 else
1163 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u",
1164 sdp->sd_table_name, sdp->sd_lockstruct.ls_jid);
1165
1163 error = init_inodes(sdp, DO); 1166 error = init_inodes(sdp, DO);
1164 if (error) 1167 if (error)
1165 goto fail_sb; 1168 goto fail_sb;
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index f2a02edcac8f..963b2d75200c 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -436,12 +436,16 @@ static void gfs2_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
436 char env_status[20]; 436 char env_status[20];
437 char *envp[] = { env_jid, env_status, NULL }; 437 char *envp[] = { env_jid, env_status, NULL };
438 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 438 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
439
439 ls->ls_recover_jid_done = jid; 440 ls->ls_recover_jid_done = jid;
440 ls->ls_recover_jid_status = message; 441 ls->ls_recover_jid_status = message;
441 sprintf(env_jid, "JID=%d", jid); 442 sprintf(env_jid, "JID=%d", jid);
442 sprintf(env_status, "RECOVERY=%s", 443 sprintf(env_status, "RECOVERY=%s",
443 message == LM_RD_SUCCESS ? "Done" : "Failed"); 444 message == LM_RD_SUCCESS ? "Done" : "Failed");
444 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp); 445 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
446
447 if (sdp->sd_lockstruct.ls_ops->lm_recovery_result)
448 sdp->sd_lockstruct.ls_ops->lm_recovery_result(sdp, jid, message);
445} 449}
446 450
447void gfs2_recover_func(struct work_struct *work) 451void gfs2_recover_func(struct work_struct *work)
@@ -512,7 +516,9 @@ void gfs2_recover_func(struct work_struct *work)
512 if (error) 516 if (error)
513 goto fail_gunlock_ji; 517 goto fail_gunlock_ji;
514 518
515 if (test_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags)) { 519 if (test_bit(SDF_RORECOVERY, &sdp->sd_flags)) {
520 ro = 1;
521 } else if (test_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags)) {
516 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) 522 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
517 ro = 1; 523 ro = 1;
518 } else { 524 } else {
@@ -577,6 +583,7 @@ fail_gunlock_j:
577 583
578 fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done"); 584 fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done");
579fail: 585fail:
586 jd->jd_recover_error = error;
580 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP); 587 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP);
581done: 588done:
582 clear_bit(JDF_RECOVERY, &jd->jd_flags); 589 clear_bit(JDF_RECOVERY, &jd->jd_flags);
@@ -605,6 +612,6 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, bool wait)
605 wait_on_bit(&jd->jd_flags, JDF_RECOVERY, gfs2_recovery_wait, 612 wait_on_bit(&jd->jd_flags, JDF_RECOVERY, gfs2_recovery_wait,
606 TASK_UNINTERRUPTIBLE); 613 TASK_UNINTERRUPTIBLE);
607 614
608 return 0; 615 return wait ? jd->jd_recover_error : 0;
609} 616}
610 617
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 22234627f684..981bfa32121a 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1108,9 +1108,9 @@ void gfs2_inplace_release(struct gfs2_inode *ip)
1108{ 1108{
1109 struct gfs2_blkreserv *rs = ip->i_res; 1109 struct gfs2_blkreserv *rs = ip->i_res;
1110 1110
1111 gfs2_blkrsv_put(ip);
1112 if (rs->rs_rgd_gh.gh_gl) 1111 if (rs->rs_rgd_gh.gh_gl)
1113 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); 1112 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
1113 gfs2_blkrsv_put(ip);
1114} 1114}
1115 1115
1116/** 1116/**
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 443cabcfcd23..d33172c291ba 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -298,7 +298,7 @@ static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
298 ssize_t ret; 298 ssize_t ret;
299 int val = 0; 299 int val = 0;
300 300
301 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags)) 301 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))
302 val = 1; 302 val = 1;
303 ret = sprintf(buf, "%d\n", val); 303 ret = sprintf(buf, "%d\n", val);
304 return ret; 304 return ret;
@@ -313,9 +313,9 @@ static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
313 val = simple_strtol(buf, NULL, 0); 313 val = simple_strtol(buf, NULL, 0);
314 314
315 if (val == 1) 315 if (val == 1)
316 set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags); 316 set_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
317 else if (val == 0) { 317 else if (val == 0) {
318 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags); 318 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags);
319 smp_mb__after_clear_bit(); 319 smp_mb__after_clear_bit();
320 gfs2_glock_thaw(sdp); 320 gfs2_glock_thaw(sdp);
321 } else { 321 } else {
@@ -350,8 +350,8 @@ static ssize_t lkfirst_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
350 goto out; 350 goto out;
351 if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) 351 if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
352 goto out; 352 goto out;
353 sdp->sd_lockstruct.ls_first = first; 353 sdp->sd_lockstruct.ls_first = first;
354 rv = 0; 354 rv = 0;
355out: 355out:
356 spin_unlock(&sdp->sd_jindex_spin); 356 spin_unlock(&sdp->sd_jindex_spin);
357 return rv ? rv : len; 357 return rv ? rv : len;
@@ -360,19 +360,14 @@ out:
360static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf) 360static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
361{ 361{
362 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 362 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
363 return sprintf(buf, "%d\n", ls->ls_first_done); 363 return sprintf(buf, "%d\n", !!test_bit(DFL_FIRST_MOUNT_DONE, &ls->ls_recover_flags));
364} 364}
365 365
366static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 366int gfs2_recover_set(struct gfs2_sbd *sdp, unsigned jid)
367{ 367{
368 unsigned jid;
369 struct gfs2_jdesc *jd; 368 struct gfs2_jdesc *jd;
370 int rv; 369 int rv;
371 370
372 rv = sscanf(buf, "%u", &jid);
373 if (rv != 1)
374 return -EINVAL;
375
376 rv = -ESHUTDOWN; 371 rv = -ESHUTDOWN;
377 spin_lock(&sdp->sd_jindex_spin); 372 spin_lock(&sdp->sd_jindex_spin);
378 if (test_bit(SDF_NORECOVERY, &sdp->sd_flags)) 373 if (test_bit(SDF_NORECOVERY, &sdp->sd_flags))
@@ -389,6 +384,20 @@ static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
389 } 384 }
390out: 385out:
391 spin_unlock(&sdp->sd_jindex_spin); 386 spin_unlock(&sdp->sd_jindex_spin);
387 return rv;
388}
389
390static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
391{
392 unsigned jid;
393 int rv;
394
395 rv = sscanf(buf, "%u", &jid);
396 if (rv != 1)
397 return -EINVAL;
398
399 rv = gfs2_recover_set(sdp, jid);
400
392 return rv ? rv : len; 401 return rv ? rv : len;
393} 402}
394 403
diff --git a/fs/gfs2/sys.h b/fs/gfs2/sys.h
index e94560e836d7..79182d6ad6ac 100644
--- a/fs/gfs2/sys.h
+++ b/fs/gfs2/sys.h
@@ -19,5 +19,7 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp);
19int gfs2_sys_init(void); 19int gfs2_sys_init(void);
20void gfs2_sys_uninit(void); 20void gfs2_sys_uninit(void);
21 21
22int gfs2_recover_set(struct gfs2_sbd *sdp, unsigned jid);
23
22#endif /* __SYS_DOT_H__ */ 24#endif /* __SYS_DOT_H__ */
23 25
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index e425ad9d0490..1e85a7ac0217 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -583,7 +583,8 @@ static int hugetlbfs_set_page_dirty(struct page *page)
583} 583}
584 584
585static int hugetlbfs_migrate_page(struct address_space *mapping, 585static int hugetlbfs_migrate_page(struct address_space *mapping,
586 struct page *newpage, struct page *page) 586 struct page *newpage, struct page *page,
587 enum migrate_mode mode)
587{ 588{
588 int rc; 589 int rc;
589 590
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 5ee92538b063..8102db9b926c 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -332,7 +332,7 @@ void nfs_commit_release_pages(struct nfs_write_data *data);
332 332
333#ifdef CONFIG_MIGRATION 333#ifdef CONFIG_MIGRATION
334extern int nfs_migrate_page(struct address_space *, 334extern int nfs_migrate_page(struct address_space *,
335 struct page *, struct page *); 335 struct page *, struct page *, enum migrate_mode);
336#else 336#else
337#define nfs_migrate_page NULL 337#define nfs_migrate_page NULL
338#endif 338#endif
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 0c3885255f97..834f0fe96f89 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1688,7 +1688,7 @@ out_error:
1688 1688
1689#ifdef CONFIG_MIGRATION 1689#ifdef CONFIG_MIGRATION
1690int nfs_migrate_page(struct address_space *mapping, struct page *newpage, 1690int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
1691 struct page *page) 1691 struct page *page, enum migrate_mode mode)
1692{ 1692{
1693 /* 1693 /*
1694 * If PagePrivate is set, then the page is currently associated with 1694 * If PagePrivate is set, then the page is currently associated with
@@ -1703,7 +1703,7 @@ int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
1703 1703
1704 nfs_fscache_release_page(page, GFP_KERNEL); 1704 nfs_fscache_release_page(page, GFP_KERNEL);
1705 1705
1706 return migrate_page(mapping, newpage, page); 1706 return migrate_page(mapping, newpage, page, mode);
1707} 1707}
1708#endif 1708#endif
1709 1709
diff --git a/fs/nfsd/Kconfig b/fs/nfsd/Kconfig
index 10e6366608f2..8df1ea4a6ff9 100644
--- a/fs/nfsd/Kconfig
+++ b/fs/nfsd/Kconfig
@@ -80,3 +80,13 @@ config NFSD_V4
80 available from http://linux-nfs.org/. 80 available from http://linux-nfs.org/.
81 81
82 If unsure, say N. 82 If unsure, say N.
83
84config NFSD_FAULT_INJECTION
85 bool "NFS server manual fault injection"
86 depends on NFSD_V4 && DEBUG_KERNEL
87 help
88 This option enables support for manually injecting faults
89 into the NFS server. This is intended to be used for
90 testing error recovery on the NFS client.
91
92 If unsure, say N.
diff --git a/fs/nfsd/Makefile b/fs/nfsd/Makefile
index 9b118ee20193..af32ef06b4fe 100644
--- a/fs/nfsd/Makefile
+++ b/fs/nfsd/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_NFSD) += nfsd.o
6 6
7nfsd-y := nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \ 7nfsd-y := nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
8 export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o 8 export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o
9nfsd-$(CONFIG_NFSD_FAULT_INJECTION) += fault_inject.o
9nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o 10nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o
10nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o 11nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o
11nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o 12nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 62f3b9074e84..cf8a6bd062fa 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -87,7 +87,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
87 struct svc_expkey key; 87 struct svc_expkey key;
88 struct svc_expkey *ek = NULL; 88 struct svc_expkey *ek = NULL;
89 89
90 if (mesg[mlen-1] != '\n') 90 if (mlen < 1 || mesg[mlen-1] != '\n')
91 return -EINVAL; 91 return -EINVAL;
92 mesg[mlen-1] = 0; 92 mesg[mlen-1] = 0;
93 93
@@ -1226,12 +1226,12 @@ nfsd_export_init(void)
1226 int rv; 1226 int rv;
1227 dprintk("nfsd: initializing export module.\n"); 1227 dprintk("nfsd: initializing export module.\n");
1228 1228
1229 rv = cache_register(&svc_export_cache); 1229 rv = cache_register_net(&svc_export_cache, &init_net);
1230 if (rv) 1230 if (rv)
1231 return rv; 1231 return rv;
1232 rv = cache_register(&svc_expkey_cache); 1232 rv = cache_register_net(&svc_expkey_cache, &init_net);
1233 if (rv) 1233 if (rv)
1234 cache_unregister(&svc_export_cache); 1234 cache_unregister_net(&svc_export_cache, &init_net);
1235 return rv; 1235 return rv;
1236 1236
1237} 1237}
@@ -1255,8 +1255,8 @@ nfsd_export_shutdown(void)
1255 1255
1256 dprintk("nfsd: shutting down export module.\n"); 1256 dprintk("nfsd: shutting down export module.\n");
1257 1257
1258 cache_unregister(&svc_expkey_cache); 1258 cache_unregister_net(&svc_expkey_cache, &init_net);
1259 cache_unregister(&svc_export_cache); 1259 cache_unregister_net(&svc_export_cache, &init_net);
1260 svcauth_unix_purge(); 1260 svcauth_unix_purge();
1261 1261
1262 dprintk("nfsd: export shutdown complete.\n"); 1262 dprintk("nfsd: export shutdown complete.\n");
diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
new file mode 100644
index 000000000000..ce7f0758d84c
--- /dev/null
+++ b/fs/nfsd/fault_inject.c
@@ -0,0 +1,91 @@
1/*
2 * Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
3 *
4 * Uses debugfs to create fault injection points for client testing
5 */
6
7#include <linux/types.h>
8#include <linux/fs.h>
9#include <linux/debugfs.h>
10#include <linux/module.h>
11
12#include "state.h"
13#include "fault_inject.h"
14
15struct nfsd_fault_inject_op {
16 char *file;
17 void (*func)(u64);
18};
19
20static struct nfsd_fault_inject_op inject_ops[] = {
21 {
22 .file = "forget_clients",
23 .func = nfsd_forget_clients,
24 },
25 {
26 .file = "forget_locks",
27 .func = nfsd_forget_locks,
28 },
29 {
30 .file = "forget_openowners",
31 .func = nfsd_forget_openowners,
32 },
33 {
34 .file = "forget_delegations",
35 .func = nfsd_forget_delegations,
36 },
37 {
38 .file = "recall_delegations",
39 .func = nfsd_recall_delegations,
40 },
41};
42
43static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op);
44static struct dentry *debug_dir;
45
46static int nfsd_inject_set(void *op_ptr, u64 val)
47{
48 struct nfsd_fault_inject_op *op = op_ptr;
49
50 if (val == 0)
51 printk(KERN_INFO "NFSD Fault Injection: %s (all)", op->file);
52 else
53 printk(KERN_INFO "NFSD Fault Injection: %s (n = %llu)", op->file, val);
54
55 op->func(val);
56 return 0;
57}
58
59static int nfsd_inject_get(void *data, u64 *val)
60{
61 return 0;
62}
63
64DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n");
65
66void nfsd_fault_inject_cleanup(void)
67{
68 debugfs_remove_recursive(debug_dir);
69}
70
71int nfsd_fault_inject_init(void)
72{
73 unsigned int i;
74 struct nfsd_fault_inject_op *op;
75 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
76
77 debug_dir = debugfs_create_dir("nfsd", NULL);
78 if (!debug_dir)
79 goto fail;
80
81 for (i = 0; i < NUM_INJECT_OPS; i++) {
82 op = &inject_ops[i];
83 if (!debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd))
84 goto fail;
85 }
86 return 0;
87
88fail:
89 nfsd_fault_inject_cleanup();
90 return -ENOMEM;
91}
diff --git a/fs/nfsd/fault_inject.h b/fs/nfsd/fault_inject.h
new file mode 100644
index 000000000000..90bd0570956c
--- /dev/null
+++ b/fs/nfsd/fault_inject.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
3 *
4 * Function definitions for fault injection
5 */
6
7#ifndef LINUX_NFSD_FAULT_INJECT_H
8#define LINUX_NFSD_FAULT_INJECT_H
9
10#ifdef CONFIG_NFSD_FAULT_INJECTION
11int nfsd_fault_inject_init(void);
12void nfsd_fault_inject_cleanup(void);
13void nfsd_forget_clients(u64);
14void nfsd_forget_locks(u64);
15void nfsd_forget_openowners(u64);
16void nfsd_forget_delegations(u64);
17void nfsd_recall_delegations(u64);
18#else /* CONFIG_NFSD_FAULT_INJECTION */
19static inline int nfsd_fault_inject_init(void) { return 0; }
20static inline void nfsd_fault_inject_cleanup(void) {}
21static inline void nfsd_forget_clients(u64 num) {}
22static inline void nfsd_forget_locks(u64 num) {}
23static inline void nfsd_forget_openowners(u64 num) {}
24static inline void nfsd_forget_delegations(u64 num) {}
25static inline void nfsd_recall_delegations(u64 num) {}
26#endif /* CONFIG_NFSD_FAULT_INJECTION */
27
28#endif /* LINUX_NFSD_FAULT_INJECT_H */
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index 55780a22fdbd..94096273cd6c 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -36,6 +36,7 @@
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <net/net_namespace.h>
39#include "idmap.h" 40#include "idmap.h"
40#include "nfsd.h" 41#include "nfsd.h"
41 42
@@ -466,20 +467,20 @@ nfsd_idmap_init(void)
466{ 467{
467 int rv; 468 int rv;
468 469
469 rv = cache_register(&idtoname_cache); 470 rv = cache_register_net(&idtoname_cache, &init_net);
470 if (rv) 471 if (rv)
471 return rv; 472 return rv;
472 rv = cache_register(&nametoid_cache); 473 rv = cache_register_net(&nametoid_cache, &init_net);
473 if (rv) 474 if (rv)
474 cache_unregister(&idtoname_cache); 475 cache_unregister_net(&idtoname_cache, &init_net);
475 return rv; 476 return rv;
476} 477}
477 478
478void 479void
479nfsd_idmap_shutdown(void) 480nfsd_idmap_shutdown(void)
480{ 481{
481 cache_unregister(&idtoname_cache); 482 cache_unregister_net(&idtoname_cache, &init_net);
482 cache_unregister(&nametoid_cache); 483 cache_unregister_net(&nametoid_cache, &init_net);
483} 484}
484 485
485static int 486static int
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index c5e28ed8bca0..896da74ec563 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -266,10 +266,6 @@ do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_
266{ 266{
267 __be32 status; 267 __be32 status;
268 268
269 /* Only reclaims from previously confirmed clients are valid */
270 if ((status = nfs4_check_open_reclaim(&open->op_clientid)))
271 return status;
272
273 /* We don't know the target directory, and therefore can not 269 /* We don't know the target directory, and therefore can not
274 * set the change info 270 * set the change info
275 */ 271 */
@@ -373,6 +369,9 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
373 break; 369 break;
374 case NFS4_OPEN_CLAIM_PREVIOUS: 370 case NFS4_OPEN_CLAIM_PREVIOUS:
375 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; 371 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
372 status = nfs4_check_open_reclaim(&open->op_clientid);
373 if (status)
374 goto out;
376 case NFS4_OPEN_CLAIM_FH: 375 case NFS4_OPEN_CLAIM_FH:
377 case NFS4_OPEN_CLAIM_DELEG_CUR_FH: 376 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
378 status = do_open_fhandle(rqstp, &cstate->current_fh, 377 status = do_open_fhandle(rqstp, &cstate->current_fh,
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index 80a0be9ed008..0b3e875d1abd 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -117,8 +117,7 @@ out_no_tfm:
117 return status; 117 return status;
118} 118}
119 119
120int 120void nfsd4_create_clid_dir(struct nfs4_client *clp)
121nfsd4_create_clid_dir(struct nfs4_client *clp)
122{ 121{
123 const struct cred *original_cred; 122 const struct cred *original_cred;
124 char *dname = clp->cl_recdir; 123 char *dname = clp->cl_recdir;
@@ -127,13 +126,14 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
127 126
128 dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname); 127 dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname);
129 128
130 if (!rec_file || clp->cl_firststate) 129 if (clp->cl_firststate)
131 return 0; 130 return;
132
133 clp->cl_firststate = 1; 131 clp->cl_firststate = 1;
132 if (!rec_file)
133 return;
134 status = nfs4_save_creds(&original_cred); 134 status = nfs4_save_creds(&original_cred);
135 if (status < 0) 135 if (status < 0)
136 return status; 136 return;
137 137
138 dir = rec_file->f_path.dentry; 138 dir = rec_file->f_path.dentry;
139 /* lock the parent */ 139 /* lock the parent */
@@ -144,8 +144,15 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
144 status = PTR_ERR(dentry); 144 status = PTR_ERR(dentry);
145 goto out_unlock; 145 goto out_unlock;
146 } 146 }
147 status = -EEXIST;
148 if (dentry->d_inode) 147 if (dentry->d_inode)
148 /*
149 * In the 4.1 case, where we're called from
150 * reclaim_complete(), records from the previous reboot
151 * may still be left, so this is OK.
152 *
153 * In the 4.0 case, we should never get here; but we may
154 * as well be forgiving and just succeed silently.
155 */
149 goto out_put; 156 goto out_put;
150 status = mnt_want_write_file(rec_file); 157 status = mnt_want_write_file(rec_file);
151 if (status) 158 if (status)
@@ -164,7 +171,6 @@ out_unlock:
164 " and is writeable", status, 171 " and is writeable", status,
165 user_recovery_dirname); 172 user_recovery_dirname);
166 nfs4_reset_creds(original_cred); 173 nfs4_reset_creds(original_cred);
167 return status;
168} 174}
169 175
170typedef int (recdir_func)(struct dentry *, struct dentry *); 176typedef int (recdir_func)(struct dentry *, struct dentry *);
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9ca16dc09e04..e8c98f009670 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -49,12 +49,20 @@
49time_t nfsd4_lease = 90; /* default lease time */ 49time_t nfsd4_lease = 90; /* default lease time */
50time_t nfsd4_grace = 90; 50time_t nfsd4_grace = 90;
51static time_t boot_time; 51static time_t boot_time;
52static stateid_t zerostateid; /* bits all 0 */ 52
53static stateid_t onestateid; /* bits all 1 */ 53#define all_ones {{~0,~0},~0}
54static const stateid_t one_stateid = {
55 .si_generation = ~0,
56 .si_opaque = all_ones,
57};
58static const stateid_t zero_stateid = {
59 /* all fields zero */
60};
61
54static u64 current_sessionid = 1; 62static u64 current_sessionid = 1;
55 63
56#define ZERO_STATEID(stateid) (!memcmp((stateid), &zerostateid, sizeof(stateid_t))) 64#define ZERO_STATEID(stateid) (!memcmp((stateid), &zero_stateid, sizeof(stateid_t)))
57#define ONE_STATEID(stateid) (!memcmp((stateid), &onestateid, sizeof(stateid_t))) 65#define ONE_STATEID(stateid) (!memcmp((stateid), &one_stateid, sizeof(stateid_t)))
58 66
59/* forward declarations */ 67/* forward declarations */
60static int check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner); 68static int check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner);
@@ -133,21 +141,21 @@ unsigned int max_delegations;
133 * Open owner state (share locks) 141 * Open owner state (share locks)
134 */ 142 */
135 143
136/* hash tables for open owners */ 144/* hash tables for lock and open owners */
137#define OPEN_OWNER_HASH_BITS 8 145#define OWNER_HASH_BITS 8
138#define OPEN_OWNER_HASH_SIZE (1 << OPEN_OWNER_HASH_BITS) 146#define OWNER_HASH_SIZE (1 << OWNER_HASH_BITS)
139#define OPEN_OWNER_HASH_MASK (OPEN_OWNER_HASH_SIZE - 1) 147#define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1)
140 148
141static unsigned int open_ownerstr_hashval(u32 clientid, struct xdr_netobj *ownername) 149static unsigned int ownerstr_hashval(u32 clientid, struct xdr_netobj *ownername)
142{ 150{
143 unsigned int ret; 151 unsigned int ret;
144 152
145 ret = opaque_hashval(ownername->data, ownername->len); 153 ret = opaque_hashval(ownername->data, ownername->len);
146 ret += clientid; 154 ret += clientid;
147 return ret & OPEN_OWNER_HASH_MASK; 155 return ret & OWNER_HASH_MASK;
148} 156}
149 157
150static struct list_head open_ownerstr_hashtbl[OPEN_OWNER_HASH_SIZE]; 158static struct list_head ownerstr_hashtbl[OWNER_HASH_SIZE];
151 159
152/* hash table for nfs4_file */ 160/* hash table for nfs4_file */
153#define FILE_HASH_BITS 8 161#define FILE_HASH_BITS 8
@@ -514,6 +522,7 @@ static void unhash_lockowner(struct nfs4_lockowner *lo)
514 522
515 list_del(&lo->lo_owner.so_strhash); 523 list_del(&lo->lo_owner.so_strhash);
516 list_del(&lo->lo_perstateid); 524 list_del(&lo->lo_perstateid);
525 list_del(&lo->lo_owner_ino_hash);
517 while (!list_empty(&lo->lo_owner.so_stateids)) { 526 while (!list_empty(&lo->lo_owner.so_stateids)) {
518 stp = list_first_entry(&lo->lo_owner.so_stateids, 527 stp = list_first_entry(&lo->lo_owner.so_stateids,
519 struct nfs4_ol_stateid, st_perstateowner); 528 struct nfs4_ol_stateid, st_perstateowner);
@@ -985,12 +994,11 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
985 clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL); 994 clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL);
986 if (clp == NULL) 995 if (clp == NULL)
987 return NULL; 996 return NULL;
988 clp->cl_name.data = kmalloc(name.len, GFP_KERNEL); 997 clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
989 if (clp->cl_name.data == NULL) { 998 if (clp->cl_name.data == NULL) {
990 kfree(clp); 999 kfree(clp);
991 return NULL; 1000 return NULL;
992 } 1001 }
993 memcpy(clp->cl_name.data, name.data, name.len);
994 clp->cl_name.len = name.len; 1002 clp->cl_name.len = name.len;
995 return clp; 1003 return clp;
996} 1004}
@@ -1058,7 +1066,6 @@ expire_client(struct nfs4_client *clp)
1058 spin_unlock(&recall_lock); 1066 spin_unlock(&recall_lock);
1059 while (!list_empty(&reaplist)) { 1067 while (!list_empty(&reaplist)) {
1060 dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru); 1068 dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru);
1061 list_del_init(&dp->dl_recall_lru);
1062 unhash_delegation(dp); 1069 unhash_delegation(dp);
1063 } 1070 }
1064 while (!list_empty(&clp->cl_openowners)) { 1071 while (!list_empty(&clp->cl_openowners)) {
@@ -2301,7 +2308,7 @@ nfsd4_free_slabs(void)
2301 nfsd4_free_slab(&deleg_slab); 2308 nfsd4_free_slab(&deleg_slab);
2302} 2309}
2303 2310
2304static int 2311int
2305nfsd4_init_slabs(void) 2312nfsd4_init_slabs(void)
2306{ 2313{
2307 openowner_slab = kmem_cache_create("nfsd4_openowners", 2314 openowner_slab = kmem_cache_create("nfsd4_openowners",
@@ -2373,7 +2380,7 @@ static inline void *alloc_stateowner(struct kmem_cache *slab, struct xdr_netobj
2373 2380
2374static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, unsigned int strhashval) 2381static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, unsigned int strhashval)
2375{ 2382{
2376 list_add(&oo->oo_owner.so_strhash, &open_ownerstr_hashtbl[strhashval]); 2383 list_add(&oo->oo_owner.so_strhash, &ownerstr_hashtbl[strhashval]);
2377 list_add(&oo->oo_perclient, &clp->cl_openowners); 2384 list_add(&oo->oo_perclient, &clp->cl_openowners);
2378} 2385}
2379 2386
@@ -2436,7 +2443,9 @@ find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open)
2436 struct nfs4_stateowner *so; 2443 struct nfs4_stateowner *so;
2437 struct nfs4_openowner *oo; 2444 struct nfs4_openowner *oo;
2438 2445
2439 list_for_each_entry(so, &open_ownerstr_hashtbl[hashval], so_strhash) { 2446 list_for_each_entry(so, &ownerstr_hashtbl[hashval], so_strhash) {
2447 if (!so->so_is_open_owner)
2448 continue;
2440 if (same_owner_str(so, &open->op_owner, &open->op_clientid)) { 2449 if (same_owner_str(so, &open->op_owner, &open->op_clientid)) {
2441 oo = openowner(so); 2450 oo = openowner(so);
2442 renew_client(oo->oo_owner.so_client); 2451 renew_client(oo->oo_owner.so_client);
@@ -2580,7 +2589,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
2580 if (open->op_file == NULL) 2589 if (open->op_file == NULL)
2581 return nfserr_jukebox; 2590 return nfserr_jukebox;
2582 2591
2583 strhashval = open_ownerstr_hashval(clientid->cl_id, &open->op_owner); 2592 strhashval = ownerstr_hashval(clientid->cl_id, &open->op_owner);
2584 oo = find_openstateowner_str(strhashval, open); 2593 oo = find_openstateowner_str(strhashval, open);
2585 open->op_openowner = oo; 2594 open->op_openowner = oo;
2586 if (!oo) { 2595 if (!oo) {
@@ -3123,7 +3132,6 @@ nfs4_laundromat(void)
3123 spin_unlock(&recall_lock); 3132 spin_unlock(&recall_lock);
3124 list_for_each_safe(pos, next, &reaplist) { 3133 list_for_each_safe(pos, next, &reaplist) {
3125 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); 3134 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
3126 list_del_init(&dp->dl_recall_lru);
3127 unhash_delegation(dp); 3135 unhash_delegation(dp);
3128 } 3136 }
3129 test_val = nfsd4_lease; 3137 test_val = nfsd4_lease;
@@ -3718,13 +3726,11 @@ out:
3718} 3726}
3719 3727
3720 3728
3721/*
3722 * Lock owner state (byte-range locks)
3723 */
3724#define LOFF_OVERFLOW(start, len) ((u64)(len) > ~(u64)(start)) 3729#define LOFF_OVERFLOW(start, len) ((u64)(len) > ~(u64)(start))
3725#define LOCK_HASH_BITS 8 3730
3726#define LOCK_HASH_SIZE (1 << LOCK_HASH_BITS) 3731#define LOCKOWNER_INO_HASH_BITS 8
3727#define LOCK_HASH_MASK (LOCK_HASH_SIZE - 1) 3732#define LOCKOWNER_INO_HASH_SIZE (1 << LOCKOWNER_INO_HASH_BITS)
3733#define LOCKOWNER_INO_HASH_MASK (LOCKOWNER_INO_HASH_SIZE - 1)
3728 3734
3729static inline u64 3735static inline u64
3730end_offset(u64 start, u64 len) 3736end_offset(u64 start, u64 len)
@@ -3746,16 +3752,14 @@ last_byte_offset(u64 start, u64 len)
3746 return end > start ? end - 1: NFS4_MAX_UINT64; 3752 return end > start ? end - 1: NFS4_MAX_UINT64;
3747} 3753}
3748 3754
3749static inline unsigned int 3755static unsigned int lockowner_ino_hashval(struct inode *inode, u32 cl_id, struct xdr_netobj *ownername)
3750lock_ownerstr_hashval(struct inode *inode, u32 cl_id,
3751 struct xdr_netobj *ownername)
3752{ 3756{
3753 return (file_hashval(inode) + cl_id 3757 return (file_hashval(inode) + cl_id
3754 + opaque_hashval(ownername->data, ownername->len)) 3758 + opaque_hashval(ownername->data, ownername->len))
3755 & LOCK_HASH_MASK; 3759 & LOCKOWNER_INO_HASH_MASK;
3756} 3760}
3757 3761
3758static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE]; 3762static struct list_head lockowner_ino_hashtbl[LOCKOWNER_INO_HASH_SIZE];
3759 3763
3760/* 3764/*
3761 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that 3765 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
@@ -3809,23 +3813,39 @@ nevermind:
3809 deny->ld_type = NFS4_WRITE_LT; 3813 deny->ld_type = NFS4_WRITE_LT;
3810} 3814}
3811 3815
3816static bool same_lockowner_ino(struct nfs4_lockowner *lo, struct inode *inode, clientid_t *clid, struct xdr_netobj *owner)
3817{
3818 struct nfs4_ol_stateid *lst;
3819
3820 if (!same_owner_str(&lo->lo_owner, owner, clid))
3821 return false;
3822 lst = list_first_entry(&lo->lo_owner.so_stateids,
3823 struct nfs4_ol_stateid, st_perstateowner);
3824 return lst->st_file->fi_inode == inode;
3825}
3826
3812static struct nfs4_lockowner * 3827static struct nfs4_lockowner *
3813find_lockowner_str(struct inode *inode, clientid_t *clid, 3828find_lockowner_str(struct inode *inode, clientid_t *clid,
3814 struct xdr_netobj *owner) 3829 struct xdr_netobj *owner)
3815{ 3830{
3816 unsigned int hashval = lock_ownerstr_hashval(inode, clid->cl_id, owner); 3831 unsigned int hashval = lockowner_ino_hashval(inode, clid->cl_id, owner);
3817 struct nfs4_stateowner *op; 3832 struct nfs4_lockowner *lo;
3818 3833
3819 list_for_each_entry(op, &lock_ownerstr_hashtbl[hashval], so_strhash) { 3834 list_for_each_entry(lo, &lockowner_ino_hashtbl[hashval], lo_owner_ino_hash) {
3820 if (same_owner_str(op, owner, clid)) 3835 if (same_lockowner_ino(lo, inode, clid, owner))
3821 return lockowner(op); 3836 return lo;
3822 } 3837 }
3823 return NULL; 3838 return NULL;
3824} 3839}
3825 3840
3826static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, struct nfs4_client *clp, struct nfs4_ol_stateid *open_stp) 3841static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, struct nfs4_client *clp, struct nfs4_ol_stateid *open_stp)
3827{ 3842{
3828 list_add(&lo->lo_owner.so_strhash, &lock_ownerstr_hashtbl[strhashval]); 3843 struct inode *inode = open_stp->st_file->fi_inode;
3844 unsigned int inohash = lockowner_ino_hashval(inode,
3845 clp->cl_clientid.cl_id, &lo->lo_owner.so_owner);
3846
3847 list_add(&lo->lo_owner.so_strhash, &ownerstr_hashtbl[strhashval]);
3848 list_add(&lo->lo_owner_ino_hash, &lockowner_ino_hashtbl[inohash]);
3829 list_add(&lo->lo_perstateid, &open_stp->st_lockowners); 3849 list_add(&lo->lo_perstateid, &open_stp->st_lockowners);
3830} 3850}
3831 3851
@@ -3834,7 +3854,7 @@ static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, s
3834 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has 3854 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has
3835 * occurred. 3855 * occurred.
3836 * 3856 *
3837 * strhashval = lock_ownerstr_hashval 3857 * strhashval = ownerstr_hashval
3838 */ 3858 */
3839 3859
3840static struct nfs4_lockowner * 3860static struct nfs4_lockowner *
@@ -3892,6 +3912,37 @@ static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
3892 __set_bit(access, &lock_stp->st_access_bmap); 3912 __set_bit(access, &lock_stp->st_access_bmap);
3893} 3913}
3894 3914
3915__be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *ost, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new)
3916{
3917 struct nfs4_file *fi = ost->st_file;
3918 struct nfs4_openowner *oo = openowner(ost->st_stateowner);
3919 struct nfs4_client *cl = oo->oo_owner.so_client;
3920 struct nfs4_lockowner *lo;
3921 unsigned int strhashval;
3922
3923 lo = find_lockowner_str(fi->fi_inode, &cl->cl_clientid, &lock->v.new.owner);
3924 if (lo) {
3925 if (!cstate->minorversion)
3926 return nfserr_bad_seqid;
3927 /* XXX: a lockowner always has exactly one stateid: */
3928 *lst = list_first_entry(&lo->lo_owner.so_stateids,
3929 struct nfs4_ol_stateid, st_perstateowner);
3930 return nfs_ok;
3931 }
3932 strhashval = ownerstr_hashval(cl->cl_clientid.cl_id,
3933 &lock->v.new.owner);
3934 lo = alloc_init_lock_stateowner(strhashval, cl, ost, lock);
3935 if (lo == NULL)
3936 return nfserr_jukebox;
3937 *lst = alloc_init_lock_stateid(lo, fi, ost);
3938 if (*lst == NULL) {
3939 release_lockowner(lo);
3940 return nfserr_jukebox;
3941 }
3942 *new = true;
3943 return nfs_ok;
3944}
3945
3895/* 3946/*
3896 * LOCK operation 3947 * LOCK operation
3897 */ 3948 */
@@ -3907,7 +3958,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3907 struct file_lock file_lock; 3958 struct file_lock file_lock;
3908 struct file_lock conflock; 3959 struct file_lock conflock;
3909 __be32 status = 0; 3960 __be32 status = 0;
3910 unsigned int strhashval; 3961 bool new_state = false;
3911 int lkflg; 3962 int lkflg;
3912 int err; 3963 int err;
3913 3964
@@ -3933,10 +3984,15 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3933 * lock stateid. 3984 * lock stateid.
3934 */ 3985 */
3935 struct nfs4_ol_stateid *open_stp = NULL; 3986 struct nfs4_ol_stateid *open_stp = NULL;
3936 3987
3988 if (nfsd4_has_session(cstate))
3989 /* See rfc 5661 18.10.3: given clientid is ignored: */
3990 memcpy(&lock->v.new.clientid,
3991 &cstate->session->se_client->cl_clientid,
3992 sizeof(clientid_t));
3993
3937 status = nfserr_stale_clientid; 3994 status = nfserr_stale_clientid;
3938 if (!nfsd4_has_session(cstate) && 3995 if (STALE_CLIENTID(&lock->lk_new_clientid))
3939 STALE_CLIENTID(&lock->lk_new_clientid))
3940 goto out; 3996 goto out;
3941 3997
3942 /* validate and update open stateid and open seqid */ 3998 /* validate and update open stateid and open seqid */
@@ -3948,25 +4004,12 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3948 goto out; 4004 goto out;
3949 open_sop = openowner(open_stp->st_stateowner); 4005 open_sop = openowner(open_stp->st_stateowner);
3950 status = nfserr_bad_stateid; 4006 status = nfserr_bad_stateid;
3951 if (!nfsd4_has_session(cstate) && 4007 if (!same_clid(&open_sop->oo_owner.so_client->cl_clientid,
3952 !same_clid(&open_sop->oo_owner.so_client->cl_clientid,
3953 &lock->v.new.clientid)) 4008 &lock->v.new.clientid))
3954 goto out; 4009 goto out;
3955 /* create lockowner and lock stateid */ 4010 status = lookup_or_create_lock_state(cstate, open_stp, lock,
3956 fp = open_stp->st_file; 4011 &lock_stp, &new_state);
3957 strhashval = lock_ownerstr_hashval(fp->fi_inode, 4012 if (status)
3958 open_sop->oo_owner.so_client->cl_clientid.cl_id,
3959 &lock->v.new.owner);
3960 /* XXX: Do we need to check for duplicate stateowners on
3961 * the same file, or should they just be allowed (and
3962 * create new stateids)? */
3963 status = nfserr_jukebox;
3964 lock_sop = alloc_init_lock_stateowner(strhashval,
3965 open_sop->oo_owner.so_client, open_stp, lock);
3966 if (lock_sop == NULL)
3967 goto out;
3968 lock_stp = alloc_init_lock_stateid(lock_sop, fp, open_stp);
3969 if (lock_stp == NULL)
3970 goto out; 4013 goto out;
3971 } else { 4014 } else {
3972 /* lock (lock owner + lock stateid) already exists */ 4015 /* lock (lock owner + lock stateid) already exists */
@@ -3976,10 +4019,9 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
3976 NFS4_LOCK_STID, &lock_stp); 4019 NFS4_LOCK_STID, &lock_stp);
3977 if (status) 4020 if (status)
3978 goto out; 4021 goto out;
3979 lock_sop = lockowner(lock_stp->st_stateowner);
3980 fp = lock_stp->st_file;
3981 } 4022 }
3982 /* lock_sop and lock_stp have been created or found */ 4023 lock_sop = lockowner(lock_stp->st_stateowner);
4024 fp = lock_stp->st_file;
3983 4025
3984 lkflg = setlkflg(lock->lk_type); 4026 lkflg = setlkflg(lock->lk_type);
3985 status = nfs4_check_openmode(lock_stp, lkflg); 4027 status = nfs4_check_openmode(lock_stp, lkflg);
@@ -4054,7 +4096,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4054 break; 4096 break;
4055 } 4097 }
4056out: 4098out:
4057 if (status && lock->lk_is_new && lock_sop) 4099 if (status && new_state)
4058 release_lockowner(lock_sop); 4100 release_lockowner(lock_sop);
4059 if (!cstate->replay_owner) 4101 if (!cstate->replay_owner)
4060 nfs4_unlock_state(); 4102 nfs4_unlock_state();
@@ -4251,7 +4293,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
4251 struct nfs4_ol_stateid *stp; 4293 struct nfs4_ol_stateid *stp;
4252 struct xdr_netobj *owner = &rlockowner->rl_owner; 4294 struct xdr_netobj *owner = &rlockowner->rl_owner;
4253 struct list_head matches; 4295 struct list_head matches;
4254 int i; 4296 unsigned int hashval = ownerstr_hashval(clid->cl_id, owner);
4255 __be32 status; 4297 __be32 status;
4256 4298
4257 dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n", 4299 dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n",
@@ -4266,22 +4308,19 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
4266 nfs4_lock_state(); 4308 nfs4_lock_state();
4267 4309
4268 status = nfserr_locks_held; 4310 status = nfserr_locks_held;
4269 /* XXX: we're doing a linear search through all the lockowners.
4270 * Yipes! For now we'll just hope clients aren't really using
4271 * release_lockowner much, but eventually we have to fix these
4272 * data structures. */
4273 INIT_LIST_HEAD(&matches); 4311 INIT_LIST_HEAD(&matches);
4274 for (i = 0; i < LOCK_HASH_SIZE; i++) { 4312
4275 list_for_each_entry(sop, &lock_ownerstr_hashtbl[i], so_strhash) { 4313 list_for_each_entry(sop, &ownerstr_hashtbl[hashval], so_strhash) {
4276 if (!same_owner_str(sop, owner, clid)) 4314 if (sop->so_is_open_owner)
4277 continue; 4315 continue;
4278 list_for_each_entry(stp, &sop->so_stateids, 4316 if (!same_owner_str(sop, owner, clid))
4279 st_perstateowner) { 4317 continue;
4280 lo = lockowner(sop); 4318 list_for_each_entry(stp, &sop->so_stateids,
4281 if (check_for_locks(stp->st_file, lo)) 4319 st_perstateowner) {
4282 goto out; 4320 lo = lockowner(sop);
4283 list_add(&lo->lo_list, &matches); 4321 if (check_for_locks(stp->st_file, lo))
4284 } 4322 goto out;
4323 list_add(&lo->lo_list, &matches);
4285 } 4324 }
4286 } 4325 }
4287 /* Clients probably won't expect us to return with some (but not all) 4326 /* Clients probably won't expect us to return with some (but not all)
@@ -4394,16 +4433,127 @@ nfs4_check_open_reclaim(clientid_t *clid)
4394 return nfs4_find_reclaim_client(clid) ? nfs_ok : nfserr_reclaim_bad; 4433 return nfs4_find_reclaim_client(clid) ? nfs_ok : nfserr_reclaim_bad;
4395} 4434}
4396 4435
4436#ifdef CONFIG_NFSD_FAULT_INJECTION
4437
4438void nfsd_forget_clients(u64 num)
4439{
4440 struct nfs4_client *clp, *next;
4441 int count = 0;
4442
4443 nfs4_lock_state();
4444 list_for_each_entry_safe(clp, next, &client_lru, cl_lru) {
4445 nfsd4_remove_clid_dir(clp);
4446 expire_client(clp);
4447 if (++count == num)
4448 break;
4449 }
4450 nfs4_unlock_state();
4451
4452 printk(KERN_INFO "NFSD: Forgot %d clients", count);
4453}
4454
4455static void release_lockowner_sop(struct nfs4_stateowner *sop)
4456{
4457 release_lockowner(lockowner(sop));
4458}
4459
4460static void release_openowner_sop(struct nfs4_stateowner *sop)
4461{
4462 release_openowner(openowner(sop));
4463}
4464
4465static int nfsd_release_n_owners(u64 num, bool is_open_owner,
4466 void (*release_sop)(struct nfs4_stateowner *))
4467{
4468 int i, count = 0;
4469 struct nfs4_stateowner *sop, *next;
4470
4471 for (i = 0; i < OWNER_HASH_SIZE; i++) {
4472 list_for_each_entry_safe(sop, next, &ownerstr_hashtbl[i], so_strhash) {
4473 if (sop->so_is_open_owner != is_open_owner)
4474 continue;
4475 release_sop(sop);
4476 if (++count == num)
4477 return count;
4478 }
4479 }
4480 return count;
4481}
4482
4483void nfsd_forget_locks(u64 num)
4484{
4485 int count;
4486
4487 nfs4_lock_state();
4488 count = nfsd_release_n_owners(num, false, release_lockowner_sop);
4489 nfs4_unlock_state();
4490
4491 printk(KERN_INFO "NFSD: Forgot %d locks", count);
4492}
4493
4494void nfsd_forget_openowners(u64 num)
4495{
4496 int count;
4497
4498 nfs4_lock_state();
4499 count = nfsd_release_n_owners(num, true, release_openowner_sop);
4500 nfs4_unlock_state();
4501
4502 printk(KERN_INFO "NFSD: Forgot %d open owners", count);
4503}
4504
4505int nfsd_process_n_delegations(u64 num, void (*deleg_func)(struct nfs4_delegation *))
4506{
4507 int i, count = 0;
4508 struct nfs4_file *fp, *fnext;
4509 struct nfs4_delegation *dp, *dnext;
4510
4511 for (i = 0; i < FILE_HASH_SIZE; i++) {
4512 list_for_each_entry_safe(fp, fnext, &file_hashtbl[i], fi_hash) {
4513 list_for_each_entry_safe(dp, dnext, &fp->fi_delegations, dl_perfile) {
4514 deleg_func(dp);
4515 if (++count == num)
4516 return count;
4517 }
4518 }
4519 }
4520
4521 return count;
4522}
4523
4524void nfsd_forget_delegations(u64 num)
4525{
4526 unsigned int count;
4527
4528 nfs4_lock_state();
4529 count = nfsd_process_n_delegations(num, unhash_delegation);
4530 nfs4_unlock_state();
4531
4532 printk(KERN_INFO "NFSD: Forgot %d delegations", count);
4533}
4534
4535void nfsd_recall_delegations(u64 num)
4536{
4537 unsigned int count;
4538
4539 nfs4_lock_state();
4540 spin_lock(&recall_lock);
4541 count = nfsd_process_n_delegations(num, nfsd_break_one_deleg);
4542 spin_unlock(&recall_lock);
4543 nfs4_unlock_state();
4544
4545 printk(KERN_INFO "NFSD: Recalled %d delegations", count);
4546}
4547
4548#endif /* CONFIG_NFSD_FAULT_INJECTION */
4549
4397/* initialization to perform at module load time: */ 4550/* initialization to perform at module load time: */
4398 4551
4399int 4552void
4400nfs4_state_init(void) 4553nfs4_state_init(void)
4401{ 4554{
4402 int i, status; 4555 int i;
4403 4556
4404 status = nfsd4_init_slabs();
4405 if (status)
4406 return status;
4407 for (i = 0; i < CLIENT_HASH_SIZE; i++) { 4557 for (i = 0; i < CLIENT_HASH_SIZE; i++) {
4408 INIT_LIST_HEAD(&conf_id_hashtbl[i]); 4558 INIT_LIST_HEAD(&conf_id_hashtbl[i]);
4409 INIT_LIST_HEAD(&conf_str_hashtbl[i]); 4559 INIT_LIST_HEAD(&conf_str_hashtbl[i]);
@@ -4416,18 +4566,15 @@ nfs4_state_init(void)
4416 for (i = 0; i < FILE_HASH_SIZE; i++) { 4566 for (i = 0; i < FILE_HASH_SIZE; i++) {
4417 INIT_LIST_HEAD(&file_hashtbl[i]); 4567 INIT_LIST_HEAD(&file_hashtbl[i]);
4418 } 4568 }
4419 for (i = 0; i < OPEN_OWNER_HASH_SIZE; i++) { 4569 for (i = 0; i < OWNER_HASH_SIZE; i++) {
4420 INIT_LIST_HEAD(&open_ownerstr_hashtbl[i]); 4570 INIT_LIST_HEAD(&ownerstr_hashtbl[i]);
4421 }
4422 for (i = 0; i < LOCK_HASH_SIZE; i++) {
4423 INIT_LIST_HEAD(&lock_ownerstr_hashtbl[i]);
4424 } 4571 }
4425 memset(&onestateid, ~0, sizeof(stateid_t)); 4572 for (i = 0; i < LOCKOWNER_INO_HASH_SIZE; i++)
4573 INIT_LIST_HEAD(&lockowner_ino_hashtbl[i]);
4426 INIT_LIST_HEAD(&close_lru); 4574 INIT_LIST_HEAD(&close_lru);
4427 INIT_LIST_HEAD(&client_lru); 4575 INIT_LIST_HEAD(&client_lru);
4428 INIT_LIST_HEAD(&del_recall_lru); 4576 INIT_LIST_HEAD(&del_recall_lru);
4429 reclaim_str_hashtbl_size = 0; 4577 reclaim_str_hashtbl_size = 0;
4430 return 0;
4431} 4578}
4432 4579
4433static void 4580static void
@@ -4526,7 +4673,6 @@ __nfs4_state_shutdown(void)
4526 spin_unlock(&recall_lock); 4673 spin_unlock(&recall_lock);
4527 list_for_each_safe(pos, next, &reaplist) { 4674 list_for_each_safe(pos, next, &reaplist) {
4528 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); 4675 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
4529 list_del_init(&dp->dl_recall_lru);
4530 unhash_delegation(dp); 4676 unhash_delegation(dp);
4531 } 4677 }
4532 4678
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index b6fa792d6b85..0ec5a1b9700e 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -215,10 +215,9 @@ defer_free(struct nfsd4_compoundargs *argp,
215static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes) 215static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
216{ 216{
217 if (p == argp->tmp) { 217 if (p == argp->tmp) {
218 p = kmalloc(nbytes, GFP_KERNEL); 218 p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
219 if (!p) 219 if (!p)
220 return NULL; 220 return NULL;
221 memcpy(p, argp->tmp, nbytes);
222 } else { 221 } else {
223 BUG_ON(p != argp->tmpp); 222 BUG_ON(p != argp->tmpp);
224 argp->tmpp = NULL; 223 argp->tmpp = NULL;
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index bb4a11d58a5a..748eda93ce59 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -18,6 +18,7 @@
18#include "idmap.h" 18#include "idmap.h"
19#include "nfsd.h" 19#include "nfsd.h"
20#include "cache.h" 20#include "cache.h"
21#include "fault_inject.h"
21 22
22/* 23/*
23 * We have a single directory with several nodes in it. 24 * We have a single directory with several nodes in it.
@@ -1128,9 +1129,13 @@ static int __init init_nfsd(void)
1128 int retval; 1129 int retval;
1129 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); 1130 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1130 1131
1131 retval = nfs4_state_init(); /* nfs4 locking state */ 1132 retval = nfsd4_init_slabs();
1132 if (retval) 1133 if (retval)
1133 return retval; 1134 return retval;
1135 nfs4_state_init();
1136 retval = nfsd_fault_inject_init(); /* nfsd fault injection controls */
1137 if (retval)
1138 goto out_free_slabs;
1134 nfsd_stat_init(); /* Statistics */ 1139 nfsd_stat_init(); /* Statistics */
1135 retval = nfsd_reply_cache_init(); 1140 retval = nfsd_reply_cache_init();
1136 if (retval) 1141 if (retval)
@@ -1161,6 +1166,8 @@ out_free_cache:
1161 nfsd_reply_cache_shutdown(); 1166 nfsd_reply_cache_shutdown();
1162out_free_stat: 1167out_free_stat:
1163 nfsd_stat_shutdown(); 1168 nfsd_stat_shutdown();
1169 nfsd_fault_inject_cleanup();
1170out_free_slabs:
1164 nfsd4_free_slabs(); 1171 nfsd4_free_slabs();
1165 return retval; 1172 return retval;
1166} 1173}
@@ -1175,6 +1182,7 @@ static void __exit exit_nfsd(void)
1175 nfsd_lockd_shutdown(); 1182 nfsd_lockd_shutdown();
1176 nfsd_idmap_shutdown(); 1183 nfsd_idmap_shutdown();
1177 nfsd4_free_slabs(); 1184 nfsd4_free_slabs();
1185 nfsd_fault_inject_cleanup();
1178 unregister_filesystem(&nfsd_fs_type); 1186 unregister_filesystem(&nfsd_fs_type);
1179} 1187}
1180 1188
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 58134a23fdfb..1d1e8589b4ce 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -104,14 +104,16 @@ static inline int nfsd_v4client(struct svc_rqst *rq)
104 */ 104 */
105#ifdef CONFIG_NFSD_V4 105#ifdef CONFIG_NFSD_V4
106extern unsigned int max_delegations; 106extern unsigned int max_delegations;
107int nfs4_state_init(void); 107void nfs4_state_init(void);
108int nfsd4_init_slabs(void);
108void nfsd4_free_slabs(void); 109void nfsd4_free_slabs(void);
109int nfs4_state_start(void); 110int nfs4_state_start(void);
110void nfs4_state_shutdown(void); 111void nfs4_state_shutdown(void);
111void nfs4_reset_lease(time_t leasetime); 112void nfs4_reset_lease(time_t leasetime);
112int nfs4_reset_recoverydir(char *recdir); 113int nfs4_reset_recoverydir(char *recdir);
113#else 114#else
114static inline int nfs4_state_init(void) { return 0; } 115static inline void nfs4_state_init(void) { }
116static inline int nfsd4_init_slabs(void) { return 0; }
115static inline void nfsd4_free_slabs(void) { } 117static inline void nfsd4_free_slabs(void) { }
116static inline int nfs4_state_start(void) { return 0; } 118static inline int nfs4_state_start(void) { return 0; }
117static inline void nfs4_state_shutdown(void) { } 119static inline void nfs4_state_shutdown(void) { }
@@ -338,15 +340,15 @@ static inline u32 nfsd_suppattrs2(u32 minorversion)
338} 340}
339 341
340/* These will return ERR_INVAL if specified in GETATTR or READDIR. */ 342/* These will return ERR_INVAL if specified in GETATTR or READDIR. */
341#define NFSD_WRITEONLY_ATTRS_WORD1 \ 343#define NFSD_WRITEONLY_ATTRS_WORD1 \
342(FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET) 344 (FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
343 345
344/* These are the only attrs allowed in CREATE/OPEN/SETATTR. */ 346/* These are the only attrs allowed in CREATE/OPEN/SETATTR. */
345#define NFSD_WRITEABLE_ATTRS_WORD0 \ 347#define NFSD_WRITEABLE_ATTRS_WORD0 \
346(FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL ) 348 (FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL)
347#define NFSD_WRITEABLE_ATTRS_WORD1 \ 349#define NFSD_WRITEABLE_ATTRS_WORD1 \
348(FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \ 350 (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \
349 | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET) 351 | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
350#define NFSD_WRITEABLE_ATTRS_WORD2 0 352#define NFSD_WRITEABLE_ATTRS_WORD2 0
351 353
352#define NFSD_SUPPATTR_EXCLCREAT_WORD0 \ 354#define NFSD_SUPPATTR_EXCLCREAT_WORD0 \
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index a3cf38476a1b..ffb5df1db94f 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -366,6 +366,7 @@ struct nfs4_openowner {
366 366
367struct nfs4_lockowner { 367struct nfs4_lockowner {
368 struct nfs4_stateowner lo_owner; /* must be first element */ 368 struct nfs4_stateowner lo_owner; /* must be first element */
369 struct list_head lo_owner_ino_hash; /* hash by owner,file */
369 struct list_head lo_perstateid; /* for lockowners only */ 370 struct list_head lo_perstateid; /* for lockowners only */
370 struct list_head lo_list; /* for temporary uses */ 371 struct list_head lo_list; /* for temporary uses */
371}; 372};
@@ -482,7 +483,7 @@ extern void nfsd4_shutdown_recdir(void);
482extern int nfs4_client_to_reclaim(const char *name); 483extern int nfs4_client_to_reclaim(const char *name);
483extern int nfs4_has_reclaimed_state(const char *name, bool use_exchange_id); 484extern int nfs4_has_reclaimed_state(const char *name, bool use_exchange_id);
484extern void nfsd4_recdir_purge_old(void); 485extern void nfsd4_recdir_purge_old(void);
485extern int nfsd4_create_clid_dir(struct nfs4_client *clp); 486extern void nfsd4_create_clid_dir(struct nfs4_client *clp);
486extern void nfsd4_remove_clid_dir(struct nfs4_client *clp); 487extern void nfsd4_remove_clid_dir(struct nfs4_client *clp);
487extern void release_session_client(struct nfsd4_session *); 488extern void release_session_client(struct nfsd4_session *);
488extern __be32 nfs4_validate_stateid(struct nfs4_client *, stateid_t *); 489extern __be32 nfs4_validate_stateid(struct nfs4_client *, stateid_t *);
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index d25a723b68ad..edf6d3ed8777 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -594,8 +594,19 @@ nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct nfs4_ac
594 return error; 594 return error;
595} 595}
596 596
597#define NFSD_XATTR_JUNCTION_PREFIX XATTR_TRUSTED_PREFIX "junction." 597/*
598#define NFSD_XATTR_JUNCTION_TYPE NFSD_XATTR_JUNCTION_PREFIX "type" 598 * NFS junction information is stored in an extended attribute.
599 */
600#define NFSD_JUNCTION_XATTR_NAME XATTR_TRUSTED_PREFIX "junction.nfs"
601
602/**
603 * nfsd4_is_junction - Test if an object could be an NFS junction
604 *
605 * @dentry: object to test
606 *
607 * Returns 1 if "dentry" appears to contain NFS junction information.
608 * Otherwise 0 is returned.
609 */
599int nfsd4_is_junction(struct dentry *dentry) 610int nfsd4_is_junction(struct dentry *dentry)
600{ 611{
601 struct inode *inode = dentry->d_inode; 612 struct inode *inode = dentry->d_inode;
@@ -606,7 +617,7 @@ int nfsd4_is_junction(struct dentry *dentry)
606 return 0; 617 return 0;
607 if (!(inode->i_mode & S_ISVTX)) 618 if (!(inode->i_mode & S_ISVTX))
608 return 0; 619 return 0;
609 if (vfs_getxattr(dentry, NFSD_XATTR_JUNCTION_TYPE, NULL, 0) <= 0) 620 if (vfs_getxattr(dentry, NFSD_JUNCTION_XATTR_NAME, NULL, 0) <= 0)
610 return 0; 621 return 0;
611 return 1; 622 return 1;
612} 623}
diff --git a/fs/pipe.c b/fs/pipe.c
index f0e485d54e64..a932ced92a16 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1137,7 +1137,7 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages)
1137 if (nr_pages < pipe->nrbufs) 1137 if (nr_pages < pipe->nrbufs)
1138 return -EBUSY; 1138 return -EBUSY;
1139 1139
1140 bufs = kcalloc(nr_pages, sizeof(struct pipe_buffer), GFP_KERNEL); 1140 bufs = kcalloc(nr_pages, sizeof(*bufs), GFP_KERNEL | __GFP_NOWARN);
1141 if (unlikely(!bufs)) 1141 if (unlikely(!bufs))
1142 return -ENOMEM; 1142 return -ENOMEM;
1143 1143
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 8c344f037bd0..9252ee3b71e3 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -464,7 +464,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
464 464
465 seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \ 465 seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
466%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \ 466%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
467%lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n", 467%lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld %lu %lu %lu\n",
468 pid_nr_ns(pid, ns), 468 pid_nr_ns(pid, ns),
469 tcomm, 469 tcomm,
470 state, 470 state,
@@ -511,7 +511,10 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
511 task->policy, 511 task->policy,
512 (unsigned long long)delayacct_blkio_ticks(task), 512 (unsigned long long)delayacct_blkio_ticks(task),
513 cputime_to_clock_t(gtime), 513 cputime_to_clock_t(gtime),
514 cputime_to_clock_t(cgtime)); 514 cputime_to_clock_t(cgtime),
515 (mm && permitted) ? mm->start_data : 0,
516 (mm && permitted) ? mm->end_data : 0,
517 (mm && permitted) ? mm->start_brk : 0);
515 if (mm) 518 if (mm)
516 mmput(mm); 519 mmput(mm);
517 return 0; 520 return 0;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 8173dfd89cb2..5485a5388ecb 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -654,6 +654,8 @@ static int proc_pid_permission(struct inode *inode, int mask)
654 bool has_perms; 654 bool has_perms;
655 655
656 task = get_proc_task(inode); 656 task = get_proc_task(inode);
657 if (!task)
658 return -ESRCH;
657 has_perms = has_pid_permissions(pid, task, 1); 659 has_perms = has_pid_permissions(pid, task, 1);
658 put_task_struct(task); 660 put_task_struct(task);
659 661
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
index f744be98cd5a..af0b73802592 100644
--- a/fs/squashfs/cache.c
+++ b/fs/squashfs/cache.c
@@ -70,11 +70,15 @@ struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
70 spin_lock(&cache->lock); 70 spin_lock(&cache->lock);
71 71
72 while (1) { 72 while (1) {
73 for (i = 0; i < cache->entries; i++) 73 for (i = cache->curr_blk, n = 0; n < cache->entries; n++) {
74 if (cache->entry[i].block == block) 74 if (cache->entry[i].block == block) {
75 cache->curr_blk = i;
75 break; 76 break;
77 }
78 i = (i + 1) % cache->entries;
79 }
76 80
77 if (i == cache->entries) { 81 if (n == cache->entries) {
78 /* 82 /*
79 * Block not in cache, if all cache entries are used 83 * Block not in cache, if all cache entries are used
80 * go to sleep waiting for one to become available. 84 * go to sleep waiting for one to become available.
@@ -245,6 +249,7 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
245 goto cleanup; 249 goto cleanup;
246 } 250 }
247 251
252 cache->curr_blk = 0;
248 cache->next_blk = 0; 253 cache->next_blk = 0;
249 cache->unused = entries; 254 cache->unused = entries;
250 cache->entries = entries; 255 cache->entries = entries;
@@ -332,17 +337,20 @@ int squashfs_read_metadata(struct super_block *sb, void *buffer,
332 u64 *block, int *offset, int length) 337 u64 *block, int *offset, int length)
333{ 338{
334 struct squashfs_sb_info *msblk = sb->s_fs_info; 339 struct squashfs_sb_info *msblk = sb->s_fs_info;
335 int bytes, copied = length; 340 int bytes, res = length;
336 struct squashfs_cache_entry *entry; 341 struct squashfs_cache_entry *entry;
337 342
338 TRACE("Entered squashfs_read_metadata [%llx:%x]\n", *block, *offset); 343 TRACE("Entered squashfs_read_metadata [%llx:%x]\n", *block, *offset);
339 344
340 while (length) { 345 while (length) {
341 entry = squashfs_cache_get(sb, msblk->block_cache, *block, 0); 346 entry = squashfs_cache_get(sb, msblk->block_cache, *block, 0);
342 if (entry->error) 347 if (entry->error) {
343 return entry->error; 348 res = entry->error;
344 else if (*offset >= entry->length) 349 goto error;
345 return -EIO; 350 } else if (*offset >= entry->length) {
351 res = -EIO;
352 goto error;
353 }
346 354
347 bytes = squashfs_copy_data(buffer, entry, *offset, length); 355 bytes = squashfs_copy_data(buffer, entry, *offset, length);
348 if (buffer) 356 if (buffer)
@@ -358,7 +366,11 @@ int squashfs_read_metadata(struct super_block *sb, void *buffer,
358 squashfs_cache_put(entry); 366 squashfs_cache_put(entry);
359 } 367 }
360 368
361 return copied; 369 return res;
370
371error:
372 squashfs_cache_put(entry);
373 return res;
362} 374}
363 375
364 376
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c
index fd7b3b3bda13..81afbccfa843 100644
--- a/fs/squashfs/inode.c
+++ b/fs/squashfs/inode.c
@@ -208,8 +208,8 @@ int squashfs_read_inode(struct inode *inode, long long ino)
208 inode->i_op = &squashfs_inode_ops; 208 inode->i_op = &squashfs_inode_ops;
209 inode->i_fop = &generic_ro_fops; 209 inode->i_fop = &generic_ro_fops;
210 inode->i_mode |= S_IFREG; 210 inode->i_mode |= S_IFREG;
211 inode->i_blocks = ((inode->i_size - 211 inode->i_blocks = (inode->i_size -
212 le64_to_cpu(sqsh_ino->sparse) - 1) >> 9) + 1; 212 le64_to_cpu(sqsh_ino->sparse) + 511) >> 9;
213 213
214 squashfs_i(inode)->fragment_block = frag_blk; 214 squashfs_i(inode)->fragment_block = frag_blk;
215 squashfs_i(inode)->fragment_size = frag_size; 215 squashfs_i(inode)->fragment_size = frag_size;
diff --git a/fs/squashfs/squashfs_fs_sb.h b/fs/squashfs/squashfs_fs_sb.h
index 651f0b31d296..52934a22f296 100644
--- a/fs/squashfs/squashfs_fs_sb.h
+++ b/fs/squashfs/squashfs_fs_sb.h
@@ -28,6 +28,7 @@
28struct squashfs_cache { 28struct squashfs_cache {
29 char *name; 29 char *name;
30 int entries; 30 int entries;
31 int curr_blk;
31 int next_blk; 32 int next_blk;
32 int num_waiters; 33 int num_waiters;
33 int unused; 34 int unused;
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index d0858c2d9a47..ecaa2f7bdb8f 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -290,7 +290,7 @@ handle_fragments:
290 290
291check_directory_table: 291check_directory_table:
292 /* Sanity check directory_table */ 292 /* Sanity check directory_table */
293 if (msblk->directory_table >= next_table) { 293 if (msblk->directory_table > next_table) {
294 err = -EINVAL; 294 err = -EINVAL;
295 goto failed_mount; 295 goto failed_mount;
296 } 296 }
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index b09ba2dd8b62..f922cbacdb96 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -38,9 +38,6 @@
38 38
39DEFINE_SPINLOCK(dbg_lock); 39DEFINE_SPINLOCK(dbg_lock);
40 40
41static char dbg_key_buf0[128];
42static char dbg_key_buf1[128];
43
44static const char *get_key_fmt(int fmt) 41static const char *get_key_fmt(int fmt)
45{ 42{
46 switch (fmt) { 43 switch (fmt) {
@@ -103,8 +100,8 @@ static const char *get_dent_type(int type)
103 } 100 }
104} 101}
105 102
106static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key, 103const char *dbg_snprintf_key(const struct ubifs_info *c,
107 char *buffer) 104 const union ubifs_key *key, char *buffer, int len)
108{ 105{
109 char *p = buffer; 106 char *p = buffer;
110 int type = key_type(c, key); 107 int type = key_type(c, key);
@@ -112,45 +109,34 @@ static void sprintf_key(const struct ubifs_info *c, const union ubifs_key *key,
112 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) { 109 if (c->key_fmt == UBIFS_SIMPLE_KEY_FMT) {
113 switch (type) { 110 switch (type) {
114 case UBIFS_INO_KEY: 111 case UBIFS_INO_KEY:
115 sprintf(p, "(%lu, %s)", (unsigned long)key_inum(c, key), 112 len -= snprintf(p, len, "(%lu, %s)",
116 get_key_type(type)); 113 (unsigned long)key_inum(c, key),
114 get_key_type(type));
117 break; 115 break;
118 case UBIFS_DENT_KEY: 116 case UBIFS_DENT_KEY:
119 case UBIFS_XENT_KEY: 117 case UBIFS_XENT_KEY:
120 sprintf(p, "(%lu, %s, %#08x)", 118 len -= snprintf(p, len, "(%lu, %s, %#08x)",
121 (unsigned long)key_inum(c, key), 119 (unsigned long)key_inum(c, key),
122 get_key_type(type), key_hash(c, key)); 120 get_key_type(type), key_hash(c, key));
123 break; 121 break;
124 case UBIFS_DATA_KEY: 122 case UBIFS_DATA_KEY:
125 sprintf(p, "(%lu, %s, %u)", 123 len -= snprintf(p, len, "(%lu, %s, %u)",
126 (unsigned long)key_inum(c, key), 124 (unsigned long)key_inum(c, key),
127 get_key_type(type), key_block(c, key)); 125 get_key_type(type), key_block(c, key));
128 break; 126 break;
129 case UBIFS_TRUN_KEY: 127 case UBIFS_TRUN_KEY:
130 sprintf(p, "(%lu, %s)", 128 len -= snprintf(p, len, "(%lu, %s)",
131 (unsigned long)key_inum(c, key), 129 (unsigned long)key_inum(c, key),
132 get_key_type(type)); 130 get_key_type(type));
133 break; 131 break;
134 default: 132 default:
135 sprintf(p, "(bad key type: %#08x, %#08x)", 133 len -= snprintf(p, len, "(bad key type: %#08x, %#08x)",
136 key->u32[0], key->u32[1]); 134 key->u32[0], key->u32[1]);
137 } 135 }
138 } else 136 } else
139 sprintf(p, "bad key format %d", c->key_fmt); 137 len -= snprintf(p, len, "bad key format %d", c->key_fmt);
140} 138 ubifs_assert(len > 0);
141 139 return p;
142const char *dbg_key_str0(const struct ubifs_info *c, const union ubifs_key *key)
143{
144 /* dbg_lock must be held */
145 sprintf_key(c, key, dbg_key_buf0);
146 return dbg_key_buf0;
147}
148
149const char *dbg_key_str1(const struct ubifs_info *c, const union ubifs_key *key)
150{
151 /* dbg_lock must be held */
152 sprintf_key(c, key, dbg_key_buf1);
153 return dbg_key_buf1;
154} 140}
155 141
156const char *dbg_ntype(int type) 142const char *dbg_ntype(int type)
@@ -319,6 +305,7 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
319 int i, n; 305 int i, n;
320 union ubifs_key key; 306 union ubifs_key key;
321 const struct ubifs_ch *ch = node; 307 const struct ubifs_ch *ch = node;
308 char key_buf[DBG_KEY_BUF_LEN];
322 309
323 if (dbg_is_tst_rcvry(c)) 310 if (dbg_is_tst_rcvry(c))
324 return; 311 return;
@@ -474,7 +461,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
474 const struct ubifs_ino_node *ino = node; 461 const struct ubifs_ino_node *ino = node;
475 462
476 key_read(c, &ino->key, &key); 463 key_read(c, &ino->key, &key);
477 printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 464 printk(KERN_DEBUG "\tkey %s\n",
465 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
478 printk(KERN_DEBUG "\tcreat_sqnum %llu\n", 466 printk(KERN_DEBUG "\tcreat_sqnum %llu\n",
479 (unsigned long long)le64_to_cpu(ino->creat_sqnum)); 467 (unsigned long long)le64_to_cpu(ino->creat_sqnum));
480 printk(KERN_DEBUG "\tsize %llu\n", 468 printk(KERN_DEBUG "\tsize %llu\n",
@@ -517,7 +505,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
517 int nlen = le16_to_cpu(dent->nlen); 505 int nlen = le16_to_cpu(dent->nlen);
518 506
519 key_read(c, &dent->key, &key); 507 key_read(c, &dent->key, &key);
520 printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 508 printk(KERN_DEBUG "\tkey %s\n",
509 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
521 printk(KERN_DEBUG "\tinum %llu\n", 510 printk(KERN_DEBUG "\tinum %llu\n",
522 (unsigned long long)le64_to_cpu(dent->inum)); 511 (unsigned long long)le64_to_cpu(dent->inum));
523 printk(KERN_DEBUG "\ttype %d\n", (int)dent->type); 512 printk(KERN_DEBUG "\ttype %d\n", (int)dent->type);
@@ -541,7 +530,8 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
541 int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ; 530 int dlen = le32_to_cpu(ch->len) - UBIFS_DATA_NODE_SZ;
542 531
543 key_read(c, &dn->key, &key); 532 key_read(c, &dn->key, &key);
544 printk(KERN_DEBUG "\tkey %s\n", DBGKEY(&key)); 533 printk(KERN_DEBUG "\tkey %s\n",
534 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
545 printk(KERN_DEBUG "\tsize %u\n", 535 printk(KERN_DEBUG "\tsize %u\n",
546 le32_to_cpu(dn->size)); 536 le32_to_cpu(dn->size));
547 printk(KERN_DEBUG "\tcompr_typ %d\n", 537 printk(KERN_DEBUG "\tcompr_typ %d\n",
@@ -582,7 +572,9 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node)
582 key_read(c, &br->key, &key); 572 key_read(c, &br->key, &key);
583 printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n", 573 printk(KERN_DEBUG "\t%d: LEB %d:%d len %d key %s\n",
584 i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs), 574 i, le32_to_cpu(br->lnum), le32_to_cpu(br->offs),
585 le32_to_cpu(br->len), DBGKEY(&key)); 575 le32_to_cpu(br->len),
576 dbg_snprintf_key(c, &key, key_buf,
577 DBG_KEY_BUF_LEN));
586 } 578 }
587 break; 579 break;
588 } 580 }
@@ -934,6 +926,7 @@ void dbg_dump_znode(const struct ubifs_info *c,
934{ 926{
935 int n; 927 int n;
936 const struct ubifs_zbranch *zbr; 928 const struct ubifs_zbranch *zbr;
929 char key_buf[DBG_KEY_BUF_LEN];
937 930
938 spin_lock(&dbg_lock); 931 spin_lock(&dbg_lock);
939 if (znode->parent) 932 if (znode->parent)
@@ -958,12 +951,16 @@ void dbg_dump_znode(const struct ubifs_info *c,
958 printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key " 951 printk(KERN_DEBUG "\t%d: znode %p LEB %d:%d len %d key "
959 "%s\n", n, zbr->znode, zbr->lnum, 952 "%s\n", n, zbr->znode, zbr->lnum,
960 zbr->offs, zbr->len, 953 zbr->offs, zbr->len,
961 DBGKEY(&zbr->key)); 954 dbg_snprintf_key(c, &zbr->key,
955 key_buf,
956 DBG_KEY_BUF_LEN));
962 else 957 else
963 printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key " 958 printk(KERN_DEBUG "\t%d: LNC %p LEB %d:%d len %d key "
964 "%s\n", n, zbr->znode, zbr->lnum, 959 "%s\n", n, zbr->znode, zbr->lnum,
965 zbr->offs, zbr->len, 960 zbr->offs, zbr->len,
966 DBGKEY(&zbr->key)); 961 dbg_snprintf_key(c, &zbr->key,
962 key_buf,
963 DBG_KEY_BUF_LEN));
967 } 964 }
968 spin_unlock(&dbg_lock); 965 spin_unlock(&dbg_lock);
969} 966}
@@ -1260,6 +1257,7 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1260 int err, nlen1, nlen2, cmp; 1257 int err, nlen1, nlen2, cmp;
1261 struct ubifs_dent_node *dent1, *dent2; 1258 struct ubifs_dent_node *dent1, *dent2;
1262 union ubifs_key key; 1259 union ubifs_key key;
1260 char key_buf[DBG_KEY_BUF_LEN];
1263 1261
1264 ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key)); 1262 ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key));
1265 dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); 1263 dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
@@ -1290,9 +1288,11 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1290 key_read(c, &dent1->key, &key); 1288 key_read(c, &dent1->key, &key);
1291 if (keys_cmp(c, &zbr1->key, &key)) { 1289 if (keys_cmp(c, &zbr1->key, &key)) {
1292 dbg_err("1st entry at %d:%d has key %s", zbr1->lnum, 1290 dbg_err("1st entry at %d:%d has key %s", zbr1->lnum,
1293 zbr1->offs, DBGKEY(&key)); 1291 zbr1->offs, dbg_snprintf_key(c, &key, key_buf,
1292 DBG_KEY_BUF_LEN));
1294 dbg_err("but it should have key %s according to tnc", 1293 dbg_err("but it should have key %s according to tnc",
1295 DBGKEY(&zbr1->key)); 1294 dbg_snprintf_key(c, &zbr1->key, key_buf,
1295 DBG_KEY_BUF_LEN));
1296 dbg_dump_node(c, dent1); 1296 dbg_dump_node(c, dent1);
1297 goto out_free; 1297 goto out_free;
1298 } 1298 }
@@ -1300,9 +1300,11 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1300 key_read(c, &dent2->key, &key); 1300 key_read(c, &dent2->key, &key);
1301 if (keys_cmp(c, &zbr2->key, &key)) { 1301 if (keys_cmp(c, &zbr2->key, &key)) {
1302 dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum, 1302 dbg_err("2nd entry at %d:%d has key %s", zbr1->lnum,
1303 zbr1->offs, DBGKEY(&key)); 1303 zbr1->offs, dbg_snprintf_key(c, &key, key_buf,
1304 DBG_KEY_BUF_LEN));
1304 dbg_err("but it should have key %s according to tnc", 1305 dbg_err("but it should have key %s according to tnc",
1305 DBGKEY(&zbr2->key)); 1306 dbg_snprintf_key(c, &zbr2->key, key_buf,
1307 DBG_KEY_BUF_LEN));
1306 dbg_dump_node(c, dent2); 1308 dbg_dump_node(c, dent2);
1307 goto out_free; 1309 goto out_free;
1308 } 1310 }
@@ -1319,7 +1321,7 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
1319 dbg_err("2 xent/dent nodes with the same name"); 1321 dbg_err("2 xent/dent nodes with the same name");
1320 else 1322 else
1321 dbg_err("bad order of colliding key %s", 1323 dbg_err("bad order of colliding key %s",
1322 DBGKEY(&key)); 1324 dbg_snprintf_key(c, &key, key_buf, DBG_KEY_BUF_LEN));
1323 1325
1324 ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs); 1326 ubifs_msg("first node at %d:%d\n", zbr1->lnum, zbr1->offs);
1325 dbg_dump_node(c, dent1); 1327 dbg_dump_node(c, dent1);
diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h
index 8d9c46810189..307ab1d23f75 100644
--- a/fs/ubifs/debug.h
+++ b/fs/ubifs/debug.h
@@ -169,40 +169,39 @@ struct ubifs_global_debug_info {
169 spin_unlock(&dbg_lock); \ 169 spin_unlock(&dbg_lock); \
170} while (0) 170} while (0)
171 171
172const char *dbg_key_str0(const struct ubifs_info *c, 172#define ubifs_dbg_msg(type, fmt, ...) \
173 const union ubifs_key *key); 173 pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__)
174const char *dbg_key_str1(const struct ubifs_info *c, 174
175 const union ubifs_key *key); 175#define DBG_KEY_BUF_LEN 32
176 176#define ubifs_dbg_msg_key(type, key, fmt, ...) do { \
177/* 177 char __tmp_key_buf[DBG_KEY_BUF_LEN]; \
178 * DBGKEY macros require @dbg_lock to be held, which it is in the dbg message 178 pr_debug("UBIFS DBG " type ": " fmt "%s\n", ##__VA_ARGS__, \
179 * macros. 179 dbg_snprintf_key(c, key, __tmp_key_buf, DBG_KEY_BUF_LEN)); \
180 */
181#define DBGKEY(key) dbg_key_str0(c, (key))
182#define DBGKEY1(key) dbg_key_str1(c, (key))
183
184extern spinlock_t dbg_lock;
185
186#define ubifs_dbg_msg(type, fmt, ...) do { \
187 spin_lock(&dbg_lock); \
188 pr_debug("UBIFS DBG " type ": " fmt "\n", ##__VA_ARGS__); \
189 spin_unlock(&dbg_lock); \
190} while (0) 180} while (0)
191 181
192/* Just a debugging messages not related to any specific UBIFS subsystem */ 182/* Just a debugging messages not related to any specific UBIFS subsystem */
193#define dbg_msg(fmt, ...) ubifs_dbg_msg("msg", fmt, ##__VA_ARGS__) 183#define dbg_msg(fmt, ...) \
184 printk(KERN_DEBUG "UBIFS DBG (pid %d): %s: " fmt "\n", current->pid, \
185 __func__, ##__VA_ARGS__)
186
194/* General messages */ 187/* General messages */
195#define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__) 188#define dbg_gen(fmt, ...) ubifs_dbg_msg("gen", fmt, ##__VA_ARGS__)
196/* Additional journal messages */ 189/* Additional journal messages */
197#define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__) 190#define dbg_jnl(fmt, ...) ubifs_dbg_msg("jnl", fmt, ##__VA_ARGS__)
191#define dbg_jnlk(key, fmt, ...) \
192 ubifs_dbg_msg_key("jnl", key, fmt, ##__VA_ARGS__)
198/* Additional TNC messages */ 193/* Additional TNC messages */
199#define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__) 194#define dbg_tnc(fmt, ...) ubifs_dbg_msg("tnc", fmt, ##__VA_ARGS__)
195#define dbg_tnck(key, fmt, ...) \
196 ubifs_dbg_msg_key("tnc", key, fmt, ##__VA_ARGS__)
200/* Additional lprops messages */ 197/* Additional lprops messages */
201#define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__) 198#define dbg_lp(fmt, ...) ubifs_dbg_msg("lp", fmt, ##__VA_ARGS__)
202/* Additional LEB find messages */ 199/* Additional LEB find messages */
203#define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__) 200#define dbg_find(fmt, ...) ubifs_dbg_msg("find", fmt, ##__VA_ARGS__)
204/* Additional mount messages */ 201/* Additional mount messages */
205#define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__) 202#define dbg_mnt(fmt, ...) ubifs_dbg_msg("mnt", fmt, ##__VA_ARGS__)
203#define dbg_mntk(key, fmt, ...) \
204 ubifs_dbg_msg_key("mnt", key, fmt, ##__VA_ARGS__)
206/* Additional I/O messages */ 205/* Additional I/O messages */
207#define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__) 206#define dbg_io(fmt, ...) ubifs_dbg_msg("io", fmt, ##__VA_ARGS__)
208/* Additional commit messages */ 207/* Additional commit messages */
@@ -218,6 +217,7 @@ extern spinlock_t dbg_lock;
218/* Additional recovery messages */ 217/* Additional recovery messages */
219#define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__) 218#define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__)
220 219
220extern spinlock_t dbg_lock;
221extern struct ubifs_global_debug_info ubifs_dbg; 221extern struct ubifs_global_debug_info ubifs_dbg;
222 222
223static inline int dbg_is_chk_gen(const struct ubifs_info *c) 223static inline int dbg_is_chk_gen(const struct ubifs_info *c)
@@ -258,6 +258,8 @@ const char *dbg_cstate(int cmt_state);
258const char *dbg_jhead(int jhead); 258const char *dbg_jhead(int jhead);
259const char *dbg_get_key_dump(const struct ubifs_info *c, 259const char *dbg_get_key_dump(const struct ubifs_info *c,
260 const union ubifs_key *key); 260 const union ubifs_key *key);
261const char *dbg_snprintf_key(const struct ubifs_info *c,
262 const union ubifs_key *key, char *buffer, int len);
261void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode); 263void dbg_dump_inode(struct ubifs_info *c, const struct inode *inode);
262void dbg_dump_node(const struct ubifs_info *c, const void *node); 264void dbg_dump_node(const struct ubifs_info *c, const void *node);
263void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum, 265void dbg_dump_lpt_node(const struct ubifs_info *c, void *node, int lnum,
@@ -368,6 +370,10 @@ static inline const char *dbg_jhead(int jhead) { return ""; }
368static inline const char * 370static inline const char *
369dbg_get_key_dump(const struct ubifs_info *c, 371dbg_get_key_dump(const struct ubifs_info *c,
370 const union ubifs_key *key) { return ""; } 372 const union ubifs_key *key) { return ""; }
373static inline const char *
374dbg_snprintf_key(const struct ubifs_info *c,
375 const union ubifs_key *key, char *buffer,
376 int len) { return ""; }
371static inline void dbg_dump_inode(struct ubifs_info *c, 377static inline void dbg_dump_inode(struct ubifs_info *c,
372 const struct inode *inode) { return; } 378 const struct inode *inode) { return; }
373static inline void dbg_dump_node(const struct ubifs_info *c, 379static inline void dbg_dump_node(const struct ubifs_info *c,
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index cef0460f4c54..2f438ab2e7a2 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -697,9 +697,8 @@ int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode,
697 int dlen = COMPRESSED_DATA_NODE_BUF_SZ, allocated = 1; 697 int dlen = COMPRESSED_DATA_NODE_BUF_SZ, allocated = 1;
698 struct ubifs_inode *ui = ubifs_inode(inode); 698 struct ubifs_inode *ui = ubifs_inode(inode);
699 699
700 dbg_jnl("ino %lu, blk %u, len %d, key %s", 700 dbg_jnlk(key, "ino %lu, blk %u, len %d, key ",
701 (unsigned long)key_inum(c, key), key_block(c, key), len, 701 (unsigned long)key_inum(c, key), key_block(c, key), len);
702 DBGKEY(key));
703 ubifs_assert(len <= UBIFS_BLOCK_SIZE); 702 ubifs_assert(len <= UBIFS_BLOCK_SIZE);
704 703
705 data = kmalloc(dlen, GFP_NOFS | __GFP_NOWARN); 704 data = kmalloc(dlen, GFP_NOFS | __GFP_NOWARN);
@@ -1177,7 +1176,7 @@ int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode,
1177 dn = (void *)trun + UBIFS_TRUN_NODE_SZ; 1176 dn = (void *)trun + UBIFS_TRUN_NODE_SZ;
1178 blk = new_size >> UBIFS_BLOCK_SHIFT; 1177 blk = new_size >> UBIFS_BLOCK_SHIFT;
1179 data_key_init(c, &key, inum, blk); 1178 data_key_init(c, &key, inum, blk);
1180 dbg_jnl("last block key %s", DBGKEY(&key)); 1179 dbg_jnlk(&key, "last block key ");
1181 err = ubifs_tnc_lookup(c, &key, dn); 1180 err = ubifs_tnc_lookup(c, &key, dn);
1182 if (err == -ENOENT) 1181 if (err == -ENOENT)
1183 dlen = 0; /* Not found (so it is a hole) */ 1182 dlen = 0; /* Not found (so it is a hole) */
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index ccabaf1164b3..b007637f0406 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -221,8 +221,8 @@ static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r)
221{ 221{
222 int err; 222 int err;
223 223
224 dbg_mnt("LEB %d:%d len %d deletion %d sqnum %llu %s", r->lnum, 224 dbg_mntk(&r->key, "LEB %d:%d len %d deletion %d sqnum %llu key ",
225 r->offs, r->len, r->deletion, r->sqnum, DBGKEY(&r->key)); 225 r->lnum, r->offs, r->len, r->deletion, r->sqnum);
226 226
227 /* Set c->replay_sqnum to help deal with dangling branches. */ 227 /* Set c->replay_sqnum to help deal with dangling branches. */
228 c->replay_sqnum = r->sqnum; 228 c->replay_sqnum = r->sqnum;
@@ -361,7 +361,7 @@ static int insert_node(struct ubifs_info *c, int lnum, int offs, int len,
361{ 361{
362 struct replay_entry *r; 362 struct replay_entry *r;
363 363
364 dbg_mnt("add LEB %d:%d, key %s", lnum, offs, DBGKEY(key)); 364 dbg_mntk(key, "add LEB %d:%d, key ", lnum, offs);
365 365
366 if (key_inum(c, key) >= c->highest_inum) 366 if (key_inum(c, key) >= c->highest_inum)
367 c->highest_inum = key_inum(c, key); 367 c->highest_inum = key_inum(c, key);
@@ -409,7 +409,7 @@ static int insert_dent(struct ubifs_info *c, int lnum, int offs, int len,
409 struct replay_entry *r; 409 struct replay_entry *r;
410 char *nbuf; 410 char *nbuf;
411 411
412 dbg_mnt("add LEB %d:%d, key %s", lnum, offs, DBGKEY(key)); 412 dbg_mntk(key, "add LEB %d:%d, key ", lnum, offs);
413 if (key_inum(c, key) >= c->highest_inum) 413 if (key_inum(c, key) >= c->highest_inum)
414 c->highest_inum = key_inum(c, key); 414 c->highest_inum = key_inum(c, key);
415 415
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index e14ee53159db..16ad84d8402f 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -505,7 +505,7 @@ static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key,
505{ 505{
506 int ret; 506 int ret;
507 507
508 dbg_tnc("LEB %d:%d, key %s", zbr->lnum, zbr->offs, DBGKEY(key)); 508 dbg_tnck(key, "LEB %d:%d, key ", zbr->lnum, zbr->offs);
509 509
510 ret = try_read_node(c, node, key_type(c, key), zbr->len, zbr->lnum, 510 ret = try_read_node(c, node, key_type(c, key), zbr->len, zbr->lnum,
511 zbr->offs); 511 zbr->offs);
@@ -519,8 +519,8 @@ static int fallible_read_node(struct ubifs_info *c, const union ubifs_key *key,
519 ret = 0; 519 ret = 0;
520 } 520 }
521 if (ret == 0 && c->replaying) 521 if (ret == 0 && c->replaying)
522 dbg_mnt("dangling branch LEB %d:%d len %d, key %s", 522 dbg_mntk(key, "dangling branch LEB %d:%d len %d, key ",
523 zbr->lnum, zbr->offs, zbr->len, DBGKEY(key)); 523 zbr->lnum, zbr->offs, zbr->len);
524 return ret; 524 return ret;
525} 525}
526 526
@@ -995,9 +995,9 @@ static int fallible_resolve_collision(struct ubifs_info *c,
995 if (adding || !o_znode) 995 if (adding || !o_znode)
996 return 0; 996 return 0;
997 997
998 dbg_mnt("dangling match LEB %d:%d len %d %s", 998 dbg_mntk(key, "dangling match LEB %d:%d len %d key ",
999 o_znode->zbranch[o_n].lnum, o_znode->zbranch[o_n].offs, 999 o_znode->zbranch[o_n].lnum, o_znode->zbranch[o_n].offs,
1000 o_znode->zbranch[o_n].len, DBGKEY(key)); 1000 o_znode->zbranch[o_n].len);
1001 *zn = o_znode; 1001 *zn = o_znode;
1002 *n = o_n; 1002 *n = o_n;
1003 return 1; 1003 return 1;
@@ -1179,7 +1179,7 @@ int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
1179 struct ubifs_znode *znode; 1179 struct ubifs_znode *znode;
1180 unsigned long time = get_seconds(); 1180 unsigned long time = get_seconds();
1181 1181
1182 dbg_tnc("search key %s", DBGKEY(key)); 1182 dbg_tnck(key, "search key ");
1183 ubifs_assert(key_type(c, key) < UBIFS_INVALID_KEY); 1183 ubifs_assert(key_type(c, key) < UBIFS_INVALID_KEY);
1184 1184
1185 znode = c->zroot.znode; 1185 znode = c->zroot.znode;
@@ -1315,7 +1315,7 @@ static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key,
1315 struct ubifs_znode *znode; 1315 struct ubifs_znode *znode;
1316 unsigned long time = get_seconds(); 1316 unsigned long time = get_seconds();
1317 1317
1318 dbg_tnc("search and dirty key %s", DBGKEY(key)); 1318 dbg_tnck(key, "search and dirty key ");
1319 1319
1320 znode = c->zroot.znode; 1320 znode = c->zroot.znode;
1321 if (unlikely(!znode)) { 1321 if (unlikely(!znode)) {
@@ -1722,8 +1722,8 @@ static int validate_data_node(struct ubifs_info *c, void *buf,
1722 if (!keys_eq(c, &zbr->key, &key1)) { 1722 if (!keys_eq(c, &zbr->key, &key1)) {
1723 ubifs_err("bad key in node at LEB %d:%d", 1723 ubifs_err("bad key in node at LEB %d:%d",
1724 zbr->lnum, zbr->offs); 1724 zbr->lnum, zbr->offs);
1725 dbg_tnc("looked for key %s found node's key %s", 1725 dbg_tnck(&zbr->key, "looked for key ");
1726 DBGKEY(&zbr->key), DBGKEY1(&key1)); 1726 dbg_tnck(&key1, "found node's key ");
1727 goto out_err; 1727 goto out_err;
1728 } 1728 }
1729 1729
@@ -1776,7 +1776,7 @@ int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu)
1776 ubifs_err("failed to read from LEB %d:%d, error %d", 1776 ubifs_err("failed to read from LEB %d:%d, error %d",
1777 lnum, offs, err); 1777 lnum, offs, err);
1778 dbg_dump_stack(); 1778 dbg_dump_stack();
1779 dbg_tnc("key %s", DBGKEY(&bu->key)); 1779 dbg_tnck(&bu->key, "key ");
1780 return err; 1780 return err;
1781 } 1781 }
1782 1782
@@ -1811,7 +1811,7 @@ static int do_lookup_nm(struct ubifs_info *c, const union ubifs_key *key,
1811 int found, n, err; 1811 int found, n, err;
1812 struct ubifs_znode *znode; 1812 struct ubifs_znode *znode;
1813 1813
1814 dbg_tnc("name '%.*s' key %s", nm->len, nm->name, DBGKEY(key)); 1814 dbg_tnck(key, "name '%.*s' key ", nm->len, nm->name);
1815 mutex_lock(&c->tnc_mutex); 1815 mutex_lock(&c->tnc_mutex);
1816 found = ubifs_lookup_level0(c, key, &znode, &n); 1816 found = ubifs_lookup_level0(c, key, &znode, &n);
1817 if (!found) { 1817 if (!found) {
@@ -1985,8 +1985,7 @@ again:
1985 zp = znode->parent; 1985 zp = znode->parent;
1986 if (znode->child_cnt < c->fanout) { 1986 if (znode->child_cnt < c->fanout) {
1987 ubifs_assert(n != c->fanout); 1987 ubifs_assert(n != c->fanout);
1988 dbg_tnc("inserted at %d level %d, key %s", n, znode->level, 1988 dbg_tnck(key, "inserted at %d level %d, key ", n, znode->level);
1989 DBGKEY(key));
1990 1989
1991 insert_zbranch(znode, zbr, n); 1990 insert_zbranch(znode, zbr, n);
1992 1991
@@ -2001,7 +2000,7 @@ again:
2001 * Unfortunately, @znode does not have more empty slots and we have to 2000 * Unfortunately, @znode does not have more empty slots and we have to
2002 * split it. 2001 * split it.
2003 */ 2002 */
2004 dbg_tnc("splitting level %d, key %s", znode->level, DBGKEY(key)); 2003 dbg_tnck(key, "splitting level %d, key ", znode->level);
2005 2004
2006 if (znode->alt) 2005 if (znode->alt)
2007 /* 2006 /*
@@ -2095,7 +2094,7 @@ do_split:
2095 } 2094 }
2096 2095
2097 /* Insert new key and branch */ 2096 /* Insert new key and branch */
2098 dbg_tnc("inserting at %d level %d, key %s", n, zn->level, DBGKEY(key)); 2097 dbg_tnck(key, "inserting at %d level %d, key ", n, zn->level);
2099 2098
2100 insert_zbranch(zi, zbr, n); 2099 insert_zbranch(zi, zbr, n);
2101 2100
@@ -2171,7 +2170,7 @@ int ubifs_tnc_add(struct ubifs_info *c, const union ubifs_key *key, int lnum,
2171 struct ubifs_znode *znode; 2170 struct ubifs_znode *znode;
2172 2171
2173 mutex_lock(&c->tnc_mutex); 2172 mutex_lock(&c->tnc_mutex);
2174 dbg_tnc("%d:%d, len %d, key %s", lnum, offs, len, DBGKEY(key)); 2173 dbg_tnck(key, "%d:%d, len %d, key ", lnum, offs, len);
2175 found = lookup_level0_dirty(c, key, &znode, &n); 2174 found = lookup_level0_dirty(c, key, &znode, &n);
2176 if (!found) { 2175 if (!found) {
2177 struct ubifs_zbranch zbr; 2176 struct ubifs_zbranch zbr;
@@ -2220,8 +2219,8 @@ int ubifs_tnc_replace(struct ubifs_info *c, const union ubifs_key *key,
2220 struct ubifs_znode *znode; 2219 struct ubifs_znode *znode;
2221 2220
2222 mutex_lock(&c->tnc_mutex); 2221 mutex_lock(&c->tnc_mutex);
2223 dbg_tnc("old LEB %d:%d, new LEB %d:%d, len %d, key %s", old_lnum, 2222 dbg_tnck(key, "old LEB %d:%d, new LEB %d:%d, len %d, key ", old_lnum,
2224 old_offs, lnum, offs, len, DBGKEY(key)); 2223 old_offs, lnum, offs, len);
2225 found = lookup_level0_dirty(c, key, &znode, &n); 2224 found = lookup_level0_dirty(c, key, &znode, &n);
2226 if (found < 0) { 2225 if (found < 0) {
2227 err = found; 2226 err = found;
@@ -2303,8 +2302,8 @@ int ubifs_tnc_add_nm(struct ubifs_info *c, const union ubifs_key *key,
2303 struct ubifs_znode *znode; 2302 struct ubifs_znode *znode;
2304 2303
2305 mutex_lock(&c->tnc_mutex); 2304 mutex_lock(&c->tnc_mutex);
2306 dbg_tnc("LEB %d:%d, name '%.*s', key %s", lnum, offs, nm->len, nm->name, 2305 dbg_tnck(key, "LEB %d:%d, name '%.*s', key ",
2307 DBGKEY(key)); 2306 lnum, offs, nm->len, nm->name);
2308 found = lookup_level0_dirty(c, key, &znode, &n); 2307 found = lookup_level0_dirty(c, key, &znode, &n);
2309 if (found < 0) { 2308 if (found < 0) {
2310 err = found; 2309 err = found;
@@ -2397,7 +2396,7 @@ static int tnc_delete(struct ubifs_info *c, struct ubifs_znode *znode, int n)
2397 /* Delete without merge for now */ 2396 /* Delete without merge for now */
2398 ubifs_assert(znode->level == 0); 2397 ubifs_assert(znode->level == 0);
2399 ubifs_assert(n >= 0 && n < c->fanout); 2398 ubifs_assert(n >= 0 && n < c->fanout);
2400 dbg_tnc("deleting %s", DBGKEY(&znode->zbranch[n].key)); 2399 dbg_tnck(&znode->zbranch[n].key, "deleting key ");
2401 2400
2402 zbr = &znode->zbranch[n]; 2401 zbr = &znode->zbranch[n];
2403 lnc_free(zbr); 2402 lnc_free(zbr);
@@ -2507,7 +2506,7 @@ int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key)
2507 struct ubifs_znode *znode; 2506 struct ubifs_znode *znode;
2508 2507
2509 mutex_lock(&c->tnc_mutex); 2508 mutex_lock(&c->tnc_mutex);
2510 dbg_tnc("key %s", DBGKEY(key)); 2509 dbg_tnck(key, "key ");
2511 found = lookup_level0_dirty(c, key, &znode, &n); 2510 found = lookup_level0_dirty(c, key, &znode, &n);
2512 if (found < 0) { 2511 if (found < 0) {
2513 err = found; 2512 err = found;
@@ -2538,7 +2537,7 @@ int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,
2538 struct ubifs_znode *znode; 2537 struct ubifs_znode *znode;
2539 2538
2540 mutex_lock(&c->tnc_mutex); 2539 mutex_lock(&c->tnc_mutex);
2541 dbg_tnc("%.*s, key %s", nm->len, nm->name, DBGKEY(key)); 2540 dbg_tnck(key, "%.*s, key ", nm->len, nm->name);
2542 err = lookup_level0_dirty(c, key, &znode, &n); 2541 err = lookup_level0_dirty(c, key, &znode, &n);
2543 if (err < 0) 2542 if (err < 0)
2544 goto out_unlock; 2543 goto out_unlock;
@@ -2653,7 +2652,7 @@ int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key,
2653 dbg_dump_znode(c, znode); 2652 dbg_dump_znode(c, znode);
2654 goto out_unlock; 2653 goto out_unlock;
2655 } 2654 }
2656 dbg_tnc("removing %s", DBGKEY(key)); 2655 dbg_tnck(key, "removing key ");
2657 } 2656 }
2658 if (k) { 2657 if (k) {
2659 for (i = n + 1 + k; i < znode->child_cnt; i++) 2658 for (i = n + 1 + k; i < znode->child_cnt; i++)
@@ -2773,7 +2772,7 @@ struct ubifs_dent_node *ubifs_tnc_next_ent(struct ubifs_info *c,
2773 struct ubifs_zbranch *zbr; 2772 struct ubifs_zbranch *zbr;
2774 union ubifs_key *dkey; 2773 union ubifs_key *dkey;
2775 2774
2776 dbg_tnc("%s %s", nm->name ? (char *)nm->name : "(lowest)", DBGKEY(key)); 2775 dbg_tnck(key, "%s ", nm->name ? (char *)nm->name : "(lowest)");
2777 ubifs_assert(is_hash_key(c, key)); 2776 ubifs_assert(is_hash_key(c, key));
2778 2777
2779 mutex_lock(&c->tnc_mutex); 2778 mutex_lock(&c->tnc_mutex);
@@ -3332,9 +3331,9 @@ int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode,
3332 3331
3333out_dump: 3332out_dump:
3334 block = key_block(c, key); 3333 block = key_block(c, key);
3335 ubifs_err("inode %lu has size %lld, but there are data at offset %lld " 3334 ubifs_err("inode %lu has size %lld, but there are data at offset %lld",
3336 "(data key %s)", (unsigned long)inode->i_ino, size, 3335 (unsigned long)inode->i_ino, size,
3337 ((loff_t)block) << UBIFS_BLOCK_SHIFT, DBGKEY(key)); 3336 ((loff_t)block) << UBIFS_BLOCK_SHIFT);
3338 mutex_unlock(&c->tnc_mutex); 3337 mutex_unlock(&c->tnc_mutex);
3339 dbg_dump_inode(c, inode); 3338 dbg_dump_inode(c, inode);
3340 dbg_dump_stack(); 3339 dbg_dump_stack();
diff --git a/fs/ubifs/tnc_misc.c b/fs/ubifs/tnc_misc.c
index b48db999903e..dc28fe6ec07a 100644
--- a/fs/ubifs/tnc_misc.c
+++ b/fs/ubifs/tnc_misc.c
@@ -328,8 +328,8 @@ static int read_znode(struct ubifs_info *c, int lnum, int offs, int len,
328 case UBIFS_XENT_KEY: 328 case UBIFS_XENT_KEY:
329 break; 329 break;
330 default: 330 default:
331 dbg_msg("bad key type at slot %d: %s", i, 331 dbg_msg("bad key type at slot %d: %d",
332 DBGKEY(&zbr->key)); 332 i, key_type(c, &zbr->key));
333 err = 3; 333 err = 3;
334 goto out_dump; 334 goto out_dump;
335 } 335 }
@@ -475,7 +475,7 @@ int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
475 zbr->offs); 475 zbr->offs);
476 476
477 if (err) { 477 if (err) {
478 dbg_tnc("key %s", DBGKEY(key)); 478 dbg_tnck(key, "key ");
479 return err; 479 return err;
480 } 480 }
481 481
@@ -484,8 +484,8 @@ int ubifs_tnc_read_node(struct ubifs_info *c, struct ubifs_zbranch *zbr,
484 if (!keys_eq(c, key, &key1)) { 484 if (!keys_eq(c, key, &key1)) {
485 ubifs_err("bad key in node at LEB %d:%d", 485 ubifs_err("bad key in node at LEB %d:%d",
486 zbr->lnum, zbr->offs); 486 zbr->lnum, zbr->offs);
487 dbg_tnc("looked for key %s found node's key %s", 487 dbg_tnck(key, "looked for key ");
488 DBGKEY(key), DBGKEY1(&key1)); 488 dbg_tnck(&key1, "but found node's key ");
489 dbg_dump_node(c, node); 489 dbg_dump_node(c, node);
490 return -EINVAL; 490 return -EINVAL;
491 } 491 }
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index e58fa777fa09..f96a5b58a975 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -139,6 +139,20 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
139 __tlb_remove_tlb_entry(tlb, ptep, address); \ 139 __tlb_remove_tlb_entry(tlb, ptep, address); \
140 } while (0) 140 } while (0)
141 141
142/**
143 * tlb_remove_pmd_tlb_entry - remember a pmd mapping for later tlb invalidation
144 * This is a nop so far, because only x86 needs it.
145 */
146#ifndef __tlb_remove_pmd_tlb_entry
147#define __tlb_remove_pmd_tlb_entry(tlb, pmdp, address) do {} while (0)
148#endif
149
150#define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \
151 do { \
152 tlb->need_flush = 1; \
153 __tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \
154 } while (0)
155
142#define pte_free_tlb(tlb, ptep, address) \ 156#define pte_free_tlb(tlb, ptep, address) \
143 do { \ 157 do { \
144 tlb->need_flush = 1; \ 158 tlb->need_flush = 1; \
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 63e4fce67288..4cd4be26722c 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -453,7 +453,7 @@ struct drm_encoder_funcs {
453#define DRM_CONNECTOR_MAX_UMODES 16 453#define DRM_CONNECTOR_MAX_UMODES 16
454#define DRM_CONNECTOR_MAX_PROPERTY 16 454#define DRM_CONNECTOR_MAX_PROPERTY 16
455#define DRM_CONNECTOR_LEN 32 455#define DRM_CONNECTOR_LEN 32
456#define DRM_CONNECTOR_MAX_ENCODER 2 456#define DRM_CONNECTOR_MAX_ENCODER 3
457 457
458/** 458/**
459 * drm_encoder - central DRM encoder structure 459 * drm_encoder - central DRM encoder structure
diff --git a/include/linux/amba/mmci.h b/include/linux/amba/mmci.h
index 21114810c7c0..0101e9c17fa1 100644
--- a/include/linux/amba/mmci.h
+++ b/include/linux/amba/mmci.h
@@ -30,6 +30,7 @@ struct dma_chan;
30 * @cd_invert: true if the gpio_cd pin value is active low 30 * @cd_invert: true if the gpio_cd pin value is active low
31 * @capabilities: the capabilities of the block as implemented in 31 * @capabilities: the capabilities of the block as implemented in
32 * this platform, signify anything MMC_CAP_* from mmc/host.h 32 * this platform, signify anything MMC_CAP_* from mmc/host.h
33 * @capabilities2: more capabilities, MMC_CAP2_* from mmc/host.h
33 * @dma_filter: function used to select an appropriate RX and TX 34 * @dma_filter: function used to select an appropriate RX and TX
34 * DMA channel to be used for DMA, if and only if you're deploying the 35 * DMA channel to be used for DMA, if and only if you're deploying the
35 * generic DMA engine 36 * generic DMA engine
@@ -52,6 +53,7 @@ struct mmci_platform_data {
52 int gpio_cd; 53 int gpio_cd;
53 bool cd_invert; 54 bool cd_invert;
54 unsigned long capabilities; 55 unsigned long capabilities;
56 unsigned long capabilities2;
55 bool (*dma_filter)(struct dma_chan *chan, void *filter_param); 57 bool (*dma_filter)(struct dma_chan *chan, void *filter_param);
56 void *dma_rx_param; 58 void *dma_rx_param;
57 void *dma_tx_param; 59 void *dma_tx_param;
diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
index 5c4abce94ad1..b936763f2236 100644
--- a/include/linux/crash_dump.h
+++ b/include/linux/crash_dump.h
@@ -5,6 +5,7 @@
5#include <linux/kexec.h> 5#include <linux/kexec.h>
6#include <linux/device.h> 6#include <linux/device.h>
7#include <linux/proc_fs.h> 7#include <linux/proc_fs.h>
8#include <linux/elf.h>
8 9
9#define ELFCORE_ADDR_MAX (-1ULL) 10#define ELFCORE_ADDR_MAX (-1ULL)
10#define ELFCORE_ADDR_ERR (-2ULL) 11#define ELFCORE_ADDR_ERR (-2ULL)
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 31f73220e7d7..d64a55b23afd 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -242,6 +242,7 @@ extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
242extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *); 242extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
243extern struct dentry * d_splice_alias(struct inode *, struct dentry *); 243extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
244extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *); 244extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
245extern struct dentry *d_find_any_alias(struct inode *inode);
245extern struct dentry * d_obtain_alias(struct inode *); 246extern struct dentry * d_obtain_alias(struct inode *);
246extern void shrink_dcache_sb(struct super_block *); 247extern void shrink_dcache_sb(struct super_block *);
247extern void shrink_dcache_parent(struct dentry *); 248extern void shrink_dcache_parent(struct dentry *);
diff --git a/include/linux/eventpoll.h b/include/linux/eventpoll.h
index f362733186a5..657ab55beda0 100644
--- a/include/linux/eventpoll.h
+++ b/include/linux/eventpoll.h
@@ -61,6 +61,7 @@ struct file;
61static inline void eventpoll_init_file(struct file *file) 61static inline void eventpoll_init_file(struct file *file)
62{ 62{
63 INIT_LIST_HEAD(&file->f_ep_links); 63 INIT_LIST_HEAD(&file->f_ep_links);
64 INIT_LIST_HEAD(&file->f_tfile_llink);
64} 65}
65 66
66 67
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7aacf31418fe..4bc8169fb5a1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -525,6 +525,7 @@ enum positive_aop_returns {
525struct page; 525struct page;
526struct address_space; 526struct address_space;
527struct writeback_control; 527struct writeback_control;
528enum migrate_mode;
528 529
529struct iov_iter { 530struct iov_iter {
530 const struct iovec *iov; 531 const struct iovec *iov;
@@ -609,9 +610,12 @@ struct address_space_operations {
609 loff_t offset, unsigned long nr_segs); 610 loff_t offset, unsigned long nr_segs);
610 int (*get_xip_mem)(struct address_space *, pgoff_t, int, 611 int (*get_xip_mem)(struct address_space *, pgoff_t, int,
611 void **, unsigned long *); 612 void **, unsigned long *);
612 /* migrate the contents of a page to the specified target */ 613 /*
614 * migrate the contents of a page to the specified target. If sync
615 * is false, it must not block.
616 */
613 int (*migratepage) (struct address_space *, 617 int (*migratepage) (struct address_space *,
614 struct page *, struct page *); 618 struct page *, struct page *, enum migrate_mode);
615 int (*launder_page) (struct page *); 619 int (*launder_page) (struct page *);
616 int (*is_partially_uptodate) (struct page *, read_descriptor_t *, 620 int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
617 unsigned long); 621 unsigned long);
@@ -656,6 +660,7 @@ struct address_space {
656 * must be enforced here for CRIS, to let the least significant bit 660 * must be enforced here for CRIS, to let the least significant bit
657 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. 661 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
658 */ 662 */
663struct request_queue;
659 664
660struct block_device { 665struct block_device {
661 dev_t bd_dev; /* not a kdev_t - it's a search key */ 666 dev_t bd_dev; /* not a kdev_t - it's a search key */
@@ -678,6 +683,7 @@ struct block_device {
678 unsigned bd_part_count; 683 unsigned bd_part_count;
679 int bd_invalidated; 684 int bd_invalidated;
680 struct gendisk * bd_disk; 685 struct gendisk * bd_disk;
686 struct request_queue * bd_queue;
681 struct list_head bd_list; 687 struct list_head bd_list;
682 /* 688 /*
683 * Private data. You must have bd_claim'ed the block_device 689 * Private data. You must have bd_claim'ed the block_device
@@ -1001,6 +1007,7 @@ struct file {
1001#ifdef CONFIG_EPOLL 1007#ifdef CONFIG_EPOLL
1002 /* Used by fs/eventpoll.c to link all the hooks to this file */ 1008 /* Used by fs/eventpoll.c to link all the hooks to this file */
1003 struct list_head f_ep_links; 1009 struct list_head f_ep_links;
1010 struct list_head f_tfile_llink;
1004#endif /* #ifdef CONFIG_EPOLL */ 1011#endif /* #ifdef CONFIG_EPOLL */
1005 struct address_space *f_mapping; 1012 struct address_space *f_mapping;
1006#ifdef CONFIG_DEBUG_WRITECOUNT 1013#ifdef CONFIG_DEBUG_WRITECOUNT
@@ -2536,7 +2543,8 @@ extern int generic_check_addressable(unsigned, u64);
2536 2543
2537#ifdef CONFIG_MIGRATION 2544#ifdef CONFIG_MIGRATION
2538extern int buffer_migrate_page(struct address_space *, 2545extern int buffer_migrate_page(struct address_space *,
2539 struct page *, struct page *); 2546 struct page *, struct page *,
2547 enum migrate_mode);
2540#else 2548#else
2541#define buffer_migrate_page NULL 2549#define buffer_migrate_page NULL
2542#endif 2550#endif
diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h
index 4f4462974c14..b148087f49a6 100644
--- a/include/linux/gfs2_ondisk.h
+++ b/include/linux/gfs2_ondisk.h
@@ -22,6 +22,8 @@
22#define GFS2_LIVE_LOCK 1 22#define GFS2_LIVE_LOCK 1
23#define GFS2_TRANS_LOCK 2 23#define GFS2_TRANS_LOCK 2
24#define GFS2_RENAME_LOCK 3 24#define GFS2_RENAME_LOCK 3
25#define GFS2_CONTROL_LOCK 4
26#define GFS2_MOUNTED_LOCK 5
25 27
26/* Format numbers for various metadata types */ 28/* Format numbers for various metadata types */
27 29
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index a9ace9c32507..1b921299abc4 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -18,7 +18,7 @@ extern struct page *follow_trans_huge_pmd(struct mm_struct *mm,
18 unsigned int flags); 18 unsigned int flags);
19extern int zap_huge_pmd(struct mmu_gather *tlb, 19extern int zap_huge_pmd(struct mmu_gather *tlb,
20 struct vm_area_struct *vma, 20 struct vm_area_struct *vma,
21 pmd_t *pmd); 21 pmd_t *pmd, unsigned long addr);
22extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, 22extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
23 unsigned long addr, unsigned long end, 23 unsigned long addr, unsigned long end,
24 unsigned char *vec); 24 unsigned char *vec);
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 114c0f6fc63d..78d3465251d6 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -652,10 +652,12 @@ struct twl4030_power_data {
652 unsigned num; 652 unsigned num;
653 struct twl4030_resconfig *resource_config; 653 struct twl4030_resconfig *resource_config;
654#define TWL4030_RESCONFIG_UNDEF ((u8)-1) 654#define TWL4030_RESCONFIG_UNDEF ((u8)-1)
655 bool use_poweroff; /* Board is wired for TWL poweroff */
655}; 656};
656 657
657extern void twl4030_power_init(struct twl4030_power_data *triton2_scripts); 658extern void twl4030_power_init(struct twl4030_power_data *triton2_scripts);
658extern int twl4030_remove_script(u8 flags); 659extern int twl4030_remove_script(u8 flags);
660extern void twl4030_power_off(void);
659 661
660struct twl4030_codec_data { 662struct twl4030_codec_data {
661 unsigned int digimic_delay; /* in ms */ 663 unsigned int digimic_delay; /* in ms */
diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
index 34e8d52c1925..f1362b5447fc 100644
--- a/include/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -22,7 +22,7 @@ struct inet_diag_sockid {
22 22
23/* Request structure */ 23/* Request structure */
24 24
25struct inet_diag_req_compat { 25struct inet_diag_req {
26 __u8 idiag_family; /* Family of addresses. */ 26 __u8 idiag_family; /* Family of addresses. */
27 __u8 idiag_src_len; 27 __u8 idiag_src_len;
28 __u8 idiag_dst_len; 28 __u8 idiag_dst_len;
@@ -34,7 +34,7 @@ struct inet_diag_req_compat {
34 __u32 idiag_dbs; /* Tables to dump (NI) */ 34 __u32 idiag_dbs; /* Tables to dump (NI) */
35}; 35};
36 36
37struct inet_diag_req { 37struct inet_diag_req_v2 {
38 __u8 sdiag_family; 38 __u8 sdiag_family;
39 __u8 sdiag_protocol; 39 __u8 sdiag_protocol;
40 __u8 idiag_ext; 40 __u8 idiag_ext;
@@ -143,12 +143,12 @@ struct netlink_callback;
143struct inet_diag_handler { 143struct inet_diag_handler {
144 void (*dump)(struct sk_buff *skb, 144 void (*dump)(struct sk_buff *skb,
145 struct netlink_callback *cb, 145 struct netlink_callback *cb,
146 struct inet_diag_req *r, 146 struct inet_diag_req_v2 *r,
147 struct nlattr *bc); 147 struct nlattr *bc);
148 148
149 int (*dump_one)(struct sk_buff *in_skb, 149 int (*dump_one)(struct sk_buff *in_skb,
150 const struct nlmsghdr *nlh, 150 const struct nlmsghdr *nlh,
151 struct inet_diag_req *req); 151 struct inet_diag_req_v2 *req);
152 152
153 void (*idiag_get_info)(struct sock *sk, 153 void (*idiag_get_info)(struct sock *sk,
154 struct inet_diag_msg *r, 154 struct inet_diag_msg *r,
@@ -158,15 +158,15 @@ struct inet_diag_handler {
158 158
159struct inet_connection_sock; 159struct inet_connection_sock;
160int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, 160int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
161 struct sk_buff *skb, struct inet_diag_req *req, 161 struct sk_buff *skb, struct inet_diag_req_v2 *req,
162 u32 pid, u32 seq, u16 nlmsg_flags, 162 u32 pid, u32 seq, u16 nlmsg_flags,
163 const struct nlmsghdr *unlh); 163 const struct nlmsghdr *unlh);
164void inet_diag_dump_icsk(struct inet_hashinfo *h, struct sk_buff *skb, 164void inet_diag_dump_icsk(struct inet_hashinfo *h, struct sk_buff *skb,
165 struct netlink_callback *cb, struct inet_diag_req *r, 165 struct netlink_callback *cb, struct inet_diag_req_v2 *r,
166 struct nlattr *bc); 166 struct nlattr *bc);
167int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, 167int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
168 struct sk_buff *in_skb, const struct nlmsghdr *nlh, 168 struct sk_buff *in_skb, const struct nlmsghdr *nlh,
169 struct inet_diag_req *req); 169 struct inet_diag_req_v2 *req);
170 170
171int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk); 171int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk);
172 172
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d0a7a0c71661..e8343422240a 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -185,16 +185,17 @@ static inline void might_fault(void)
185 185
186extern struct atomic_notifier_head panic_notifier_list; 186extern struct atomic_notifier_head panic_notifier_list;
187extern long (*panic_blink)(int state); 187extern long (*panic_blink)(int state);
188NORET_TYPE void panic(const char * fmt, ...) 188__printf(1, 2)
189 __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; 189void panic(const char *fmt, ...)
190 __noreturn __cold;
190extern void oops_enter(void); 191extern void oops_enter(void);
191extern void oops_exit(void); 192extern void oops_exit(void);
192void print_oops_end_marker(void); 193void print_oops_end_marker(void);
193extern int oops_may_print(void); 194extern int oops_may_print(void);
194NORET_TYPE void do_exit(long error_code) 195void do_exit(long error_code)
195 ATTRIB_NORET; 196 __noreturn;
196NORET_TYPE void complete_and_exit(struct completion *, long) 197void complete_and_exit(struct completion *, long)
197 ATTRIB_NORET; 198 __noreturn;
198 199
199/* Internal, do not use. */ 200/* Internal, do not use. */
200int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); 201int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h
index ee0c952188de..fee66317e071 100644
--- a/include/linux/kmsg_dump.h
+++ b/include/linux/kmsg_dump.h
@@ -18,7 +18,6 @@
18enum kmsg_dump_reason { 18enum kmsg_dump_reason {
19 KMSG_DUMP_OOPS, 19 KMSG_DUMP_OOPS,
20 KMSG_DUMP_PANIC, 20 KMSG_DUMP_PANIC,
21 KMSG_DUMP_KEXEC,
22 KMSG_DUMP_RESTART, 21 KMSG_DUMP_RESTART,
23 KMSG_DUMP_HALT, 22 KMSG_DUMP_HALT,
24 KMSG_DUMP_POWEROFF, 23 KMSG_DUMP_POWEROFF,
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 3f46aedea42f..807f1e533226 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -88,8 +88,4 @@
88 88
89#endif 89#endif
90 90
91#define NORET_TYPE /**/
92#define ATTRIB_NORET __attribute__((noreturn))
93#define NORET_AND noreturn,
94
95#endif 91#endif
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index f944591765eb..4d34356fe644 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -32,13 +32,11 @@ enum mem_cgroup_page_stat_item {
32 MEMCG_NR_FILE_MAPPED, /* # of pages charged as file rss */ 32 MEMCG_NR_FILE_MAPPED, /* # of pages charged as file rss */
33}; 33};
34 34
35extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, 35struct mem_cgroup_reclaim_cookie {
36 struct list_head *dst, 36 struct zone *zone;
37 unsigned long *scanned, int order, 37 int priority;
38 isolate_mode_t mode, 38 unsigned int generation;
39 struct zone *z, 39};
40 struct mem_cgroup *mem_cont,
41 int active, int file);
42 40
43#ifdef CONFIG_CGROUP_MEM_RES_CTLR 41#ifdef CONFIG_CGROUP_MEM_RES_CTLR
44/* 42/*
@@ -56,20 +54,21 @@ extern int mem_cgroup_newpage_charge(struct page *page, struct mm_struct *mm,
56 gfp_t gfp_mask); 54 gfp_t gfp_mask);
57/* for swap handling */ 55/* for swap handling */
58extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm, 56extern int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
59 struct page *page, gfp_t mask, struct mem_cgroup **ptr); 57 struct page *page, gfp_t mask, struct mem_cgroup **memcgp);
60extern void mem_cgroup_commit_charge_swapin(struct page *page, 58extern void mem_cgroup_commit_charge_swapin(struct page *page,
61 struct mem_cgroup *ptr); 59 struct mem_cgroup *memcg);
62extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr); 60extern void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg);
63 61
64extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, 62extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
65 gfp_t gfp_mask); 63 gfp_t gfp_mask);
66extern void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru); 64
67extern void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru); 65struct lruvec *mem_cgroup_zone_lruvec(struct zone *, struct mem_cgroup *);
68extern void mem_cgroup_rotate_reclaimable_page(struct page *page); 66struct lruvec *mem_cgroup_lru_add_list(struct zone *, struct page *,
69extern void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru); 67 enum lru_list);
70extern void mem_cgroup_del_lru(struct page *page); 68void mem_cgroup_lru_del_list(struct page *, enum lru_list);
71extern void mem_cgroup_move_lists(struct page *page, 69void mem_cgroup_lru_del(struct page *);
72 enum lru_list from, enum lru_list to); 70struct lruvec *mem_cgroup_lru_move_lists(struct zone *, struct page *,
71 enum lru_list, enum lru_list);
73 72
74/* For coalescing uncharge for reducing memcg' overhead*/ 73/* For coalescing uncharge for reducing memcg' overhead*/
75extern void mem_cgroup_uncharge_start(void); 74extern void mem_cgroup_uncharge_start(void);
@@ -102,10 +101,15 @@ extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
102 101
103extern int 102extern int
104mem_cgroup_prepare_migration(struct page *page, 103mem_cgroup_prepare_migration(struct page *page,
105 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask); 104 struct page *newpage, struct mem_cgroup **memcgp, gfp_t gfp_mask);
106extern void mem_cgroup_end_migration(struct mem_cgroup *memcg, 105extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
107 struct page *oldpage, struct page *newpage, bool migration_ok); 106 struct page *oldpage, struct page *newpage, bool migration_ok);
108 107
108struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *,
109 struct mem_cgroup *,
110 struct mem_cgroup_reclaim_cookie *);
111void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
112
109/* 113/*
110 * For memory reclaim. 114 * For memory reclaim.
111 */ 115 */
@@ -122,7 +126,10 @@ struct zone_reclaim_stat*
122mem_cgroup_get_reclaim_stat_from_page(struct page *page); 126mem_cgroup_get_reclaim_stat_from_page(struct page *page);
123extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, 127extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
124 struct task_struct *p); 128 struct task_struct *p);
129extern void mem_cgroup_replace_page_cache(struct page *oldpage,
130 struct page *newpage);
125 131
132extern void mem_cgroup_reset_owner(struct page *page);
126#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP 133#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
127extern int do_swap_account; 134extern int do_swap_account;
128#endif 135#endif
@@ -157,7 +164,7 @@ u64 mem_cgroup_get_limit(struct mem_cgroup *memcg);
157 164
158void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx); 165void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
159#ifdef CONFIG_TRANSPARENT_HUGEPAGE 166#ifdef CONFIG_TRANSPARENT_HUGEPAGE
160void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail); 167void mem_cgroup_split_huge_fixup(struct page *head);
161#endif 168#endif
162 169
163#ifdef CONFIG_DEBUG_VM 170#ifdef CONFIG_DEBUG_VM
@@ -180,17 +187,17 @@ static inline int mem_cgroup_cache_charge(struct page *page,
180} 187}
181 188
182static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm, 189static inline int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
183 struct page *page, gfp_t gfp_mask, struct mem_cgroup **ptr) 190 struct page *page, gfp_t gfp_mask, struct mem_cgroup **memcgp)
184{ 191{
185 return 0; 192 return 0;
186} 193}
187 194
188static inline void mem_cgroup_commit_charge_swapin(struct page *page, 195static inline void mem_cgroup_commit_charge_swapin(struct page *page,
189 struct mem_cgroup *ptr) 196 struct mem_cgroup *memcg)
190{ 197{
191} 198}
192 199
193static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *ptr) 200static inline void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
194{ 201{
195} 202}
196 203
@@ -210,33 +217,33 @@ static inline void mem_cgroup_uncharge_cache_page(struct page *page)
210{ 217{
211} 218}
212 219
213static inline void mem_cgroup_add_lru_list(struct page *page, int lru) 220static inline struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
214{ 221 struct mem_cgroup *memcg)
215}
216
217static inline void mem_cgroup_del_lru_list(struct page *page, int lru)
218{ 222{
219 return ; 223 return &zone->lruvec;
220} 224}
221 225
222static inline void mem_cgroup_rotate_reclaimable_page(struct page *page) 226static inline struct lruvec *mem_cgroup_lru_add_list(struct zone *zone,
227 struct page *page,
228 enum lru_list lru)
223{ 229{
224 return ; 230 return &zone->lruvec;
225} 231}
226 232
227static inline void mem_cgroup_rotate_lru_list(struct page *page, int lru) 233static inline void mem_cgroup_lru_del_list(struct page *page, enum lru_list lru)
228{ 234{
229 return ;
230} 235}
231 236
232static inline void mem_cgroup_del_lru(struct page *page) 237static inline void mem_cgroup_lru_del(struct page *page)
233{ 238{
234 return ;
235} 239}
236 240
237static inline void 241static inline struct lruvec *mem_cgroup_lru_move_lists(struct zone *zone,
238mem_cgroup_move_lists(struct page *page, enum lru_list from, enum lru_list to) 242 struct page *page,
243 enum lru_list from,
244 enum lru_list to)
239{ 245{
246 return &zone->lruvec;
240} 247}
241 248
242static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) 249static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
@@ -269,7 +276,7 @@ static inline struct cgroup_subsys_state
269 276
270static inline int 277static inline int
271mem_cgroup_prepare_migration(struct page *page, struct page *newpage, 278mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
272 struct mem_cgroup **ptr, gfp_t gfp_mask) 279 struct mem_cgroup **memcgp, gfp_t gfp_mask)
273{ 280{
274 return 0; 281 return 0;
275} 282}
@@ -279,6 +286,19 @@ static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
279{ 286{
280} 287}
281 288
289static inline struct mem_cgroup *
290mem_cgroup_iter(struct mem_cgroup *root,
291 struct mem_cgroup *prev,
292 struct mem_cgroup_reclaim_cookie *reclaim)
293{
294 return NULL;
295}
296
297static inline void mem_cgroup_iter_break(struct mem_cgroup *root,
298 struct mem_cgroup *prev)
299{
300}
301
282static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *memcg) 302static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *memcg)
283{ 303{
284 return 0; 304 return 0;
@@ -360,8 +380,7 @@ u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
360 return 0; 380 return 0;
361} 381}
362 382
363static inline void mem_cgroup_split_huge_fixup(struct page *head, 383static inline void mem_cgroup_split_huge_fixup(struct page *head)
364 struct page *tail)
365{ 384{
366} 385}
367 386
@@ -369,6 +388,14 @@ static inline
369void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx) 388void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
370{ 389{
371} 390}
391static inline void mem_cgroup_replace_page_cache(struct page *oldpage,
392 struct page *newpage)
393{
394}
395
396static inline void mem_cgroup_reset_owner(struct page *page)
397{
398}
372#endif /* CONFIG_CGROUP_MEM_CONT */ 399#endif /* CONFIG_CGROUP_MEM_CONT */
373 400
374#if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM) 401#if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM)
diff --git a/include/linux/mfd/88pm860x.h b/include/linux/mfd/88pm860x.h
index 63b4fb8e3b6f..92be3476c9f5 100644
--- a/include/linux/mfd/88pm860x.h
+++ b/include/linux/mfd/88pm860x.h
@@ -297,10 +297,11 @@ enum {
297 297
298struct pm860x_chip { 298struct pm860x_chip {
299 struct device *dev; 299 struct device *dev;
300 struct mutex io_lock;
301 struct mutex irq_lock; 300 struct mutex irq_lock;
302 struct i2c_client *client; 301 struct i2c_client *client;
303 struct i2c_client *companion; /* companion chip client */ 302 struct i2c_client *companion; /* companion chip client */
303 struct regmap *regmap;
304 struct regmap *regmap_companion;
304 305
305 int buck3_double; /* DVC ramp slope double */ 306 int buck3_double; /* DVC ramp slope double */
306 unsigned short companion_addr; 307 unsigned short companion_addr;
diff --git a/include/linux/mfd/ab5500/ab5500.h b/include/linux/mfd/abx500/ab5500.h
index a720051ae933..a720051ae933 100644
--- a/include/linux/mfd/ab5500/ab5500.h
+++ b/include/linux/mfd/abx500/ab5500.h
diff --git a/include/linux/mfd/ab8500/gpadc.h b/include/linux/mfd/abx500/ab8500-gpadc.h
index 252966769d93..252966769d93 100644
--- a/include/linux/mfd/ab8500/gpadc.h
+++ b/include/linux/mfd/abx500/ab8500-gpadc.h
diff --git a/include/linux/mfd/ab8500/gpio.h b/include/linux/mfd/abx500/ab8500-gpio.h
index 488a8c920a29..488a8c920a29 100644
--- a/include/linux/mfd/ab8500/gpio.h
+++ b/include/linux/mfd/abx500/ab8500-gpio.h
diff --git a/include/linux/mfd/ab8500/sysctrl.h b/include/linux/mfd/abx500/ab8500-sysctrl.h
index 10da0291f8f8..10da0291f8f8 100644
--- a/include/linux/mfd/ab8500/sysctrl.h
+++ b/include/linux/mfd/abx500/ab8500-sysctrl.h
diff --git a/include/linux/mfd/ab8500.h b/include/linux/mfd/abx500/ab8500.h
index 838c6b487cc5..838c6b487cc5 100644
--- a/include/linux/mfd/ab8500.h
+++ b/include/linux/mfd/abx500/ab8500.h
diff --git a/include/linux/mfd/max8925.h b/include/linux/mfd/max8925.h
index b8e6d9449086..15b2392a56fb 100644
--- a/include/linux/mfd/max8925.h
+++ b/include/linux/mfd/max8925.h
@@ -203,6 +203,8 @@ struct max8925_chip {
203 int irq_base; 203 int irq_base;
204 int core_irq; 204 int core_irq;
205 int tsc_irq; 205 int tsc_irq;
206
207 unsigned int wakeup_flag;
206}; 208};
207 209
208struct max8925_backlight_pdata { 210struct max8925_backlight_pdata {
diff --git a/include/linux/mfd/max8997.h b/include/linux/mfd/max8997.h
index 0bbd13dbe336..fff590521e50 100644
--- a/include/linux/mfd/max8997.h
+++ b/include/linux/mfd/max8997.h
@@ -77,6 +77,82 @@ struct max8997_regulator_data {
77 struct regulator_init_data *initdata; 77 struct regulator_init_data *initdata;
78}; 78};
79 79
80enum max8997_muic_usb_type {
81 MAX8997_USB_HOST,
82 MAX8997_USB_DEVICE,
83};
84
85enum max8997_muic_charger_type {
86 MAX8997_CHARGER_TYPE_NONE = 0,
87 MAX8997_CHARGER_TYPE_USB,
88 MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT,
89 MAX8997_CHARGER_TYPE_DEDICATED_CHG,
90 MAX8997_CHARGER_TYPE_500MA,
91 MAX8997_CHARGER_TYPE_1A,
92 MAX8997_CHARGER_TYPE_DEAD_BATTERY = 7,
93};
94
95struct max8997_muic_reg_data {
96 u8 addr;
97 u8 data;
98};
99
100/**
101 * struct max8997_muic_platform_data
102 * @usb_callback: callback function for USB
103 * inform callee of USB type (HOST or DEVICE)
104 * and attached state(true or false)
105 * @charger_callback: callback function for charger
106 * inform callee of charger_type
107 * and attached state(true or false)
108 * @deskdock_callback: callback function for desk dock
109 * inform callee of attached state(true or false)
110 * @cardock_callback: callback function for car dock
111 * inform callee of attached state(true or false)
112 * @mhl_callback: callback function for MHL (Mobile High-definition Link)
113 * inform callee of attached state(true or false)
114 * @uart_callback: callback function for JIG UART
115 * inform callee of attached state(true or false)
116 * @init_data: array of max8997_muic_reg_data
117 * used for initializing registers of MAX8997 MUIC device
118 * @num_init_data: array size of init_data
119 */
120struct max8997_muic_platform_data {
121 void (*usb_callback)(enum max8997_muic_usb_type usb_type,
122 bool attached);
123 void (*charger_callback)(bool attached,
124 enum max8997_muic_charger_type charger_type);
125 void (*deskdock_callback) (bool attached);
126 void (*cardock_callback) (bool attached);
127 void (*mhl_callback) (bool attached);
128 void (*uart_callback) (bool attached);
129
130 struct max8997_muic_reg_data *init_data;
131 int num_init_data;
132};
133
134enum max8997_led_mode {
135 MAX8997_NONE,
136 MAX8997_FLASH_MODE,
137 MAX8997_MOVIE_MODE,
138 MAX8997_FLASH_PIN_CONTROL_MODE,
139 MAX8997_MOVIE_PIN_CONTROL_MODE,
140};
141
142/**
143 * struct max8997_led_platform_data
144 * The number of LED devices for MAX8997 is two
145 * @mode: LED mode for each LED device
146 * @brightness: initial brightness for each LED device
147 * range:
148 * [0 - 31]: MAX8997_FLASH_MODE and MAX8997_FLASH_PIN_CONTROL_MODE
149 * [0 - 15]: MAX8997_MOVIE_MODE and MAX8997_MOVIE_PIN_CONTROL_MODE
150 */
151struct max8997_led_platform_data {
152 enum max8997_led_mode mode[2];
153 u8 brightness[2];
154};
155
80struct max8997_platform_data { 156struct max8997_platform_data {
81 /* IRQ */ 157 /* IRQ */
82 int irq_base; 158 int irq_base;
@@ -113,10 +189,13 @@ struct max8997_platform_data {
113 /* charge Full Timeout */ 189 /* charge Full Timeout */
114 int timeout; /* 0 (no timeout), 5, 6, 7 hours */ 190 int timeout; /* 0 (no timeout), 5, 6, 7 hours */
115 191
116 /* MUIC: Not implemented */ 192 /* ---- MUIC ---- */
193 struct max8997_muic_platform_data *muic_pdata;
194
117 /* HAPTIC: Not implemented */ 195 /* HAPTIC: Not implemented */
118 /* RTC: Not implemented */ 196 /* RTC: Not implemented */
119 /* Flash: Not implemented */ 197 /* ---- LED ---- */
198 struct max8997_led_platform_data *led_pdata;
120}; 199};
121 200
122#endif /* __LINUX_MFD_MAX8998_H */ 201#endif /* __LINUX_MFD_MAX8998_H */
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index a98e2a316d1f..b86ee45c8b03 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -174,6 +174,9 @@ struct mc13xxx_platform_data {
174#define MC13XXX_ADC_MODE_MULT_CHAN 3 174#define MC13XXX_ADC_MODE_MULT_CHAN 3
175 175
176#define MC13XXX_ADC0 43 176#define MC13XXX_ADC0 43
177#define MC13XXX_ADC0_LICELLCON (1 << 0)
178#define MC13XXX_ADC0_CHRGICON (1 << 1)
179#define MC13XXX_ADC0_BATICON (1 << 2)
177#define MC13XXX_ADC0_ADREFEN (1 << 10) 180#define MC13XXX_ADC0_ADREFEN (1 << 10)
178#define MC13XXX_ADC0_TSMOD0 (1 << 12) 181#define MC13XXX_ADC0_TSMOD0 (1 << 12)
179#define MC13XXX_ADC0_TSMOD1 (1 << 13) 182#define MC13XXX_ADC0_TSMOD1 (1 << 13)
@@ -185,4 +188,9 @@ struct mc13xxx_platform_data {
185 MC13XXX_ADC0_TSMOD1 | \ 188 MC13XXX_ADC0_TSMOD1 | \
186 MC13XXX_ADC0_TSMOD2) 189 MC13XXX_ADC0_TSMOD2)
187 190
191#define MC13XXX_ADC0_CONFIG_MASK (MC13XXX_ADC0_TSMOD_MASK | \
192 MC13XXX_ADC0_LICELLCON | \
193 MC13XXX_ADC0_CHRGICON | \
194 MC13XXX_ADC0_BATICON)
195
188#endif /* ifndef __LINUX_MFD_MC13XXX_H */ 196#endif /* ifndef __LINUX_MFD_MC13XXX_H */
diff --git a/include/linux/mfd/mcp.h b/include/linux/mfd/mcp.h
index ee496708e38b..1515e64e3663 100644
--- a/include/linux/mfd/mcp.h
+++ b/include/linux/mfd/mcp.h
@@ -10,6 +10,7 @@
10#ifndef MCP_H 10#ifndef MCP_H
11#define MCP_H 11#define MCP_H
12 12
13#include <linux/mod_devicetable.h>
13#include <mach/dma.h> 14#include <mach/dma.h>
14 15
15struct mcp_ops; 16struct mcp_ops;
@@ -26,7 +27,7 @@ struct mcp {
26 dma_device_t dma_telco_rd; 27 dma_device_t dma_telco_rd;
27 dma_device_t dma_telco_wr; 28 dma_device_t dma_telco_wr;
28 struct device attached_device; 29 struct device attached_device;
29 int gpio_base; 30 const char *codec;
30}; 31};
31 32
32struct mcp_ops { 33struct mcp_ops {
@@ -44,10 +45,11 @@ void mcp_reg_write(struct mcp *, unsigned int, unsigned int);
44unsigned int mcp_reg_read(struct mcp *, unsigned int); 45unsigned int mcp_reg_read(struct mcp *, unsigned int);
45void mcp_enable(struct mcp *); 46void mcp_enable(struct mcp *);
46void mcp_disable(struct mcp *); 47void mcp_disable(struct mcp *);
48const struct mcp_device_id *mcp_get_device_id(const struct mcp *mcp);
47#define mcp_get_sclk_rate(mcp) ((mcp)->sclk_rate) 49#define mcp_get_sclk_rate(mcp) ((mcp)->sclk_rate)
48 50
49struct mcp *mcp_host_alloc(struct device *, size_t); 51struct mcp *mcp_host_alloc(struct device *, size_t);
50int mcp_host_register(struct mcp *); 52int mcp_host_register(struct mcp *, void *);
51void mcp_host_unregister(struct mcp *); 53void mcp_host_unregister(struct mcp *);
52 54
53struct mcp_driver { 55struct mcp_driver {
@@ -56,6 +58,7 @@ struct mcp_driver {
56 void (*remove)(struct mcp *); 58 void (*remove)(struct mcp *);
57 int (*suspend)(struct mcp *, pm_message_t); 59 int (*suspend)(struct mcp *, pm_message_t);
58 int (*resume)(struct mcp *); 60 int (*resume)(struct mcp *);
61 const struct mcp_device_id *id_table;
59}; 62};
60 63
61int mcp_driver_register(struct mcp_driver *); 64int mcp_driver_register(struct mcp_driver *);
diff --git a/include/linux/mfd/s5m87xx/s5m-core.h b/include/linux/mfd/s5m87xx/s5m-core.h
new file mode 100644
index 000000000000..a7480b57f92d
--- /dev/null
+++ b/include/linux/mfd/s5m87xx/s5m-core.h
@@ -0,0 +1,373 @@
1/*
2 * s5m-core.h
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#ifndef __LINUX_MFD_S5M_CORE_H
15#define __LINUX_MFD_S5M_CORE_H
16
17#define NUM_IRQ_REGS 4
18
19enum s5m_device_type {
20 S5M8751X,
21 S5M8763X,
22 S5M8767X,
23};
24
25/* S5M8767 registers */
26enum s5m8767_reg {
27 S5M8767_REG_ID,
28 S5M8767_REG_INT1,
29 S5M8767_REG_INT2,
30 S5M8767_REG_INT3,
31 S5M8767_REG_INT1M,
32 S5M8767_REG_INT2M,
33 S5M8767_REG_INT3M,
34 S5M8767_REG_STATUS1,
35 S5M8767_REG_STATUS2,
36 S5M8767_REG_STATUS3,
37 S5M8767_REG_CTRL1,
38 S5M8767_REG_CTRL2,
39 S5M8767_REG_LOWBAT1,
40 S5M8767_REG_LOWBAT2,
41 S5M8767_REG_BUCHG,
42 S5M8767_REG_DVSRAMP,
43 S5M8767_REG_DVSTIMER2 = 0x10,
44 S5M8767_REG_DVSTIMER3,
45 S5M8767_REG_DVSTIMER4,
46 S5M8767_REG_LDO1,
47 S5M8767_REG_LDO2,
48 S5M8767_REG_LDO3,
49 S5M8767_REG_LDO4,
50 S5M8767_REG_LDO5,
51 S5M8767_REG_LDO6,
52 S5M8767_REG_LDO7,
53 S5M8767_REG_LDO8,
54 S5M8767_REG_LDO9,
55 S5M8767_REG_LDO10,
56 S5M8767_REG_LDO11,
57 S5M8767_REG_LDO12,
58 S5M8767_REG_LDO13,
59 S5M8767_REG_LDO14 = 0x20,
60 S5M8767_REG_LDO15,
61 S5M8767_REG_LDO16,
62 S5M8767_REG_LDO17,
63 S5M8767_REG_LDO18,
64 S5M8767_REG_LDO19,
65 S5M8767_REG_LDO20,
66 S5M8767_REG_LDO21,
67 S5M8767_REG_LDO22,
68 S5M8767_REG_LDO23,
69 S5M8767_REG_LDO24,
70 S5M8767_REG_LDO25,
71 S5M8767_REG_LDO26,
72 S5M8767_REG_LDO27,
73 S5M8767_REG_LDO28,
74 S5M8767_REG_UVLO = 0x31,
75 S5M8767_REG_BUCK1CTRL1,
76 S5M8767_REG_BUCK1CTRL2,
77 S5M8767_REG_BUCK2CTRL,
78 S5M8767_REG_BUCK2DVS1,
79 S5M8767_REG_BUCK2DVS2,
80 S5M8767_REG_BUCK2DVS3,
81 S5M8767_REG_BUCK2DVS4,
82 S5M8767_REG_BUCK2DVS5,
83 S5M8767_REG_BUCK2DVS6,
84 S5M8767_REG_BUCK2DVS7,
85 S5M8767_REG_BUCK2DVS8,
86 S5M8767_REG_BUCK3CTRL,
87 S5M8767_REG_BUCK3DVS1,
88 S5M8767_REG_BUCK3DVS2,
89 S5M8767_REG_BUCK3DVS3,
90 S5M8767_REG_BUCK3DVS4,
91 S5M8767_REG_BUCK3DVS5,
92 S5M8767_REG_BUCK3DVS6,
93 S5M8767_REG_BUCK3DVS7,
94 S5M8767_REG_BUCK3DVS8,
95 S5M8767_REG_BUCK4CTRL,
96 S5M8767_REG_BUCK4DVS1,
97 S5M8767_REG_BUCK4DVS2,
98 S5M8767_REG_BUCK4DVS3,
99 S5M8767_REG_BUCK4DVS4,
100 S5M8767_REG_BUCK4DVS5,
101 S5M8767_REG_BUCK4DVS6,
102 S5M8767_REG_BUCK4DVS7,
103 S5M8767_REG_BUCK4DVS8,
104 S5M8767_REG_BUCK5CTRL1,
105 S5M8767_REG_BUCK5CTRL2,
106 S5M8767_REG_BUCK5CTRL3,
107 S5M8767_REG_BUCK5CTRL4,
108 S5M8767_REG_BUCK5CTRL5,
109 S5M8767_REG_BUCK6CTRL1,
110 S5M8767_REG_BUCK6CTRL2,
111 S5M8767_REG_BUCK7CTRL1,
112 S5M8767_REG_BUCK7CTRL2,
113 S5M8767_REG_BUCK8CTRL1,
114 S5M8767_REG_BUCK8CTRL2,
115 S5M8767_REG_BUCK9CTRL1,
116 S5M8767_REG_BUCK9CTRL2,
117 S5M8767_REG_LDO1CTRL,
118 S5M8767_REG_LDO2_1CTRL,
119 S5M8767_REG_LDO2_2CTRL,
120 S5M8767_REG_LDO2_3CTRL,
121 S5M8767_REG_LDO2_4CTRL,
122 S5M8767_REG_LDO3CTRL,
123 S5M8767_REG_LDO4CTRL,
124 S5M8767_REG_LDO5CTRL,
125 S5M8767_REG_LDO6CTRL,
126 S5M8767_REG_LDO7CTRL,
127 S5M8767_REG_LDO8CTRL,
128 S5M8767_REG_LDO9CTRL,
129 S5M8767_REG_LDO10CTRL,
130 S5M8767_REG_LDO11CTRL,
131 S5M8767_REG_LDO12CTRL,
132 S5M8767_REG_LDO13CTRL,
133 S5M8767_REG_LDO14CTRL,
134 S5M8767_REG_LDO15CTRL,
135 S5M8767_REG_LDO16CTRL,
136 S5M8767_REG_LDO17CTRL,
137 S5M8767_REG_LDO18CTRL,
138 S5M8767_REG_LDO19CTRL,
139 S5M8767_REG_LDO20CTRL,
140 S5M8767_REG_LDO21CTRL,
141 S5M8767_REG_LDO22CTRL,
142 S5M8767_REG_LDO23CTRL,
143 S5M8767_REG_LDO24CTRL,
144 S5M8767_REG_LDO25CTRL,
145 S5M8767_REG_LDO26CTRL,
146 S5M8767_REG_LDO27CTRL,
147 S5M8767_REG_LDO28CTRL,
148};
149
150/* S5M8763 registers */
151enum s5m8763_reg {
152 S5M8763_REG_IRQ1,
153 S5M8763_REG_IRQ2,
154 S5M8763_REG_IRQ3,
155 S5M8763_REG_IRQ4,
156 S5M8763_REG_IRQM1,
157 S5M8763_REG_IRQM2,
158 S5M8763_REG_IRQM3,
159 S5M8763_REG_IRQM4,
160 S5M8763_REG_STATUS1,
161 S5M8763_REG_STATUS2,
162 S5M8763_REG_STATUSM1,
163 S5M8763_REG_STATUSM2,
164 S5M8763_REG_CHGR1,
165 S5M8763_REG_CHGR2,
166 S5M8763_REG_LDO_ACTIVE_DISCHARGE1,
167 S5M8763_REG_LDO_ACTIVE_DISCHARGE2,
168 S5M8763_REG_BUCK_ACTIVE_DISCHARGE3,
169 S5M8763_REG_ONOFF1,
170 S5M8763_REG_ONOFF2,
171 S5M8763_REG_ONOFF3,
172 S5M8763_REG_ONOFF4,
173 S5M8763_REG_BUCK1_VOLTAGE1,
174 S5M8763_REG_BUCK1_VOLTAGE2,
175 S5M8763_REG_BUCK1_VOLTAGE3,
176 S5M8763_REG_BUCK1_VOLTAGE4,
177 S5M8763_REG_BUCK2_VOLTAGE1,
178 S5M8763_REG_BUCK2_VOLTAGE2,
179 S5M8763_REG_BUCK3,
180 S5M8763_REG_BUCK4,
181 S5M8763_REG_LDO1_LDO2,
182 S5M8763_REG_LDO3,
183 S5M8763_REG_LDO4,
184 S5M8763_REG_LDO5,
185 S5M8763_REG_LDO6,
186 S5M8763_REG_LDO7,
187 S5M8763_REG_LDO7_LDO8,
188 S5M8763_REG_LDO9_LDO10,
189 S5M8763_REG_LDO11,
190 S5M8763_REG_LDO12,
191 S5M8763_REG_LDO13,
192 S5M8763_REG_LDO14,
193 S5M8763_REG_LDO15,
194 S5M8763_REG_LDO16,
195 S5M8763_REG_BKCHR,
196 S5M8763_REG_LBCNFG1,
197 S5M8763_REG_LBCNFG2,
198};
199
200enum s5m8767_irq {
201 S5M8767_IRQ_PWRR,
202 S5M8767_IRQ_PWRF,
203 S5M8767_IRQ_PWR1S,
204 S5M8767_IRQ_JIGR,
205 S5M8767_IRQ_JIGF,
206 S5M8767_IRQ_LOWBAT2,
207 S5M8767_IRQ_LOWBAT1,
208
209 S5M8767_IRQ_MRB,
210 S5M8767_IRQ_DVSOK2,
211 S5M8767_IRQ_DVSOK3,
212 S5M8767_IRQ_DVSOK4,
213
214 S5M8767_IRQ_RTC60S,
215 S5M8767_IRQ_RTCA1,
216 S5M8767_IRQ_RTCA2,
217 S5M8767_IRQ_SMPL,
218 S5M8767_IRQ_RTC1S,
219 S5M8767_IRQ_WTSR,
220
221 S5M8767_IRQ_NR,
222};
223
224#define S5M8767_IRQ_PWRR_MASK (1 << 0)
225#define S5M8767_IRQ_PWRF_MASK (1 << 1)
226#define S5M8767_IRQ_PWR1S_MASK (1 << 3)
227#define S5M8767_IRQ_JIGR_MASK (1 << 4)
228#define S5M8767_IRQ_JIGF_MASK (1 << 5)
229#define S5M8767_IRQ_LOWBAT2_MASK (1 << 6)
230#define S5M8767_IRQ_LOWBAT1_MASK (1 << 7)
231
232#define S5M8767_IRQ_MRB_MASK (1 << 2)
233#define S5M8767_IRQ_DVSOK2_MASK (1 << 3)
234#define S5M8767_IRQ_DVSOK3_MASK (1 << 4)
235#define S5M8767_IRQ_DVSOK4_MASK (1 << 5)
236
237#define S5M8767_IRQ_RTC60S_MASK (1 << 0)
238#define S5M8767_IRQ_RTCA1_MASK (1 << 1)
239#define S5M8767_IRQ_RTCA2_MASK (1 << 2)
240#define S5M8767_IRQ_SMPL_MASK (1 << 3)
241#define S5M8767_IRQ_RTC1S_MASK (1 << 4)
242#define S5M8767_IRQ_WTSR_MASK (1 << 5)
243
244enum s5m8763_irq {
245 S5M8763_IRQ_DCINF,
246 S5M8763_IRQ_DCINR,
247 S5M8763_IRQ_JIGF,
248 S5M8763_IRQ_JIGR,
249 S5M8763_IRQ_PWRONF,
250 S5M8763_IRQ_PWRONR,
251
252 S5M8763_IRQ_WTSREVNT,
253 S5M8763_IRQ_SMPLEVNT,
254 S5M8763_IRQ_ALARM1,
255 S5M8763_IRQ_ALARM0,
256
257 S5M8763_IRQ_ONKEY1S,
258 S5M8763_IRQ_TOPOFFR,
259 S5M8763_IRQ_DCINOVPR,
260 S5M8763_IRQ_CHGRSTF,
261 S5M8763_IRQ_DONER,
262 S5M8763_IRQ_CHGFAULT,
263
264 S5M8763_IRQ_LOBAT1,
265 S5M8763_IRQ_LOBAT2,
266
267 S5M8763_IRQ_NR,
268};
269
270#define S5M8763_IRQ_DCINF_MASK (1 << 2)
271#define S5M8763_IRQ_DCINR_MASK (1 << 3)
272#define S5M8763_IRQ_JIGF_MASK (1 << 4)
273#define S5M8763_IRQ_JIGR_MASK (1 << 5)
274#define S5M8763_IRQ_PWRONF_MASK (1 << 6)
275#define S5M8763_IRQ_PWRONR_MASK (1 << 7)
276
277#define S5M8763_IRQ_WTSREVNT_MASK (1 << 0)
278#define S5M8763_IRQ_SMPLEVNT_MASK (1 << 1)
279#define S5M8763_IRQ_ALARM1_MASK (1 << 2)
280#define S5M8763_IRQ_ALARM0_MASK (1 << 3)
281
282#define S5M8763_IRQ_ONKEY1S_MASK (1 << 0)
283#define S5M8763_IRQ_TOPOFFR_MASK (1 << 2)
284#define S5M8763_IRQ_DCINOVPR_MASK (1 << 3)
285#define S5M8763_IRQ_CHGRSTF_MASK (1 << 4)
286#define S5M8763_IRQ_DONER_MASK (1 << 5)
287#define S5M8763_IRQ_CHGFAULT_MASK (1 << 7)
288
289#define S5M8763_IRQ_LOBAT1_MASK (1 << 0)
290#define S5M8763_IRQ_LOBAT2_MASK (1 << 1)
291
292#define S5M8763_ENRAMP (1 << 4)
293
294/**
295 * struct s5m87xx_dev - s5m87xx master device for sub-drivers
296 * @dev: master device of the chip (can be used to access platform data)
297 * @i2c: i2c client private data for regulator
298 * @rtc: i2c client private data for rtc
299 * @iolock: mutex for serializing io access
300 * @irqlock: mutex for buslock
301 * @irq_base: base IRQ number for s5m87xx, required for IRQs
302 * @irq: generic IRQ number for s5m87xx
303 * @ono: power onoff IRQ number for s5m87xx
304 * @irq_masks_cur: currently active value
305 * @irq_masks_cache: cached hardware value
306 * @type: indicate which s5m87xx "variant" is used
307 */
308struct s5m87xx_dev {
309 struct device *dev;
310 struct regmap *regmap;
311 struct i2c_client *i2c;
312 struct i2c_client *rtc;
313 struct mutex iolock;
314 struct mutex irqlock;
315
316 int device_type;
317 int irq_base;
318 int irq;
319 int ono;
320 u8 irq_masks_cur[NUM_IRQ_REGS];
321 u8 irq_masks_cache[NUM_IRQ_REGS];
322 int type;
323 bool wakeup;
324};
325
326int s5m_irq_init(struct s5m87xx_dev *s5m87xx);
327void s5m_irq_exit(struct s5m87xx_dev *s5m87xx);
328int s5m_irq_resume(struct s5m87xx_dev *s5m87xx);
329
330extern int s5m_reg_read(struct s5m87xx_dev *s5m87xx, u8 reg, void *dest);
331extern int s5m_bulk_read(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf);
332extern int s5m_reg_write(struct s5m87xx_dev *s5m87xx, u8 reg, u8 value);
333extern int s5m_bulk_write(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf);
334extern int s5m_reg_update(struct s5m87xx_dev *s5m87xx, u8 reg, u8 val, u8 mask);
335
336struct s5m_platform_data {
337 struct s5m_regulator_data *regulators;
338 int device_type;
339 int num_regulators;
340
341 int irq_base;
342 int (*cfg_pmic_irq)(void);
343
344 int ono;
345 bool wakeup;
346 bool buck_voltage_lock;
347
348 int buck_gpios[3];
349 int buck2_voltage[8];
350 bool buck2_gpiodvs;
351 int buck3_voltage[8];
352 bool buck3_gpiodvs;
353 int buck4_voltage[8];
354 bool buck4_gpiodvs;
355
356 int buck_set1;
357 int buck_set2;
358 int buck_set3;
359 int buck2_enable;
360 int buck3_enable;
361 int buck4_enable;
362 int buck_default_idx;
363 int buck2_default_idx;
364 int buck3_default_idx;
365 int buck4_default_idx;
366
367 int buck_ramp_delay;
368 bool buck2_ramp_enable;
369 bool buck3_ramp_enable;
370 bool buck4_ramp_enable;
371};
372
373#endif /* __LINUX_MFD_S5M_CORE_H */
diff --git a/include/linux/mfd/s5m87xx/s5m-pmic.h b/include/linux/mfd/s5m87xx/s5m-pmic.h
new file mode 100644
index 000000000000..a72a5d27e62e
--- /dev/null
+++ b/include/linux/mfd/s5m87xx/s5m-pmic.h
@@ -0,0 +1,100 @@
1/* s5m87xx.h
2 *
3 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
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 version 2 as
8 * published by the Free Software Foundation.
9*/
10
11#ifndef __LINUX_MFD_S5M_PMIC_H
12#define __LINUX_MFD_S5M_PMIC_H
13
14#include <linux/regulator/machine.h>
15
16/* S5M8767 regulator ids */
17enum s5m8767_regulators {
18 S5M8767_LDO1,
19 S5M8767_LDO2,
20 S5M8767_LDO3,
21 S5M8767_LDO4,
22 S5M8767_LDO5,
23 S5M8767_LDO6,
24 S5M8767_LDO7,
25 S5M8767_LDO8,
26 S5M8767_LDO9,
27 S5M8767_LDO10,
28 S5M8767_LDO11,
29 S5M8767_LDO12,
30 S5M8767_LDO13,
31 S5M8767_LDO14,
32 S5M8767_LDO15,
33 S5M8767_LDO16,
34 S5M8767_LDO17,
35 S5M8767_LDO18,
36 S5M8767_LDO19,
37 S5M8767_LDO20,
38 S5M8767_LDO21,
39 S5M8767_LDO22,
40 S5M8767_LDO23,
41 S5M8767_LDO24,
42 S5M8767_LDO25,
43 S5M8767_LDO26,
44 S5M8767_LDO27,
45 S5M8767_LDO28,
46 S5M8767_BUCK1,
47 S5M8767_BUCK2,
48 S5M8767_BUCK3,
49 S5M8767_BUCK4,
50 S5M8767_BUCK5,
51 S5M8767_BUCK6,
52 S5M8767_BUCK7,
53 S5M8767_BUCK8,
54 S5M8767_BUCK9,
55 S5M8767_AP_EN32KHZ,
56 S5M8767_CP_EN32KHZ,
57
58 S5M8767_REG_MAX,
59};
60
61/* S5M8763 regulator ids */
62enum s5m8763_regulators {
63 S5M8763_LDO1,
64 S5M8763_LDO2,
65 S5M8763_LDO3,
66 S5M8763_LDO4,
67 S5M8763_LDO5,
68 S5M8763_LDO6,
69 S5M8763_LDO7,
70 S5M8763_LDO8,
71 S5M8763_LDO9,
72 S5M8763_LDO10,
73 S5M8763_LDO11,
74 S5M8763_LDO12,
75 S5M8763_LDO13,
76 S5M8763_LDO14,
77 S5M8763_LDO15,
78 S5M8763_LDO16,
79 S5M8763_BUCK1,
80 S5M8763_BUCK2,
81 S5M8763_BUCK3,
82 S5M8763_BUCK4,
83 S5M8763_AP_EN32KHZ,
84 S5M8763_CP_EN32KHZ,
85 S5M8763_ENCHGVI,
86 S5M8763_ESAFEUSB1,
87 S5M8763_ESAFEUSB2,
88};
89
90/**
91 * s5m87xx_regulator_data - regulator data
92 * @id: regulator id
93 * @initdata: regulator init data (contraints, supplies, ...)
94 */
95struct s5m_regulator_data {
96 int id;
97 struct regulator_init_data *initdata;
98};
99
100#endif /* __LINUX_MFD_S5M_PMIC_H */
diff --git a/include/linux/mfd/s5m87xx/s5m-rtc.h b/include/linux/mfd/s5m87xx/s5m-rtc.h
new file mode 100644
index 000000000000..6ce8da264cec
--- /dev/null
+++ b/include/linux/mfd/s5m87xx/s5m-rtc.h
@@ -0,0 +1,84 @@
1/*
2 * s5m-rtc.h
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#ifndef __LINUX_MFD_S5M_RTC_H
15#define __LINUX_MFD_S5M_RTC_H
16
17enum s5m87xx_rtc_reg {
18 S5M87XX_RTC_SEC,
19 S5M87XX_RTC_MIN,
20 S5M87XX_RTC_HOUR,
21 S5M87XX_RTC_WEEKDAY,
22 S5M87XX_RTC_DATE,
23 S5M87XX_RTC_MONTH,
24 S5M87XX_RTC_YEAR1,
25 S5M87XX_RTC_YEAR2,
26 S5M87XX_ALARM0_SEC,
27 S5M87XX_ALARM0_MIN,
28 S5M87XX_ALARM0_HOUR,
29 S5M87XX_ALARM0_WEEKDAY,
30 S5M87XX_ALARM0_DATE,
31 S5M87XX_ALARM0_MONTH,
32 S5M87XX_ALARM0_YEAR1,
33 S5M87XX_ALARM0_YEAR2,
34 S5M87XX_ALARM1_SEC,
35 S5M87XX_ALARM1_MIN,
36 S5M87XX_ALARM1_HOUR,
37 S5M87XX_ALARM1_WEEKDAY,
38 S5M87XX_ALARM1_DATE,
39 S5M87XX_ALARM1_MONTH,
40 S5M87XX_ALARM1_YEAR1,
41 S5M87XX_ALARM1_YEAR2,
42 S5M87XX_ALARM0_CONF,
43 S5M87XX_ALARM1_CONF,
44 S5M87XX_RTC_STATUS,
45 S5M87XX_WTSR_SMPL_CNTL,
46 S5M87XX_RTC_UDR_CON,
47};
48
49#define RTC_I2C_ADDR (0x0C >> 1)
50
51#define HOUR_12 (1 << 7)
52#define HOUR_AMPM (1 << 6)
53#define HOUR_PM (1 << 5)
54#define ALARM0_STATUS (1 << 1)
55#define ALARM1_STATUS (1 << 2)
56#define UPDATE_AD (1 << 0)
57
58/* RTC Control Register */
59#define BCD_EN_SHIFT 0
60#define BCD_EN_MASK (1 << BCD_EN_SHIFT)
61#define MODEL24_SHIFT 1
62#define MODEL24_MASK (1 << MODEL24_SHIFT)
63/* RTC Update Register1 */
64#define RTC_UDR_SHIFT 0
65#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT)
66/* RTC Hour register */
67#define HOUR_PM_SHIFT 6
68#define HOUR_PM_MASK (1 << HOUR_PM_SHIFT)
69/* RTC Alarm Enable */
70#define ALARM_ENABLE_SHIFT 7
71#define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT)
72
73enum {
74 RTC_SEC = 0,
75 RTC_MIN,
76 RTC_HOUR,
77 RTC_WEEKDAY,
78 RTC_DATE,
79 RTC_MONTH,
80 RTC_YEAR1,
81 RTC_YEAR2,
82};
83
84#endif /* __LINUX_MFD_S5M_RTC_H */
diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
index be1af7c42e57..ca1d7a347600 100644
--- a/include/linux/mfd/stmpe.h
+++ b/include/linux/mfd/stmpe.h
@@ -20,6 +20,8 @@ enum stmpe_block {
20}; 20};
21 21
22enum stmpe_partnum { 22enum stmpe_partnum {
23 STMPE610,
24 STMPE801,
23 STMPE811, 25 STMPE811,
24 STMPE1601, 26 STMPE1601,
25 STMPE2401, 27 STMPE2401,
@@ -50,17 +52,20 @@ enum {
50 52
51 53
52struct stmpe_variant_info; 54struct stmpe_variant_info;
55struct stmpe_client_info;
53 56
54/** 57/**
55 * struct stmpe - STMPE MFD structure 58 * struct stmpe - STMPE MFD structure
56 * @lock: lock protecting I/O operations 59 * @lock: lock protecting I/O operations
57 * @irq_lock: IRQ bus lock 60 * @irq_lock: IRQ bus lock
58 * @dev: device, mostly for dev_dbg() 61 * @dev: device, mostly for dev_dbg()
59 * @i2c: i2c client 62 * @client: client - i2c or spi
63 * @ci: client specific information
60 * @partnum: part number 64 * @partnum: part number
61 * @variant: the detected STMPE model number 65 * @variant: the detected STMPE model number
62 * @regs: list of addresses of registers which are at different addresses on 66 * @regs: list of addresses of registers which are at different addresses on
63 * different variants. Indexed by one of STMPE_IDX_*. 67 * different variants. Indexed by one of STMPE_IDX_*.
68 * @irq: irq number for stmpe
64 * @irq_base: starting IRQ number for internal IRQs 69 * @irq_base: starting IRQ number for internal IRQs
65 * @num_gpios: number of gpios, differs for variants 70 * @num_gpios: number of gpios, differs for variants
66 * @ier: cache of IER registers for bus_lock 71 * @ier: cache of IER registers for bus_lock
@@ -71,11 +76,13 @@ struct stmpe {
71 struct mutex lock; 76 struct mutex lock;
72 struct mutex irq_lock; 77 struct mutex irq_lock;
73 struct device *dev; 78 struct device *dev;
74 struct i2c_client *i2c; 79 void *client;
80 struct stmpe_client_info *ci;
75 enum stmpe_partnum partnum; 81 enum stmpe_partnum partnum;
76 struct stmpe_variant_info *variant; 82 struct stmpe_variant_info *variant;
77 const u8 *regs; 83 const u8 *regs;
78 84
85 int irq;
79 int irq_base; 86 int irq_base;
80 int num_gpios; 87 int num_gpios;
81 u8 ier[2]; 88 u8 ier[2];
@@ -183,6 +190,9 @@ struct stmpe_ts_platform_data {
183 * @autosleep_timeout: inactivity timeout in milliseconds for autosleep 190 * @autosleep_timeout: inactivity timeout in milliseconds for autosleep
184 * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or 191 * @irq_base: base IRQ number. %STMPE_NR_IRQS irqs will be used, or
185 * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used. 192 * %STMPE_NR_INTERNAL_IRQS if the GPIO driver is not used.
193 * @irq_over_gpio: true if gpio is used to get irq
194 * @irq_gpio: gpio number over which irq will be requested (significant only if
195 * irq_over_gpio is true)
186 * @gpio: GPIO-specific platform data 196 * @gpio: GPIO-specific platform data
187 * @keypad: keypad-specific platform data 197 * @keypad: keypad-specific platform data
188 * @ts: touchscreen-specific platform data 198 * @ts: touchscreen-specific platform data
@@ -194,6 +204,8 @@ struct stmpe_platform_data {
194 unsigned int irq_trigger; 204 unsigned int irq_trigger;
195 bool irq_invert_polarity; 205 bool irq_invert_polarity;
196 bool autosleep; 206 bool autosleep;
207 bool irq_over_gpio;
208 int irq_gpio;
197 int autosleep_timeout; 209 int autosleep_timeout;
198 210
199 struct stmpe_gpio_platform_data *gpio; 211 struct stmpe_gpio_platform_data *gpio;
diff --git a/include/linux/mfd/ucb1x00.h b/include/linux/mfd/ucb1x00.h
index 4321f044d1e4..bc19e5fb7ea8 100644
--- a/include/linux/mfd/ucb1x00.h
+++ b/include/linux/mfd/ucb1x00.h
@@ -104,6 +104,9 @@
104#define UCB_MODE_DYN_VFLAG_ENA (1 << 12) 104#define UCB_MODE_DYN_VFLAG_ENA (1 << 12)
105#define UCB_MODE_AUD_OFF_CAN (1 << 13) 105#define UCB_MODE_AUD_OFF_CAN (1 << 13)
106 106
107struct ucb1x00_plat_data {
108 int gpio_base;
109};
107 110
108struct ucb1x00_irq { 111struct ucb1x00_irq {
109 void *devid; 112 void *devid;
@@ -116,7 +119,7 @@ struct ucb1x00 {
116 unsigned int irq; 119 unsigned int irq;
117 struct semaphore adc_sem; 120 struct semaphore adc_sem;
118 spinlock_t io_lock; 121 spinlock_t io_lock;
119 u16 id; 122 const struct mcp_device_id *id;
120 u16 io_dir; 123 u16 io_dir;
121 u16 io_out; 124 u16 io_out;
122 u16 adc_cr; 125 u16 adc_cr;
diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index e39aeecfe9a2..eaf867412f7a 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -6,18 +6,31 @@
6 6
7typedef struct page *new_page_t(struct page *, unsigned long private, int **); 7typedef struct page *new_page_t(struct page *, unsigned long private, int **);
8 8
9/*
10 * MIGRATE_ASYNC means never block
11 * MIGRATE_SYNC_LIGHT in the current implementation means to allow blocking
12 * on most operations but not ->writepage as the potential stall time
13 * is too significant
14 * MIGRATE_SYNC will block when migrating pages
15 */
16enum migrate_mode {
17 MIGRATE_ASYNC,
18 MIGRATE_SYNC_LIGHT,
19 MIGRATE_SYNC,
20};
21
9#ifdef CONFIG_MIGRATION 22#ifdef CONFIG_MIGRATION
10#define PAGE_MIGRATION 1 23#define PAGE_MIGRATION 1
11 24
12extern void putback_lru_pages(struct list_head *l); 25extern void putback_lru_pages(struct list_head *l);
13extern int migrate_page(struct address_space *, 26extern int migrate_page(struct address_space *,
14 struct page *, struct page *); 27 struct page *, struct page *, enum migrate_mode);
15extern int migrate_pages(struct list_head *l, new_page_t x, 28extern int migrate_pages(struct list_head *l, new_page_t x,
16 unsigned long private, bool offlining, 29 unsigned long private, bool offlining,
17 bool sync); 30 enum migrate_mode mode);
18extern int migrate_huge_pages(struct list_head *l, new_page_t x, 31extern int migrate_huge_pages(struct list_head *l, new_page_t x,
19 unsigned long private, bool offlining, 32 unsigned long private, bool offlining,
20 bool sync); 33 enum migrate_mode mode);
21 34
22extern int fail_migrate_page(struct address_space *, 35extern int fail_migrate_page(struct address_space *,
23 struct page *, struct page *); 36 struct page *, struct page *);
@@ -36,10 +49,10 @@ extern int migrate_huge_page_move_mapping(struct address_space *mapping,
36static inline void putback_lru_pages(struct list_head *l) {} 49static inline void putback_lru_pages(struct list_head *l) {}
37static inline int migrate_pages(struct list_head *l, new_page_t x, 50static inline int migrate_pages(struct list_head *l, new_page_t x,
38 unsigned long private, bool offlining, 51 unsigned long private, bool offlining,
39 bool sync) { return -ENOSYS; } 52 enum migrate_mode mode) { return -ENOSYS; }
40static inline int migrate_huge_pages(struct list_head *l, new_page_t x, 53static inline int migrate_huge_pages(struct list_head *l, new_page_t x,
41 unsigned long private, bool offlining, 54 unsigned long private, bool offlining,
42 bool sync) { return -ENOSYS; } 55 enum migrate_mode mode) { return -ENOSYS; }
43 56
44static inline int migrate_prep(void) { return -ENOSYS; } 57static inline int migrate_prep(void) { return -ENOSYS; }
45static inline int migrate_prep_local(void) { return -ENOSYS; } 58static inline int migrate_prep_local(void) { return -ENOSYS; }
diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index 8f7d24712dc1..227fd3e9a9c9 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -22,26 +22,21 @@ static inline int page_is_file_cache(struct page *page)
22} 22}
23 23
24static inline void 24static inline void
25__add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l, 25add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list lru)
26 struct list_head *head)
27{ 26{
28 list_add(&page->lru, head); 27 struct lruvec *lruvec;
29 __mod_zone_page_state(zone, NR_LRU_BASE + l, hpage_nr_pages(page));
30 mem_cgroup_add_lru_list(page, l);
31}
32 28
33static inline void 29 lruvec = mem_cgroup_lru_add_list(zone, page, lru);
34add_page_to_lru_list(struct zone *zone, struct page *page, enum lru_list l) 30 list_add(&page->lru, &lruvec->lists[lru]);
35{ 31 __mod_zone_page_state(zone, NR_LRU_BASE + lru, hpage_nr_pages(page));
36 __add_page_to_lru_list(zone, page, l, &zone->lru[l].list);
37} 32}
38 33
39static inline void 34static inline void
40del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list l) 35del_page_from_lru_list(struct zone *zone, struct page *page, enum lru_list lru)
41{ 36{
37 mem_cgroup_lru_del_list(page, lru);
42 list_del(&page->lru); 38 list_del(&page->lru);
43 __mod_zone_page_state(zone, NR_LRU_BASE + l, -hpage_nr_pages(page)); 39 __mod_zone_page_state(zone, NR_LRU_BASE + lru, -hpage_nr_pages(page));
44 mem_cgroup_del_lru_list(page, l);
45} 40}
46 41
47/** 42/**
@@ -59,24 +54,28 @@ static inline enum lru_list page_lru_base_type(struct page *page)
59 return LRU_INACTIVE_ANON; 54 return LRU_INACTIVE_ANON;
60} 55}
61 56
62static inline void 57/**
63del_page_from_lru(struct zone *zone, struct page *page) 58 * page_off_lru - which LRU list was page on? clearing its lru flags.
59 * @page: the page to test
60 *
61 * Returns the LRU list a page was on, as an index into the array of LRU
62 * lists; and clears its Unevictable or Active flags, ready for freeing.
63 */
64static inline enum lru_list page_off_lru(struct page *page)
64{ 65{
65 enum lru_list l; 66 enum lru_list lru;
66 67
67 list_del(&page->lru);
68 if (PageUnevictable(page)) { 68 if (PageUnevictable(page)) {
69 __ClearPageUnevictable(page); 69 __ClearPageUnevictable(page);
70 l = LRU_UNEVICTABLE; 70 lru = LRU_UNEVICTABLE;
71 } else { 71 } else {
72 l = page_lru_base_type(page); 72 lru = page_lru_base_type(page);
73 if (PageActive(page)) { 73 if (PageActive(page)) {
74 __ClearPageActive(page); 74 __ClearPageActive(page);
75 l += LRU_ACTIVE; 75 lru += LRU_ACTIVE;
76 } 76 }
77 } 77 }
78 __mod_zone_page_state(zone, NR_LRU_BASE + l, -hpage_nr_pages(page)); 78 return lru;
79 mem_cgroup_del_lru_list(page, l);
80} 79}
81 80
82/** 81/**
@@ -97,7 +96,6 @@ static inline enum lru_list page_lru(struct page *page)
97 if (PageActive(page)) 96 if (PageActive(page))
98 lru += LRU_ACTIVE; 97 lru += LRU_ACTIVE;
99 } 98 }
100
101 return lru; 99 return lru;
102} 100}
103 101
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 5b42f1b34eb7..3cc3062b3767 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -151,12 +151,11 @@ struct page {
151#endif 151#endif
152} 152}
153/* 153/*
154 * If another subsystem starts using the double word pairing for atomic 154 * The struct page can be forced to be double word aligned so that atomic ops
155 * operations on struct page then it must change the #if to ensure 155 * on double words work. The SLUB allocator can make use of such a feature.
156 * proper alignment of the page struct.
157 */ 156 */
158#if defined(CONFIG_SLUB) && defined(CONFIG_CMPXCHG_LOCAL) 157#ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
159 __attribute__((__aligned__(2*sizeof(unsigned long)))) 158 __aligned(2 * sizeof(unsigned long))
160#endif 159#endif
161; 160;
162 161
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index c8ef9bc54d50..9f22ba572de0 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -71,6 +71,8 @@ struct mmc_ext_csd {
71 bool hpi_en; /* HPI enablebit */ 71 bool hpi_en; /* HPI enablebit */
72 bool hpi; /* HPI support bit */ 72 bool hpi; /* HPI support bit */
73 unsigned int hpi_cmd; /* cmd used as HPI */ 73 unsigned int hpi_cmd; /* cmd used as HPI */
74 unsigned int boot_ro_lock; /* ro lock support */
75 bool boot_ro_lockable;
74 u8 raw_partition_support; /* 160 */ 76 u8 raw_partition_support; /* 160 */
75 u8 raw_erased_mem_count; /* 181 */ 77 u8 raw_erased_mem_count; /* 181 */
76 u8 raw_ext_csd_structure; /* 194 */ 78 u8 raw_ext_csd_structure; /* 194 */
@@ -110,6 +112,7 @@ struct sd_ssr {
110struct sd_switch_caps { 112struct sd_switch_caps {
111 unsigned int hs_max_dtr; 113 unsigned int hs_max_dtr;
112 unsigned int uhs_max_dtr; 114 unsigned int uhs_max_dtr;
115#define HIGH_SPEED_MAX_DTR 50000000
113#define UHS_SDR104_MAX_DTR 208000000 116#define UHS_SDR104_MAX_DTR 208000000
114#define UHS_SDR50_MAX_DTR 100000000 117#define UHS_SDR50_MAX_DTR 100000000
115#define UHS_DDR50_MAX_DTR 50000000 118#define UHS_DDR50_MAX_DTR 50000000
@@ -117,11 +120,13 @@ struct sd_switch_caps {
117#define UHS_SDR12_MAX_DTR 25000000 120#define UHS_SDR12_MAX_DTR 25000000
118 unsigned int sd3_bus_mode; 121 unsigned int sd3_bus_mode;
119#define UHS_SDR12_BUS_SPEED 0 122#define UHS_SDR12_BUS_SPEED 0
123#define HIGH_SPEED_BUS_SPEED 1
120#define UHS_SDR25_BUS_SPEED 1 124#define UHS_SDR25_BUS_SPEED 1
121#define UHS_SDR50_BUS_SPEED 2 125#define UHS_SDR50_BUS_SPEED 2
122#define UHS_SDR104_BUS_SPEED 3 126#define UHS_SDR104_BUS_SPEED 3
123#define UHS_DDR50_BUS_SPEED 4 127#define UHS_DDR50_BUS_SPEED 4
124 128
129#define SD_MODE_HIGH_SPEED (1 << HIGH_SPEED_BUS_SPEED)
125#define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED) 130#define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED)
126#define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED) 131#define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED)
127#define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED) 132#define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED)
@@ -184,6 +189,10 @@ struct mmc_part {
184 unsigned int part_cfg; /* partition type */ 189 unsigned int part_cfg; /* partition type */
185 char name[MAX_MMC_PART_NAME_LEN]; 190 char name[MAX_MMC_PART_NAME_LEN];
186 bool force_ro; /* to make boot parts RO by default */ 191 bool force_ro; /* to make boot parts RO by default */
192 unsigned int area_type;
193#define MMC_BLK_DATA_AREA_MAIN (1<<0)
194#define MMC_BLK_DATA_AREA_BOOT (1<<1)
195#define MMC_BLK_DATA_AREA_GP (1<<2)
187}; 196};
188 197
189/* 198/*
@@ -206,6 +215,8 @@ struct mmc_card {
206#define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */ 215#define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */
207#define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */ 216#define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */
208#define MMC_CARD_SDXC (1<<6) /* card is SDXC */ 217#define MMC_CARD_SDXC (1<<6) /* card is SDXC */
218#define MMC_CARD_REMOVED (1<<7) /* card has been removed */
219#define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */
209 unsigned int quirks; /* card quirks */ 220 unsigned int quirks; /* card quirks */
210#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ 221#define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
211#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ 222#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
@@ -261,12 +272,14 @@ struct mmc_card {
261 * This function fill contents in mmc_part. 272 * This function fill contents in mmc_part.
262 */ 273 */
263static inline void mmc_part_add(struct mmc_card *card, unsigned int size, 274static inline void mmc_part_add(struct mmc_card *card, unsigned int size,
264 unsigned int part_cfg, char *name, int idx, bool ro) 275 unsigned int part_cfg, char *name, int idx, bool ro,
276 int area_type)
265{ 277{
266 card->part[card->nr_parts].size = size; 278 card->part[card->nr_parts].size = size;
267 card->part[card->nr_parts].part_cfg = part_cfg; 279 card->part[card->nr_parts].part_cfg = part_cfg;
268 sprintf(card->part[card->nr_parts].name, name, idx); 280 sprintf(card->part[card->nr_parts].name, name, idx);
269 card->part[card->nr_parts].force_ro = ro; 281 card->part[card->nr_parts].force_ro = ro;
282 card->part[card->nr_parts].area_type = area_type;
270 card->nr_parts++; 283 card->nr_parts++;
271} 284}
272 285
@@ -362,18 +375,24 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
362#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT) 375#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
363#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) 376#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
364#define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED) 377#define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED)
378#define mmc_card_hs200(c) ((c)->state & MMC_STATE_HIGHSPEED_200)
365#define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) 379#define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
366#define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR) 380#define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR)
367#define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) 381#define mmc_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
382#define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
368#define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) 383#define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
384#define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
369 385
370#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) 386#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
371#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) 387#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
372#define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED) 388#define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED)
389#define mmc_card_set_hs200(c) ((c)->state |= MMC_STATE_HIGHSPEED_200)
373#define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) 390#define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
374#define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR) 391#define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
392#define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
375#define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) 393#define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
376#define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) 394#define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
395#define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
377 396
378/* 397/*
379 * Quirk add/remove for MMC products. 398 * Quirk add/remove for MMC products.
diff --git a/include/linux/mmc/cd-gpio.h b/include/linux/mmc/cd-gpio.h
new file mode 100644
index 000000000000..a8e469783318
--- /dev/null
+++ b/include/linux/mmc/cd-gpio.h
@@ -0,0 +1,19 @@
1/*
2 * Generic GPIO card-detect helper header
3 *
4 * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef MMC_CD_GPIO_H
12#define MMC_CD_GPIO_H
13
14struct mmc_host;
15int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio,
16 unsigned int irq, unsigned long flags);
17void mmc_cd_gpio_free(struct mmc_host *host);
18
19#endif
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 174a844a5dda..87a976cc5654 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -180,6 +180,8 @@ extern int mmc_try_claim_host(struct mmc_host *host);
180 180
181extern int mmc_flush_cache(struct mmc_card *); 181extern int mmc_flush_cache(struct mmc_card *);
182 182
183extern int mmc_detect_card_removed(struct mmc_host *host);
184
183/** 185/**
184 * mmc_claim_host - exclusively claim a host 186 * mmc_claim_host - exclusively claim a host
185 * @host: mmc host to claim 187 * @host: mmc host to claim
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 6dc9b80568a0..e8779c6d1759 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -214,6 +214,7 @@ struct dw_mci_board {
214 unsigned int bus_hz; /* Bus speed */ 214 unsigned int bus_hz; /* Bus speed */
215 215
216 unsigned int caps; /* Capabilities */ 216 unsigned int caps; /* Capabilities */
217 unsigned int caps2; /* More capabilities */
217 /* 218 /*
218 * Override fifo depth. If 0, autodetect it from the FIFOTH register, 219 * Override fifo depth. If 0, autodetect it from the FIFOTH register,
219 * but note that this may not be reliable after a bootloader has used 220 * but note that this may not be reliable after a bootloader has used
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 8ef7894a48d0..0beba1e5e1ed 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -56,10 +56,13 @@ struct mmc_ios {
56#define MMC_TIMING_UHS_SDR50 3 56#define MMC_TIMING_UHS_SDR50 3
57#define MMC_TIMING_UHS_SDR104 4 57#define MMC_TIMING_UHS_SDR104 4
58#define MMC_TIMING_UHS_DDR50 5 58#define MMC_TIMING_UHS_DDR50 5
59#define MMC_TIMING_MMC_HS200 6
59 60
60#define MMC_SDR_MODE 0 61#define MMC_SDR_MODE 0
61#define MMC_1_2V_DDR_MODE 1 62#define MMC_1_2V_DDR_MODE 1
62#define MMC_1_8V_DDR_MODE 2 63#define MMC_1_8V_DDR_MODE 2
64#define MMC_1_2V_SDR_MODE 3
65#define MMC_1_8V_SDR_MODE 4
63 66
64 unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */ 67 unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */
65 68
@@ -148,7 +151,9 @@ struct mmc_host_ops {
148 void (*init_card)(struct mmc_host *host, struct mmc_card *card); 151 void (*init_card)(struct mmc_host *host, struct mmc_card *card);
149 152
150 int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios); 153 int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios);
151 int (*execute_tuning)(struct mmc_host *host); 154
155 /* The tuning command opcode value is different for SD and eMMC cards */
156 int (*execute_tuning)(struct mmc_host *host, u32 opcode);
152 void (*enable_preset_value)(struct mmc_host *host, bool enable); 157 void (*enable_preset_value)(struct mmc_host *host, bool enable);
153 int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv); 158 int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
154 void (*hw_reset)(struct mmc_host *host); 159 void (*hw_reset)(struct mmc_host *host);
@@ -167,6 +172,11 @@ struct mmc_async_req {
167 int (*err_check) (struct mmc_card *, struct mmc_async_req *); 172 int (*err_check) (struct mmc_card *, struct mmc_async_req *);
168}; 173};
169 174
175struct mmc_hotplug {
176 unsigned int irq;
177 void *handler_priv;
178};
179
170struct mmc_host { 180struct mmc_host {
171 struct device *parent; 181 struct device *parent;
172 struct device class_dev; 182 struct device class_dev;
@@ -242,6 +252,11 @@ struct mmc_host {
242#define MMC_CAP2_CACHE_CTRL (1 << 1) /* Allow cache control */ 252#define MMC_CAP2_CACHE_CTRL (1 << 1) /* Allow cache control */
243#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */ 253#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */
244#define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */ 254#define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */
255#define MMC_CAP2_NO_SLEEP_CMD (1 << 4) /* Don't allow sleep command */
256#define MMC_CAP2_HS200_1_8V_SDR (1 << 5) /* can support */
257#define MMC_CAP2_HS200_1_2V_SDR (1 << 6) /* can support */
258#define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \
259 MMC_CAP2_HS200_1_2V_SDR)
245 260
246 mmc_pm_flag_t pm_caps; /* supported pm features */ 261 mmc_pm_flag_t pm_caps; /* supported pm features */
247 unsigned int power_notify_type; 262 unsigned int power_notify_type;
@@ -253,10 +268,12 @@ struct mmc_host {
253 int clk_requests; /* internal reference counter */ 268 int clk_requests; /* internal reference counter */
254 unsigned int clk_delay; /* number of MCI clk hold cycles */ 269 unsigned int clk_delay; /* number of MCI clk hold cycles */
255 bool clk_gated; /* clock gated */ 270 bool clk_gated; /* clock gated */
256 struct work_struct clk_gate_work; /* delayed clock gate */ 271 struct delayed_work clk_gate_work; /* delayed clock gate */
257 unsigned int clk_old; /* old clock value cache */ 272 unsigned int clk_old; /* old clock value cache */
258 spinlock_t clk_lock; /* lock for clk fields */ 273 spinlock_t clk_lock; /* lock for clk fields */
259 struct mutex clk_gate_mutex; /* mutex for clock gating */ 274 struct mutex clk_gate_mutex; /* mutex for clock gating */
275 struct device_attribute clkgate_delay_attr;
276 unsigned long clkgate_delay;
260#endif 277#endif
261 278
262 /* host specific block data */ 279 /* host specific block data */
@@ -297,6 +314,8 @@ struct mmc_host {
297 int claim_cnt; /* "claim" nesting count */ 314 int claim_cnt; /* "claim" nesting count */
298 315
299 struct delayed_work detect; 316 struct delayed_work detect;
317 int detect_change; /* card detect flag */
318 struct mmc_hotplug hotplug;
300 319
301 const struct mmc_bus_ops *bus_ops; /* current bus driver */ 320 const struct mmc_bus_ops *bus_ops; /* current bus driver */
302 unsigned int bus_refs; /* reference counter */ 321 unsigned int bus_refs; /* reference counter */
@@ -323,6 +342,8 @@ struct mmc_host {
323 struct fault_attr fail_mmc_request; 342 struct fault_attr fail_mmc_request;
324#endif 343#endif
325 344
345 unsigned int actual_clock; /* Actual HC clock rate */
346
326 unsigned long private[0] ____cacheline_aligned; 347 unsigned long private[0] ____cacheline_aligned;
327}; 348};
328 349
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 0e7135697d11..fb9f6e116e1c 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -51,6 +51,7 @@
51#define MMC_READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1 */ 51#define MMC_READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1 */
52#define MMC_READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1 */ 52#define MMC_READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1 */
53#define MMC_SEND_TUNING_BLOCK 19 /* adtc R1 */ 53#define MMC_SEND_TUNING_BLOCK 19 /* adtc R1 */
54#define MMC_SEND_TUNING_BLOCK_HS200 21 /* adtc R1 */
54 55
55 /* class 3 */ 56 /* class 3 */
56#define MMC_WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */ 57#define MMC_WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */
@@ -280,6 +281,7 @@ struct _mmc_csd {
280#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ 281#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
281#define EXT_CSD_SANITIZE_START 165 /* W */ 282#define EXT_CSD_SANITIZE_START 165 /* W */
282#define EXT_CSD_WR_REL_PARAM 166 /* RO */ 283#define EXT_CSD_WR_REL_PARAM 166 /* RO */
284#define EXT_CSD_BOOT_WP 173 /* R/W */
283#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ 285#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
284#define EXT_CSD_PART_CONFIG 179 /* R/W */ 286#define EXT_CSD_PART_CONFIG 179 /* R/W */
285#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ 287#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
@@ -321,6 +323,11 @@ struct _mmc_csd {
321 323
322#define EXT_CSD_WR_REL_PARAM_EN (1<<2) 324#define EXT_CSD_WR_REL_PARAM_EN (1<<2)
323 325
326#define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40)
327#define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10)
328#define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04)
329#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01)
330
324#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) 331#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7)
325#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) 332#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
326#define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4) 333#define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4)
@@ -333,13 +340,76 @@ struct _mmc_csd {
333 340
334#define EXT_CSD_CARD_TYPE_26 (1<<0) /* Card can run at 26MHz */ 341#define EXT_CSD_CARD_TYPE_26 (1<<0) /* Card can run at 26MHz */
335#define EXT_CSD_CARD_TYPE_52 (1<<1) /* Card can run at 52MHz */ 342#define EXT_CSD_CARD_TYPE_52 (1<<1) /* Card can run at 52MHz */
336#define EXT_CSD_CARD_TYPE_MASK 0xF /* Mask out reserved bits */ 343#define EXT_CSD_CARD_TYPE_MASK 0x3F /* Mask out reserved bits */
337#define EXT_CSD_CARD_TYPE_DDR_1_8V (1<<2) /* Card can run at 52MHz */ 344#define EXT_CSD_CARD_TYPE_DDR_1_8V (1<<2) /* Card can run at 52MHz */
338 /* DDR mode @1.8V or 3V I/O */ 345 /* DDR mode @1.8V or 3V I/O */
339#define EXT_CSD_CARD_TYPE_DDR_1_2V (1<<3) /* Card can run at 52MHz */ 346#define EXT_CSD_CARD_TYPE_DDR_1_2V (1<<3) /* Card can run at 52MHz */
340 /* DDR mode @1.2V I/O */ 347 /* DDR mode @1.2V I/O */
341#define EXT_CSD_CARD_TYPE_DDR_52 (EXT_CSD_CARD_TYPE_DDR_1_8V \ 348#define EXT_CSD_CARD_TYPE_DDR_52 (EXT_CSD_CARD_TYPE_DDR_1_8V \
342 | EXT_CSD_CARD_TYPE_DDR_1_2V) 349 | EXT_CSD_CARD_TYPE_DDR_1_2V)
350#define EXT_CSD_CARD_TYPE_SDR_1_8V (1<<4) /* Card can run at 200MHz */
351#define EXT_CSD_CARD_TYPE_SDR_1_2V (1<<5) /* Card can run at 200MHz */
352 /* SDR mode @1.2V I/O */
353
354#define EXT_CSD_CARD_TYPE_SDR_200 (EXT_CSD_CARD_TYPE_SDR_1_8V | \
355 EXT_CSD_CARD_TYPE_SDR_1_2V)
356
357#define EXT_CSD_CARD_TYPE_SDR_ALL (EXT_CSD_CARD_TYPE_SDR_200 | \
358 EXT_CSD_CARD_TYPE_52 | \
359 EXT_CSD_CARD_TYPE_26)
360
361#define EXT_CSD_CARD_TYPE_SDR_1_2V_ALL (EXT_CSD_CARD_TYPE_SDR_1_2V | \
362 EXT_CSD_CARD_TYPE_52 | \
363 EXT_CSD_CARD_TYPE_26)
364
365#define EXT_CSD_CARD_TYPE_SDR_1_8V_ALL (EXT_CSD_CARD_TYPE_SDR_1_8V | \
366 EXT_CSD_CARD_TYPE_52 | \
367 EXT_CSD_CARD_TYPE_26)
368
369#define EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_8V (EXT_CSD_CARD_TYPE_SDR_1_2V | \
370 EXT_CSD_CARD_TYPE_DDR_1_8V | \
371 EXT_CSD_CARD_TYPE_52 | \
372 EXT_CSD_CARD_TYPE_26)
373
374#define EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_8V (EXT_CSD_CARD_TYPE_SDR_1_8V | \
375 EXT_CSD_CARD_TYPE_DDR_1_8V | \
376 EXT_CSD_CARD_TYPE_52 | \
377 EXT_CSD_CARD_TYPE_26)
378
379#define EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_1_2V (EXT_CSD_CARD_TYPE_SDR_1_2V | \
380 EXT_CSD_CARD_TYPE_DDR_1_2V | \
381 EXT_CSD_CARD_TYPE_52 | \
382 EXT_CSD_CARD_TYPE_26)
383
384#define EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_1_2V (EXT_CSD_CARD_TYPE_SDR_1_8V | \
385 EXT_CSD_CARD_TYPE_DDR_1_2V | \
386 EXT_CSD_CARD_TYPE_52 | \
387 EXT_CSD_CARD_TYPE_26)
388
389#define EXT_CSD_CARD_TYPE_SDR_1_2V_DDR_52 (EXT_CSD_CARD_TYPE_SDR_1_2V | \
390 EXT_CSD_CARD_TYPE_DDR_52 | \
391 EXT_CSD_CARD_TYPE_52 | \
392 EXT_CSD_CARD_TYPE_26)
393
394#define EXT_CSD_CARD_TYPE_SDR_1_8V_DDR_52 (EXT_CSD_CARD_TYPE_SDR_1_8V | \
395 EXT_CSD_CARD_TYPE_DDR_52 | \
396 EXT_CSD_CARD_TYPE_52 | \
397 EXT_CSD_CARD_TYPE_26)
398
399#define EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_8V (EXT_CSD_CARD_TYPE_SDR_200 | \
400 EXT_CSD_CARD_TYPE_DDR_1_8V | \
401 EXT_CSD_CARD_TYPE_52 | \
402 EXT_CSD_CARD_TYPE_26)
403
404#define EXT_CSD_CARD_TYPE_SDR_ALL_DDR_1_2V (EXT_CSD_CARD_TYPE_SDR_200 | \
405 EXT_CSD_CARD_TYPE_DDR_1_2V | \
406 EXT_CSD_CARD_TYPE_52 | \
407 EXT_CSD_CARD_TYPE_26)
408
409#define EXT_CSD_CARD_TYPE_SDR_ALL_DDR_52 (EXT_CSD_CARD_TYPE_SDR_200 | \
410 EXT_CSD_CARD_TYPE_DDR_52 | \
411 EXT_CSD_CARD_TYPE_52 | \
412 EXT_CSD_CARD_TYPE_26)
343 413
344#define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */ 414#define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */
345#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ 415#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
diff --git a/include/linux/mmc/sdhci-pci-data.h b/include/linux/mmc/sdhci-pci-data.h
new file mode 100644
index 000000000000..8959604a13d3
--- /dev/null
+++ b/include/linux/mmc/sdhci-pci-data.h
@@ -0,0 +1,18 @@
1#ifndef LINUX_MMC_SDHCI_PCI_DATA_H
2#define LINUX_MMC_SDHCI_PCI_DATA_H
3
4struct pci_dev;
5
6struct sdhci_pci_data {
7 struct pci_dev *pdev;
8 int slotno;
9 int rst_n_gpio; /* Set to -EINVAL if unused */
10 int cd_gpio; /* Set to -EINVAL if unused */
11 int (*setup)(struct sdhci_pci_data *data);
12 void (*cleanup)(struct sdhci_pci_data *data);
13};
14
15extern struct sdhci_pci_data *(*sdhci_pci_get_data)(struct pci_dev *pdev,
16 int slotno);
17
18#endif
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index e4b69353678d..c750f85177d9 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -90,8 +90,6 @@ struct sdhci_host {
90 90
91 unsigned int quirks2; /* More deviations from spec. */ 91 unsigned int quirks2; /* More deviations from spec. */
92 92
93#define SDHCI_QUIRK2_OWN_CARD_DETECTION (1<<0)
94
95 int irq; /* Device IRQ */ 93 int irq; /* Device IRQ */
96 void __iomem *ioaddr; /* Mapped address */ 94 void __iomem *ioaddr; /* Mapped address */
97 95
@@ -121,6 +119,7 @@ struct sdhci_host {
121#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */ 119#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
122#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */ 120#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
123#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */ 121#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
122#define SDHCI_HS200_NEEDS_TUNING (1<<10) /* HS200 needs tuning */
124 123
125 unsigned int version; /* SDHCI spec. version */ 124 unsigned int version; /* SDHCI spec. version */
126 125
diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h
index e0b1123497b9..c9fe66c58f8f 100644
--- a/include/linux/mmc/sdio.h
+++ b/include/linux/mmc/sdio.h
@@ -38,6 +38,7 @@
38 * [8:0] Byte/block count 38 * [8:0] Byte/block count
39 */ 39 */
40 40
41#define R4_18V_PRESENT (1<<24)
41#define R4_MEMORY_PRESENT (1 << 27) 42#define R4_MEMORY_PRESENT (1 << 27)
42 43
43/* 44/*
@@ -85,6 +86,7 @@
85#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */ 86#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */
86#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */ 87#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */
87#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */ 88#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */
89#define SDIO_SD_REV_3_00 3 /* SD Physical Spev Version 3.00 */
88 90
89#define SDIO_CCCR_IOEx 0x02 91#define SDIO_CCCR_IOEx 0x02
90#define SDIO_CCCR_IORx 0x03 92#define SDIO_CCCR_IORx 0x03
@@ -134,8 +136,31 @@
134#define SDIO_CCCR_SPEED 0x13 136#define SDIO_CCCR_SPEED 0x13
135 137
136#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */ 138#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */
137#define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */ 139#define SDIO_SPEED_BSS_SHIFT 1
138 140#define SDIO_SPEED_BSS_MASK (7<<SDIO_SPEED_BSS_SHIFT)
141#define SDIO_SPEED_SDR12 (0<<SDIO_SPEED_BSS_SHIFT)
142#define SDIO_SPEED_SDR25 (1<<SDIO_SPEED_BSS_SHIFT)
143#define SDIO_SPEED_SDR50 (2<<SDIO_SPEED_BSS_SHIFT)
144#define SDIO_SPEED_SDR104 (3<<SDIO_SPEED_BSS_SHIFT)
145#define SDIO_SPEED_DDR50 (4<<SDIO_SPEED_BSS_SHIFT)
146#define SDIO_SPEED_EHS SDIO_SPEED_SDR25 /* Enable High-Speed */
147
148#define SDIO_CCCR_UHS 0x14
149#define SDIO_UHS_SDR50 0x01
150#define SDIO_UHS_SDR104 0x02
151#define SDIO_UHS_DDR50 0x04
152
153#define SDIO_CCCR_DRIVE_STRENGTH 0x15
154#define SDIO_SDTx_MASK 0x07
155#define SDIO_DRIVE_SDTA (1<<0)
156#define SDIO_DRIVE_SDTC (1<<1)
157#define SDIO_DRIVE_SDTD (1<<2)
158#define SDIO_DRIVE_DTSx_MASK 0x03
159#define SDIO_DRIVE_DTSx_SHIFT 4
160#define SDIO_DTSx_SET_TYPE_B (0 << SDIO_DRIVE_DTSx_SHIFT)
161#define SDIO_DTSx_SET_TYPE_A (1 << SDIO_DRIVE_DTSx_SHIFT)
162#define SDIO_DTSx_SET_TYPE_C (2 << SDIO_DRIVE_DTSx_SHIFT)
163#define SDIO_DTSx_SET_TYPE_D (3 << SDIO_DRIVE_DTSx_SHIFT)
139/* 164/*
140 * Function Basic Registers (FBR) 165 * Function Basic Registers (FBR)
141 */ 166 */
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index ca6ca92418a6..650ba2fb3301 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -140,25 +140,29 @@ enum lru_list {
140 NR_LRU_LISTS 140 NR_LRU_LISTS
141}; 141};
142 142
143#define for_each_lru(l) for (l = 0; l < NR_LRU_LISTS; l++) 143#define for_each_lru(lru) for (lru = 0; lru < NR_LRU_LISTS; lru++)
144 144
145#define for_each_evictable_lru(l) for (l = 0; l <= LRU_ACTIVE_FILE; l++) 145#define for_each_evictable_lru(lru) for (lru = 0; lru <= LRU_ACTIVE_FILE; lru++)
146 146
147static inline int is_file_lru(enum lru_list l) 147static inline int is_file_lru(enum lru_list lru)
148{ 148{
149 return (l == LRU_INACTIVE_FILE || l == LRU_ACTIVE_FILE); 149 return (lru == LRU_INACTIVE_FILE || lru == LRU_ACTIVE_FILE);
150} 150}
151 151
152static inline int is_active_lru(enum lru_list l) 152static inline int is_active_lru(enum lru_list lru)
153{ 153{
154 return (l == LRU_ACTIVE_ANON || l == LRU_ACTIVE_FILE); 154 return (lru == LRU_ACTIVE_ANON || lru == LRU_ACTIVE_FILE);
155} 155}
156 156
157static inline int is_unevictable_lru(enum lru_list l) 157static inline int is_unevictable_lru(enum lru_list lru)
158{ 158{
159 return (l == LRU_UNEVICTABLE); 159 return (lru == LRU_UNEVICTABLE);
160} 160}
161 161
162struct lruvec {
163 struct list_head lists[NR_LRU_LISTS];
164};
165
162/* Mask used at gathering information at once (see memcontrol.c) */ 166/* Mask used at gathering information at once (see memcontrol.c) */
163#define LRU_ALL_FILE (BIT(LRU_INACTIVE_FILE) | BIT(LRU_ACTIVE_FILE)) 167#define LRU_ALL_FILE (BIT(LRU_INACTIVE_FILE) | BIT(LRU_ACTIVE_FILE))
164#define LRU_ALL_ANON (BIT(LRU_INACTIVE_ANON) | BIT(LRU_ACTIVE_ANON)) 168#define LRU_ALL_ANON (BIT(LRU_INACTIVE_ANON) | BIT(LRU_ACTIVE_ANON))
@@ -173,6 +177,8 @@ static inline int is_unevictable_lru(enum lru_list l)
173#define ISOLATE_CLEAN ((__force isolate_mode_t)0x4) 177#define ISOLATE_CLEAN ((__force isolate_mode_t)0x4)
174/* Isolate unmapped file */ 178/* Isolate unmapped file */
175#define ISOLATE_UNMAPPED ((__force isolate_mode_t)0x8) 179#define ISOLATE_UNMAPPED ((__force isolate_mode_t)0x8)
180/* Isolate for asynchronous migration */
181#define ISOLATE_ASYNC_MIGRATE ((__force isolate_mode_t)0x10)
176 182
177/* LRU Isolation modes. */ 183/* LRU Isolation modes. */
178typedef unsigned __bitwise__ isolate_mode_t; 184typedef unsigned __bitwise__ isolate_mode_t;
@@ -364,10 +370,8 @@ struct zone {
364 ZONE_PADDING(_pad1_) 370 ZONE_PADDING(_pad1_)
365 371
366 /* Fields commonly accessed by the page reclaim scanner */ 372 /* Fields commonly accessed by the page reclaim scanner */
367 spinlock_t lru_lock; 373 spinlock_t lru_lock;
368 struct zone_lru { 374 struct lruvec lruvec;
369 struct list_head list;
370 } lru[NR_LRU_LISTS];
371 375
372 struct zone_reclaim_stat reclaim_stat; 376 struct zone_reclaim_stat reclaim_stat;
373 377
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 83ac0713ed0a..b29e7f6f8fa5 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -436,6 +436,17 @@ struct spi_device_id {
436 __attribute__((aligned(sizeof(kernel_ulong_t)))); 436 __attribute__((aligned(sizeof(kernel_ulong_t))));
437}; 437};
438 438
439/* mcp */
440
441#define MCP_NAME_SIZE 20
442#define MCP_MODULE_PREFIX "mcp:"
443
444struct mcp_device_id {
445 char name[MCP_NAME_SIZE];
446 kernel_ulong_t driver_data /* Data private to the driver */
447 __attribute__((aligned(sizeof(kernel_ulong_t))));
448};
449
439/* dmi */ 450/* dmi */
440enum dmi_field { 451enum dmi_field {
441 DMI_NONE, 452 DMI_NONE,
diff --git a/include/linux/oom.h b/include/linux/oom.h
index 6f9d04a85336..552fba9c7d5a 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -43,7 +43,7 @@ enum oom_constraint {
43extern void compare_swap_oom_score_adj(int old_val, int new_val); 43extern void compare_swap_oom_score_adj(int old_val, int new_val);
44extern int test_set_oom_score_adj(int new_val); 44extern int test_set_oom_score_adj(int new_val);
45 45
46extern unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, 46extern unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *memcg,
47 const nodemask_t *nodemask, unsigned long totalpages); 47 const nodemask_t *nodemask, unsigned long totalpages);
48extern int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags); 48extern int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
49extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags); 49extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
diff --git a/include/linux/page_cgroup.h b/include/linux/page_cgroup.h
index 961ecc7d30bc..a2d11771c84b 100644
--- a/include/linux/page_cgroup.h
+++ b/include/linux/page_cgroup.h
@@ -10,8 +10,6 @@ enum {
10 /* flags for mem_cgroup and file and I/O status */ 10 /* flags for mem_cgroup and file and I/O status */
11 PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */ 11 PCG_MOVE_LOCK, /* For race between move_account v.s. following bits */
12 PCG_FILE_MAPPED, /* page is accounted as "mapped" */ 12 PCG_FILE_MAPPED, /* page is accounted as "mapped" */
13 /* No lock in page_cgroup */
14 PCG_ACCT_LRU, /* page has been accounted for (under lru_lock) */
15 __NR_PCG_FLAGS, 13 __NR_PCG_FLAGS,
16}; 14};
17 15
@@ -31,7 +29,6 @@ enum {
31struct page_cgroup { 29struct page_cgroup {
32 unsigned long flags; 30 unsigned long flags;
33 struct mem_cgroup *mem_cgroup; 31 struct mem_cgroup *mem_cgroup;
34 struct list_head lru; /* per cgroup LRU list */
35}; 32};
36 33
37void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat); 34void __meminit pgdat_page_cgroup_init(struct pglist_data *pgdat);
@@ -76,12 +73,6 @@ TESTPCGFLAG(Used, USED)
76CLEARPCGFLAG(Used, USED) 73CLEARPCGFLAG(Used, USED)
77SETPCGFLAG(Used, USED) 74SETPCGFLAG(Used, USED)
78 75
79SETPCGFLAG(AcctLRU, ACCT_LRU)
80CLEARPCGFLAG(AcctLRU, ACCT_LRU)
81TESTPCGFLAG(AcctLRU, ACCT_LRU)
82TESTCLEARPCGFLAG(AcctLRU, ACCT_LRU)
83
84
85SETPCGFLAG(FileMapped, FILE_MAPPED) 76SETPCGFLAG(FileMapped, FILE_MAPPED)
86CLEARPCGFLAG(FileMapped, FILE_MAPPED) 77CLEARPCGFLAG(FileMapped, FILE_MAPPED)
87TESTPCGFLAG(FileMapped, FILE_MAPPED) 78TESTPCGFLAG(FileMapped, FILE_MAPPED)
@@ -122,39 +113,6 @@ static inline void move_unlock_page_cgroup(struct page_cgroup *pc,
122 local_irq_restore(*flags); 113 local_irq_restore(*flags);
123} 114}
124 115
125#ifdef CONFIG_SPARSEMEM
126#define PCG_ARRAYID_WIDTH SECTIONS_SHIFT
127#else
128#define PCG_ARRAYID_WIDTH NODES_SHIFT
129#endif
130
131#if (PCG_ARRAYID_WIDTH > BITS_PER_LONG - NR_PCG_FLAGS)
132#error Not enough space left in pc->flags to store page_cgroup array IDs
133#endif
134
135/* pc->flags: ARRAY-ID | FLAGS */
136
137#define PCG_ARRAYID_MASK ((1UL << PCG_ARRAYID_WIDTH) - 1)
138
139#define PCG_ARRAYID_OFFSET (BITS_PER_LONG - PCG_ARRAYID_WIDTH)
140/*
141 * Zero the shift count for non-existent fields, to prevent compiler
142 * warnings and ensure references are optimized away.
143 */
144#define PCG_ARRAYID_SHIFT (PCG_ARRAYID_OFFSET * (PCG_ARRAYID_WIDTH != 0))
145
146static inline void set_page_cgroup_array_id(struct page_cgroup *pc,
147 unsigned long id)
148{
149 pc->flags &= ~(PCG_ARRAYID_MASK << PCG_ARRAYID_SHIFT);
150 pc->flags |= (id & PCG_ARRAYID_MASK) << PCG_ARRAYID_SHIFT;
151}
152
153static inline unsigned long page_cgroup_array_id(struct page_cgroup *pc)
154{
155 return (pc->flags >> PCG_ARRAYID_SHIFT) & PCG_ARRAYID_MASK;
156}
157
158#else /* CONFIG_CGROUP_MEM_RES_CTLR */ 116#else /* CONFIG_CGROUP_MEM_RES_CTLR */
159struct page_cgroup; 117struct page_cgroup;
160 118
@@ -183,7 +141,7 @@ static inline void __init page_cgroup_init_flatmem(void)
183extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, 141extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
184 unsigned short old, unsigned short new); 142 unsigned short old, unsigned short new);
185extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id); 143extern unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id);
186extern unsigned short lookup_swap_cgroup(swp_entry_t ent); 144extern unsigned short lookup_swap_cgroup_id(swp_entry_t ent);
187extern int swap_cgroup_swapon(int type, unsigned long max_pages); 145extern int swap_cgroup_swapon(int type, unsigned long max_pages);
188extern void swap_cgroup_swapoff(int type); 146extern void swap_cgroup_swapoff(int type);
189#else 147#else
@@ -195,7 +153,7 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
195} 153}
196 154
197static inline 155static inline
198unsigned short lookup_swap_cgroup(swp_entry_t ent) 156unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
199{ 157{
200 return 0; 158 return 0;
201} 159}
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index ed17024d2ebe..2aa12b8499c0 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -21,8 +21,7 @@ struct pagevec {
21}; 21};
22 22
23void __pagevec_release(struct pagevec *pvec); 23void __pagevec_release(struct pagevec *pvec);
24void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru); 24void __pagevec_lru_add(struct pagevec *pvec, enum lru_list lru);
25void pagevec_strip(struct pagevec *pvec);
26unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping, 25unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
27 pgoff_t start, unsigned nr_pages); 26 pgoff_t start, unsigned nr_pages);
28unsigned pagevec_lookup_tag(struct pagevec *pvec, 27unsigned pagevec_lookup_tag(struct pagevec *pvec,
@@ -59,7 +58,6 @@ static inline unsigned pagevec_add(struct pagevec *pvec, struct page *page)
59 return pagevec_space(pvec); 58 return pagevec_space(pvec);
60} 59}
61 60
62
63static inline void pagevec_release(struct pagevec *pvec) 61static inline void pagevec_release(struct pagevec *pvec)
64{ 62{
65 if (pagevec_count(pvec)) 63 if (pagevec_count(pvec))
@@ -68,22 +66,22 @@ static inline void pagevec_release(struct pagevec *pvec)
68 66
69static inline void __pagevec_lru_add_anon(struct pagevec *pvec) 67static inline void __pagevec_lru_add_anon(struct pagevec *pvec)
70{ 68{
71 ____pagevec_lru_add(pvec, LRU_INACTIVE_ANON); 69 __pagevec_lru_add(pvec, LRU_INACTIVE_ANON);
72} 70}
73 71
74static inline void __pagevec_lru_add_active_anon(struct pagevec *pvec) 72static inline void __pagevec_lru_add_active_anon(struct pagevec *pvec)
75{ 73{
76 ____pagevec_lru_add(pvec, LRU_ACTIVE_ANON); 74 __pagevec_lru_add(pvec, LRU_ACTIVE_ANON);
77} 75}
78 76
79static inline void __pagevec_lru_add_file(struct pagevec *pvec) 77static inline void __pagevec_lru_add_file(struct pagevec *pvec)
80{ 78{
81 ____pagevec_lru_add(pvec, LRU_INACTIVE_FILE); 79 __pagevec_lru_add(pvec, LRU_INACTIVE_FILE);
82} 80}
83 81
84static inline void __pagevec_lru_add_active_file(struct pagevec *pvec) 82static inline void __pagevec_lru_add_active_file(struct pagevec *pvec)
85{ 83{
86 ____pagevec_lru_add(pvec, LRU_ACTIVE_FILE); 84 __pagevec_lru_add(pvec, LRU_ACTIVE_FILE);
87} 85}
88 86
89static inline void pagevec_lru_add_file(struct pagevec *pvec) 87static inline void pagevec_lru_add_file(struct pagevec *pvec)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 79f337c47388..c599f7eca1e7 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -129,7 +129,12 @@ struct mii_bus {
129}; 129};
130#define to_mii_bus(d) container_of(d, struct mii_bus, dev) 130#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
131 131
132struct mii_bus *mdiobus_alloc(void); 132struct mii_bus *mdiobus_alloc_size(size_t);
133static inline struct mii_bus *mdiobus_alloc(void)
134{
135 return mdiobus_alloc_size(0);
136}
137
133int mdiobus_register(struct mii_bus *bus); 138int mdiobus_register(struct mii_bus *bus);
134void mdiobus_unregister(struct mii_bus *bus); 139void mdiobus_unregister(struct mii_bus *bus);
135void mdiobus_free(struct mii_bus *bus); 140void mdiobus_free(struct mii_bus *bus);
diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
index 8f1b928f777c..0d5b79365d03 100644
--- a/include/linux/pkt_sched.h
+++ b/include/linux/pkt_sched.h
@@ -162,10 +162,30 @@ struct tc_sfq_qopt {
162 unsigned flows; /* Maximal number of flows */ 162 unsigned flows; /* Maximal number of flows */
163}; 163};
164 164
165struct tc_sfqred_stats {
166 __u32 prob_drop; /* Early drops, below max threshold */
167 __u32 forced_drop; /* Early drops, after max threshold */
168 __u32 prob_mark; /* Marked packets, below max threshold */
169 __u32 forced_mark; /* Marked packets, after max threshold */
170 __u32 prob_mark_head; /* Marked packets, below max threshold */
171 __u32 forced_mark_head;/* Marked packets, after max threshold */
172};
173
165struct tc_sfq_qopt_v1 { 174struct tc_sfq_qopt_v1 {
166 struct tc_sfq_qopt v0; 175 struct tc_sfq_qopt v0;
167 unsigned int depth; /* max number of packets per flow */ 176 unsigned int depth; /* max number of packets per flow */
168 unsigned int headdrop; 177 unsigned int headdrop;
178/* SFQRED parameters */
179 __u32 limit; /* HARD maximal flow queue length (bytes) */
180 __u32 qth_min; /* Min average length threshold (bytes) */
181 __u32 qth_max; /* Max average length threshold (bytes) */
182 unsigned char Wlog; /* log(W) */
183 unsigned char Plog; /* log(P_max/(qth_max-qth_min)) */
184 unsigned char Scell_log; /* cell size for idle damping */
185 unsigned char flags;
186 __u32 max_P; /* probability, high resolution */
187/* SFQRED stats */
188 struct tc_sfqred_stats stats;
169}; 189};
170 190
171 191
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index a3baeb2c2161..7ddc7f1b480f 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -102,4 +102,16 @@
102 102
103#define PR_MCE_KILL_GET 34 103#define PR_MCE_KILL_GET 34
104 104
105/*
106 * Tune up process memory map specifics.
107 */
108#define PR_SET_MM 35
109# define PR_SET_MM_START_CODE 1
110# define PR_SET_MM_END_CODE 2
111# define PR_SET_MM_START_DATA 3
112# define PR_SET_MM_END_DATA 4
113# define PR_SET_MM_START_STACK 5
114# define PR_SET_MM_START_BRK 6
115# define PR_SET_MM_BRK 7
116
105#endif /* _LINUX_PRCTL_H */ 117#endif /* _LINUX_PRCTL_H */
diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index 9d4539c52e53..07e360b1b282 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -49,9 +49,6 @@
49#define RADIX_TREE_EXCEPTIONAL_ENTRY 2 49#define RADIX_TREE_EXCEPTIONAL_ENTRY 2
50#define RADIX_TREE_EXCEPTIONAL_SHIFT 2 50#define RADIX_TREE_EXCEPTIONAL_SHIFT 2
51 51
52#define radix_tree_indirect_to_ptr(ptr) \
53 radix_tree_indirect_to_ptr((void __force *)(ptr))
54
55static inline int radix_tree_is_indirect_ptr(void *ptr) 52static inline int radix_tree_is_indirect_ptr(void *ptr)
56{ 53{
57 return (int)((unsigned long)ptr & RADIX_TREE_INDIRECT_PTR); 54 return (int)((unsigned long)ptr & RADIX_TREE_INDIRECT_PTR);
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 1afb9954bbf1..1cdd62a2788a 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -158,7 +158,7 @@ static inline void page_dup_rmap(struct page *page)
158 * Called from mm/vmscan.c to handle paging out 158 * Called from mm/vmscan.c to handle paging out
159 */ 159 */
160int page_referenced(struct page *, int is_locked, 160int page_referenced(struct page *, int is_locked,
161 struct mem_cgroup *cnt, unsigned long *vm_flags); 161 struct mem_cgroup *memcg, unsigned long *vm_flags);
162int page_referenced_one(struct page *, struct vm_area_struct *, 162int page_referenced_one(struct page *, struct vm_area_struct *,
163 unsigned long address, unsigned int *mapcount, unsigned long *vm_flags); 163 unsigned long address, unsigned int *mapcount, unsigned long *vm_flags);
164 164
@@ -236,7 +236,7 @@ int rmap_walk(struct page *page, int (*rmap_one)(struct page *,
236#define anon_vma_link(vma) do {} while (0) 236#define anon_vma_link(vma) do {} while (0)
237 237
238static inline int page_referenced(struct page *page, int is_locked, 238static inline int page_referenced(struct page *page, int is_locked,
239 struct mem_cgroup *cnt, 239 struct mem_cgroup *memcg,
240 unsigned long *vm_flags) 240 unsigned long *vm_flags)
241{ 241{
242 *vm_flags = 0; 242 *vm_flags = 0;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 21cd0303af51..4032ec1cf836 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2275,7 +2275,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
2275extern void exit_itimers(struct signal_struct *); 2275extern void exit_itimers(struct signal_struct *);
2276extern void flush_itimer_signals(void); 2276extern void flush_itimer_signals(void);
2277 2277
2278extern NORET_TYPE void do_group_exit(int); 2278extern void do_group_exit(int);
2279 2279
2280extern void daemonize(const char *, ...); 2280extern void daemonize(const char *, ...);
2281extern int allow_signal(int); 2281extern int allow_signal(int);
diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
index 8620f79658d4..dfa900948af7 100644
--- a/include/linux/sunrpc/svc_xprt.h
+++ b/include/linux/sunrpc/svc_xprt.h
@@ -109,7 +109,7 @@ static inline int register_xpt_user(struct svc_xprt *xpt, struct svc_xpt_user *u
109 109
110int svc_reg_xprt_class(struct svc_xprt_class *); 110int svc_reg_xprt_class(struct svc_xprt_class *);
111void svc_unreg_xprt_class(struct svc_xprt_class *); 111void svc_unreg_xprt_class(struct svc_xprt_class *);
112void svc_xprt_init(struct svc_xprt_class *, struct svc_xprt *, 112void svc_xprt_init(struct net *, struct svc_xprt_class *, struct svc_xprt *,
113 struct svc_serv *); 113 struct svc_serv *);
114int svc_create_xprt(struct svc_serv *, const char *, struct net *, 114int svc_create_xprt(struct svc_serv *, const char *, struct net *,
115 const int, const unsigned short, int); 115 const int, const unsigned short, int);
@@ -118,7 +118,6 @@ void svc_xprt_received(struct svc_xprt *);
118void svc_xprt_put(struct svc_xprt *xprt); 118void svc_xprt_put(struct svc_xprt *xprt);
119void svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt); 119void svc_xprt_copy_addrs(struct svc_rqst *rqstp, struct svc_xprt *xprt);
120void svc_close_xprt(struct svc_xprt *xprt); 120void svc_close_xprt(struct svc_xprt *xprt);
121void svc_delete_xprt(struct svc_xprt *xprt);
122int svc_port_is_privileged(struct sockaddr *sin); 121int svc_port_is_privileged(struct sockaddr *sin);
123int svc_print_xprts(char *buf, int maxlen); 122int svc_print_xprts(char *buf, int maxlen);
124struct svc_xprt *svc_find_xprt(struct svc_serv *serv, const char *xcl_name, 123struct svc_xprt *svc_find_xprt(struct svc_serv *serv, const char *xcl_name,
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index 85c50b40759d..c84e9741cb2a 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -34,7 +34,7 @@ struct svc_sock {
34/* 34/*
35 * Function prototypes. 35 * Function prototypes.
36 */ 36 */
37void svc_close_all(struct list_head *); 37void svc_close_all(struct svc_serv *);
38int svc_recv(struct svc_rqst *, long); 38int svc_recv(struct svc_rqst *, long);
39int svc_send(struct svc_rqst *); 39int svc_send(struct svc_rqst *);
40void svc_drop(struct svc_rqst *); 40void svc_drop(struct svc_rqst *);
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 5e2e98458496..ea9231f4935f 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -127,7 +127,7 @@ struct hci_dev {
127 __u8 major_class; 127 __u8 major_class;
128 __u8 minor_class; 128 __u8 minor_class;
129 __u8 features[8]; 129 __u8 features[8];
130 __u8 extfeatures[8]; 130 __u8 host_features[8];
131 __u8 commands[64]; 131 __u8 commands[64];
132 __u8 ssp_mode; 132 __u8 ssp_mode;
133 __u8 hci_ver; 133 __u8 hci_ver;
@@ -676,7 +676,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
676#define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE) 676#define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE)
677 677
678/* ----- Extended LMP capabilities ----- */ 678/* ----- Extended LMP capabilities ----- */
679#define lmp_host_le_capable(dev) ((dev)->extfeatures[0] & LMP_HOST_LE) 679#define lmp_host_le_capable(dev) ((dev)->host_features[0] & LMP_HOST_LE)
680 680
681/* ----- HCI protocols ----- */ 681/* ----- HCI protocols ----- */
682static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 682static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
diff --git a/include/net/red.h b/include/net/red.h
index baab385a4736..28068ec614b2 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -199,7 +199,8 @@ static inline void red_set_parms(struct red_parms *p,
199 p->Scell_log = Scell_log; 199 p->Scell_log = Scell_log;
200 p->Scell_max = (255 << Scell_log); 200 p->Scell_max = (255 << Scell_log);
201 201
202 memcpy(p->Stab, stab, sizeof(p->Stab)); 202 if (stab)
203 memcpy(p->Stab, stab, sizeof(p->Stab));
203} 204}
204 205
205static inline int red_is_idling(const struct red_vars *v) 206static inline int red_is_idling(const struct red_vars *v)
diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h
index edc4b3d25a2d..f64560e204bc 100644
--- a/include/trace/events/vmscan.h
+++ b/include/trace/events/vmscan.h
@@ -266,9 +266,10 @@ DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
266 unsigned long nr_lumpy_taken, 266 unsigned long nr_lumpy_taken,
267 unsigned long nr_lumpy_dirty, 267 unsigned long nr_lumpy_dirty,
268 unsigned long nr_lumpy_failed, 268 unsigned long nr_lumpy_failed,
269 isolate_mode_t isolate_mode), 269 isolate_mode_t isolate_mode,
270 int file),
270 271
271 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode), 272 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode, file),
272 273
273 TP_STRUCT__entry( 274 TP_STRUCT__entry(
274 __field(int, order) 275 __field(int, order)
@@ -279,6 +280,7 @@ DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
279 __field(unsigned long, nr_lumpy_dirty) 280 __field(unsigned long, nr_lumpy_dirty)
280 __field(unsigned long, nr_lumpy_failed) 281 __field(unsigned long, nr_lumpy_failed)
281 __field(isolate_mode_t, isolate_mode) 282 __field(isolate_mode_t, isolate_mode)
283 __field(int, file)
282 ), 284 ),
283 285
284 TP_fast_assign( 286 TP_fast_assign(
@@ -290,9 +292,10 @@ DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
290 __entry->nr_lumpy_dirty = nr_lumpy_dirty; 292 __entry->nr_lumpy_dirty = nr_lumpy_dirty;
291 __entry->nr_lumpy_failed = nr_lumpy_failed; 293 __entry->nr_lumpy_failed = nr_lumpy_failed;
292 __entry->isolate_mode = isolate_mode; 294 __entry->isolate_mode = isolate_mode;
295 __entry->file = file;
293 ), 296 ),
294 297
295 TP_printk("isolate_mode=%d order=%d nr_requested=%lu nr_scanned=%lu nr_taken=%lu contig_taken=%lu contig_dirty=%lu contig_failed=%lu", 298 TP_printk("isolate_mode=%d order=%d nr_requested=%lu nr_scanned=%lu nr_taken=%lu contig_taken=%lu contig_dirty=%lu contig_failed=%lu file=%d",
296 __entry->isolate_mode, 299 __entry->isolate_mode,
297 __entry->order, 300 __entry->order,
298 __entry->nr_requested, 301 __entry->nr_requested,
@@ -300,7 +303,8 @@ DECLARE_EVENT_CLASS(mm_vmscan_lru_isolate_template,
300 __entry->nr_taken, 303 __entry->nr_taken,
301 __entry->nr_lumpy_taken, 304 __entry->nr_lumpy_taken,
302 __entry->nr_lumpy_dirty, 305 __entry->nr_lumpy_dirty,
303 __entry->nr_lumpy_failed) 306 __entry->nr_lumpy_failed,
307 __entry->file)
304); 308);
305 309
306DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_lru_isolate, 310DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_lru_isolate,
@@ -312,9 +316,10 @@ DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_lru_isolate,
312 unsigned long nr_lumpy_taken, 316 unsigned long nr_lumpy_taken,
313 unsigned long nr_lumpy_dirty, 317 unsigned long nr_lumpy_dirty,
314 unsigned long nr_lumpy_failed, 318 unsigned long nr_lumpy_failed,
315 isolate_mode_t isolate_mode), 319 isolate_mode_t isolate_mode,
320 int file),
316 321
317 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode) 322 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode, file)
318 323
319); 324);
320 325
@@ -327,9 +332,10 @@ DEFINE_EVENT(mm_vmscan_lru_isolate_template, mm_vmscan_memcg_isolate,
327 unsigned long nr_lumpy_taken, 332 unsigned long nr_lumpy_taken,
328 unsigned long nr_lumpy_dirty, 333 unsigned long nr_lumpy_dirty,
329 unsigned long nr_lumpy_failed, 334 unsigned long nr_lumpy_failed,
330 isolate_mode_t isolate_mode), 335 isolate_mode_t isolate_mode,
336 int file),
331 337
332 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode) 338 TP_ARGS(order, nr_requested, nr_scanned, nr_taken, nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, isolate_mode, file)
333 339
334); 340);
335 341
diff --git a/init/Kconfig b/init/Kconfig
index 018d206c21f7..6ac2236244c3 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -783,6 +783,17 @@ config DEBUG_BLK_CGROUP
783 783
784endif # CGROUPS 784endif # CGROUPS
785 785
786config CHECKPOINT_RESTORE
787 bool "Checkpoint/restore support" if EXPERT
788 default n
789 help
790 Enables additional kernel features in a sake of checkpoint/restore.
791 In particular it adds auxiliary prctl codes to setup process text,
792 data and heap segment sizes, and a few additional /proc filesystem
793 entries.
794
795 If unsure, say N here.
796
786menuconfig NAMESPACES 797menuconfig NAMESPACES
787 bool "Namespaces support" if EXPERT 798 bool "Namespaces support" if EXPERT
788 default !EXPERT 799 default !EXPERT
diff --git a/kernel/exit.c b/kernel/exit.c
index 94ed6e20bb53..c44738267be7 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -887,7 +887,7 @@ static void check_stack_usage(void)
887static inline void check_stack_usage(void) {} 887static inline void check_stack_usage(void) {}
888#endif 888#endif
889 889
890NORET_TYPE void do_exit(long code) 890void do_exit(long code)
891{ 891{
892 struct task_struct *tsk = current; 892 struct task_struct *tsk = current;
893 int group_dead; 893 int group_dead;
@@ -1051,7 +1051,7 @@ NORET_TYPE void do_exit(long code)
1051 1051
1052EXPORT_SYMBOL_GPL(do_exit); 1052EXPORT_SYMBOL_GPL(do_exit);
1053 1053
1054NORET_TYPE void complete_and_exit(struct completion *comp, long code) 1054void complete_and_exit(struct completion *comp, long code)
1055{ 1055{
1056 if (comp) 1056 if (comp)
1057 complete(comp); 1057 complete(comp);
@@ -1070,7 +1070,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
1070 * Take down every thread in the group. This is called by fatal signals 1070 * Take down every thread in the group. This is called by fatal signals
1071 * as well as by sys_exit_group (below). 1071 * as well as by sys_exit_group (below).
1072 */ 1072 */
1073NORET_TYPE void 1073void
1074do_group_exit(int exit_code) 1074do_group_exit(int exit_code)
1075{ 1075{
1076 struct signal_struct *sig = current->signal; 1076 struct signal_struct *sig = current->signal;
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 090ee10d9604..7b0886786701 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -32,7 +32,6 @@
32#include <linux/console.h> 32#include <linux/console.h>
33#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
34#include <linux/swap.h> 34#include <linux/swap.h>
35#include <linux/kmsg_dump.h>
36#include <linux/syscore_ops.h> 35#include <linux/syscore_ops.h>
37 36
38#include <asm/page.h> 37#include <asm/page.h>
@@ -1094,8 +1093,6 @@ void crash_kexec(struct pt_regs *regs)
1094 if (kexec_crash_image) { 1093 if (kexec_crash_image) {
1095 struct pt_regs fixed_regs; 1094 struct pt_regs fixed_regs;
1096 1095
1097 kmsg_dump(KMSG_DUMP_KEXEC);
1098
1099 crash_setup_regs(&fixed_regs, regs); 1096 crash_setup_regs(&fixed_regs, regs);
1100 crash_save_vmcoreinfo(); 1097 crash_save_vmcoreinfo();
1101 machine_crash_shutdown(&fixed_regs); 1098 machine_crash_shutdown(&fixed_regs);
@@ -1132,6 +1129,8 @@ int crash_shrink_memory(unsigned long new_size)
1132{ 1129{
1133 int ret = 0; 1130 int ret = 0;
1134 unsigned long start, end; 1131 unsigned long start, end;
1132 unsigned long old_size;
1133 struct resource *ram_res;
1135 1134
1136 mutex_lock(&kexec_mutex); 1135 mutex_lock(&kexec_mutex);
1137 1136
@@ -1141,11 +1140,15 @@ int crash_shrink_memory(unsigned long new_size)
1141 } 1140 }
1142 start = crashk_res.start; 1141 start = crashk_res.start;
1143 end = crashk_res.end; 1142 end = crashk_res.end;
1143 old_size = (end == 0) ? 0 : end - start + 1;
1144 if (new_size >= old_size) {
1145 ret = (new_size == old_size) ? 0 : -EINVAL;
1146 goto unlock;
1147 }
1144 1148
1145 if (new_size >= end - start + 1) { 1149 ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL);
1146 ret = -EINVAL; 1150 if (!ram_res) {
1147 if (new_size == end - start + 1) 1151 ret = -ENOMEM;
1148 ret = 0;
1149 goto unlock; 1152 goto unlock;
1150 } 1153 }
1151 1154
@@ -1157,7 +1160,15 @@ int crash_shrink_memory(unsigned long new_size)
1157 1160
1158 if ((start == end) && (crashk_res.parent != NULL)) 1161 if ((start == end) && (crashk_res.parent != NULL))
1159 release_resource(&crashk_res); 1162 release_resource(&crashk_res);
1163
1164 ram_res->start = end;
1165 ram_res->end = crashk_res.end;
1166 ram_res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
1167 ram_res->name = "System RAM";
1168
1160 crashk_res.end = end - 1; 1169 crashk_res.end = end - 1;
1170
1171 insert_resource(&iomem_resource, ram_res);
1161 crash_unmap_reserved_pages(); 1172 crash_unmap_reserved_pages();
1162 1173
1163unlock: 1174unlock:
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index e5d84644823b..95dd7212e610 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2198,7 +2198,7 @@ static ssize_t write_enabled_file_bool(struct file *file,
2198 const char __user *user_buf, size_t count, loff_t *ppos) 2198 const char __user *user_buf, size_t count, loff_t *ppos)
2199{ 2199{
2200 char buf[32]; 2200 char buf[32];
2201 int buf_size; 2201 size_t buf_size;
2202 2202
2203 buf_size = min(count, (sizeof(buf)-1)); 2203 buf_size = min(count, (sizeof(buf)-1));
2204 if (copy_from_user(buf, user_buf, buf_size)) 2204 if (copy_from_user(buf, user_buf, buf_size))
diff --git a/kernel/panic.c b/kernel/panic.c
index 3458469eb7c3..80aed44e345a 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -49,6 +49,15 @@ static long no_blink(int state)
49long (*panic_blink)(int state); 49long (*panic_blink)(int state);
50EXPORT_SYMBOL(panic_blink); 50EXPORT_SYMBOL(panic_blink);
51 51
52/*
53 * Stop ourself in panic -- architecture code may override this
54 */
55void __weak panic_smp_self_stop(void)
56{
57 while (1)
58 cpu_relax();
59}
60
52/** 61/**
53 * panic - halt the system 62 * panic - halt the system
54 * @fmt: The text string to print 63 * @fmt: The text string to print
@@ -57,8 +66,9 @@ EXPORT_SYMBOL(panic_blink);
57 * 66 *
58 * This function never returns. 67 * This function never returns.
59 */ 68 */
60NORET_TYPE void panic(const char * fmt, ...) 69void panic(const char *fmt, ...)
61{ 70{
71 static DEFINE_SPINLOCK(panic_lock);
62 static char buf[1024]; 72 static char buf[1024];
63 va_list args; 73 va_list args;
64 long i, i_next = 0; 74 long i, i_next = 0;
@@ -68,8 +78,14 @@ NORET_TYPE void panic(const char * fmt, ...)
68 * It's possible to come here directly from a panic-assertion and 78 * It's possible to come here directly from a panic-assertion and
69 * not have preempt disabled. Some functions called from here want 79 * not have preempt disabled. Some functions called from here want
70 * preempt to be disabled. No point enabling it later though... 80 * preempt to be disabled. No point enabling it later though...
81 *
82 * Only one CPU is allowed to execute the panic code from here. For
83 * multiple parallel invocations of panic, all other CPUs either
84 * stop themself or will wait until they are stopped by the 1st CPU
85 * with smp_send_stop().
71 */ 86 */
72 preempt_disable(); 87 if (!spin_trylock(&panic_lock))
88 panic_smp_self_stop();
73 89
74 console_verbose(); 90 console_verbose();
75 bust_spinlocks(1); 91 bust_spinlocks(1);
@@ -78,7 +94,11 @@ NORET_TYPE void panic(const char * fmt, ...)
78 va_end(args); 94 va_end(args);
79 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf); 95 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
80#ifdef CONFIG_DEBUG_BUGVERBOSE 96#ifdef CONFIG_DEBUG_BUGVERBOSE
81 dump_stack(); 97 /*
98 * Avoid nested stack-dumping if a panic occurs during oops processing
99 */
100 if (!oops_in_progress)
101 dump_stack();
82#endif 102#endif
83 103
84 /* 104 /*
diff --git a/kernel/pid.c b/kernel/pid.c
index fa5f72227e5f..ce8e00deaccb 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -137,7 +137,9 @@ static int pid_before(int base, int a, int b)
137} 137}
138 138
139/* 139/*
140 * We might be racing with someone else trying to set pid_ns->last_pid. 140 * We might be racing with someone else trying to set pid_ns->last_pid
141 * at the pid allocation time (there's also a sysctl for this, but racing
142 * with this one is OK, see comment in kernel/pid_namespace.c about it).
141 * We want the winner to have the "later" value, because if the 143 * We want the winner to have the "later" value, because if the
142 * "earlier" value prevails, then a pid may get reused immediately. 144 * "earlier" value prevails, then a pid may get reused immediately.
143 * 145 *
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index e9c9adc84ca6..a8968396046d 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -191,9 +191,40 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
191 return; 191 return;
192} 192}
193 193
194static int pid_ns_ctl_handler(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos)
196{
197 struct ctl_table tmp = *table;
198
199 if (write && !capable(CAP_SYS_ADMIN))
200 return -EPERM;
201
202 /*
203 * Writing directly to ns' last_pid field is OK, since this field
204 * is volatile in a living namespace anyway and a code writing to
205 * it should synchronize its usage with external means.
206 */
207
208 tmp.data = &current->nsproxy->pid_ns->last_pid;
209 return proc_dointvec(&tmp, write, buffer, lenp, ppos);
210}
211
212static struct ctl_table pid_ns_ctl_table[] = {
213 {
214 .procname = "ns_last_pid",
215 .maxlen = sizeof(int),
216 .mode = 0666, /* permissions are checked in the handler */
217 .proc_handler = pid_ns_ctl_handler,
218 },
219 { }
220};
221
222static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } };
223
194static __init int pid_namespaces_init(void) 224static __init int pid_namespaces_init(void)
195{ 225{
196 pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC); 226 pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
227 register_sysctl_paths(kern_path, pid_ns_ctl_table);
197 return 0; 228 return 0;
198} 229}
199 230
diff --git a/kernel/sys.c b/kernel/sys.c
index ddf8155bf3f8..40701538fbd1 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1692,6 +1692,124 @@ SYSCALL_DEFINE1(umask, int, mask)
1692 return mask; 1692 return mask;
1693} 1693}
1694 1694
1695#ifdef CONFIG_CHECKPOINT_RESTORE
1696static int prctl_set_mm(int opt, unsigned long addr,
1697 unsigned long arg4, unsigned long arg5)
1698{
1699 unsigned long rlim = rlimit(RLIMIT_DATA);
1700 unsigned long vm_req_flags;
1701 unsigned long vm_bad_flags;
1702 struct vm_area_struct *vma;
1703 int error = 0;
1704 struct mm_struct *mm = current->mm;
1705
1706 if (arg4 | arg5)
1707 return -EINVAL;
1708
1709 if (!capable(CAP_SYS_ADMIN))
1710 return -EPERM;
1711
1712 if (addr >= TASK_SIZE)
1713 return -EINVAL;
1714
1715 down_read(&mm->mmap_sem);
1716 vma = find_vma(mm, addr);
1717
1718 if (opt != PR_SET_MM_START_BRK && opt != PR_SET_MM_BRK) {
1719 /* It must be existing VMA */
1720 if (!vma || vma->vm_start > addr)
1721 goto out;
1722 }
1723
1724 error = -EINVAL;
1725 switch (opt) {
1726 case PR_SET_MM_START_CODE:
1727 case PR_SET_MM_END_CODE:
1728 vm_req_flags = VM_READ | VM_EXEC;
1729 vm_bad_flags = VM_WRITE | VM_MAYSHARE;
1730
1731 if ((vma->vm_flags & vm_req_flags) != vm_req_flags ||
1732 (vma->vm_flags & vm_bad_flags))
1733 goto out;
1734
1735 if (opt == PR_SET_MM_START_CODE)
1736 mm->start_code = addr;
1737 else
1738 mm->end_code = addr;
1739 break;
1740
1741 case PR_SET_MM_START_DATA:
1742 case PR_SET_MM_END_DATA:
1743 vm_req_flags = VM_READ | VM_WRITE;
1744 vm_bad_flags = VM_EXEC | VM_MAYSHARE;
1745
1746 if ((vma->vm_flags & vm_req_flags) != vm_req_flags ||
1747 (vma->vm_flags & vm_bad_flags))
1748 goto out;
1749
1750 if (opt == PR_SET_MM_START_DATA)
1751 mm->start_data = addr;
1752 else
1753 mm->end_data = addr;
1754 break;
1755
1756 case PR_SET_MM_START_STACK:
1757
1758#ifdef CONFIG_STACK_GROWSUP
1759 vm_req_flags = VM_READ | VM_WRITE | VM_GROWSUP;
1760#else
1761 vm_req_flags = VM_READ | VM_WRITE | VM_GROWSDOWN;
1762#endif
1763 if ((vma->vm_flags & vm_req_flags) != vm_req_flags)
1764 goto out;
1765
1766 mm->start_stack = addr;
1767 break;
1768
1769 case PR_SET_MM_START_BRK:
1770 if (addr <= mm->end_data)
1771 goto out;
1772
1773 if (rlim < RLIM_INFINITY &&
1774 (mm->brk - addr) +
1775 (mm->end_data - mm->start_data) > rlim)
1776 goto out;
1777
1778 mm->start_brk = addr;
1779 break;
1780
1781 case PR_SET_MM_BRK:
1782 if (addr <= mm->end_data)
1783 goto out;
1784
1785 if (rlim < RLIM_INFINITY &&
1786 (addr - mm->start_brk) +
1787 (mm->end_data - mm->start_data) > rlim)
1788 goto out;
1789
1790 mm->brk = addr;
1791 break;
1792
1793 default:
1794 error = -EINVAL;
1795 goto out;
1796 }
1797
1798 error = 0;
1799
1800out:
1801 up_read(&mm->mmap_sem);
1802
1803 return error;
1804}
1805#else /* CONFIG_CHECKPOINT_RESTORE */
1806static int prctl_set_mm(int opt, unsigned long addr,
1807 unsigned long arg4, unsigned long arg5)
1808{
1809 return -EINVAL;
1810}
1811#endif
1812
1695SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, 1813SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
1696 unsigned long, arg4, unsigned long, arg5) 1814 unsigned long, arg4, unsigned long, arg5)
1697{ 1815{
@@ -1841,6 +1959,9 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
1841 else 1959 else
1842 error = PR_MCE_KILL_DEFAULT; 1960 error = PR_MCE_KILL_DEFAULT;
1843 break; 1961 break;
1962 case PR_SET_MM:
1963 error = prctl_set_mm(arg2, arg3, arg4, arg5);
1964 break;
1844 default: 1965 default:
1845 error = -EINVAL; 1966 error = -EINVAL;
1846 break; 1967 break;
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c
index 5a7a2adf4c4c..4531294fa62f 100644
--- a/lib/decompress_unlzo.c
+++ b/lib/decompress_unlzo.c
@@ -279,7 +279,7 @@ STATIC inline int INIT unlzo(u8 *input, int in_len,
279 ret = 0; 279 ret = 0;
280exit_2: 280exit_2:
281 if (!input) 281 if (!input)
282 free(in_buf); 282 free(in_buf_save);
283exit_1: 283exit_1:
284 if (!output) 284 if (!output)
285 free(out_buf); 285 free(out_buf);
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index d9df7454519c..dc63d0818394 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -48,16 +48,14 @@
48struct radix_tree_node { 48struct radix_tree_node {
49 unsigned int height; /* Height from the bottom */ 49 unsigned int height; /* Height from the bottom */
50 unsigned int count; 50 unsigned int count;
51 struct rcu_head rcu_head; 51 union {
52 struct radix_tree_node *parent; /* Used when ascending tree */
53 struct rcu_head rcu_head; /* Used when freeing node */
54 };
52 void __rcu *slots[RADIX_TREE_MAP_SIZE]; 55 void __rcu *slots[RADIX_TREE_MAP_SIZE];
53 unsigned long tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS]; 56 unsigned long tags[RADIX_TREE_MAX_TAGS][RADIX_TREE_TAG_LONGS];
54}; 57};
55 58
56struct radix_tree_path {
57 struct radix_tree_node *node;
58 int offset;
59};
60
61#define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long)) 59#define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
62#define RADIX_TREE_MAX_PATH (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \ 60#define RADIX_TREE_MAX_PATH (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \
63 RADIX_TREE_MAP_SHIFT)) 61 RADIX_TREE_MAP_SHIFT))
@@ -256,6 +254,7 @@ static inline unsigned long radix_tree_maxindex(unsigned int height)
256static int radix_tree_extend(struct radix_tree_root *root, unsigned long index) 254static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
257{ 255{
258 struct radix_tree_node *node; 256 struct radix_tree_node *node;
257 struct radix_tree_node *slot;
259 unsigned int height; 258 unsigned int height;
260 int tag; 259 int tag;
261 260
@@ -274,18 +273,23 @@ static int radix_tree_extend(struct radix_tree_root *root, unsigned long index)
274 if (!(node = radix_tree_node_alloc(root))) 273 if (!(node = radix_tree_node_alloc(root)))
275 return -ENOMEM; 274 return -ENOMEM;
276 275
277 /* Increase the height. */
278 node->slots[0] = indirect_to_ptr(root->rnode);
279
280 /* Propagate the aggregated tag info into the new root */ 276 /* Propagate the aggregated tag info into the new root */
281 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) { 277 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) {
282 if (root_tag_get(root, tag)) 278 if (root_tag_get(root, tag))
283 tag_set(node, tag, 0); 279 tag_set(node, tag, 0);
284 } 280 }
285 281
282 /* Increase the height. */
286 newheight = root->height+1; 283 newheight = root->height+1;
287 node->height = newheight; 284 node->height = newheight;
288 node->count = 1; 285 node->count = 1;
286 node->parent = NULL;
287 slot = root->rnode;
288 if (newheight > 1) {
289 slot = indirect_to_ptr(slot);
290 slot->parent = node;
291 }
292 node->slots[0] = slot;
289 node = ptr_to_indirect(node); 293 node = ptr_to_indirect(node);
290 rcu_assign_pointer(root->rnode, node); 294 rcu_assign_pointer(root->rnode, node);
291 root->height = newheight; 295 root->height = newheight;
@@ -331,6 +335,7 @@ int radix_tree_insert(struct radix_tree_root *root,
331 if (!(slot = radix_tree_node_alloc(root))) 335 if (!(slot = radix_tree_node_alloc(root)))
332 return -ENOMEM; 336 return -ENOMEM;
333 slot->height = height; 337 slot->height = height;
338 slot->parent = node;
334 if (node) { 339 if (node) {
335 rcu_assign_pointer(node->slots[offset], slot); 340 rcu_assign_pointer(node->slots[offset], slot);
336 node->count++; 341 node->count++;
@@ -504,47 +509,41 @@ EXPORT_SYMBOL(radix_tree_tag_set);
504void *radix_tree_tag_clear(struct radix_tree_root *root, 509void *radix_tree_tag_clear(struct radix_tree_root *root,
505 unsigned long index, unsigned int tag) 510 unsigned long index, unsigned int tag)
506{ 511{
507 /* 512 struct radix_tree_node *node = NULL;
508 * The radix tree path needs to be one longer than the maximum path
509 * since the "list" is null terminated.
510 */
511 struct radix_tree_path path[RADIX_TREE_MAX_PATH + 1], *pathp = path;
512 struct radix_tree_node *slot = NULL; 513 struct radix_tree_node *slot = NULL;
513 unsigned int height, shift; 514 unsigned int height, shift;
515 int uninitialized_var(offset);
514 516
515 height = root->height; 517 height = root->height;
516 if (index > radix_tree_maxindex(height)) 518 if (index > radix_tree_maxindex(height))
517 goto out; 519 goto out;
518 520
519 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 521 shift = height * RADIX_TREE_MAP_SHIFT;
520 pathp->node = NULL;
521 slot = indirect_to_ptr(root->rnode); 522 slot = indirect_to_ptr(root->rnode);
522 523
523 while (height > 0) { 524 while (shift) {
524 int offset;
525
526 if (slot == NULL) 525 if (slot == NULL)
527 goto out; 526 goto out;
528 527
528 shift -= RADIX_TREE_MAP_SHIFT;
529 offset = (index >> shift) & RADIX_TREE_MAP_MASK; 529 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
530 pathp[1].offset = offset; 530 node = slot;
531 pathp[1].node = slot;
532 slot = slot->slots[offset]; 531 slot = slot->slots[offset];
533 pathp++;
534 shift -= RADIX_TREE_MAP_SHIFT;
535 height--;
536 } 532 }
537 533
538 if (slot == NULL) 534 if (slot == NULL)
539 goto out; 535 goto out;
540 536
541 while (pathp->node) { 537 while (node) {
542 if (!tag_get(pathp->node, tag, pathp->offset)) 538 if (!tag_get(node, tag, offset))
543 goto out; 539 goto out;
544 tag_clear(pathp->node, tag, pathp->offset); 540 tag_clear(node, tag, offset);
545 if (any_tag_set(pathp->node, tag)) 541 if (any_tag_set(node, tag))
546 goto out; 542 goto out;
547 pathp--; 543
544 index >>= RADIX_TREE_MAP_SHIFT;
545 offset = index & RADIX_TREE_MAP_MASK;
546 node = node->parent;
548 } 547 }
549 548
550 /* clear the root's tag bit */ 549 /* clear the root's tag bit */
@@ -646,8 +645,7 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
646 unsigned int iftag, unsigned int settag) 645 unsigned int iftag, unsigned int settag)
647{ 646{
648 unsigned int height = root->height; 647 unsigned int height = root->height;
649 struct radix_tree_path path[height]; 648 struct radix_tree_node *node = NULL;
650 struct radix_tree_path *pathp = path;
651 struct radix_tree_node *slot; 649 struct radix_tree_node *slot;
652 unsigned int shift; 650 unsigned int shift;
653 unsigned long tagged = 0; 651 unsigned long tagged = 0;
@@ -671,14 +669,8 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
671 shift = (height - 1) * RADIX_TREE_MAP_SHIFT; 669 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
672 slot = indirect_to_ptr(root->rnode); 670 slot = indirect_to_ptr(root->rnode);
673 671
674 /*
675 * we fill the path from (root->height - 2) to 0, leaving the index at
676 * (root->height - 1) as a terminator. Zero the node in the terminator
677 * so that we can use this to end walk loops back up the path.
678 */
679 path[height - 1].node = NULL;
680
681 for (;;) { 672 for (;;) {
673 unsigned long upindex;
682 int offset; 674 int offset;
683 675
684 offset = (index >> shift) & RADIX_TREE_MAP_MASK; 676 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
@@ -686,12 +678,10 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
686 goto next; 678 goto next;
687 if (!tag_get(slot, iftag, offset)) 679 if (!tag_get(slot, iftag, offset))
688 goto next; 680 goto next;
689 if (height > 1) { 681 if (shift) {
690 /* Go down one level */ 682 /* Go down one level */
691 height--;
692 shift -= RADIX_TREE_MAP_SHIFT; 683 shift -= RADIX_TREE_MAP_SHIFT;
693 path[height - 1].node = slot; 684 node = slot;
694 path[height - 1].offset = offset;
695 slot = slot->slots[offset]; 685 slot = slot->slots[offset];
696 continue; 686 continue;
697 } 687 }
@@ -701,15 +691,27 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
701 tag_set(slot, settag, offset); 691 tag_set(slot, settag, offset);
702 692
703 /* walk back up the path tagging interior nodes */ 693 /* walk back up the path tagging interior nodes */
704 pathp = &path[0]; 694 upindex = index;
705 while (pathp->node) { 695 while (node) {
696 upindex >>= RADIX_TREE_MAP_SHIFT;
697 offset = upindex & RADIX_TREE_MAP_MASK;
698
706 /* stop if we find a node with the tag already set */ 699 /* stop if we find a node with the tag already set */
707 if (tag_get(pathp->node, settag, pathp->offset)) 700 if (tag_get(node, settag, offset))
708 break; 701 break;
709 tag_set(pathp->node, settag, pathp->offset); 702 tag_set(node, settag, offset);
710 pathp++; 703 node = node->parent;
711 } 704 }
712 705
706 /*
707 * Small optimization: now clear that node pointer.
708 * Since all of this slot's ancestors now have the tag set
709 * from setting it above, we have no further need to walk
710 * back up the tree setting tags, until we update slot to
711 * point to another radix_tree_node.
712 */
713 node = NULL;
714
713next: 715next:
714 /* Go to next item at level determined by 'shift' */ 716 /* Go to next item at level determined by 'shift' */
715 index = ((index >> shift) + 1) << shift; 717 index = ((index >> shift) + 1) << shift;
@@ -724,8 +726,7 @@ next:
724 * last_index is guaranteed to be in the tree, what 726 * last_index is guaranteed to be in the tree, what
725 * we do below cannot wander astray. 727 * we do below cannot wander astray.
726 */ 728 */
727 slot = path[height - 1].node; 729 slot = slot->parent;
728 height++;
729 shift += RADIX_TREE_MAP_SHIFT; 730 shift += RADIX_TREE_MAP_SHIFT;
730 } 731 }
731 } 732 }
@@ -1299,7 +1300,7 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1299 /* try to shrink tree height */ 1300 /* try to shrink tree height */
1300 while (root->height > 0) { 1301 while (root->height > 0) {
1301 struct radix_tree_node *to_free = root->rnode; 1302 struct radix_tree_node *to_free = root->rnode;
1302 void *newptr; 1303 struct radix_tree_node *slot;
1303 1304
1304 BUG_ON(!radix_tree_is_indirect_ptr(to_free)); 1305 BUG_ON(!radix_tree_is_indirect_ptr(to_free));
1305 to_free = indirect_to_ptr(to_free); 1306 to_free = indirect_to_ptr(to_free);
@@ -1320,10 +1321,12 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1320 * (to_free->slots[0]), it will be safe to dereference the new 1321 * (to_free->slots[0]), it will be safe to dereference the new
1321 * one (root->rnode) as far as dependent read barriers go. 1322 * one (root->rnode) as far as dependent read barriers go.
1322 */ 1323 */
1323 newptr = to_free->slots[0]; 1324 slot = to_free->slots[0];
1324 if (root->height > 1) 1325 if (root->height > 1) {
1325 newptr = ptr_to_indirect(newptr); 1326 slot->parent = NULL;
1326 root->rnode = newptr; 1327 slot = ptr_to_indirect(slot);
1328 }
1329 root->rnode = slot;
1327 root->height--; 1330 root->height--;
1328 1331
1329 /* 1332 /*
@@ -1363,16 +1366,12 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
1363 */ 1366 */
1364void *radix_tree_delete(struct radix_tree_root *root, unsigned long index) 1367void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1365{ 1368{
1366 /* 1369 struct radix_tree_node *node = NULL;
1367 * The radix tree path needs to be one longer than the maximum path
1368 * since the "list" is null terminated.
1369 */
1370 struct radix_tree_path path[RADIX_TREE_MAX_PATH + 1], *pathp = path;
1371 struct radix_tree_node *slot = NULL; 1370 struct radix_tree_node *slot = NULL;
1372 struct radix_tree_node *to_free; 1371 struct radix_tree_node *to_free;
1373 unsigned int height, shift; 1372 unsigned int height, shift;
1374 int tag; 1373 int tag;
1375 int offset; 1374 int uninitialized_var(offset);
1376 1375
1377 height = root->height; 1376 height = root->height;
1378 if (index > radix_tree_maxindex(height)) 1377 if (index > radix_tree_maxindex(height))
@@ -1385,39 +1384,35 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1385 goto out; 1384 goto out;
1386 } 1385 }
1387 slot = indirect_to_ptr(slot); 1386 slot = indirect_to_ptr(slot);
1388 1387 shift = height * RADIX_TREE_MAP_SHIFT;
1389 shift = (height - 1) * RADIX_TREE_MAP_SHIFT;
1390 pathp->node = NULL;
1391 1388
1392 do { 1389 do {
1393 if (slot == NULL) 1390 if (slot == NULL)
1394 goto out; 1391 goto out;
1395 1392
1396 pathp++; 1393 shift -= RADIX_TREE_MAP_SHIFT;
1397 offset = (index >> shift) & RADIX_TREE_MAP_MASK; 1394 offset = (index >> shift) & RADIX_TREE_MAP_MASK;
1398 pathp->offset = offset; 1395 node = slot;
1399 pathp->node = slot;
1400 slot = slot->slots[offset]; 1396 slot = slot->slots[offset];
1401 shift -= RADIX_TREE_MAP_SHIFT; 1397 } while (shift);
1402 height--;
1403 } while (height > 0);
1404 1398
1405 if (slot == NULL) 1399 if (slot == NULL)
1406 goto out; 1400 goto out;
1407 1401
1408 /* 1402 /*
1409 * Clear all tags associated with the just-deleted item 1403 * Clear all tags associated with the item to be deleted.
1404 * This way of doing it would be inefficient, but seldom is any set.
1410 */ 1405 */
1411 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) { 1406 for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++) {
1412 if (tag_get(pathp->node, tag, pathp->offset)) 1407 if (tag_get(node, tag, offset))
1413 radix_tree_tag_clear(root, index, tag); 1408 radix_tree_tag_clear(root, index, tag);
1414 } 1409 }
1415 1410
1416 to_free = NULL; 1411 to_free = NULL;
1417 /* Now free the nodes we do not need anymore */ 1412 /* Now free the nodes we do not need anymore */
1418 while (pathp->node) { 1413 while (node) {
1419 pathp->node->slots[pathp->offset] = NULL; 1414 node->slots[offset] = NULL;
1420 pathp->node->count--; 1415 node->count--;
1421 /* 1416 /*
1422 * Queue the node for deferred freeing after the 1417 * Queue the node for deferred freeing after the
1423 * last reference to it disappears (set NULL, above). 1418 * last reference to it disappears (set NULL, above).
@@ -1425,17 +1420,20 @@ void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
1425 if (to_free) 1420 if (to_free)
1426 radix_tree_node_free(to_free); 1421 radix_tree_node_free(to_free);
1427 1422
1428 if (pathp->node->count) { 1423 if (node->count) {
1429 if (pathp->node == indirect_to_ptr(root->rnode)) 1424 if (node == indirect_to_ptr(root->rnode))
1430 radix_tree_shrink(root); 1425 radix_tree_shrink(root);
1431 goto out; 1426 goto out;
1432 } 1427 }
1433 1428
1434 /* Node with zero slots in use so free it */ 1429 /* Node with zero slots in use so free it */
1435 to_free = pathp->node; 1430 to_free = node;
1436 pathp--;
1437 1431
1432 index >>= RADIX_TREE_MAP_SHIFT;
1433 offset = index & RADIX_TREE_MAP_MASK;
1434 node = node->parent;
1438 } 1435 }
1436
1439 root_tag_clear_all(root); 1437 root_tag_clear_all(root);
1440 root->height = 0; 1438 root->height = 0;
1441 root->rnode = NULL; 1439 root->rnode = NULL;
diff --git a/mm/compaction.c b/mm/compaction.c
index e6670c34eb49..71a58f67f481 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -350,7 +350,7 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone,
350 } 350 }
351 351
352 if (!cc->sync) 352 if (!cc->sync)
353 mode |= ISOLATE_CLEAN; 353 mode |= ISOLATE_ASYNC_MIGRATE;
354 354
355 /* Try isolate the page */ 355 /* Try isolate the page */
356 if (__isolate_lru_page(page, mode, 0) != 0) 356 if (__isolate_lru_page(page, mode, 0) != 0)
@@ -557,7 +557,7 @@ static int compact_zone(struct zone *zone, struct compact_control *cc)
557 nr_migrate = cc->nr_migratepages; 557 nr_migrate = cc->nr_migratepages;
558 err = migrate_pages(&cc->migratepages, compaction_alloc, 558 err = migrate_pages(&cc->migratepages, compaction_alloc,
559 (unsigned long)cc, false, 559 (unsigned long)cc, false,
560 cc->sync); 560 cc->sync ? MIGRATE_SYNC_LIGHT : MIGRATE_ASYNC);
561 update_nr_listpages(cc); 561 update_nr_listpages(cc);
562 nr_remaining = cc->nr_migratepages; 562 nr_remaining = cc->nr_migratepages;
563 563
@@ -671,6 +671,7 @@ static int compact_node(int nid)
671 .nr_freepages = 0, 671 .nr_freepages = 0,
672 .nr_migratepages = 0, 672 .nr_migratepages = 0,
673 .order = -1, 673 .order = -1,
674 .sync = true,
674 }; 675 };
675 676
676 zone = &pgdat->node_zones[zoneid]; 677 zone = &pgdat->node_zones[zoneid];
diff --git a/mm/filemap.c b/mm/filemap.c
index c4ee2e918bea..97f49ed35bd2 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -393,24 +393,11 @@ EXPORT_SYMBOL(filemap_write_and_wait_range);
393int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask) 393int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
394{ 394{
395 int error; 395 int error;
396 struct mem_cgroup *memcg = NULL;
397 396
398 VM_BUG_ON(!PageLocked(old)); 397 VM_BUG_ON(!PageLocked(old));
399 VM_BUG_ON(!PageLocked(new)); 398 VM_BUG_ON(!PageLocked(new));
400 VM_BUG_ON(new->mapping); 399 VM_BUG_ON(new->mapping);
401 400
402 /*
403 * This is not page migration, but prepare_migration and
404 * end_migration does enough work for charge replacement.
405 *
406 * In the longer term we probably want a specialized function
407 * for moving the charge from old to new in a more efficient
408 * manner.
409 */
410 error = mem_cgroup_prepare_migration(old, new, &memcg, gfp_mask);
411 if (error)
412 return error;
413
414 error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM); 401 error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM);
415 if (!error) { 402 if (!error) {
416 struct address_space *mapping = old->mapping; 403 struct address_space *mapping = old->mapping;
@@ -432,13 +419,12 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
432 if (PageSwapBacked(new)) 419 if (PageSwapBacked(new))
433 __inc_zone_page_state(new, NR_SHMEM); 420 __inc_zone_page_state(new, NR_SHMEM);
434 spin_unlock_irq(&mapping->tree_lock); 421 spin_unlock_irq(&mapping->tree_lock);
422 /* mem_cgroup codes must not be called under tree_lock */
423 mem_cgroup_replace_page_cache(old, new);
435 radix_tree_preload_end(); 424 radix_tree_preload_end();
436 if (freepage) 425 if (freepage)
437 freepage(old); 426 freepage(old);
438 page_cache_release(old); 427 page_cache_release(old);
439 mem_cgroup_end_migration(memcg, old, new, true);
440 } else {
441 mem_cgroup_end_migration(memcg, old, new, false);
442 } 428 }
443 429
444 return error; 430 return error;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 36b3d988b4ef..b3ffc21ce801 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -487,41 +487,68 @@ static struct attribute_group khugepaged_attr_group = {
487 .attrs = khugepaged_attr, 487 .attrs = khugepaged_attr,
488 .name = "khugepaged", 488 .name = "khugepaged",
489}; 489};
490#endif /* CONFIG_SYSFS */
491 490
492static int __init hugepage_init(void) 491static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj)
493{ 492{
494 int err; 493 int err;
495#ifdef CONFIG_SYSFS
496 static struct kobject *hugepage_kobj;
497#endif
498
499 err = -EINVAL;
500 if (!has_transparent_hugepage()) {
501 transparent_hugepage_flags = 0;
502 goto out;
503 }
504 494
505#ifdef CONFIG_SYSFS 495 *hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj);
506 err = -ENOMEM; 496 if (unlikely(!*hugepage_kobj)) {
507 hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj);
508 if (unlikely(!hugepage_kobj)) {
509 printk(KERN_ERR "hugepage: failed kobject create\n"); 497 printk(KERN_ERR "hugepage: failed kobject create\n");
510 goto out; 498 return -ENOMEM;
511 } 499 }
512 500
513 err = sysfs_create_group(hugepage_kobj, &hugepage_attr_group); 501 err = sysfs_create_group(*hugepage_kobj, &hugepage_attr_group);
514 if (err) { 502 if (err) {
515 printk(KERN_ERR "hugepage: failed register hugeage group\n"); 503 printk(KERN_ERR "hugepage: failed register hugeage group\n");
516 goto out; 504 goto delete_obj;
517 } 505 }
518 506
519 err = sysfs_create_group(hugepage_kobj, &khugepaged_attr_group); 507 err = sysfs_create_group(*hugepage_kobj, &khugepaged_attr_group);
520 if (err) { 508 if (err) {
521 printk(KERN_ERR "hugepage: failed register hugeage group\n"); 509 printk(KERN_ERR "hugepage: failed register hugeage group\n");
522 goto out; 510 goto remove_hp_group;
523 } 511 }
524#endif 512
513 return 0;
514
515remove_hp_group:
516 sysfs_remove_group(*hugepage_kobj, &hugepage_attr_group);
517delete_obj:
518 kobject_put(*hugepage_kobj);
519 return err;
520}
521
522static void __init hugepage_exit_sysfs(struct kobject *hugepage_kobj)
523{
524 sysfs_remove_group(hugepage_kobj, &khugepaged_attr_group);
525 sysfs_remove_group(hugepage_kobj, &hugepage_attr_group);
526 kobject_put(hugepage_kobj);
527}
528#else
529static inline int hugepage_init_sysfs(struct kobject **hugepage_kobj)
530{
531 return 0;
532}
533
534static inline void hugepage_exit_sysfs(struct kobject *hugepage_kobj)
535{
536}
537#endif /* CONFIG_SYSFS */
538
539static int __init hugepage_init(void)
540{
541 int err;
542 struct kobject *hugepage_kobj;
543
544 if (!has_transparent_hugepage()) {
545 transparent_hugepage_flags = 0;
546 return -EINVAL;
547 }
548
549 err = hugepage_init_sysfs(&hugepage_kobj);
550 if (err)
551 return err;
525 552
526 err = khugepaged_slab_init(); 553 err = khugepaged_slab_init();
527 if (err) 554 if (err)
@@ -545,7 +572,9 @@ static int __init hugepage_init(void)
545 572
546 set_recommended_min_free_kbytes(); 573 set_recommended_min_free_kbytes();
547 574
575 return 0;
548out: 576out:
577 hugepage_exit_sysfs(hugepage_kobj);
549 return err; 578 return err;
550} 579}
551module_init(hugepage_init) 580module_init(hugepage_init)
@@ -997,7 +1026,7 @@ out:
997} 1026}
998 1027
999int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, 1028int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
1000 pmd_t *pmd) 1029 pmd_t *pmd, unsigned long addr)
1001{ 1030{
1002 int ret = 0; 1031 int ret = 0;
1003 1032
@@ -1013,6 +1042,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
1013 pgtable = get_pmd_huge_pte(tlb->mm); 1042 pgtable = get_pmd_huge_pte(tlb->mm);
1014 page = pmd_page(*pmd); 1043 page = pmd_page(*pmd);
1015 pmd_clear(pmd); 1044 pmd_clear(pmd);
1045 tlb_remove_pmd_tlb_entry(tlb, pmd, addr);
1016 page_remove_rmap(page); 1046 page_remove_rmap(page);
1017 VM_BUG_ON(page_mapcount(page) < 0); 1047 VM_BUG_ON(page_mapcount(page) < 0);
1018 add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR); 1048 add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
@@ -1116,7 +1146,6 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
1116 entry = pmd_modify(entry, newprot); 1146 entry = pmd_modify(entry, newprot);
1117 set_pmd_at(mm, addr, pmd, entry); 1147 set_pmd_at(mm, addr, pmd, entry);
1118 spin_unlock(&vma->vm_mm->page_table_lock); 1148 spin_unlock(&vma->vm_mm->page_table_lock);
1119 flush_tlb_range(vma, addr, addr + HPAGE_PMD_SIZE);
1120 ret = 1; 1149 ret = 1;
1121 } 1150 }
1122 } else 1151 } else
@@ -1199,16 +1228,16 @@ static int __split_huge_page_splitting(struct page *page,
1199static void __split_huge_page_refcount(struct page *page) 1228static void __split_huge_page_refcount(struct page *page)
1200{ 1229{
1201 int i; 1230 int i;
1202 unsigned long head_index = page->index;
1203 struct zone *zone = page_zone(page); 1231 struct zone *zone = page_zone(page);
1204 int zonestat;
1205 int tail_count = 0; 1232 int tail_count = 0;
1206 1233
1207 /* prevent PageLRU to go away from under us, and freeze lru stats */ 1234 /* prevent PageLRU to go away from under us, and freeze lru stats */
1208 spin_lock_irq(&zone->lru_lock); 1235 spin_lock_irq(&zone->lru_lock);
1209 compound_lock(page); 1236 compound_lock(page);
1237 /* complete memcg works before add pages to LRU */
1238 mem_cgroup_split_huge_fixup(page);
1210 1239
1211 for (i = 1; i < HPAGE_PMD_NR; i++) { 1240 for (i = HPAGE_PMD_NR - 1; i >= 1; i--) {
1212 struct page *page_tail = page + i; 1241 struct page *page_tail = page + i;
1213 1242
1214 /* tail_page->_mapcount cannot change */ 1243 /* tail_page->_mapcount cannot change */
@@ -1271,14 +1300,13 @@ static void __split_huge_page_refcount(struct page *page)
1271 BUG_ON(page_tail->mapping); 1300 BUG_ON(page_tail->mapping);
1272 page_tail->mapping = page->mapping; 1301 page_tail->mapping = page->mapping;
1273 1302
1274 page_tail->index = ++head_index; 1303 page_tail->index = page->index + i;
1275 1304
1276 BUG_ON(!PageAnon(page_tail)); 1305 BUG_ON(!PageAnon(page_tail));
1277 BUG_ON(!PageUptodate(page_tail)); 1306 BUG_ON(!PageUptodate(page_tail));
1278 BUG_ON(!PageDirty(page_tail)); 1307 BUG_ON(!PageDirty(page_tail));
1279 BUG_ON(!PageSwapBacked(page_tail)); 1308 BUG_ON(!PageSwapBacked(page_tail));
1280 1309
1281 mem_cgroup_split_huge_fixup(page, page_tail);
1282 1310
1283 lru_add_page_tail(zone, page, page_tail); 1311 lru_add_page_tail(zone, page, page_tail);
1284 } 1312 }
@@ -1288,15 +1316,6 @@ static void __split_huge_page_refcount(struct page *page)
1288 __dec_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES); 1316 __dec_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES);
1289 __mod_zone_page_state(zone, NR_ANON_PAGES, HPAGE_PMD_NR); 1317 __mod_zone_page_state(zone, NR_ANON_PAGES, HPAGE_PMD_NR);
1290 1318
1291 /*
1292 * A hugepage counts for HPAGE_PMD_NR pages on the LRU statistics,
1293 * so adjust those appropriately if this page is on the LRU.
1294 */
1295 if (PageLRU(page)) {
1296 zonestat = NR_LRU_BASE + page_lru(page);
1297 __mod_zone_page_state(zone, zonestat, -(HPAGE_PMD_NR-1));
1298 }
1299
1300 ClearPageCompound(page); 1319 ClearPageCompound(page);
1301 compound_unlock(page); 1320 compound_unlock(page);
1302 spin_unlock_irq(&zone->lru_lock); 1321 spin_unlock_irq(&zone->lru_lock);
diff --git a/mm/ksm.c b/mm/ksm.c
index 310544a379ae..1925ffbfb27f 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -28,6 +28,7 @@
28#include <linux/kthread.h> 28#include <linux/kthread.h>
29#include <linux/wait.h> 29#include <linux/wait.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/memcontrol.h>
31#include <linux/rbtree.h> 32#include <linux/rbtree.h>
32#include <linux/memory.h> 33#include <linux/memory.h>
33#include <linux/mmu_notifier.h> 34#include <linux/mmu_notifier.h>
@@ -1571,6 +1572,16 @@ struct page *ksm_does_need_to_copy(struct page *page,
1571 1572
1572 new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); 1573 new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address);
1573 if (new_page) { 1574 if (new_page) {
1575 /*
1576 * The memcg-specific accounting when moving
1577 * pages around the LRU lists relies on the
1578 * page's owner (memcg) to be valid. Usually,
1579 * pages are assigned to a new owner before
1580 * being put on the LRU list, but since this
1581 * is not the case here, the stale owner from
1582 * a previous allocation cycle must be reset.
1583 */
1584 mem_cgroup_reset_owner(new_page);
1574 copy_user_highpage(new_page, page, address, vma); 1585 copy_user_highpage(new_page, page, address, vma);
1575 1586
1576 SetPageDirty(new_page); 1587 SetPageDirty(new_page);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d87aa3510c5e..602207be9853 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -123,16 +123,22 @@ struct mem_cgroup_stat_cpu {
123 unsigned long targets[MEM_CGROUP_NTARGETS]; 123 unsigned long targets[MEM_CGROUP_NTARGETS];
124}; 124};
125 125
126struct mem_cgroup_reclaim_iter {
127 /* css_id of the last scanned hierarchy member */
128 int position;
129 /* scan generation, increased every round-trip */
130 unsigned int generation;
131};
132
126/* 133/*
127 * per-zone information in memory controller. 134 * per-zone information in memory controller.
128 */ 135 */
129struct mem_cgroup_per_zone { 136struct mem_cgroup_per_zone {
130 /* 137 struct lruvec lruvec;
131 * spin_lock to protect the per cgroup LRU
132 */
133 struct list_head lists[NR_LRU_LISTS];
134 unsigned long count[NR_LRU_LISTS]; 138 unsigned long count[NR_LRU_LISTS];
135 139
140 struct mem_cgroup_reclaim_iter reclaim_iter[DEF_PRIORITY + 1];
141
136 struct zone_reclaim_stat reclaim_stat; 142 struct zone_reclaim_stat reclaim_stat;
137 struct rb_node tree_node; /* RB tree node */ 143 struct rb_node tree_node; /* RB tree node */
138 unsigned long long usage_in_excess;/* Set to the value by which */ 144 unsigned long long usage_in_excess;/* Set to the value by which */
@@ -233,11 +239,6 @@ struct mem_cgroup {
233 * per zone LRU lists. 239 * per zone LRU lists.
234 */ 240 */
235 struct mem_cgroup_lru_info info; 241 struct mem_cgroup_lru_info info;
236 /*
237 * While reclaiming in a hierarchy, we cache the last child we
238 * reclaimed from.
239 */
240 int last_scanned_child;
241 int last_scanned_node; 242 int last_scanned_node;
242#if MAX_NUMNODES > 1 243#if MAX_NUMNODES > 1
243 nodemask_t scan_nodes; 244 nodemask_t scan_nodes;
@@ -366,8 +367,6 @@ enum charge_type {
366#define MEM_CGROUP_RECLAIM_NOSWAP (1 << MEM_CGROUP_RECLAIM_NOSWAP_BIT) 367#define MEM_CGROUP_RECLAIM_NOSWAP (1 << MEM_CGROUP_RECLAIM_NOSWAP_BIT)
367#define MEM_CGROUP_RECLAIM_SHRINK_BIT 0x1 368#define MEM_CGROUP_RECLAIM_SHRINK_BIT 0x1
368#define MEM_CGROUP_RECLAIM_SHRINK (1 << MEM_CGROUP_RECLAIM_SHRINK_BIT) 369#define MEM_CGROUP_RECLAIM_SHRINK (1 << MEM_CGROUP_RECLAIM_SHRINK_BIT)
369#define MEM_CGROUP_RECLAIM_SOFT_BIT 0x2
370#define MEM_CGROUP_RECLAIM_SOFT (1 << MEM_CGROUP_RECLAIM_SOFT_BIT)
371 370
372static void mem_cgroup_get(struct mem_cgroup *memcg); 371static void mem_cgroup_get(struct mem_cgroup *memcg);
373static void mem_cgroup_put(struct mem_cgroup *memcg); 372static void mem_cgroup_put(struct mem_cgroup *memcg);
@@ -566,7 +565,7 @@ static void mem_cgroup_remove_from_trees(struct mem_cgroup *memcg)
566 struct mem_cgroup_per_zone *mz; 565 struct mem_cgroup_per_zone *mz;
567 struct mem_cgroup_tree_per_zone *mctz; 566 struct mem_cgroup_tree_per_zone *mctz;
568 567
569 for_each_node_state(node, N_POSSIBLE) { 568 for_each_node(node) {
570 for (zone = 0; zone < MAX_NR_ZONES; zone++) { 569 for (zone = 0; zone < MAX_NR_ZONES; zone++) {
571 mz = mem_cgroup_zoneinfo(memcg, node, zone); 570 mz = mem_cgroup_zoneinfo(memcg, node, zone);
572 mctz = soft_limit_tree_node_zone(node, zone); 571 mctz = soft_limit_tree_node_zone(node, zone);
@@ -656,16 +655,6 @@ static void mem_cgroup_swap_statistics(struct mem_cgroup *memcg,
656 this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_SWAPOUT], val); 655 this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_SWAPOUT], val);
657} 656}
658 657
659void mem_cgroup_pgfault(struct mem_cgroup *memcg, int val)
660{
661 this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGFAULT], val);
662}
663
664void mem_cgroup_pgmajfault(struct mem_cgroup *memcg, int val)
665{
666 this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGMAJFAULT], val);
667}
668
669static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg, 658static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
670 enum mem_cgroup_events_index idx) 659 enum mem_cgroup_events_index idx)
671{ 660{
@@ -749,37 +738,32 @@ static unsigned long mem_cgroup_nr_lru_pages(struct mem_cgroup *memcg,
749 return total; 738 return total;
750} 739}
751 740
752static bool __memcg_event_check(struct mem_cgroup *memcg, int target) 741static bool mem_cgroup_event_ratelimit(struct mem_cgroup *memcg,
742 enum mem_cgroup_events_target target)
753{ 743{
754 unsigned long val, next; 744 unsigned long val, next;
755 745
756 val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]); 746 val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]);
757 next = __this_cpu_read(memcg->stat->targets[target]); 747 next = __this_cpu_read(memcg->stat->targets[target]);
758 /* from time_after() in jiffies.h */ 748 /* from time_after() in jiffies.h */
759 return ((long)next - (long)val < 0); 749 if ((long)next - (long)val < 0) {
760} 750 switch (target) {
761 751 case MEM_CGROUP_TARGET_THRESH:
762static void __mem_cgroup_target_update(struct mem_cgroup *memcg, int target) 752 next = val + THRESHOLDS_EVENTS_TARGET;
763{ 753 break;
764 unsigned long val, next; 754 case MEM_CGROUP_TARGET_SOFTLIMIT:
765 755 next = val + SOFTLIMIT_EVENTS_TARGET;
766 val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]); 756 break;
767 757 case MEM_CGROUP_TARGET_NUMAINFO:
768 switch (target) { 758 next = val + NUMAINFO_EVENTS_TARGET;
769 case MEM_CGROUP_TARGET_THRESH: 759 break;
770 next = val + THRESHOLDS_EVENTS_TARGET; 760 default:
771 break; 761 break;
772 case MEM_CGROUP_TARGET_SOFTLIMIT: 762 }
773 next = val + SOFTLIMIT_EVENTS_TARGET; 763 __this_cpu_write(memcg->stat->targets[target], next);
774 break; 764 return true;
775 case MEM_CGROUP_TARGET_NUMAINFO:
776 next = val + NUMAINFO_EVENTS_TARGET;
777 break;
778 default:
779 return;
780 } 765 }
781 766 return false;
782 __this_cpu_write(memcg->stat->targets[target], next);
783} 767}
784 768
785/* 769/*
@@ -790,25 +774,27 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
790{ 774{
791 preempt_disable(); 775 preempt_disable();
792 /* threshold event is triggered in finer grain than soft limit */ 776 /* threshold event is triggered in finer grain than soft limit */
793 if (unlikely(__memcg_event_check(memcg, MEM_CGROUP_TARGET_THRESH))) { 777 if (unlikely(mem_cgroup_event_ratelimit(memcg,
778 MEM_CGROUP_TARGET_THRESH))) {
779 bool do_softlimit, do_numainfo;
780
781 do_softlimit = mem_cgroup_event_ratelimit(memcg,
782 MEM_CGROUP_TARGET_SOFTLIMIT);
783#if MAX_NUMNODES > 1
784 do_numainfo = mem_cgroup_event_ratelimit(memcg,
785 MEM_CGROUP_TARGET_NUMAINFO);
786#endif
787 preempt_enable();
788
794 mem_cgroup_threshold(memcg); 789 mem_cgroup_threshold(memcg);
795 __mem_cgroup_target_update(memcg, MEM_CGROUP_TARGET_THRESH); 790 if (unlikely(do_softlimit))
796 if (unlikely(__memcg_event_check(memcg,
797 MEM_CGROUP_TARGET_SOFTLIMIT))) {
798 mem_cgroup_update_tree(memcg, page); 791 mem_cgroup_update_tree(memcg, page);
799 __mem_cgroup_target_update(memcg,
800 MEM_CGROUP_TARGET_SOFTLIMIT);
801 }
802#if MAX_NUMNODES > 1 792#if MAX_NUMNODES > 1
803 if (unlikely(__memcg_event_check(memcg, 793 if (unlikely(do_numainfo))
804 MEM_CGROUP_TARGET_NUMAINFO))) {
805 atomic_inc(&memcg->numainfo_events); 794 atomic_inc(&memcg->numainfo_events);
806 __mem_cgroup_target_update(memcg,
807 MEM_CGROUP_TARGET_NUMAINFO);
808 }
809#endif 795#endif
810 } 796 } else
811 preempt_enable(); 797 preempt_enable();
812} 798}
813 799
814struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) 800struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
@@ -853,83 +839,116 @@ struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
853 return memcg; 839 return memcg;
854} 840}
855 841
856/* The caller has to guarantee "mem" exists before calling this */ 842/**
857static struct mem_cgroup *mem_cgroup_start_loop(struct mem_cgroup *memcg) 843 * mem_cgroup_iter - iterate over memory cgroup hierarchy
844 * @root: hierarchy root
845 * @prev: previously returned memcg, NULL on first invocation
846 * @reclaim: cookie for shared reclaim walks, NULL for full walks
847 *
848 * Returns references to children of the hierarchy below @root, or
849 * @root itself, or %NULL after a full round-trip.
850 *
851 * Caller must pass the return value in @prev on subsequent
852 * invocations for reference counting, or use mem_cgroup_iter_break()
853 * to cancel a hierarchy walk before the round-trip is complete.
854 *
855 * Reclaimers can specify a zone and a priority level in @reclaim to
856 * divide up the memcgs in the hierarchy among all concurrent
857 * reclaimers operating on the same zone and priority.
858 */
859struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root,
860 struct mem_cgroup *prev,
861 struct mem_cgroup_reclaim_cookie *reclaim)
858{ 862{
859 struct cgroup_subsys_state *css; 863 struct mem_cgroup *memcg = NULL;
860 int found; 864 int id = 0;
861 865
862 if (!memcg) /* ROOT cgroup has the smallest ID */ 866 if (mem_cgroup_disabled())
863 return root_mem_cgroup; /*css_put/get against root is ignored*/
864 if (!memcg->use_hierarchy) {
865 if (css_tryget(&memcg->css))
866 return memcg;
867 return NULL; 867 return NULL;
868 }
869 rcu_read_lock();
870 /*
871 * searching a memory cgroup which has the smallest ID under given
872 * ROOT cgroup. (ID >= 1)
873 */
874 css = css_get_next(&mem_cgroup_subsys, 1, &memcg->css, &found);
875 if (css && css_tryget(css))
876 memcg = container_of(css, struct mem_cgroup, css);
877 else
878 memcg = NULL;
879 rcu_read_unlock();
880 return memcg;
881}
882 868
883static struct mem_cgroup *mem_cgroup_get_next(struct mem_cgroup *iter, 869 if (!root)
884 struct mem_cgroup *root, 870 root = root_mem_cgroup;
885 bool cond)
886{
887 int nextid = css_id(&iter->css) + 1;
888 int found;
889 int hierarchy_used;
890 struct cgroup_subsys_state *css;
891 871
892 hierarchy_used = iter->use_hierarchy; 872 if (prev && !reclaim)
873 id = css_id(&prev->css);
893 874
894 css_put(&iter->css); 875 if (prev && prev != root)
895 /* If no ROOT, walk all, ignore hierarchy */ 876 css_put(&prev->css);
896 if (!cond || (root && !hierarchy_used))
897 return NULL;
898 877
899 if (!root) 878 if (!root->use_hierarchy && root != root_mem_cgroup) {
900 root = root_mem_cgroup; 879 if (prev)
880 return NULL;
881 return root;
882 }
901 883
902 do { 884 while (!memcg) {
903 iter = NULL; 885 struct mem_cgroup_reclaim_iter *uninitialized_var(iter);
904 rcu_read_lock(); 886 struct cgroup_subsys_state *css;
887
888 if (reclaim) {
889 int nid = zone_to_nid(reclaim->zone);
890 int zid = zone_idx(reclaim->zone);
891 struct mem_cgroup_per_zone *mz;
905 892
906 css = css_get_next(&mem_cgroup_subsys, nextid, 893 mz = mem_cgroup_zoneinfo(root, nid, zid);
907 &root->css, &found); 894 iter = &mz->reclaim_iter[reclaim->priority];
908 if (css && css_tryget(css)) 895 if (prev && reclaim->generation != iter->generation)
909 iter = container_of(css, struct mem_cgroup, css); 896 return NULL;
897 id = iter->position;
898 }
899
900 rcu_read_lock();
901 css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id);
902 if (css) {
903 if (css == &root->css || css_tryget(css))
904 memcg = container_of(css,
905 struct mem_cgroup, css);
906 } else
907 id = 0;
910 rcu_read_unlock(); 908 rcu_read_unlock();
911 /* If css is NULL, no more cgroups will be found */
912 nextid = found + 1;
913 } while (css && !iter);
914 909
915 return iter; 910 if (reclaim) {
911 iter->position = id;
912 if (!css)
913 iter->generation++;
914 else if (!prev && memcg)
915 reclaim->generation = iter->generation;
916 }
917
918 if (prev && !css)
919 return NULL;
920 }
921 return memcg;
916} 922}
917/*
918 * for_eacn_mem_cgroup_tree() for visiting all cgroup under tree. Please
919 * be careful that "break" loop is not allowed. We have reference count.
920 * Instead of that modify "cond" to be false and "continue" to exit the loop.
921 */
922#define for_each_mem_cgroup_tree_cond(iter, root, cond) \
923 for (iter = mem_cgroup_start_loop(root);\
924 iter != NULL;\
925 iter = mem_cgroup_get_next(iter, root, cond))
926 923
927#define for_each_mem_cgroup_tree(iter, root) \ 924/**
928 for_each_mem_cgroup_tree_cond(iter, root, true) 925 * mem_cgroup_iter_break - abort a hierarchy walk prematurely
926 * @root: hierarchy root
927 * @prev: last visited hierarchy member as returned by mem_cgroup_iter()
928 */
929void mem_cgroup_iter_break(struct mem_cgroup *root,
930 struct mem_cgroup *prev)
931{
932 if (!root)
933 root = root_mem_cgroup;
934 if (prev && prev != root)
935 css_put(&prev->css);
936}
929 937
930#define for_each_mem_cgroup_all(iter) \ 938/*
931 for_each_mem_cgroup_tree_cond(iter, NULL, true) 939 * Iteration constructs for visiting all cgroups (under a tree). If
940 * loops are exited prematurely (break), mem_cgroup_iter_break() must
941 * be used for reference counting.
942 */
943#define for_each_mem_cgroup_tree(iter, root) \
944 for (iter = mem_cgroup_iter(root, NULL, NULL); \
945 iter != NULL; \
946 iter = mem_cgroup_iter(root, iter, NULL))
932 947
948#define for_each_mem_cgroup(iter) \
949 for (iter = mem_cgroup_iter(NULL, NULL, NULL); \
950 iter != NULL; \
951 iter = mem_cgroup_iter(NULL, iter, NULL))
933 952
934static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) 953static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
935{ 954{
@@ -949,11 +968,11 @@ void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
949 goto out; 968 goto out;
950 969
951 switch (idx) { 970 switch (idx) {
952 case PGMAJFAULT:
953 mem_cgroup_pgmajfault(memcg, 1);
954 break;
955 case PGFAULT: 971 case PGFAULT:
956 mem_cgroup_pgfault(memcg, 1); 972 this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGFAULT]);
973 break;
974 case PGMAJFAULT:
975 this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGMAJFAULT]);
957 break; 976 break;
958 default: 977 default:
959 BUG(); 978 BUG();
@@ -963,6 +982,27 @@ out:
963} 982}
964EXPORT_SYMBOL(mem_cgroup_count_vm_event); 983EXPORT_SYMBOL(mem_cgroup_count_vm_event);
965 984
985/**
986 * mem_cgroup_zone_lruvec - get the lru list vector for a zone and memcg
987 * @zone: zone of the wanted lruvec
988 * @mem: memcg of the wanted lruvec
989 *
990 * Returns the lru list vector holding pages for the given @zone and
991 * @mem. This can be the global zone lruvec, if the memory controller
992 * is disabled.
993 */
994struct lruvec *mem_cgroup_zone_lruvec(struct zone *zone,
995 struct mem_cgroup *memcg)
996{
997 struct mem_cgroup_per_zone *mz;
998
999 if (mem_cgroup_disabled())
1000 return &zone->lruvec;
1001
1002 mz = mem_cgroup_zoneinfo(memcg, zone_to_nid(zone), zone_idx(zone));
1003 return &mz->lruvec;
1004}
1005
966/* 1006/*
967 * Following LRU functions are allowed to be used without PCG_LOCK. 1007 * Following LRU functions are allowed to be used without PCG_LOCK.
968 * Operations are called by routine of global LRU independently from memcg. 1008 * Operations are called by routine of global LRU independently from memcg.
@@ -977,180 +1017,91 @@ EXPORT_SYMBOL(mem_cgroup_count_vm_event);
977 * When moving account, the page is not on LRU. It's isolated. 1017 * When moving account, the page is not on LRU. It's isolated.
978 */ 1018 */
979 1019
980void mem_cgroup_del_lru_list(struct page *page, enum lru_list lru) 1020/**
981{ 1021 * mem_cgroup_lru_add_list - account for adding an lru page and return lruvec
982 struct page_cgroup *pc; 1022 * @zone: zone of the page
983 struct mem_cgroup_per_zone *mz; 1023 * @page: the page
984 1024 * @lru: current lru
985 if (mem_cgroup_disabled()) 1025 *
986 return; 1026 * This function accounts for @page being added to @lru, and returns
987 pc = lookup_page_cgroup(page); 1027 * the lruvec for the given @zone and the memcg @page is charged to.
988 /* can happen while we handle swapcache. */ 1028 *
989 if (!TestClearPageCgroupAcctLRU(pc)) 1029 * The callsite is then responsible for physically linking the page to
990 return; 1030 * the returned lruvec->lists[@lru].
991 VM_BUG_ON(!pc->mem_cgroup);
992 /*
993 * We don't check PCG_USED bit. It's cleared when the "page" is finally
994 * removed from global LRU.
995 */
996 mz = page_cgroup_zoneinfo(pc->mem_cgroup, page);
997 /* huge page split is done under lru_lock. so, we have no races. */
998 MEM_CGROUP_ZSTAT(mz, lru) -= 1 << compound_order(page);
999 if (mem_cgroup_is_root(pc->mem_cgroup))
1000 return;
1001 VM_BUG_ON(list_empty(&pc->lru));
1002 list_del_init(&pc->lru);
1003}
1004
1005void mem_cgroup_del_lru(struct page *page)
1006{
1007 mem_cgroup_del_lru_list(page, page_lru(page));
1008}
1009
1010/*
1011 * Writeback is about to end against a page which has been marked for immediate
1012 * reclaim. If it still appears to be reclaimable, move it to the tail of the
1013 * inactive list.
1014 */ 1031 */
1015void mem_cgroup_rotate_reclaimable_page(struct page *page) 1032struct lruvec *mem_cgroup_lru_add_list(struct zone *zone, struct page *page,
1033 enum lru_list lru)
1016{ 1034{
1017 struct mem_cgroup_per_zone *mz; 1035 struct mem_cgroup_per_zone *mz;
1036 struct mem_cgroup *memcg;
1018 struct page_cgroup *pc; 1037 struct page_cgroup *pc;
1019 enum lru_list lru = page_lru(page);
1020 1038
1021 if (mem_cgroup_disabled()) 1039 if (mem_cgroup_disabled())
1022 return; 1040 return &zone->lruvec;
1023 1041
1024 pc = lookup_page_cgroup(page); 1042 pc = lookup_page_cgroup(page);
1025 /* unused or root page is not rotated. */ 1043 memcg = pc->mem_cgroup;
1026 if (!PageCgroupUsed(pc)) 1044 mz = page_cgroup_zoneinfo(memcg, page);
1027 return; 1045 /* compound_order() is stabilized through lru_lock */
1028 /* Ensure pc->mem_cgroup is visible after reading PCG_USED. */ 1046 MEM_CGROUP_ZSTAT(mz, lru) += 1 << compound_order(page);
1029 smp_rmb(); 1047 return &mz->lruvec;
1030 if (mem_cgroup_is_root(pc->mem_cgroup))
1031 return;
1032 mz = page_cgroup_zoneinfo(pc->mem_cgroup, page);
1033 list_move_tail(&pc->lru, &mz->lists[lru]);
1034} 1048}
1035 1049
1036void mem_cgroup_rotate_lru_list(struct page *page, enum lru_list lru) 1050/**
1051 * mem_cgroup_lru_del_list - account for removing an lru page
1052 * @page: the page
1053 * @lru: target lru
1054 *
1055 * This function accounts for @page being removed from @lru.
1056 *
1057 * The callsite is then responsible for physically unlinking
1058 * @page->lru.
1059 */
1060void mem_cgroup_lru_del_list(struct page *page, enum lru_list lru)
1037{ 1061{
1038 struct mem_cgroup_per_zone *mz; 1062 struct mem_cgroup_per_zone *mz;
1063 struct mem_cgroup *memcg;
1039 struct page_cgroup *pc; 1064 struct page_cgroup *pc;
1040 1065
1041 if (mem_cgroup_disabled()) 1066 if (mem_cgroup_disabled())
1042 return; 1067 return;
1043 1068
1044 pc = lookup_page_cgroup(page); 1069 pc = lookup_page_cgroup(page);
1045 /* unused or root page is not rotated. */ 1070 memcg = pc->mem_cgroup;
1046 if (!PageCgroupUsed(pc)) 1071 VM_BUG_ON(!memcg);
1047 return; 1072 mz = page_cgroup_zoneinfo(memcg, page);
1048 /* Ensure pc->mem_cgroup is visible after reading PCG_USED. */
1049 smp_rmb();
1050 if (mem_cgroup_is_root(pc->mem_cgroup))
1051 return;
1052 mz = page_cgroup_zoneinfo(pc->mem_cgroup, page);
1053 list_move(&pc->lru, &mz->lists[lru]);
1054}
1055
1056void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru)
1057{
1058 struct page_cgroup *pc;
1059 struct mem_cgroup_per_zone *mz;
1060
1061 if (mem_cgroup_disabled())
1062 return;
1063 pc = lookup_page_cgroup(page);
1064 VM_BUG_ON(PageCgroupAcctLRU(pc));
1065 /*
1066 * putback: charge:
1067 * SetPageLRU SetPageCgroupUsed
1068 * smp_mb smp_mb
1069 * PageCgroupUsed && add to memcg LRU PageLRU && add to memcg LRU
1070 *
1071 * Ensure that one of the two sides adds the page to the memcg
1072 * LRU during a race.
1073 */
1074 smp_mb();
1075 if (!PageCgroupUsed(pc))
1076 return;
1077 /* Ensure pc->mem_cgroup is visible after reading PCG_USED. */
1078 smp_rmb();
1079 mz = page_cgroup_zoneinfo(pc->mem_cgroup, page);
1080 /* huge page split is done under lru_lock. so, we have no races. */ 1073 /* huge page split is done under lru_lock. so, we have no races. */
1081 MEM_CGROUP_ZSTAT(mz, lru) += 1 << compound_order(page); 1074 VM_BUG_ON(MEM_CGROUP_ZSTAT(mz, lru) < (1 << compound_order(page)));
1082 SetPageCgroupAcctLRU(pc); 1075 MEM_CGROUP_ZSTAT(mz, lru) -= 1 << compound_order(page);
1083 if (mem_cgroup_is_root(pc->mem_cgroup))
1084 return;
1085 list_add(&pc->lru, &mz->lists[lru]);
1086}
1087
1088/*
1089 * At handling SwapCache and other FUSE stuff, pc->mem_cgroup may be changed
1090 * while it's linked to lru because the page may be reused after it's fully
1091 * uncharged. To handle that, unlink page_cgroup from LRU when charge it again.
1092 * It's done under lock_page and expected that zone->lru_lock isnever held.
1093 */
1094static void mem_cgroup_lru_del_before_commit(struct page *page)
1095{
1096 unsigned long flags;
1097 struct zone *zone = page_zone(page);
1098 struct page_cgroup *pc = lookup_page_cgroup(page);
1099
1100 /*
1101 * Doing this check without taking ->lru_lock seems wrong but this
1102 * is safe. Because if page_cgroup's USED bit is unset, the page
1103 * will not be added to any memcg's LRU. If page_cgroup's USED bit is
1104 * set, the commit after this will fail, anyway.
1105 * This all charge/uncharge is done under some mutual execustion.
1106 * So, we don't need to taking care of changes in USED bit.
1107 */
1108 if (likely(!PageLRU(page)))
1109 return;
1110
1111 spin_lock_irqsave(&zone->lru_lock, flags);
1112 /*
1113 * Forget old LRU when this page_cgroup is *not* used. This Used bit
1114 * is guarded by lock_page() because the page is SwapCache.
1115 */
1116 if (!PageCgroupUsed(pc))
1117 mem_cgroup_del_lru_list(page, page_lru(page));
1118 spin_unlock_irqrestore(&zone->lru_lock, flags);
1119} 1076}
1120 1077
1121static void mem_cgroup_lru_add_after_commit(struct page *page) 1078void mem_cgroup_lru_del(struct page *page)
1122{ 1079{
1123 unsigned long flags; 1080 mem_cgroup_lru_del_list(page, page_lru(page));
1124 struct zone *zone = page_zone(page);
1125 struct page_cgroup *pc = lookup_page_cgroup(page);
1126 /*
1127 * putback: charge:
1128 * SetPageLRU SetPageCgroupUsed
1129 * smp_mb smp_mb
1130 * PageCgroupUsed && add to memcg LRU PageLRU && add to memcg LRU
1131 *
1132 * Ensure that one of the two sides adds the page to the memcg
1133 * LRU during a race.
1134 */
1135 smp_mb();
1136 /* taking care of that the page is added to LRU while we commit it */
1137 if (likely(!PageLRU(page)))
1138 return;
1139 spin_lock_irqsave(&zone->lru_lock, flags);
1140 /* link when the page is linked to LRU but page_cgroup isn't */
1141 if (PageLRU(page) && !PageCgroupAcctLRU(pc))
1142 mem_cgroup_add_lru_list(page, page_lru(page));
1143 spin_unlock_irqrestore(&zone->lru_lock, flags);
1144} 1081}
1145 1082
1146 1083/**
1147void mem_cgroup_move_lists(struct page *page, 1084 * mem_cgroup_lru_move_lists - account for moving a page between lrus
1148 enum lru_list from, enum lru_list to) 1085 * @zone: zone of the page
1086 * @page: the page
1087 * @from: current lru
1088 * @to: target lru
1089 *
1090 * This function accounts for @page being moved between the lrus @from
1091 * and @to, and returns the lruvec for the given @zone and the memcg
1092 * @page is charged to.
1093 *
1094 * The callsite is then responsible for physically relinking
1095 * @page->lru to the returned lruvec->lists[@to].
1096 */
1097struct lruvec *mem_cgroup_lru_move_lists(struct zone *zone,
1098 struct page *page,
1099 enum lru_list from,
1100 enum lru_list to)
1149{ 1101{
1150 if (mem_cgroup_disabled()) 1102 /* XXX: Optimize this, especially for @from == @to */
1151 return; 1103 mem_cgroup_lru_del_list(page, from);
1152 mem_cgroup_del_lru_list(page, from); 1104 return mem_cgroup_lru_add_list(zone, page, to);
1153 mem_cgroup_add_lru_list(page, to);
1154} 1105}
1155 1106
1156/* 1107/*
@@ -1175,10 +1126,21 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg)
1175 struct task_struct *p; 1126 struct task_struct *p;
1176 1127
1177 p = find_lock_task_mm(task); 1128 p = find_lock_task_mm(task);
1178 if (!p) 1129 if (p) {
1179 return 0; 1130 curr = try_get_mem_cgroup_from_mm(p->mm);
1180 curr = try_get_mem_cgroup_from_mm(p->mm); 1131 task_unlock(p);
1181 task_unlock(p); 1132 } else {
1133 /*
1134 * All threads may have already detached their mm's, but the oom
1135 * killer still needs to detect if they have already been oom
1136 * killed to prevent needlessly killing additional tasks.
1137 */
1138 task_lock(task);
1139 curr = mem_cgroup_from_task(task);
1140 if (curr)
1141 css_get(&curr->css);
1142 task_unlock(task);
1143 }
1182 if (!curr) 1144 if (!curr)
1183 return 0; 1145 return 0;
1184 /* 1146 /*
@@ -1258,68 +1220,6 @@ mem_cgroup_get_reclaim_stat_from_page(struct page *page)
1258 return &mz->reclaim_stat; 1220 return &mz->reclaim_stat;
1259} 1221}
1260 1222
1261unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
1262 struct list_head *dst,
1263 unsigned long *scanned, int order,
1264 isolate_mode_t mode,
1265 struct zone *z,
1266 struct mem_cgroup *mem_cont,
1267 int active, int file)
1268{
1269 unsigned long nr_taken = 0;
1270 struct page *page;
1271 unsigned long scan;
1272 LIST_HEAD(pc_list);
1273 struct list_head *src;
1274 struct page_cgroup *pc, *tmp;
1275 int nid = zone_to_nid(z);
1276 int zid = zone_idx(z);
1277 struct mem_cgroup_per_zone *mz;
1278 int lru = LRU_FILE * file + active;
1279 int ret;
1280
1281 BUG_ON(!mem_cont);
1282 mz = mem_cgroup_zoneinfo(mem_cont, nid, zid);
1283 src = &mz->lists[lru];
1284
1285 scan = 0;
1286 list_for_each_entry_safe_reverse(pc, tmp, src, lru) {
1287 if (scan >= nr_to_scan)
1288 break;
1289
1290 if (unlikely(!PageCgroupUsed(pc)))
1291 continue;
1292
1293 page = lookup_cgroup_page(pc);
1294
1295 if (unlikely(!PageLRU(page)))
1296 continue;
1297
1298 scan++;
1299 ret = __isolate_lru_page(page, mode, file);
1300 switch (ret) {
1301 case 0:
1302 list_move(&page->lru, dst);
1303 mem_cgroup_del_lru(page);
1304 nr_taken += hpage_nr_pages(page);
1305 break;
1306 case -EBUSY:
1307 /* we don't affect global LRU but rotate in our LRU */
1308 mem_cgroup_rotate_lru_list(page, page_lru(page));
1309 break;
1310 default:
1311 break;
1312 }
1313 }
1314
1315 *scanned = scan;
1316
1317 trace_mm_vmscan_memcg_isolate(0, nr_to_scan, scan, nr_taken,
1318 0, 0, 0, mode);
1319
1320 return nr_taken;
1321}
1322
1323#define mem_cgroup_from_res_counter(counter, member) \ 1223#define mem_cgroup_from_res_counter(counter, member) \
1324 container_of(counter, struct mem_cgroup, member) 1224 container_of(counter, struct mem_cgroup, member)
1325 1225
@@ -1536,41 +1436,40 @@ u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
1536 return min(limit, memsw); 1436 return min(limit, memsw);
1537} 1437}
1538 1438
1539/* 1439static unsigned long mem_cgroup_reclaim(struct mem_cgroup *memcg,
1540 * Visit the first child (need not be the first child as per the ordering 1440 gfp_t gfp_mask,
1541 * of the cgroup list, since we track last_scanned_child) of @mem and use 1441 unsigned long flags)
1542 * that to reclaim free pages from.
1543 */
1544static struct mem_cgroup *
1545mem_cgroup_select_victim(struct mem_cgroup *root_memcg)
1546{ 1442{
1547 struct mem_cgroup *ret = NULL; 1443 unsigned long total = 0;
1548 struct cgroup_subsys_state *css; 1444 bool noswap = false;
1549 int nextid, found; 1445 int loop;
1550
1551 if (!root_memcg->use_hierarchy) {
1552 css_get(&root_memcg->css);
1553 ret = root_memcg;
1554 }
1555 1446
1556 while (!ret) { 1447 if (flags & MEM_CGROUP_RECLAIM_NOSWAP)
1557 rcu_read_lock(); 1448 noswap = true;
1558 nextid = root_memcg->last_scanned_child + 1; 1449 if (!(flags & MEM_CGROUP_RECLAIM_SHRINK) && memcg->memsw_is_minimum)
1559 css = css_get_next(&mem_cgroup_subsys, nextid, &root_memcg->css, 1450 noswap = true;
1560 &found);
1561 if (css && css_tryget(css))
1562 ret = container_of(css, struct mem_cgroup, css);
1563 1451
1564 rcu_read_unlock(); 1452 for (loop = 0; loop < MEM_CGROUP_MAX_RECLAIM_LOOPS; loop++) {
1565 /* Updates scanning parameter */ 1453 if (loop)
1566 if (!css) { 1454 drain_all_stock_async(memcg);
1567 /* this means start scan from ID:1 */ 1455 total += try_to_free_mem_cgroup_pages(memcg, gfp_mask, noswap);
1568 root_memcg->last_scanned_child = 0; 1456 /*
1569 } else 1457 * Allow limit shrinkers, which are triggered directly
1570 root_memcg->last_scanned_child = found; 1458 * by userspace, to catch signals and stop reclaim
1459 * after minimal progress, regardless of the margin.
1460 */
1461 if (total && (flags & MEM_CGROUP_RECLAIM_SHRINK))
1462 break;
1463 if (mem_cgroup_margin(memcg))
1464 break;
1465 /*
1466 * If nothing was reclaimed after two attempts, there
1467 * may be no reclaimable pages in this hierarchy.
1468 */
1469 if (loop && !total)
1470 break;
1571 } 1471 }
1572 1472 return total;
1573 return ret;
1574} 1473}
1575 1474
1576/** 1475/**
@@ -1710,61 +1609,35 @@ bool mem_cgroup_reclaimable(struct mem_cgroup *memcg, bool noswap)
1710} 1609}
1711#endif 1610#endif
1712 1611
1713/* 1612static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg,
1714 * Scan the hierarchy if needed to reclaim memory. We remember the last child 1613 struct zone *zone,
1715 * we reclaimed from, so that we don't end up penalizing one child extensively 1614 gfp_t gfp_mask,
1716 * based on its position in the children list. 1615 unsigned long *total_scanned)
1717 * 1616{
1718 * root_memcg is the original ancestor that we've been reclaim from. 1617 struct mem_cgroup *victim = NULL;
1719 * 1618 int total = 0;
1720 * We give up and return to the caller when we visit root_memcg twice.
1721 * (other groups can be removed while we're walking....)
1722 *
1723 * If shrink==true, for avoiding to free too much, this returns immedieately.
1724 */
1725static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_memcg,
1726 struct zone *zone,
1727 gfp_t gfp_mask,
1728 unsigned long reclaim_options,
1729 unsigned long *total_scanned)
1730{
1731 struct mem_cgroup *victim;
1732 int ret, total = 0;
1733 int loop = 0; 1619 int loop = 0;
1734 bool noswap = reclaim_options & MEM_CGROUP_RECLAIM_NOSWAP;
1735 bool shrink = reclaim_options & MEM_CGROUP_RECLAIM_SHRINK;
1736 bool check_soft = reclaim_options & MEM_CGROUP_RECLAIM_SOFT;
1737 unsigned long excess; 1620 unsigned long excess;
1738 unsigned long nr_scanned; 1621 unsigned long nr_scanned;
1622 struct mem_cgroup_reclaim_cookie reclaim = {
1623 .zone = zone,
1624 .priority = 0,
1625 };
1739 1626
1740 excess = res_counter_soft_limit_excess(&root_memcg->res) >> PAGE_SHIFT; 1627 excess = res_counter_soft_limit_excess(&root_memcg->res) >> PAGE_SHIFT;
1741 1628
1742 /* If memsw_is_minimum==1, swap-out is of-no-use. */
1743 if (!check_soft && !shrink && root_memcg->memsw_is_minimum)
1744 noswap = true;
1745
1746 while (1) { 1629 while (1) {
1747 victim = mem_cgroup_select_victim(root_memcg); 1630 victim = mem_cgroup_iter(root_memcg, victim, &reclaim);
1748 if (victim == root_memcg) { 1631 if (!victim) {
1749 loop++; 1632 loop++;
1750 /*
1751 * We are not draining per cpu cached charges during
1752 * soft limit reclaim because global reclaim doesn't
1753 * care about charges. It tries to free some memory and
1754 * charges will not give any.
1755 */
1756 if (!check_soft && loop >= 1)
1757 drain_all_stock_async(root_memcg);
1758 if (loop >= 2) { 1633 if (loop >= 2) {
1759 /* 1634 /*
1760 * If we have not been able to reclaim 1635 * If we have not been able to reclaim
1761 * anything, it might because there are 1636 * anything, it might because there are
1762 * no reclaimable pages under this hierarchy 1637 * no reclaimable pages under this hierarchy
1763 */ 1638 */
1764 if (!check_soft || !total) { 1639 if (!total)
1765 css_put(&victim->css);
1766 break; 1640 break;
1767 }
1768 /* 1641 /*
1769 * We want to do more targeted reclaim. 1642 * We want to do more targeted reclaim.
1770 * excess >> 2 is not to excessive so as to 1643 * excess >> 2 is not to excessive so as to
@@ -1772,40 +1645,20 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_memcg,
1772 * coming back to reclaim from this cgroup 1645 * coming back to reclaim from this cgroup
1773 */ 1646 */
1774 if (total >= (excess >> 2) || 1647 if (total >= (excess >> 2) ||
1775 (loop > MEM_CGROUP_MAX_RECLAIM_LOOPS)) { 1648 (loop > MEM_CGROUP_MAX_RECLAIM_LOOPS))
1776 css_put(&victim->css);
1777 break; 1649 break;
1778 }
1779 } 1650 }
1780 }
1781 if (!mem_cgroup_reclaimable(victim, noswap)) {
1782 /* this cgroup's local usage == 0 */
1783 css_put(&victim->css);
1784 continue; 1651 continue;
1785 } 1652 }
1786 /* we use swappiness of local cgroup */ 1653 if (!mem_cgroup_reclaimable(victim, false))
1787 if (check_soft) { 1654 continue;
1788 ret = mem_cgroup_shrink_node_zone(victim, gfp_mask, 1655 total += mem_cgroup_shrink_node_zone(victim, gfp_mask, false,
1789 noswap, zone, &nr_scanned); 1656 zone, &nr_scanned);
1790 *total_scanned += nr_scanned; 1657 *total_scanned += nr_scanned;
1791 } else 1658 if (!res_counter_soft_limit_excess(&root_memcg->res))
1792 ret = try_to_free_mem_cgroup_pages(victim, gfp_mask, 1659 break;
1793 noswap);
1794 css_put(&victim->css);
1795 /*
1796 * At shrinking usage, we can't check we should stop here or
1797 * reclaim more. It's depends on callers. last_scanned_child
1798 * will work enough for keeping fairness under tree.
1799 */
1800 if (shrink)
1801 return ret;
1802 total += ret;
1803 if (check_soft) {
1804 if (!res_counter_soft_limit_excess(&root_memcg->res))
1805 return total;
1806 } else if (mem_cgroup_margin(root_memcg))
1807 return total;
1808 } 1660 }
1661 mem_cgroup_iter_break(root_memcg, victim);
1809 return total; 1662 return total;
1810} 1663}
1811 1664
@@ -1817,16 +1670,16 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_memcg,
1817static bool mem_cgroup_oom_lock(struct mem_cgroup *memcg) 1670static bool mem_cgroup_oom_lock(struct mem_cgroup *memcg)
1818{ 1671{
1819 struct mem_cgroup *iter, *failed = NULL; 1672 struct mem_cgroup *iter, *failed = NULL;
1820 bool cond = true;
1821 1673
1822 for_each_mem_cgroup_tree_cond(iter, memcg, cond) { 1674 for_each_mem_cgroup_tree(iter, memcg) {
1823 if (iter->oom_lock) { 1675 if (iter->oom_lock) {
1824 /* 1676 /*
1825 * this subtree of our hierarchy is already locked 1677 * this subtree of our hierarchy is already locked
1826 * so we cannot give a lock. 1678 * so we cannot give a lock.
1827 */ 1679 */
1828 failed = iter; 1680 failed = iter;
1829 cond = false; 1681 mem_cgroup_iter_break(memcg, iter);
1682 break;
1830 } else 1683 } else
1831 iter->oom_lock = true; 1684 iter->oom_lock = true;
1832 } 1685 }
@@ -1838,11 +1691,10 @@ static bool mem_cgroup_oom_lock(struct mem_cgroup *memcg)
1838 * OK, we failed to lock the whole subtree so we have to clean up 1691 * OK, we failed to lock the whole subtree so we have to clean up
1839 * what we set up to the failing subtree 1692 * what we set up to the failing subtree
1840 */ 1693 */
1841 cond = true; 1694 for_each_mem_cgroup_tree(iter, memcg) {
1842 for_each_mem_cgroup_tree_cond(iter, memcg, cond) {
1843 if (iter == failed) { 1695 if (iter == failed) {
1844 cond = false; 1696 mem_cgroup_iter_break(memcg, iter);
1845 continue; 1697 break;
1846 } 1698 }
1847 iter->oom_lock = false; 1699 iter->oom_lock = false;
1848 } 1700 }
@@ -2007,7 +1859,7 @@ void mem_cgroup_update_page_stat(struct page *page,
2007 bool need_unlock = false; 1859 bool need_unlock = false;
2008 unsigned long uninitialized_var(flags); 1860 unsigned long uninitialized_var(flags);
2009 1861
2010 if (unlikely(!pc)) 1862 if (mem_cgroup_disabled())
2011 return; 1863 return;
2012 1864
2013 rcu_read_lock(); 1865 rcu_read_lock();
@@ -2238,7 +2090,7 @@ static int __cpuinit memcg_cpu_hotplug_callback(struct notifier_block *nb,
2238 struct mem_cgroup *iter; 2090 struct mem_cgroup *iter;
2239 2091
2240 if ((action == CPU_ONLINE)) { 2092 if ((action == CPU_ONLINE)) {
2241 for_each_mem_cgroup_all(iter) 2093 for_each_mem_cgroup(iter)
2242 synchronize_mem_cgroup_on_move(iter, cpu); 2094 synchronize_mem_cgroup_on_move(iter, cpu);
2243 return NOTIFY_OK; 2095 return NOTIFY_OK;
2244 } 2096 }
@@ -2246,7 +2098,7 @@ static int __cpuinit memcg_cpu_hotplug_callback(struct notifier_block *nb,
2246 if ((action != CPU_DEAD) || action != CPU_DEAD_FROZEN) 2098 if ((action != CPU_DEAD) || action != CPU_DEAD_FROZEN)
2247 return NOTIFY_OK; 2099 return NOTIFY_OK;
2248 2100
2249 for_each_mem_cgroup_all(iter) 2101 for_each_mem_cgroup(iter)
2250 mem_cgroup_drain_pcp_counter(iter, cpu); 2102 mem_cgroup_drain_pcp_counter(iter, cpu);
2251 2103
2252 stock = &per_cpu(memcg_stock, cpu); 2104 stock = &per_cpu(memcg_stock, cpu);
@@ -2300,8 +2152,7 @@ static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
2300 if (!(gfp_mask & __GFP_WAIT)) 2152 if (!(gfp_mask & __GFP_WAIT))
2301 return CHARGE_WOULDBLOCK; 2153 return CHARGE_WOULDBLOCK;
2302 2154
2303 ret = mem_cgroup_hierarchical_reclaim(mem_over_limit, NULL, 2155 ret = mem_cgroup_reclaim(mem_over_limit, gfp_mask, flags);
2304 gfp_mask, flags, NULL);
2305 if (mem_cgroup_margin(mem_over_limit) >= nr_pages) 2156 if (mem_cgroup_margin(mem_over_limit) >= nr_pages)
2306 return CHARGE_RETRY; 2157 return CHARGE_RETRY;
2307 /* 2158 /*
@@ -2334,8 +2185,25 @@ static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
2334} 2185}
2335 2186
2336/* 2187/*
2337 * Unlike exported interface, "oom" parameter is added. if oom==true, 2188 * __mem_cgroup_try_charge() does
2338 * oom-killer can be invoked. 2189 * 1. detect memcg to be charged against from passed *mm and *ptr,
2190 * 2. update res_counter
2191 * 3. call memory reclaim if necessary.
2192 *
2193 * In some special case, if the task is fatal, fatal_signal_pending() or
2194 * has TIF_MEMDIE, this function returns -EINTR while writing root_mem_cgroup
2195 * to *ptr. There are two reasons for this. 1: fatal threads should quit as soon
2196 * as possible without any hazards. 2: all pages should have a valid
2197 * pc->mem_cgroup. If mm is NULL and the caller doesn't pass a valid memcg
2198 * pointer, that is treated as a charge to root_mem_cgroup.
2199 *
2200 * So __mem_cgroup_try_charge() will return
2201 * 0 ... on success, filling *ptr with a valid memcg pointer.
2202 * -ENOMEM ... charge failure because of resource limits.
2203 * -EINTR ... if thread is fatal. *ptr is filled with root_mem_cgroup.
2204 *
2205 * Unlike the exported interface, an "oom" parameter is added. if oom==true,
2206 * the oom-killer can be invoked.
2339 */ 2207 */
2340static int __mem_cgroup_try_charge(struct mm_struct *mm, 2208static int __mem_cgroup_try_charge(struct mm_struct *mm,
2341 gfp_t gfp_mask, 2209 gfp_t gfp_mask,
@@ -2364,7 +2232,7 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
2364 * set, if so charge the init_mm (happens for pagecache usage). 2232 * set, if so charge the init_mm (happens for pagecache usage).
2365 */ 2233 */
2366 if (!*ptr && !mm) 2234 if (!*ptr && !mm)
2367 goto bypass; 2235 *ptr = root_mem_cgroup;
2368again: 2236again:
2369 if (*ptr) { /* css should be a valid one */ 2237 if (*ptr) { /* css should be a valid one */
2370 memcg = *ptr; 2238 memcg = *ptr;
@@ -2390,7 +2258,9 @@ again:
2390 * task-struct. So, mm->owner can be NULL. 2258 * task-struct. So, mm->owner can be NULL.
2391 */ 2259 */
2392 memcg = mem_cgroup_from_task(p); 2260 memcg = mem_cgroup_from_task(p);
2393 if (!memcg || mem_cgroup_is_root(memcg)) { 2261 if (!memcg)
2262 memcg = root_mem_cgroup;
2263 if (mem_cgroup_is_root(memcg)) {
2394 rcu_read_unlock(); 2264 rcu_read_unlock();
2395 goto done; 2265 goto done;
2396 } 2266 }
@@ -2465,8 +2335,8 @@ nomem:
2465 *ptr = NULL; 2335 *ptr = NULL;
2466 return -ENOMEM; 2336 return -ENOMEM;
2467bypass: 2337bypass:
2468 *ptr = NULL; 2338 *ptr = root_mem_cgroup;
2469 return 0; 2339 return -EINTR;
2470} 2340}
2471 2341
2472/* 2342/*
@@ -2522,7 +2392,7 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
2522 memcg = NULL; 2392 memcg = NULL;
2523 } else if (PageSwapCache(page)) { 2393 } else if (PageSwapCache(page)) {
2524 ent.val = page_private(page); 2394 ent.val = page_private(page);
2525 id = lookup_swap_cgroup(ent); 2395 id = lookup_swap_cgroup_id(ent);
2526 rcu_read_lock(); 2396 rcu_read_lock();
2527 memcg = mem_cgroup_lookup(id); 2397 memcg = mem_cgroup_lookup(id);
2528 if (memcg && !css_tryget(&memcg->css)) 2398 if (memcg && !css_tryget(&memcg->css))
@@ -2574,6 +2444,7 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,
2574 2444
2575 mem_cgroup_charge_statistics(memcg, PageCgroupCache(pc), nr_pages); 2445 mem_cgroup_charge_statistics(memcg, PageCgroupCache(pc), nr_pages);
2576 unlock_page_cgroup(pc); 2446 unlock_page_cgroup(pc);
2447 WARN_ON_ONCE(PageLRU(page));
2577 /* 2448 /*
2578 * "charge_statistics" updated event counter. Then, check it. 2449 * "charge_statistics" updated event counter. Then, check it.
2579 * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree. 2450 * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree.
@@ -2585,44 +2456,29 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,
2585#ifdef CONFIG_TRANSPARENT_HUGEPAGE 2456#ifdef CONFIG_TRANSPARENT_HUGEPAGE
2586 2457
2587#define PCGF_NOCOPY_AT_SPLIT ((1 << PCG_LOCK) | (1 << PCG_MOVE_LOCK) |\ 2458#define PCGF_NOCOPY_AT_SPLIT ((1 << PCG_LOCK) | (1 << PCG_MOVE_LOCK) |\
2588 (1 << PCG_ACCT_LRU) | (1 << PCG_MIGRATION)) 2459 (1 << PCG_MIGRATION))
2589/* 2460/*
2590 * Because tail pages are not marked as "used", set it. We're under 2461 * Because tail pages are not marked as "used", set it. We're under
2591 * zone->lru_lock, 'splitting on pmd' and compund_lock. 2462 * zone->lru_lock, 'splitting on pmd' and compound_lock.
2463 * charge/uncharge will be never happen and move_account() is done under
2464 * compound_lock(), so we don't have to take care of races.
2592 */ 2465 */
2593void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail) 2466void mem_cgroup_split_huge_fixup(struct page *head)
2594{ 2467{
2595 struct page_cgroup *head_pc = lookup_page_cgroup(head); 2468 struct page_cgroup *head_pc = lookup_page_cgroup(head);
2596 struct page_cgroup *tail_pc = lookup_page_cgroup(tail); 2469 struct page_cgroup *pc;
2597 unsigned long flags; 2470 int i;
2598 2471
2599 if (mem_cgroup_disabled()) 2472 if (mem_cgroup_disabled())
2600 return; 2473 return;
2601 /* 2474 for (i = 1; i < HPAGE_PMD_NR; i++) {
2602 * We have no races with charge/uncharge but will have races with 2475 pc = head_pc + i;
2603 * page state accounting. 2476 pc->mem_cgroup = head_pc->mem_cgroup;
2604 */ 2477 smp_wmb();/* see __commit_charge() */
2605 move_lock_page_cgroup(head_pc, &flags); 2478 pc->flags = head_pc->flags & ~PCGF_NOCOPY_AT_SPLIT;
2606
2607 tail_pc->mem_cgroup = head_pc->mem_cgroup;
2608 smp_wmb(); /* see __commit_charge() */
2609 if (PageCgroupAcctLRU(head_pc)) {
2610 enum lru_list lru;
2611 struct mem_cgroup_per_zone *mz;
2612
2613 /*
2614 * LRU flags cannot be copied because we need to add tail
2615 *.page to LRU by generic call and our hook will be called.
2616 * We hold lru_lock, then, reduce counter directly.
2617 */
2618 lru = page_lru(head);
2619 mz = page_cgroup_zoneinfo(head_pc->mem_cgroup, head);
2620 MEM_CGROUP_ZSTAT(mz, lru) -= 1;
2621 } 2479 }
2622 tail_pc->flags = head_pc->flags & ~PCGF_NOCOPY_AT_SPLIT;
2623 move_unlock_page_cgroup(head_pc, &flags);
2624} 2480}
2625#endif 2481#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
2626 2482
2627/** 2483/**
2628 * mem_cgroup_move_account - move account of the page 2484 * mem_cgroup_move_account - move account of the page
@@ -2737,7 +2593,7 @@ static int mem_cgroup_move_parent(struct page *page,
2737 2593
2738 parent = mem_cgroup_from_cont(pcg); 2594 parent = mem_cgroup_from_cont(pcg);
2739 ret = __mem_cgroup_try_charge(NULL, gfp_mask, nr_pages, &parent, false); 2595 ret = __mem_cgroup_try_charge(NULL, gfp_mask, nr_pages, &parent, false);
2740 if (ret || !parent) 2596 if (ret)
2741 goto put_back; 2597 goto put_back;
2742 2598
2743 if (nr_pages > 1) 2599 if (nr_pages > 1)
@@ -2783,12 +2639,9 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
2783 } 2639 }
2784 2640
2785 pc = lookup_page_cgroup(page); 2641 pc = lookup_page_cgroup(page);
2786 BUG_ON(!pc); /* XXX: remove this and move pc lookup into commit */
2787
2788 ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &memcg, oom); 2642 ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &memcg, oom);
2789 if (ret || !memcg) 2643 if (ret == -ENOMEM)
2790 return ret; 2644 return ret;
2791
2792 __mem_cgroup_commit_charge(memcg, page, nr_pages, pc, ctype); 2645 __mem_cgroup_commit_charge(memcg, page, nr_pages, pc, ctype);
2793 return 0; 2646 return 0;
2794} 2647}
@@ -2798,19 +2651,11 @@ int mem_cgroup_newpage_charge(struct page *page,
2798{ 2651{
2799 if (mem_cgroup_disabled()) 2652 if (mem_cgroup_disabled())
2800 return 0; 2653 return 0;
2801 /* 2654 VM_BUG_ON(page_mapped(page));
2802 * If already mapped, we don't have to account. 2655 VM_BUG_ON(page->mapping && !PageAnon(page));
2803 * If page cache, page->mapping has address_space. 2656 VM_BUG_ON(!mm);
2804 * But page->mapping may have out-of-use anon_vma pointer,
2805 * detecit it by PageAnon() check. newly-mapped-anon's page->mapping
2806 * is NULL.
2807 */
2808 if (page_mapped(page) || (page->mapping && !PageAnon(page)))
2809 return 0;
2810 if (unlikely(!mm))
2811 mm = &init_mm;
2812 return mem_cgroup_charge_common(page, mm, gfp_mask, 2657 return mem_cgroup_charge_common(page, mm, gfp_mask,
2813 MEM_CGROUP_CHARGE_TYPE_MAPPED); 2658 MEM_CGROUP_CHARGE_TYPE_MAPPED);
2814} 2659}
2815 2660
2816static void 2661static void
@@ -2822,14 +2667,27 @@ __mem_cgroup_commit_charge_lrucare(struct page *page, struct mem_cgroup *memcg,
2822 enum charge_type ctype) 2667 enum charge_type ctype)
2823{ 2668{
2824 struct page_cgroup *pc = lookup_page_cgroup(page); 2669 struct page_cgroup *pc = lookup_page_cgroup(page);
2670 struct zone *zone = page_zone(page);
2671 unsigned long flags;
2672 bool removed = false;
2673
2825 /* 2674 /*
2826 * In some case, SwapCache, FUSE(splice_buf->radixtree), the page 2675 * In some case, SwapCache, FUSE(splice_buf->radixtree), the page
2827 * is already on LRU. It means the page may on some other page_cgroup's 2676 * is already on LRU. It means the page may on some other page_cgroup's
2828 * LRU. Take care of it. 2677 * LRU. Take care of it.
2829 */ 2678 */
2830 mem_cgroup_lru_del_before_commit(page); 2679 spin_lock_irqsave(&zone->lru_lock, flags);
2680 if (PageLRU(page)) {
2681 del_page_from_lru_list(zone, page, page_lru(page));
2682 ClearPageLRU(page);
2683 removed = true;
2684 }
2831 __mem_cgroup_commit_charge(memcg, page, 1, pc, ctype); 2685 __mem_cgroup_commit_charge(memcg, page, 1, pc, ctype);
2832 mem_cgroup_lru_add_after_commit(page); 2686 if (removed) {
2687 add_page_to_lru_list(zone, page, page_lru(page));
2688 SetPageLRU(page);
2689 }
2690 spin_unlock_irqrestore(&zone->lru_lock, flags);
2833 return; 2691 return;
2834} 2692}
2835 2693
@@ -2837,6 +2695,7 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
2837 gfp_t gfp_mask) 2695 gfp_t gfp_mask)
2838{ 2696{
2839 struct mem_cgroup *memcg = NULL; 2697 struct mem_cgroup *memcg = NULL;
2698 enum charge_type type = MEM_CGROUP_CHARGE_TYPE_CACHE;
2840 int ret; 2699 int ret;
2841 2700
2842 if (mem_cgroup_disabled()) 2701 if (mem_cgroup_disabled())
@@ -2846,31 +2705,16 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
2846 2705
2847 if (unlikely(!mm)) 2706 if (unlikely(!mm))
2848 mm = &init_mm; 2707 mm = &init_mm;
2708 if (!page_is_file_cache(page))
2709 type = MEM_CGROUP_CHARGE_TYPE_SHMEM;
2849 2710
2850 if (page_is_file_cache(page)) { 2711 if (!PageSwapCache(page))
2851 ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &memcg, true); 2712 ret = mem_cgroup_charge_common(page, mm, gfp_mask, type);
2852 if (ret || !memcg) 2713 else { /* page is swapcache/shmem */
2853 return ret;
2854
2855 /*
2856 * FUSE reuses pages without going through the final
2857 * put that would remove them from the LRU list, make
2858 * sure that they get relinked properly.
2859 */
2860 __mem_cgroup_commit_charge_lrucare(page, memcg,
2861 MEM_CGROUP_CHARGE_TYPE_CACHE);
2862 return ret;
2863 }
2864 /* shmem */
2865 if (PageSwapCache(page)) {
2866 ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg); 2714 ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg);
2867 if (!ret) 2715 if (!ret)
2868 __mem_cgroup_commit_charge_swapin(page, memcg, 2716 __mem_cgroup_commit_charge_swapin(page, memcg, type);
2869 MEM_CGROUP_CHARGE_TYPE_SHMEM); 2717 }
2870 } else
2871 ret = mem_cgroup_charge_common(page, mm, gfp_mask,
2872 MEM_CGROUP_CHARGE_TYPE_SHMEM);
2873
2874 return ret; 2718 return ret;
2875} 2719}
2876 2720
@@ -2882,12 +2726,12 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
2882 */ 2726 */
2883int mem_cgroup_try_charge_swapin(struct mm_struct *mm, 2727int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
2884 struct page *page, 2728 struct page *page,
2885 gfp_t mask, struct mem_cgroup **ptr) 2729 gfp_t mask, struct mem_cgroup **memcgp)
2886{ 2730{
2887 struct mem_cgroup *memcg; 2731 struct mem_cgroup *memcg;
2888 int ret; 2732 int ret;
2889 2733
2890 *ptr = NULL; 2734 *memcgp = NULL;
2891 2735
2892 if (mem_cgroup_disabled()) 2736 if (mem_cgroup_disabled())
2893 return 0; 2737 return 0;
@@ -2905,27 +2749,32 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
2905 memcg = try_get_mem_cgroup_from_page(page); 2749 memcg = try_get_mem_cgroup_from_page(page);
2906 if (!memcg) 2750 if (!memcg)
2907 goto charge_cur_mm; 2751 goto charge_cur_mm;
2908 *ptr = memcg; 2752 *memcgp = memcg;
2909 ret = __mem_cgroup_try_charge(NULL, mask, 1, ptr, true); 2753 ret = __mem_cgroup_try_charge(NULL, mask, 1, memcgp, true);
2910 css_put(&memcg->css); 2754 css_put(&memcg->css);
2755 if (ret == -EINTR)
2756 ret = 0;
2911 return ret; 2757 return ret;
2912charge_cur_mm: 2758charge_cur_mm:
2913 if (unlikely(!mm)) 2759 if (unlikely(!mm))
2914 mm = &init_mm; 2760 mm = &init_mm;
2915 return __mem_cgroup_try_charge(mm, mask, 1, ptr, true); 2761 ret = __mem_cgroup_try_charge(mm, mask, 1, memcgp, true);
2762 if (ret == -EINTR)
2763 ret = 0;
2764 return ret;
2916} 2765}
2917 2766
2918static void 2767static void
2919__mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr, 2768__mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *memcg,
2920 enum charge_type ctype) 2769 enum charge_type ctype)
2921{ 2770{
2922 if (mem_cgroup_disabled()) 2771 if (mem_cgroup_disabled())
2923 return; 2772 return;
2924 if (!ptr) 2773 if (!memcg)
2925 return; 2774 return;
2926 cgroup_exclude_rmdir(&ptr->css); 2775 cgroup_exclude_rmdir(&memcg->css);
2927 2776
2928 __mem_cgroup_commit_charge_lrucare(page, ptr, ctype); 2777 __mem_cgroup_commit_charge_lrucare(page, memcg, ctype);
2929 /* 2778 /*
2930 * Now swap is on-memory. This means this page may be 2779 * Now swap is on-memory. This means this page may be
2931 * counted both as mem and swap....double count. 2780 * counted both as mem and swap....double count.
@@ -2935,21 +2784,22 @@ __mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr,
2935 */ 2784 */
2936 if (do_swap_account && PageSwapCache(page)) { 2785 if (do_swap_account && PageSwapCache(page)) {
2937 swp_entry_t ent = {.val = page_private(page)}; 2786 swp_entry_t ent = {.val = page_private(page)};
2787 struct mem_cgroup *swap_memcg;
2938 unsigned short id; 2788 unsigned short id;
2939 struct mem_cgroup *memcg;
2940 2789
2941 id = swap_cgroup_record(ent, 0); 2790 id = swap_cgroup_record(ent, 0);
2942 rcu_read_lock(); 2791 rcu_read_lock();
2943 memcg = mem_cgroup_lookup(id); 2792 swap_memcg = mem_cgroup_lookup(id);
2944 if (memcg) { 2793 if (swap_memcg) {
2945 /* 2794 /*
2946 * This recorded memcg can be obsolete one. So, avoid 2795 * This recorded memcg can be obsolete one. So, avoid
2947 * calling css_tryget 2796 * calling css_tryget
2948 */ 2797 */
2949 if (!mem_cgroup_is_root(memcg)) 2798 if (!mem_cgroup_is_root(swap_memcg))
2950 res_counter_uncharge(&memcg->memsw, PAGE_SIZE); 2799 res_counter_uncharge(&swap_memcg->memsw,
2951 mem_cgroup_swap_statistics(memcg, false); 2800 PAGE_SIZE);
2952 mem_cgroup_put(memcg); 2801 mem_cgroup_swap_statistics(swap_memcg, false);
2802 mem_cgroup_put(swap_memcg);
2953 } 2803 }
2954 rcu_read_unlock(); 2804 rcu_read_unlock();
2955 } 2805 }
@@ -2958,13 +2808,14 @@ __mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr,
2958 * So, rmdir()->pre_destroy() can be called while we do this charge. 2808 * So, rmdir()->pre_destroy() can be called while we do this charge.
2959 * In that case, we need to call pre_destroy() again. check it here. 2809 * In that case, we need to call pre_destroy() again. check it here.
2960 */ 2810 */
2961 cgroup_release_and_wakeup_rmdir(&ptr->css); 2811 cgroup_release_and_wakeup_rmdir(&memcg->css);
2962} 2812}
2963 2813
2964void mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr) 2814void mem_cgroup_commit_charge_swapin(struct page *page,
2815 struct mem_cgroup *memcg)
2965{ 2816{
2966 __mem_cgroup_commit_charge_swapin(page, ptr, 2817 __mem_cgroup_commit_charge_swapin(page, memcg,
2967 MEM_CGROUP_CHARGE_TYPE_MAPPED); 2818 MEM_CGROUP_CHARGE_TYPE_MAPPED);
2968} 2819}
2969 2820
2970void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg) 2821void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
@@ -3054,7 +2905,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
3054 * Check if our page_cgroup is valid 2905 * Check if our page_cgroup is valid
3055 */ 2906 */
3056 pc = lookup_page_cgroup(page); 2907 pc = lookup_page_cgroup(page);
3057 if (unlikely(!pc || !PageCgroupUsed(pc))) 2908 if (unlikely(!PageCgroupUsed(pc)))
3058 return NULL; 2909 return NULL;
3059 2910
3060 lock_page_cgroup(pc); 2911 lock_page_cgroup(pc);
@@ -3117,8 +2968,7 @@ void mem_cgroup_uncharge_page(struct page *page)
3117 /* early check. */ 2968 /* early check. */
3118 if (page_mapped(page)) 2969 if (page_mapped(page))
3119 return; 2970 return;
3120 if (page->mapping && !PageAnon(page)) 2971 VM_BUG_ON(page->mapping && !PageAnon(page));
3121 return;
3122 __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_MAPPED); 2972 __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_MAPPED);
3123} 2973}
3124 2974
@@ -3176,6 +3026,23 @@ void mem_cgroup_uncharge_end(void)
3176 batch->memcg = NULL; 3026 batch->memcg = NULL;
3177} 3027}
3178 3028
3029/*
3030 * A function for resetting pc->mem_cgroup for newly allocated pages.
3031 * This function should be called if the newpage will be added to LRU
3032 * before start accounting.
3033 */
3034void mem_cgroup_reset_owner(struct page *newpage)
3035{
3036 struct page_cgroup *pc;
3037
3038 if (mem_cgroup_disabled())
3039 return;
3040
3041 pc = lookup_page_cgroup(newpage);
3042 VM_BUG_ON(PageCgroupUsed(pc));
3043 pc->mem_cgroup = root_mem_cgroup;
3044}
3045
3179#ifdef CONFIG_SWAP 3046#ifdef CONFIG_SWAP
3180/* 3047/*
3181 * called after __delete_from_swap_cache() and drop "page" account. 3048 * called after __delete_from_swap_cache() and drop "page" account.
@@ -3293,14 +3160,14 @@ static inline int mem_cgroup_move_swap_account(swp_entry_t entry,
3293 * page belongs to. 3160 * page belongs to.
3294 */ 3161 */
3295int mem_cgroup_prepare_migration(struct page *page, 3162int mem_cgroup_prepare_migration(struct page *page,
3296 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask) 3163 struct page *newpage, struct mem_cgroup **memcgp, gfp_t gfp_mask)
3297{ 3164{
3298 struct mem_cgroup *memcg = NULL; 3165 struct mem_cgroup *memcg = NULL;
3299 struct page_cgroup *pc; 3166 struct page_cgroup *pc;
3300 enum charge_type ctype; 3167 enum charge_type ctype;
3301 int ret = 0; 3168 int ret = 0;
3302 3169
3303 *ptr = NULL; 3170 *memcgp = NULL;
3304 3171
3305 VM_BUG_ON(PageTransHuge(page)); 3172 VM_BUG_ON(PageTransHuge(page));
3306 if (mem_cgroup_disabled()) 3173 if (mem_cgroup_disabled())
@@ -3351,10 +3218,10 @@ int mem_cgroup_prepare_migration(struct page *page,
3351 if (!memcg) 3218 if (!memcg)
3352 return 0; 3219 return 0;
3353 3220
3354 *ptr = memcg; 3221 *memcgp = memcg;
3355 ret = __mem_cgroup_try_charge(NULL, gfp_mask, 1, ptr, false); 3222 ret = __mem_cgroup_try_charge(NULL, gfp_mask, 1, memcgp, false);
3356 css_put(&memcg->css);/* drop extra refcnt */ 3223 css_put(&memcg->css);/* drop extra refcnt */
3357 if (ret || *ptr == NULL) { 3224 if (ret) {
3358 if (PageAnon(page)) { 3225 if (PageAnon(page)) {
3359 lock_page_cgroup(pc); 3226 lock_page_cgroup(pc);
3360 ClearPageCgroupMigration(pc); 3227 ClearPageCgroupMigration(pc);
@@ -3364,6 +3231,7 @@ int mem_cgroup_prepare_migration(struct page *page,
3364 */ 3231 */
3365 mem_cgroup_uncharge_page(page); 3232 mem_cgroup_uncharge_page(page);
3366 } 3233 }
3234 /* we'll need to revisit this error code (we have -EINTR) */
3367 return -ENOMEM; 3235 return -ENOMEM;
3368 } 3236 }
3369 /* 3237 /*
@@ -3432,12 +3300,51 @@ void mem_cgroup_end_migration(struct mem_cgroup *memcg,
3432 cgroup_release_and_wakeup_rmdir(&memcg->css); 3300 cgroup_release_and_wakeup_rmdir(&memcg->css);
3433} 3301}
3434 3302
3303/*
3304 * At replace page cache, newpage is not under any memcg but it's on
3305 * LRU. So, this function doesn't touch res_counter but handles LRU
3306 * in correct way. Both pages are locked so we cannot race with uncharge.
3307 */
3308void mem_cgroup_replace_page_cache(struct page *oldpage,
3309 struct page *newpage)
3310{
3311 struct mem_cgroup *memcg;
3312 struct page_cgroup *pc;
3313 enum charge_type type = MEM_CGROUP_CHARGE_TYPE_CACHE;
3314
3315 if (mem_cgroup_disabled())
3316 return;
3317
3318 pc = lookup_page_cgroup(oldpage);
3319 /* fix accounting on old pages */
3320 lock_page_cgroup(pc);
3321 memcg = pc->mem_cgroup;
3322 mem_cgroup_charge_statistics(memcg, PageCgroupCache(pc), -1);
3323 ClearPageCgroupUsed(pc);
3324 unlock_page_cgroup(pc);
3325
3326 if (PageSwapBacked(oldpage))
3327 type = MEM_CGROUP_CHARGE_TYPE_SHMEM;
3328
3329 /*
3330 * Even if newpage->mapping was NULL before starting replacement,
3331 * the newpage may be on LRU(or pagevec for LRU) already. We lock
3332 * LRU while we overwrite pc->mem_cgroup.
3333 */
3334 __mem_cgroup_commit_charge_lrucare(newpage, memcg, type);
3335}
3336
3435#ifdef CONFIG_DEBUG_VM 3337#ifdef CONFIG_DEBUG_VM
3436static struct page_cgroup *lookup_page_cgroup_used(struct page *page) 3338static struct page_cgroup *lookup_page_cgroup_used(struct page *page)
3437{ 3339{
3438 struct page_cgroup *pc; 3340 struct page_cgroup *pc;
3439 3341
3440 pc = lookup_page_cgroup(page); 3342 pc = lookup_page_cgroup(page);
3343 /*
3344 * Can be NULL while feeding pages into the page allocator for
3345 * the first time, i.e. during boot or memory hotplug;
3346 * or when mem_cgroup_disabled().
3347 */
3441 if (likely(pc) && PageCgroupUsed(pc)) 3348 if (likely(pc) && PageCgroupUsed(pc))
3442 return pc; 3349 return pc;
3443 return NULL; 3350 return NULL;
@@ -3457,23 +3364,8 @@ void mem_cgroup_print_bad_page(struct page *page)
3457 3364
3458 pc = lookup_page_cgroup_used(page); 3365 pc = lookup_page_cgroup_used(page);
3459 if (pc) { 3366 if (pc) {
3460 int ret = -1; 3367 printk(KERN_ALERT "pc:%p pc->flags:%lx pc->mem_cgroup:%p\n",
3461 char *path;
3462
3463 printk(KERN_ALERT "pc:%p pc->flags:%lx pc->mem_cgroup:%p",
3464 pc, pc->flags, pc->mem_cgroup); 3368 pc, pc->flags, pc->mem_cgroup);
3465
3466 path = kmalloc(PATH_MAX, GFP_KERNEL);
3467 if (path) {
3468 rcu_read_lock();
3469 ret = cgroup_path(pc->mem_cgroup->css.cgroup,
3470 path, PATH_MAX);
3471 rcu_read_unlock();
3472 }
3473
3474 printk(KERN_CONT "(%s)\n",
3475 (ret < 0) ? "cannot get the path" : path);
3476 kfree(path);
3477 } 3369 }
3478} 3370}
3479#endif 3371#endif
@@ -3534,9 +3426,8 @@ static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
3534 if (!ret) 3426 if (!ret)
3535 break; 3427 break;
3536 3428
3537 mem_cgroup_hierarchical_reclaim(memcg, NULL, GFP_KERNEL, 3429 mem_cgroup_reclaim(memcg, GFP_KERNEL,
3538 MEM_CGROUP_RECLAIM_SHRINK, 3430 MEM_CGROUP_RECLAIM_SHRINK);
3539 NULL);
3540 curusage = res_counter_read_u64(&memcg->res, RES_USAGE); 3431 curusage = res_counter_read_u64(&memcg->res, RES_USAGE);
3541 /* Usage is reduced ? */ 3432 /* Usage is reduced ? */
3542 if (curusage >= oldusage) 3433 if (curusage >= oldusage)
@@ -3594,10 +3485,9 @@ static int mem_cgroup_resize_memsw_limit(struct mem_cgroup *memcg,
3594 if (!ret) 3485 if (!ret)
3595 break; 3486 break;
3596 3487
3597 mem_cgroup_hierarchical_reclaim(memcg, NULL, GFP_KERNEL, 3488 mem_cgroup_reclaim(memcg, GFP_KERNEL,
3598 MEM_CGROUP_RECLAIM_NOSWAP | 3489 MEM_CGROUP_RECLAIM_NOSWAP |
3599 MEM_CGROUP_RECLAIM_SHRINK, 3490 MEM_CGROUP_RECLAIM_SHRINK);
3600 NULL);
3601 curusage = res_counter_read_u64(&memcg->memsw, RES_USAGE); 3491 curusage = res_counter_read_u64(&memcg->memsw, RES_USAGE);
3602 /* Usage is reduced ? */ 3492 /* Usage is reduced ? */
3603 if (curusage >= oldusage) 3493 if (curusage >= oldusage)
@@ -3640,10 +3530,8 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
3640 break; 3530 break;
3641 3531
3642 nr_scanned = 0; 3532 nr_scanned = 0;
3643 reclaimed = mem_cgroup_hierarchical_reclaim(mz->mem, zone, 3533 reclaimed = mem_cgroup_soft_reclaim(mz->mem, zone,
3644 gfp_mask, 3534 gfp_mask, &nr_scanned);
3645 MEM_CGROUP_RECLAIM_SOFT,
3646 &nr_scanned);
3647 nr_reclaimed += reclaimed; 3535 nr_reclaimed += reclaimed;
3648 *total_scanned += nr_scanned; 3536 *total_scanned += nr_scanned;
3649 spin_lock(&mctz->lock); 3537 spin_lock(&mctz->lock);
@@ -3711,22 +3599,23 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
3711static int mem_cgroup_force_empty_list(struct mem_cgroup *memcg, 3599static int mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
3712 int node, int zid, enum lru_list lru) 3600 int node, int zid, enum lru_list lru)
3713{ 3601{
3714 struct zone *zone;
3715 struct mem_cgroup_per_zone *mz; 3602 struct mem_cgroup_per_zone *mz;
3716 struct page_cgroup *pc, *busy;
3717 unsigned long flags, loop; 3603 unsigned long flags, loop;
3718 struct list_head *list; 3604 struct list_head *list;
3605 struct page *busy;
3606 struct zone *zone;
3719 int ret = 0; 3607 int ret = 0;
3720 3608
3721 zone = &NODE_DATA(node)->node_zones[zid]; 3609 zone = &NODE_DATA(node)->node_zones[zid];
3722 mz = mem_cgroup_zoneinfo(memcg, node, zid); 3610 mz = mem_cgroup_zoneinfo(memcg, node, zid);
3723 list = &mz->lists[lru]; 3611 list = &mz->lruvec.lists[lru];
3724 3612
3725 loop = MEM_CGROUP_ZSTAT(mz, lru); 3613 loop = MEM_CGROUP_ZSTAT(mz, lru);
3726 /* give some margin against EBUSY etc...*/ 3614 /* give some margin against EBUSY etc...*/
3727 loop += 256; 3615 loop += 256;
3728 busy = NULL; 3616 busy = NULL;
3729 while (loop--) { 3617 while (loop--) {
3618 struct page_cgroup *pc;
3730 struct page *page; 3619 struct page *page;
3731 3620
3732 ret = 0; 3621 ret = 0;
@@ -3735,24 +3624,24 @@ static int mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
3735 spin_unlock_irqrestore(&zone->lru_lock, flags); 3624 spin_unlock_irqrestore(&zone->lru_lock, flags);
3736 break; 3625 break;
3737 } 3626 }
3738 pc = list_entry(list->prev, struct page_cgroup, lru); 3627 page = list_entry(list->prev, struct page, lru);
3739 if (busy == pc) { 3628 if (busy == page) {
3740 list_move(&pc->lru, list); 3629 list_move(&page->lru, list);
3741 busy = NULL; 3630 busy = NULL;
3742 spin_unlock_irqrestore(&zone->lru_lock, flags); 3631 spin_unlock_irqrestore(&zone->lru_lock, flags);
3743 continue; 3632 continue;
3744 } 3633 }
3745 spin_unlock_irqrestore(&zone->lru_lock, flags); 3634 spin_unlock_irqrestore(&zone->lru_lock, flags);
3746 3635
3747 page = lookup_cgroup_page(pc); 3636 pc = lookup_page_cgroup(page);
3748 3637
3749 ret = mem_cgroup_move_parent(page, pc, memcg, GFP_KERNEL); 3638 ret = mem_cgroup_move_parent(page, pc, memcg, GFP_KERNEL);
3750 if (ret == -ENOMEM) 3639 if (ret == -ENOMEM || ret == -EINTR)
3751 break; 3640 break;
3752 3641
3753 if (ret == -EBUSY || ret == -EINVAL) { 3642 if (ret == -EBUSY || ret == -EINVAL) {
3754 /* found lock contention or "pc" is obsolete. */ 3643 /* found lock contention or "pc" is obsolete. */
3755 busy = pc; 3644 busy = page;
3756 cond_resched(); 3645 cond_resched();
3757 } else 3646 } else
3758 busy = NULL; 3647 busy = NULL;
@@ -4846,7 +4735,7 @@ static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *memcg, int node)
4846 for (zone = 0; zone < MAX_NR_ZONES; zone++) { 4735 for (zone = 0; zone < MAX_NR_ZONES; zone++) {
4847 mz = &pn->zoneinfo[zone]; 4736 mz = &pn->zoneinfo[zone];
4848 for_each_lru(l) 4737 for_each_lru(l)
4849 INIT_LIST_HEAD(&mz->lists[l]); 4738 INIT_LIST_HEAD(&mz->lruvec.lists[l]);
4850 mz->usage_in_excess = 0; 4739 mz->usage_in_excess = 0;
4851 mz->on_tree = false; 4740 mz->on_tree = false;
4852 mz->mem = memcg; 4741 mz->mem = memcg;
@@ -4906,7 +4795,7 @@ static void __mem_cgroup_free(struct mem_cgroup *memcg)
4906 mem_cgroup_remove_from_trees(memcg); 4795 mem_cgroup_remove_from_trees(memcg);
4907 free_css_id(&mem_cgroup_subsys, &memcg->css); 4796 free_css_id(&mem_cgroup_subsys, &memcg->css);
4908 4797
4909 for_each_node_state(node, N_POSSIBLE) 4798 for_each_node(node)
4910 free_mem_cgroup_per_zone_info(memcg, node); 4799 free_mem_cgroup_per_zone_info(memcg, node);
4911 4800
4912 free_percpu(memcg->stat); 4801 free_percpu(memcg->stat);
@@ -4965,13 +4854,13 @@ static int mem_cgroup_soft_limit_tree_init(void)
4965 struct mem_cgroup_tree_per_zone *rtpz; 4854 struct mem_cgroup_tree_per_zone *rtpz;
4966 int tmp, node, zone; 4855 int tmp, node, zone;
4967 4856
4968 for_each_node_state(node, N_POSSIBLE) { 4857 for_each_node(node) {
4969 tmp = node; 4858 tmp = node;
4970 if (!node_state(node, N_NORMAL_MEMORY)) 4859 if (!node_state(node, N_NORMAL_MEMORY))
4971 tmp = -1; 4860 tmp = -1;
4972 rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, tmp); 4861 rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, tmp);
4973 if (!rtpn) 4862 if (!rtpn)
4974 return 1; 4863 goto err_cleanup;
4975 4864
4976 soft_limit_tree.rb_tree_per_node[node] = rtpn; 4865 soft_limit_tree.rb_tree_per_node[node] = rtpn;
4977 4866
@@ -4982,6 +4871,16 @@ static int mem_cgroup_soft_limit_tree_init(void)
4982 } 4871 }
4983 } 4872 }
4984 return 0; 4873 return 0;
4874
4875err_cleanup:
4876 for_each_node(node) {
4877 if (!soft_limit_tree.rb_tree_per_node[node])
4878 break;
4879 kfree(soft_limit_tree.rb_tree_per_node[node]);
4880 soft_limit_tree.rb_tree_per_node[node] = NULL;
4881 }
4882 return 1;
4883
4985} 4884}
4986 4885
4987static struct cgroup_subsys_state * __ref 4886static struct cgroup_subsys_state * __ref
@@ -4995,7 +4894,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
4995 if (!memcg) 4894 if (!memcg)
4996 return ERR_PTR(error); 4895 return ERR_PTR(error);
4997 4896
4998 for_each_node_state(node, N_POSSIBLE) 4897 for_each_node(node)
4999 if (alloc_mem_cgroup_per_zone_info(memcg, node)) 4898 if (alloc_mem_cgroup_per_zone_info(memcg, node))
5000 goto free_out; 4899 goto free_out;
5001 4900
@@ -5033,7 +4932,6 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
5033 res_counter_init(&memcg->res, NULL); 4932 res_counter_init(&memcg->res, NULL);
5034 res_counter_init(&memcg->memsw, NULL); 4933 res_counter_init(&memcg->memsw, NULL);
5035 } 4934 }
5036 memcg->last_scanned_child = 0;
5037 memcg->last_scanned_node = MAX_NUMNODES; 4935 memcg->last_scanned_node = MAX_NUMNODES;
5038 INIT_LIST_HEAD(&memcg->oom_notify); 4936 INIT_LIST_HEAD(&memcg->oom_notify);
5039 4937
@@ -5129,9 +5027,9 @@ one_by_one:
5129 } 5027 }
5130 ret = __mem_cgroup_try_charge(NULL, 5028 ret = __mem_cgroup_try_charge(NULL,
5131 GFP_KERNEL, 1, &memcg, false); 5029 GFP_KERNEL, 1, &memcg, false);
5132 if (ret || !memcg) 5030 if (ret)
5133 /* mem_cgroup_clear_mc() will do uncharge later */ 5031 /* mem_cgroup_clear_mc() will do uncharge later */
5134 return -ENOMEM; 5032 return ret;
5135 mc.precharge++; 5033 mc.precharge++;
5136 } 5034 }
5137 return ret; 5035 return ret;
@@ -5276,7 +5174,7 @@ static int is_target_pte_for_mc(struct vm_area_struct *vma,
5276 } 5174 }
5277 /* There is a swap entry and a page doesn't exist or isn't charged */ 5175 /* There is a swap entry and a page doesn't exist or isn't charged */
5278 if (ent.val && !ret && 5176 if (ent.val && !ret &&
5279 css_id(&mc.from->css) == lookup_swap_cgroup(ent)) { 5177 css_id(&mc.from->css) == lookup_swap_cgroup_id(ent)) {
5280 ret = MC_TARGET_SWAP; 5178 ret = MC_TARGET_SWAP;
5281 if (target) 5179 if (target)
5282 target->ent = ent; 5180 target->ent = ent;
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 06d3479513aa..56080ea36140 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1557,7 +1557,7 @@ int soft_offline_page(struct page *page, int flags)
1557 page_is_file_cache(page)); 1557 page_is_file_cache(page));
1558 list_add(&page->lru, &pagelist); 1558 list_add(&page->lru, &pagelist);
1559 ret = migrate_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL, 1559 ret = migrate_pages(&pagelist, new_page, MPOL_MF_MOVE_ALL,
1560 0, true); 1560 0, MIGRATE_SYNC);
1561 if (ret) { 1561 if (ret) {
1562 putback_lru_pages(&pagelist); 1562 putback_lru_pages(&pagelist);
1563 pr_info("soft offline: %#lx: migration failed %d, type %lx\n", 1563 pr_info("soft offline: %#lx: migration failed %d, type %lx\n",
diff --git a/mm/memory.c b/mm/memory.c
index 829d43735402..5e30583c2605 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -293,7 +293,7 @@ int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
293{ 293{
294 struct mmu_gather_batch *batch; 294 struct mmu_gather_batch *batch;
295 295
296 tlb->need_flush = 1; 296 VM_BUG_ON(!tlb->need_flush);
297 297
298 if (tlb_fast_mode(tlb)) { 298 if (tlb_fast_mode(tlb)) {
299 free_page_and_swap_cache(page); 299 free_page_and_swap_cache(page);
@@ -1231,7 +1231,7 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb,
1231 if (next-addr != HPAGE_PMD_SIZE) { 1231 if (next-addr != HPAGE_PMD_SIZE) {
1232 VM_BUG_ON(!rwsem_is_locked(&tlb->mm->mmap_sem)); 1232 VM_BUG_ON(!rwsem_is_locked(&tlb->mm->mmap_sem));
1233 split_huge_page_pmd(vma->vm_mm, pmd); 1233 split_huge_page_pmd(vma->vm_mm, pmd);
1234 } else if (zap_huge_pmd(tlb, vma, pmd)) 1234 } else if (zap_huge_pmd(tlb, vma, pmd, addr))
1235 continue; 1235 continue;
1236 /* fall through */ 1236 /* fall through */
1237 } 1237 }
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 2168489c0bc9..6629fafd6ce4 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -809,7 +809,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
809 } 809 }
810 /* this function returns # of failed pages */ 810 /* this function returns # of failed pages */
811 ret = migrate_pages(&source, hotremove_migrate_alloc, 0, 811 ret = migrate_pages(&source, hotremove_migrate_alloc, 0,
812 true, true); 812 true, MIGRATE_SYNC);
813 if (ret) 813 if (ret)
814 putback_lru_pages(&source); 814 putback_lru_pages(&source);
815 } 815 }
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index e3d58f088466..06b145fb64ab 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -942,7 +942,7 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
942 942
943 if (!list_empty(&pagelist)) { 943 if (!list_empty(&pagelist)) {
944 err = migrate_pages(&pagelist, new_node_page, dest, 944 err = migrate_pages(&pagelist, new_node_page, dest,
945 false, true); 945 false, MIGRATE_SYNC);
946 if (err) 946 if (err)
947 putback_lru_pages(&pagelist); 947 putback_lru_pages(&pagelist);
948 } 948 }
diff --git a/mm/migrate.c b/mm/migrate.c
index 89ea0854332e..9871a56d82c3 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -216,6 +216,56 @@ out:
216 pte_unmap_unlock(ptep, ptl); 216 pte_unmap_unlock(ptep, ptl);
217} 217}
218 218
219#ifdef CONFIG_BLOCK
220/* Returns true if all buffers are successfully locked */
221static bool buffer_migrate_lock_buffers(struct buffer_head *head,
222 enum migrate_mode mode)
223{
224 struct buffer_head *bh = head;
225
226 /* Simple case, sync compaction */
227 if (mode != MIGRATE_ASYNC) {
228 do {
229 get_bh(bh);
230 lock_buffer(bh);
231 bh = bh->b_this_page;
232
233 } while (bh != head);
234
235 return true;
236 }
237
238 /* async case, we cannot block on lock_buffer so use trylock_buffer */
239 do {
240 get_bh(bh);
241 if (!trylock_buffer(bh)) {
242 /*
243 * We failed to lock the buffer and cannot stall in
244 * async migration. Release the taken locks
245 */
246 struct buffer_head *failed_bh = bh;
247 put_bh(failed_bh);
248 bh = head;
249 while (bh != failed_bh) {
250 unlock_buffer(bh);
251 put_bh(bh);
252 bh = bh->b_this_page;
253 }
254 return false;
255 }
256
257 bh = bh->b_this_page;
258 } while (bh != head);
259 return true;
260}
261#else
262static inline bool buffer_migrate_lock_buffers(struct buffer_head *head,
263 enum migrate_mode mode)
264{
265 return true;
266}
267#endif /* CONFIG_BLOCK */
268
219/* 269/*
220 * Replace the page in the mapping. 270 * Replace the page in the mapping.
221 * 271 *
@@ -225,7 +275,8 @@ out:
225 * 3 for pages with a mapping and PagePrivate/PagePrivate2 set. 275 * 3 for pages with a mapping and PagePrivate/PagePrivate2 set.
226 */ 276 */
227static int migrate_page_move_mapping(struct address_space *mapping, 277static int migrate_page_move_mapping(struct address_space *mapping,
228 struct page *newpage, struct page *page) 278 struct page *newpage, struct page *page,
279 struct buffer_head *head, enum migrate_mode mode)
229{ 280{
230 int expected_count; 281 int expected_count;
231 void **pslot; 282 void **pslot;
@@ -255,6 +306,20 @@ static int migrate_page_move_mapping(struct address_space *mapping,
255 } 306 }
256 307
257 /* 308 /*
309 * In the async migration case of moving a page with buffers, lock the
310 * buffers using trylock before the mapping is moved. If the mapping
311 * was moved, we later failed to lock the buffers and could not move
312 * the mapping back due to an elevated page count, we would have to
313 * block waiting on other references to be dropped.
314 */
315 if (mode == MIGRATE_ASYNC && head &&
316 !buffer_migrate_lock_buffers(head, mode)) {
317 page_unfreeze_refs(page, expected_count);
318 spin_unlock_irq(&mapping->tree_lock);
319 return -EAGAIN;
320 }
321
322 /*
258 * Now we know that no one else is looking at the page. 323 * Now we know that no one else is looking at the page.
259 */ 324 */
260 get_page(newpage); /* add cache reference */ 325 get_page(newpage); /* add cache reference */
@@ -409,13 +474,14 @@ EXPORT_SYMBOL(fail_migrate_page);
409 * Pages are locked upon entry and exit. 474 * Pages are locked upon entry and exit.
410 */ 475 */
411int migrate_page(struct address_space *mapping, 476int migrate_page(struct address_space *mapping,
412 struct page *newpage, struct page *page) 477 struct page *newpage, struct page *page,
478 enum migrate_mode mode)
413{ 479{
414 int rc; 480 int rc;
415 481
416 BUG_ON(PageWriteback(page)); /* Writeback must be complete */ 482 BUG_ON(PageWriteback(page)); /* Writeback must be complete */
417 483
418 rc = migrate_page_move_mapping(mapping, newpage, page); 484 rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode);
419 485
420 if (rc) 486 if (rc)
421 return rc; 487 return rc;
@@ -432,28 +498,28 @@ EXPORT_SYMBOL(migrate_page);
432 * exist. 498 * exist.
433 */ 499 */
434int buffer_migrate_page(struct address_space *mapping, 500int buffer_migrate_page(struct address_space *mapping,
435 struct page *newpage, struct page *page) 501 struct page *newpage, struct page *page, enum migrate_mode mode)
436{ 502{
437 struct buffer_head *bh, *head; 503 struct buffer_head *bh, *head;
438 int rc; 504 int rc;
439 505
440 if (!page_has_buffers(page)) 506 if (!page_has_buffers(page))
441 return migrate_page(mapping, newpage, page); 507 return migrate_page(mapping, newpage, page, mode);
442 508
443 head = page_buffers(page); 509 head = page_buffers(page);
444 510
445 rc = migrate_page_move_mapping(mapping, newpage, page); 511 rc = migrate_page_move_mapping(mapping, newpage, page, head, mode);
446 512
447 if (rc) 513 if (rc)
448 return rc; 514 return rc;
449 515
450 bh = head; 516 /*
451 do { 517 * In the async case, migrate_page_move_mapping locked the buffers
452 get_bh(bh); 518 * with an IRQ-safe spinlock held. In the sync case, the buffers
453 lock_buffer(bh); 519 * need to be locked now
454 bh = bh->b_this_page; 520 */
455 521 if (mode != MIGRATE_ASYNC)
456 } while (bh != head); 522 BUG_ON(!buffer_migrate_lock_buffers(head, mode));
457 523
458 ClearPagePrivate(page); 524 ClearPagePrivate(page);
459 set_page_private(newpage, page_private(page)); 525 set_page_private(newpage, page_private(page));
@@ -530,10 +596,14 @@ static int writeout(struct address_space *mapping, struct page *page)
530 * Default handling if a filesystem does not provide a migration function. 596 * Default handling if a filesystem does not provide a migration function.
531 */ 597 */
532static int fallback_migrate_page(struct address_space *mapping, 598static int fallback_migrate_page(struct address_space *mapping,
533 struct page *newpage, struct page *page) 599 struct page *newpage, struct page *page, enum migrate_mode mode)
534{ 600{
535 if (PageDirty(page)) 601 if (PageDirty(page)) {
602 /* Only writeback pages in full synchronous migration */
603 if (mode != MIGRATE_SYNC)
604 return -EBUSY;
536 return writeout(mapping, page); 605 return writeout(mapping, page);
606 }
537 607
538 /* 608 /*
539 * Buffers may be managed in a filesystem specific way. 609 * Buffers may be managed in a filesystem specific way.
@@ -543,7 +613,7 @@ static int fallback_migrate_page(struct address_space *mapping,
543 !try_to_release_page(page, GFP_KERNEL)) 613 !try_to_release_page(page, GFP_KERNEL))
544 return -EAGAIN; 614 return -EAGAIN;
545 615
546 return migrate_page(mapping, newpage, page); 616 return migrate_page(mapping, newpage, page, mode);
547} 617}
548 618
549/* 619/*
@@ -558,7 +628,7 @@ static int fallback_migrate_page(struct address_space *mapping,
558 * == 0 - success 628 * == 0 - success
559 */ 629 */
560static int move_to_new_page(struct page *newpage, struct page *page, 630static int move_to_new_page(struct page *newpage, struct page *page,
561 int remap_swapcache, bool sync) 631 int remap_swapcache, enum migrate_mode mode)
562{ 632{
563 struct address_space *mapping; 633 struct address_space *mapping;
564 int rc; 634 int rc;
@@ -579,29 +649,18 @@ static int move_to_new_page(struct page *newpage, struct page *page,
579 649
580 mapping = page_mapping(page); 650 mapping = page_mapping(page);
581 if (!mapping) 651 if (!mapping)
582 rc = migrate_page(mapping, newpage, page); 652 rc = migrate_page(mapping, newpage, page, mode);
583 else { 653 else if (mapping->a_ops->migratepage)
584 /* 654 /*
585 * Do not writeback pages if !sync and migratepage is 655 * Most pages have a mapping and most filesystems provide a
586 * not pointing to migrate_page() which is nonblocking 656 * migratepage callback. Anonymous pages are part of swap
587 * (swapcache/tmpfs uses migratepage = migrate_page). 657 * space which also has its own migratepage callback. This
658 * is the most common path for page migration.
588 */ 659 */
589 if (PageDirty(page) && !sync && 660 rc = mapping->a_ops->migratepage(mapping,
590 mapping->a_ops->migratepage != migrate_page) 661 newpage, page, mode);
591 rc = -EBUSY; 662 else
592 else if (mapping->a_ops->migratepage) 663 rc = fallback_migrate_page(mapping, newpage, page, mode);
593 /*
594 * Most pages have a mapping and most filesystems
595 * should provide a migration function. Anonymous
596 * pages are part of swap space which also has its
597 * own migration function. This is the most common
598 * path for page migration.
599 */
600 rc = mapping->a_ops->migratepage(mapping,
601 newpage, page);
602 else
603 rc = fallback_migrate_page(mapping, newpage, page);
604 }
605 664
606 if (rc) { 665 if (rc) {
607 newpage->mapping = NULL; 666 newpage->mapping = NULL;
@@ -616,7 +675,7 @@ static int move_to_new_page(struct page *newpage, struct page *page,
616} 675}
617 676
618static int __unmap_and_move(struct page *page, struct page *newpage, 677static int __unmap_and_move(struct page *page, struct page *newpage,
619 int force, bool offlining, bool sync) 678 int force, bool offlining, enum migrate_mode mode)
620{ 679{
621 int rc = -EAGAIN; 680 int rc = -EAGAIN;
622 int remap_swapcache = 1; 681 int remap_swapcache = 1;
@@ -625,7 +684,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
625 struct anon_vma *anon_vma = NULL; 684 struct anon_vma *anon_vma = NULL;
626 685
627 if (!trylock_page(page)) { 686 if (!trylock_page(page)) {
628 if (!force || !sync) 687 if (!force || mode == MIGRATE_ASYNC)
629 goto out; 688 goto out;
630 689
631 /* 690 /*
@@ -671,10 +730,12 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
671 730
672 if (PageWriteback(page)) { 731 if (PageWriteback(page)) {
673 /* 732 /*
674 * For !sync, there is no point retrying as the retry loop 733 * Only in the case of a full syncronous migration is it
675 * is expected to be too short for PageWriteback to be cleared 734 * necessary to wait for PageWriteback. In the async case,
735 * the retry loop is too short and in the sync-light case,
736 * the overhead of stalling is too much
676 */ 737 */
677 if (!sync) { 738 if (mode != MIGRATE_SYNC) {
678 rc = -EBUSY; 739 rc = -EBUSY;
679 goto uncharge; 740 goto uncharge;
680 } 741 }
@@ -745,7 +806,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,
745 806
746skip_unmap: 807skip_unmap:
747 if (!page_mapped(page)) 808 if (!page_mapped(page))
748 rc = move_to_new_page(newpage, page, remap_swapcache, sync); 809 rc = move_to_new_page(newpage, page, remap_swapcache, mode);
749 810
750 if (rc && remap_swapcache) 811 if (rc && remap_swapcache)
751 remove_migration_ptes(page, page); 812 remove_migration_ptes(page, page);
@@ -768,7 +829,8 @@ out:
768 * to the newly allocated page in newpage. 829 * to the newly allocated page in newpage.
769 */ 830 */
770static int unmap_and_move(new_page_t get_new_page, unsigned long private, 831static int unmap_and_move(new_page_t get_new_page, unsigned long private,
771 struct page *page, int force, bool offlining, bool sync) 832 struct page *page, int force, bool offlining,
833 enum migrate_mode mode)
772{ 834{
773 int rc = 0; 835 int rc = 0;
774 int *result = NULL; 836 int *result = NULL;
@@ -777,6 +839,8 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
777 if (!newpage) 839 if (!newpage)
778 return -ENOMEM; 840 return -ENOMEM;
779 841
842 mem_cgroup_reset_owner(newpage);
843
780 if (page_count(page) == 1) { 844 if (page_count(page) == 1) {
781 /* page was freed from under us. So we are done. */ 845 /* page was freed from under us. So we are done. */
782 goto out; 846 goto out;
@@ -786,7 +850,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
786 if (unlikely(split_huge_page(page))) 850 if (unlikely(split_huge_page(page)))
787 goto out; 851 goto out;
788 852
789 rc = __unmap_and_move(page, newpage, force, offlining, sync); 853 rc = __unmap_and_move(page, newpage, force, offlining, mode);
790out: 854out:
791 if (rc != -EAGAIN) { 855 if (rc != -EAGAIN) {
792 /* 856 /*
@@ -834,7 +898,8 @@ out:
834 */ 898 */
835static int unmap_and_move_huge_page(new_page_t get_new_page, 899static int unmap_and_move_huge_page(new_page_t get_new_page,
836 unsigned long private, struct page *hpage, 900 unsigned long private, struct page *hpage,
837 int force, bool offlining, bool sync) 901 int force, bool offlining,
902 enum migrate_mode mode)
838{ 903{
839 int rc = 0; 904 int rc = 0;
840 int *result = NULL; 905 int *result = NULL;
@@ -847,7 +912,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
847 rc = -EAGAIN; 912 rc = -EAGAIN;
848 913
849 if (!trylock_page(hpage)) { 914 if (!trylock_page(hpage)) {
850 if (!force || !sync) 915 if (!force || mode != MIGRATE_SYNC)
851 goto out; 916 goto out;
852 lock_page(hpage); 917 lock_page(hpage);
853 } 918 }
@@ -858,7 +923,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
858 try_to_unmap(hpage, TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS); 923 try_to_unmap(hpage, TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS);
859 924
860 if (!page_mapped(hpage)) 925 if (!page_mapped(hpage))
861 rc = move_to_new_page(new_hpage, hpage, 1, sync); 926 rc = move_to_new_page(new_hpage, hpage, 1, mode);
862 927
863 if (rc) 928 if (rc)
864 remove_migration_ptes(hpage, hpage); 929 remove_migration_ptes(hpage, hpage);
@@ -901,7 +966,7 @@ out:
901 */ 966 */
902int migrate_pages(struct list_head *from, 967int migrate_pages(struct list_head *from,
903 new_page_t get_new_page, unsigned long private, bool offlining, 968 new_page_t get_new_page, unsigned long private, bool offlining,
904 bool sync) 969 enum migrate_mode mode)
905{ 970{
906 int retry = 1; 971 int retry = 1;
907 int nr_failed = 0; 972 int nr_failed = 0;
@@ -922,7 +987,7 @@ int migrate_pages(struct list_head *from,
922 987
923 rc = unmap_and_move(get_new_page, private, 988 rc = unmap_and_move(get_new_page, private,
924 page, pass > 2, offlining, 989 page, pass > 2, offlining,
925 sync); 990 mode);
926 991
927 switch(rc) { 992 switch(rc) {
928 case -ENOMEM: 993 case -ENOMEM:
@@ -952,7 +1017,7 @@ out:
952 1017
953int migrate_huge_pages(struct list_head *from, 1018int migrate_huge_pages(struct list_head *from,
954 new_page_t get_new_page, unsigned long private, bool offlining, 1019 new_page_t get_new_page, unsigned long private, bool offlining,
955 bool sync) 1020 enum migrate_mode mode)
956{ 1021{
957 int retry = 1; 1022 int retry = 1;
958 int nr_failed = 0; 1023 int nr_failed = 0;
@@ -969,7 +1034,7 @@ int migrate_huge_pages(struct list_head *from,
969 1034
970 rc = unmap_and_move_huge_page(get_new_page, 1035 rc = unmap_and_move_huge_page(get_new_page,
971 private, page, pass > 2, offlining, 1036 private, page, pass > 2, offlining,
972 sync); 1037 mode);
973 1038
974 switch(rc) { 1039 switch(rc) {
975 case -ENOMEM: 1040 case -ENOMEM:
@@ -1098,7 +1163,7 @@ set_status:
1098 err = 0; 1163 err = 0;
1099 if (!list_empty(&pagelist)) { 1164 if (!list_empty(&pagelist)) {
1100 err = migrate_pages(&pagelist, new_page_node, 1165 err = migrate_pages(&pagelist, new_page_node,
1101 (unsigned long)pm, 0, true); 1166 (unsigned long)pm, 0, MIGRATE_SYNC);
1102 if (err) 1167 if (err)
1103 putback_lru_pages(&pagelist); 1168 putback_lru_pages(&pagelist);
1104 } 1169 }
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 7c122faa05c5..2958fd8e7c9a 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -152,7 +152,7 @@ struct task_struct *find_lock_task_mm(struct task_struct *p)
152 152
153/* return true if the task is not adequate as candidate victim task. */ 153/* return true if the task is not adequate as candidate victim task. */
154static bool oom_unkillable_task(struct task_struct *p, 154static bool oom_unkillable_task(struct task_struct *p,
155 const struct mem_cgroup *mem, const nodemask_t *nodemask) 155 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
156{ 156{
157 if (is_global_init(p)) 157 if (is_global_init(p))
158 return true; 158 return true;
@@ -160,7 +160,7 @@ static bool oom_unkillable_task(struct task_struct *p,
160 return true; 160 return true;
161 161
162 /* When mem_cgroup_out_of_memory() and p is not member of the group */ 162 /* When mem_cgroup_out_of_memory() and p is not member of the group */
163 if (mem && !task_in_mem_cgroup(p, mem)) 163 if (memcg && !task_in_mem_cgroup(p, memcg))
164 return true; 164 return true;
165 165
166 /* p may not have freeable memory in nodemask */ 166 /* p may not have freeable memory in nodemask */
@@ -179,12 +179,12 @@ static bool oom_unkillable_task(struct task_struct *p,
179 * predictable as possible. The goal is to return the highest value for the 179 * predictable as possible. The goal is to return the highest value for the
180 * task consuming the most memory to avoid subsequent oom failures. 180 * task consuming the most memory to avoid subsequent oom failures.
181 */ 181 */
182unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem, 182unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *memcg,
183 const nodemask_t *nodemask, unsigned long totalpages) 183 const nodemask_t *nodemask, unsigned long totalpages)
184{ 184{
185 long points; 185 long points;
186 186
187 if (oom_unkillable_task(p, mem, nodemask)) 187 if (oom_unkillable_task(p, memcg, nodemask))
188 return 0; 188 return 0;
189 189
190 p = find_lock_task_mm(p); 190 p = find_lock_task_mm(p);
@@ -308,7 +308,7 @@ static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
308 * (not docbooked, we don't want this one cluttering up the manual) 308 * (not docbooked, we don't want this one cluttering up the manual)
309 */ 309 */
310static struct task_struct *select_bad_process(unsigned int *ppoints, 310static struct task_struct *select_bad_process(unsigned int *ppoints,
311 unsigned long totalpages, struct mem_cgroup *mem, 311 unsigned long totalpages, struct mem_cgroup *memcg,
312 const nodemask_t *nodemask) 312 const nodemask_t *nodemask)
313{ 313{
314 struct task_struct *g, *p; 314 struct task_struct *g, *p;
@@ -320,7 +320,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
320 320
321 if (p->exit_state) 321 if (p->exit_state)
322 continue; 322 continue;
323 if (oom_unkillable_task(p, mem, nodemask)) 323 if (oom_unkillable_task(p, memcg, nodemask))
324 continue; 324 continue;
325 325
326 /* 326 /*
@@ -364,7 +364,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
364 } 364 }
365 } 365 }
366 366
367 points = oom_badness(p, mem, nodemask, totalpages); 367 points = oom_badness(p, memcg, nodemask, totalpages);
368 if (points > *ppoints) { 368 if (points > *ppoints) {
369 chosen = p; 369 chosen = p;
370 *ppoints = points; 370 *ppoints = points;
@@ -387,14 +387,14 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
387 * 387 *
388 * Call with tasklist_lock read-locked. 388 * Call with tasklist_lock read-locked.
389 */ 389 */
390static void dump_tasks(const struct mem_cgroup *mem, const nodemask_t *nodemask) 390static void dump_tasks(const struct mem_cgroup *memcg, const nodemask_t *nodemask)
391{ 391{
392 struct task_struct *p; 392 struct task_struct *p;
393 struct task_struct *task; 393 struct task_struct *task;
394 394
395 pr_info("[ pid ] uid tgid total_vm rss cpu oom_adj oom_score_adj name\n"); 395 pr_info("[ pid ] uid tgid total_vm rss cpu oom_adj oom_score_adj name\n");
396 for_each_process(p) { 396 for_each_process(p) {
397 if (oom_unkillable_task(p, mem, nodemask)) 397 if (oom_unkillable_task(p, memcg, nodemask))
398 continue; 398 continue;
399 399
400 task = find_lock_task_mm(p); 400 task = find_lock_task_mm(p);
@@ -417,7 +417,7 @@ static void dump_tasks(const struct mem_cgroup *mem, const nodemask_t *nodemask)
417} 417}
418 418
419static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order, 419static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
420 struct mem_cgroup *mem, const nodemask_t *nodemask) 420 struct mem_cgroup *memcg, const nodemask_t *nodemask)
421{ 421{
422 task_lock(current); 422 task_lock(current);
423 pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, " 423 pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, "
@@ -427,14 +427,14 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
427 cpuset_print_task_mems_allowed(current); 427 cpuset_print_task_mems_allowed(current);
428 task_unlock(current); 428 task_unlock(current);
429 dump_stack(); 429 dump_stack();
430 mem_cgroup_print_oom_info(mem, p); 430 mem_cgroup_print_oom_info(memcg, p);
431 show_mem(SHOW_MEM_FILTER_NODES); 431 show_mem(SHOW_MEM_FILTER_NODES);
432 if (sysctl_oom_dump_tasks) 432 if (sysctl_oom_dump_tasks)
433 dump_tasks(mem, nodemask); 433 dump_tasks(memcg, nodemask);
434} 434}
435 435
436#define K(x) ((x) << (PAGE_SHIFT-10)) 436#define K(x) ((x) << (PAGE_SHIFT-10))
437static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) 437static int oom_kill_task(struct task_struct *p)
438{ 438{
439 struct task_struct *q; 439 struct task_struct *q;
440 struct mm_struct *mm; 440 struct mm_struct *mm;
@@ -484,7 +484,7 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
484 484
485static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, 485static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
486 unsigned int points, unsigned long totalpages, 486 unsigned int points, unsigned long totalpages,
487 struct mem_cgroup *mem, nodemask_t *nodemask, 487 struct mem_cgroup *memcg, nodemask_t *nodemask,
488 const char *message) 488 const char *message)
489{ 489{
490 struct task_struct *victim = p; 490 struct task_struct *victim = p;
@@ -493,7 +493,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
493 unsigned int victim_points = 0; 493 unsigned int victim_points = 0;
494 494
495 if (printk_ratelimit()) 495 if (printk_ratelimit())
496 dump_header(p, gfp_mask, order, mem, nodemask); 496 dump_header(p, gfp_mask, order, memcg, nodemask);
497 497
498 /* 498 /*
499 * If the task is already exiting, don't alarm the sysadmin or kill 499 * If the task is already exiting, don't alarm the sysadmin or kill
@@ -524,7 +524,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
524 /* 524 /*
525 * oom_badness() returns 0 if the thread is unkillable 525 * oom_badness() returns 0 if the thread is unkillable
526 */ 526 */
527 child_points = oom_badness(child, mem, nodemask, 527 child_points = oom_badness(child, memcg, nodemask,
528 totalpages); 528 totalpages);
529 if (child_points > victim_points) { 529 if (child_points > victim_points) {
530 victim = child; 530 victim = child;
@@ -533,7 +533,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
533 } 533 }
534 } while_each_thread(p, t); 534 } while_each_thread(p, t);
535 535
536 return oom_kill_task(victim, mem); 536 return oom_kill_task(victim);
537} 537}
538 538
539/* 539/*
@@ -561,7 +561,7 @@ static void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask,
561} 561}
562 562
563#ifdef CONFIG_CGROUP_MEM_RES_CTLR 563#ifdef CONFIG_CGROUP_MEM_RES_CTLR
564void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask) 564void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask)
565{ 565{
566 unsigned long limit; 566 unsigned long limit;
567 unsigned int points = 0; 567 unsigned int points = 0;
@@ -578,14 +578,14 @@ void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
578 } 578 }
579 579
580 check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, 0, NULL); 580 check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, 0, NULL);
581 limit = mem_cgroup_get_limit(mem) >> PAGE_SHIFT; 581 limit = mem_cgroup_get_limit(memcg) >> PAGE_SHIFT;
582 read_lock(&tasklist_lock); 582 read_lock(&tasklist_lock);
583retry: 583retry:
584 p = select_bad_process(&points, limit, mem, NULL); 584 p = select_bad_process(&points, limit, memcg, NULL);
585 if (!p || PTR_ERR(p) == -1UL) 585 if (!p || PTR_ERR(p) == -1UL)
586 goto out; 586 goto out;
587 587
588 if (oom_kill_process(p, gfp_mask, 0, points, limit, mem, NULL, 588 if (oom_kill_process(p, gfp_mask, 0, points, limit, memcg, NULL,
589 "Memory cgroup out of memory")) 589 "Memory cgroup out of memory"))
590 goto retry; 590 goto retry;
591out: 591out:
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 794e6715c226..0027d8f4a1bb 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1981,14 +1981,20 @@ static struct page *
1981__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, 1981__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
1982 struct zonelist *zonelist, enum zone_type high_zoneidx, 1982 struct zonelist *zonelist, enum zone_type high_zoneidx,
1983 nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone, 1983 nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone,
1984 int migratetype, unsigned long *did_some_progress, 1984 int migratetype, bool sync_migration,
1985 bool sync_migration) 1985 bool *deferred_compaction,
1986 unsigned long *did_some_progress)
1986{ 1987{
1987 struct page *page; 1988 struct page *page;
1988 1989
1989 if (!order || compaction_deferred(preferred_zone)) 1990 if (!order)
1990 return NULL; 1991 return NULL;
1991 1992
1993 if (compaction_deferred(preferred_zone)) {
1994 *deferred_compaction = true;
1995 return NULL;
1996 }
1997
1992 current->flags |= PF_MEMALLOC; 1998 current->flags |= PF_MEMALLOC;
1993 *did_some_progress = try_to_compact_pages(zonelist, order, gfp_mask, 1999 *did_some_progress = try_to_compact_pages(zonelist, order, gfp_mask,
1994 nodemask, sync_migration); 2000 nodemask, sync_migration);
@@ -2016,7 +2022,13 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
2016 * but not enough to satisfy watermarks. 2022 * but not enough to satisfy watermarks.
2017 */ 2023 */
2018 count_vm_event(COMPACTFAIL); 2024 count_vm_event(COMPACTFAIL);
2019 defer_compaction(preferred_zone); 2025
2026 /*
2027 * As async compaction considers a subset of pageblocks, only
2028 * defer if the failure was a sync compaction failure.
2029 */
2030 if (sync_migration)
2031 defer_compaction(preferred_zone);
2020 2032
2021 cond_resched(); 2033 cond_resched();
2022 } 2034 }
@@ -2028,8 +2040,9 @@ static inline struct page *
2028__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, 2040__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
2029 struct zonelist *zonelist, enum zone_type high_zoneidx, 2041 struct zonelist *zonelist, enum zone_type high_zoneidx,
2030 nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone, 2042 nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone,
2031 int migratetype, unsigned long *did_some_progress, 2043 int migratetype, bool sync_migration,
2032 bool sync_migration) 2044 bool *deferred_compaction,
2045 unsigned long *did_some_progress)
2033{ 2046{
2034 return NULL; 2047 return NULL;
2035} 2048}
@@ -2179,6 +2192,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
2179 unsigned long pages_reclaimed = 0; 2192 unsigned long pages_reclaimed = 0;
2180 unsigned long did_some_progress; 2193 unsigned long did_some_progress;
2181 bool sync_migration = false; 2194 bool sync_migration = false;
2195 bool deferred_compaction = false;
2182 2196
2183 /* 2197 /*
2184 * In the slowpath, we sanity check order to avoid ever trying to 2198 * In the slowpath, we sanity check order to avoid ever trying to
@@ -2259,12 +2273,22 @@ rebalance:
2259 zonelist, high_zoneidx, 2273 zonelist, high_zoneidx,
2260 nodemask, 2274 nodemask,
2261 alloc_flags, preferred_zone, 2275 alloc_flags, preferred_zone,
2262 migratetype, &did_some_progress, 2276 migratetype, sync_migration,
2263 sync_migration); 2277 &deferred_compaction,
2278 &did_some_progress);
2264 if (page) 2279 if (page)
2265 goto got_pg; 2280 goto got_pg;
2266 sync_migration = true; 2281 sync_migration = true;
2267 2282
2283 /*
2284 * If compaction is deferred for high-order allocations, it is because
2285 * sync compaction recently failed. In this is the case and the caller
2286 * has requested the system not be heavily disrupted, fail the
2287 * allocation now instead of entering direct reclaim
2288 */
2289 if (deferred_compaction && (gfp_mask & __GFP_NO_KSWAPD))
2290 goto nopage;
2291
2268 /* Try direct reclaim and then allocating */ 2292 /* Try direct reclaim and then allocating */
2269 page = __alloc_pages_direct_reclaim(gfp_mask, order, 2293 page = __alloc_pages_direct_reclaim(gfp_mask, order,
2270 zonelist, high_zoneidx, 2294 zonelist, high_zoneidx,
@@ -2328,8 +2352,9 @@ rebalance:
2328 zonelist, high_zoneidx, 2352 zonelist, high_zoneidx,
2329 nodemask, 2353 nodemask,
2330 alloc_flags, preferred_zone, 2354 alloc_flags, preferred_zone,
2331 migratetype, &did_some_progress, 2355 migratetype, sync_migration,
2332 sync_migration); 2356 &deferred_compaction,
2357 &did_some_progress);
2333 if (page) 2358 if (page)
2334 goto got_pg; 2359 goto got_pg;
2335 } 2360 }
@@ -4237,7 +4262,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat,
4237 for (j = 0; j < MAX_NR_ZONES; j++) { 4262 for (j = 0; j < MAX_NR_ZONES; j++) {
4238 struct zone *zone = pgdat->node_zones + j; 4263 struct zone *zone = pgdat->node_zones + j;
4239 unsigned long size, realsize, memmap_pages; 4264 unsigned long size, realsize, memmap_pages;
4240 enum lru_list l; 4265 enum lru_list lru;
4241 4266
4242 size = zone_spanned_pages_in_node(nid, j, zones_size); 4267 size = zone_spanned_pages_in_node(nid, j, zones_size);
4243 realsize = size - zone_absent_pages_in_node(nid, j, 4268 realsize = size - zone_absent_pages_in_node(nid, j,
@@ -4287,8 +4312,8 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat,
4287 zone->zone_pgdat = pgdat; 4312 zone->zone_pgdat = pgdat;
4288 4313
4289 zone_pcp_init(zone); 4314 zone_pcp_init(zone);
4290 for_each_lru(l) 4315 for_each_lru(lru)
4291 INIT_LIST_HEAD(&zone->lru[l].list); 4316 INIT_LIST_HEAD(&zone->lruvec.lists[lru]);
4292 zone->reclaim_stat.recent_rotated[0] = 0; 4317 zone->reclaim_stat.recent_rotated[0] = 0;
4293 zone->reclaim_stat.recent_rotated[1] = 0; 4318 zone->reclaim_stat.recent_rotated[1] = 0;
4294 zone->reclaim_stat.recent_scanned[0] = 0; 4319 zone->reclaim_stat.recent_scanned[0] = 0;
@@ -4642,8 +4667,10 @@ static void check_for_regular_memory(pg_data_t *pgdat)
4642 4667
4643 for (zone_type = 0; zone_type <= ZONE_NORMAL; zone_type++) { 4668 for (zone_type = 0; zone_type <= ZONE_NORMAL; zone_type++) {
4644 struct zone *zone = &pgdat->node_zones[zone_type]; 4669 struct zone *zone = &pgdat->node_zones[zone_type];
4645 if (zone->present_pages) 4670 if (zone->present_pages) {
4646 node_set_state(zone_to_nid(zone), N_NORMAL_MEMORY); 4671 node_set_state(zone_to_nid(zone), N_NORMAL_MEMORY);
4672 break;
4673 }
4647 } 4674 }
4648#endif 4675#endif
4649} 4676}
diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c
index 2d123f94a8df..de1616aa9b1e 100644
--- a/mm/page_cgroup.c
+++ b/mm/page_cgroup.c
@@ -11,13 +11,6 @@
11#include <linux/swapops.h> 11#include <linux/swapops.h>
12#include <linux/kmemleak.h> 12#include <linux/kmemleak.h>
13 13
14static void __meminit init_page_cgroup(struct page_cgroup *pc, unsigned long id)
15{
16 pc->flags = 0;
17 set_page_cgroup_array_id(pc, id);
18 pc->mem_cgroup = NULL;
19 INIT_LIST_HEAD(&pc->lru);
20}
21static unsigned long total_usage; 14static unsigned long total_usage;
22 15
23#if !defined(CONFIG_SPARSEMEM) 16#if !defined(CONFIG_SPARSEMEM)
@@ -35,35 +28,27 @@ struct page_cgroup *lookup_page_cgroup(struct page *page)
35 struct page_cgroup *base; 28 struct page_cgroup *base;
36 29
37 base = NODE_DATA(page_to_nid(page))->node_page_cgroup; 30 base = NODE_DATA(page_to_nid(page))->node_page_cgroup;
31#ifdef CONFIG_DEBUG_VM
32 /*
33 * The sanity checks the page allocator does upon freeing a
34 * page can reach here before the page_cgroup arrays are
35 * allocated when feeding a range of pages to the allocator
36 * for the first time during bootup or memory hotplug.
37 */
38 if (unlikely(!base)) 38 if (unlikely(!base))
39 return NULL; 39 return NULL;
40 40#endif
41 offset = pfn - NODE_DATA(page_to_nid(page))->node_start_pfn; 41 offset = pfn - NODE_DATA(page_to_nid(page))->node_start_pfn;
42 return base + offset; 42 return base + offset;
43} 43}
44 44
45struct page *lookup_cgroup_page(struct page_cgroup *pc)
46{
47 unsigned long pfn;
48 struct page *page;
49 pg_data_t *pgdat;
50
51 pgdat = NODE_DATA(page_cgroup_array_id(pc));
52 pfn = pc - pgdat->node_page_cgroup + pgdat->node_start_pfn;
53 page = pfn_to_page(pfn);
54 VM_BUG_ON(pc != lookup_page_cgroup(page));
55 return page;
56}
57
58static int __init alloc_node_page_cgroup(int nid) 45static int __init alloc_node_page_cgroup(int nid)
59{ 46{
60 struct page_cgroup *base, *pc; 47 struct page_cgroup *base;
61 unsigned long table_size; 48 unsigned long table_size;
62 unsigned long start_pfn, nr_pages, index; 49 unsigned long nr_pages;
63 50
64 start_pfn = NODE_DATA(nid)->node_start_pfn;
65 nr_pages = NODE_DATA(nid)->node_spanned_pages; 51 nr_pages = NODE_DATA(nid)->node_spanned_pages;
66
67 if (!nr_pages) 52 if (!nr_pages)
68 return 0; 53 return 0;
69 54
@@ -73,10 +58,6 @@ static int __init alloc_node_page_cgroup(int nid)
73 table_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS)); 58 table_size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
74 if (!base) 59 if (!base)
75 return -ENOMEM; 60 return -ENOMEM;
76 for (index = 0; index < nr_pages; index++) {
77 pc = base + index;
78 init_page_cgroup(pc, nid);
79 }
80 NODE_DATA(nid)->node_page_cgroup = base; 61 NODE_DATA(nid)->node_page_cgroup = base;
81 total_usage += table_size; 62 total_usage += table_size;
82 return 0; 63 return 0;
@@ -111,29 +92,23 @@ struct page_cgroup *lookup_page_cgroup(struct page *page)
111{ 92{
112 unsigned long pfn = page_to_pfn(page); 93 unsigned long pfn = page_to_pfn(page);
113 struct mem_section *section = __pfn_to_section(pfn); 94 struct mem_section *section = __pfn_to_section(pfn);
114 95#ifdef CONFIG_DEBUG_VM
96 /*
97 * The sanity checks the page allocator does upon freeing a
98 * page can reach here before the page_cgroup arrays are
99 * allocated when feeding a range of pages to the allocator
100 * for the first time during bootup or memory hotplug.
101 */
115 if (!section->page_cgroup) 102 if (!section->page_cgroup)
116 return NULL; 103 return NULL;
104#endif
117 return section->page_cgroup + pfn; 105 return section->page_cgroup + pfn;
118} 106}
119 107
120struct page *lookup_cgroup_page(struct page_cgroup *pc)
121{
122 struct mem_section *section;
123 struct page *page;
124 unsigned long nr;
125
126 nr = page_cgroup_array_id(pc);
127 section = __nr_to_section(nr);
128 page = pfn_to_page(pc - section->page_cgroup);
129 VM_BUG_ON(pc != lookup_page_cgroup(page));
130 return page;
131}
132
133static void *__meminit alloc_page_cgroup(size_t size, int nid) 108static void *__meminit alloc_page_cgroup(size_t size, int nid)
134{ 109{
110 gfp_t flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN;
135 void *addr = NULL; 111 void *addr = NULL;
136 gfp_t flags = GFP_KERNEL | __GFP_NOWARN;
137 112
138 addr = alloc_pages_exact_nid(nid, size, flags); 113 addr = alloc_pages_exact_nid(nid, size, flags);
139 if (addr) { 114 if (addr) {
@@ -142,39 +117,20 @@ static void *__meminit alloc_page_cgroup(size_t size, int nid)
142 } 117 }
143 118
144 if (node_state(nid, N_HIGH_MEMORY)) 119 if (node_state(nid, N_HIGH_MEMORY))
145 addr = vmalloc_node(size, nid); 120 addr = vzalloc_node(size, nid);
146 else 121 else
147 addr = vmalloc(size); 122 addr = vzalloc(size);
148 123
149 return addr; 124 return addr;
150} 125}
151 126
152#ifdef CONFIG_MEMORY_HOTPLUG
153static void free_page_cgroup(void *addr)
154{
155 if (is_vmalloc_addr(addr)) {
156 vfree(addr);
157 } else {
158 struct page *page = virt_to_page(addr);
159 size_t table_size =
160 sizeof(struct page_cgroup) * PAGES_PER_SECTION;
161
162 BUG_ON(PageReserved(page));
163 free_pages_exact(addr, table_size);
164 }
165}
166#endif
167
168static int __meminit init_section_page_cgroup(unsigned long pfn, int nid) 127static int __meminit init_section_page_cgroup(unsigned long pfn, int nid)
169{ 128{
170 struct page_cgroup *base, *pc;
171 struct mem_section *section; 129 struct mem_section *section;
130 struct page_cgroup *base;
172 unsigned long table_size; 131 unsigned long table_size;
173 unsigned long nr;
174 int index;
175 132
176 nr = pfn_to_section_nr(pfn); 133 section = __pfn_to_section(pfn);
177 section = __nr_to_section(nr);
178 134
179 if (section->page_cgroup) 135 if (section->page_cgroup)
180 return 0; 136 return 0;
@@ -194,10 +150,6 @@ static int __meminit init_section_page_cgroup(unsigned long pfn, int nid)
194 return -ENOMEM; 150 return -ENOMEM;
195 } 151 }
196 152
197 for (index = 0; index < PAGES_PER_SECTION; index++) {
198 pc = base + index;
199 init_page_cgroup(pc, nr);
200 }
201 /* 153 /*
202 * The passed "pfn" may not be aligned to SECTION. For the calculation 154 * The passed "pfn" may not be aligned to SECTION. For the calculation
203 * we need to apply a mask. 155 * we need to apply a mask.
@@ -208,6 +160,20 @@ static int __meminit init_section_page_cgroup(unsigned long pfn, int nid)
208 return 0; 160 return 0;
209} 161}
210#ifdef CONFIG_MEMORY_HOTPLUG 162#ifdef CONFIG_MEMORY_HOTPLUG
163static void free_page_cgroup(void *addr)
164{
165 if (is_vmalloc_addr(addr)) {
166 vfree(addr);
167 } else {
168 struct page *page = virt_to_page(addr);
169 size_t table_size =
170 sizeof(struct page_cgroup) * PAGES_PER_SECTION;
171
172 BUG_ON(PageReserved(page));
173 free_pages_exact(addr, table_size);
174 }
175}
176
211void __free_page_cgroup(unsigned long pfn) 177void __free_page_cgroup(unsigned long pfn)
212{ 178{
213 struct mem_section *ms; 179 struct mem_section *ms;
@@ -366,7 +332,6 @@ struct swap_cgroup {
366 unsigned short id; 332 unsigned short id;
367}; 333};
368#define SC_PER_PAGE (PAGE_SIZE/sizeof(struct swap_cgroup)) 334#define SC_PER_PAGE (PAGE_SIZE/sizeof(struct swap_cgroup))
369#define SC_POS_MASK (SC_PER_PAGE - 1)
370 335
371/* 336/*
372 * SwapCgroup implements "lookup" and "exchange" operations. 337 * SwapCgroup implements "lookup" and "exchange" operations.
@@ -408,6 +373,21 @@ not_enough_page:
408 return -ENOMEM; 373 return -ENOMEM;
409} 374}
410 375
376static struct swap_cgroup *lookup_swap_cgroup(swp_entry_t ent,
377 struct swap_cgroup_ctrl **ctrlp)
378{
379 pgoff_t offset = swp_offset(ent);
380 struct swap_cgroup_ctrl *ctrl;
381 struct page *mappage;
382
383 ctrl = &swap_cgroup_ctrl[swp_type(ent)];
384 if (ctrlp)
385 *ctrlp = ctrl;
386
387 mappage = ctrl->map[offset / SC_PER_PAGE];
388 return page_address(mappage) + offset % SC_PER_PAGE;
389}
390
411/** 391/**
412 * swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry. 392 * swap_cgroup_cmpxchg - cmpxchg mem_cgroup's id for this swp_entry.
413 * @end: swap entry to be cmpxchged 393 * @end: swap entry to be cmpxchged
@@ -420,21 +400,13 @@ not_enough_page:
420unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, 400unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
421 unsigned short old, unsigned short new) 401 unsigned short old, unsigned short new)
422{ 402{
423 int type = swp_type(ent);
424 unsigned long offset = swp_offset(ent);
425 unsigned long idx = offset / SC_PER_PAGE;
426 unsigned long pos = offset & SC_POS_MASK;
427 struct swap_cgroup_ctrl *ctrl; 403 struct swap_cgroup_ctrl *ctrl;
428 struct page *mappage;
429 struct swap_cgroup *sc; 404 struct swap_cgroup *sc;
430 unsigned long flags; 405 unsigned long flags;
431 unsigned short retval; 406 unsigned short retval;
432 407
433 ctrl = &swap_cgroup_ctrl[type]; 408 sc = lookup_swap_cgroup(ent, &ctrl);
434 409
435 mappage = ctrl->map[idx];
436 sc = page_address(mappage);
437 sc += pos;
438 spin_lock_irqsave(&ctrl->lock, flags); 410 spin_lock_irqsave(&ctrl->lock, flags);
439 retval = sc->id; 411 retval = sc->id;
440 if (retval == old) 412 if (retval == old)
@@ -455,21 +427,13 @@ unsigned short swap_cgroup_cmpxchg(swp_entry_t ent,
455 */ 427 */
456unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id) 428unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
457{ 429{
458 int type = swp_type(ent);
459 unsigned long offset = swp_offset(ent);
460 unsigned long idx = offset / SC_PER_PAGE;
461 unsigned long pos = offset & SC_POS_MASK;
462 struct swap_cgroup_ctrl *ctrl; 430 struct swap_cgroup_ctrl *ctrl;
463 struct page *mappage;
464 struct swap_cgroup *sc; 431 struct swap_cgroup *sc;
465 unsigned short old; 432 unsigned short old;
466 unsigned long flags; 433 unsigned long flags;
467 434
468 ctrl = &swap_cgroup_ctrl[type]; 435 sc = lookup_swap_cgroup(ent, &ctrl);
469 436
470 mappage = ctrl->map[idx];
471 sc = page_address(mappage);
472 sc += pos;
473 spin_lock_irqsave(&ctrl->lock, flags); 437 spin_lock_irqsave(&ctrl->lock, flags);
474 old = sc->id; 438 old = sc->id;
475 sc->id = id; 439 sc->id = id;
@@ -479,28 +443,14 @@ unsigned short swap_cgroup_record(swp_entry_t ent, unsigned short id)
479} 443}
480 444
481/** 445/**
482 * lookup_swap_cgroup - lookup mem_cgroup tied to swap entry 446 * lookup_swap_cgroup_id - lookup mem_cgroup id tied to swap entry
483 * @ent: swap entry to be looked up. 447 * @ent: swap entry to be looked up.
484 * 448 *
485 * Returns CSS ID of mem_cgroup at success. 0 at failure. (0 is invalid ID) 449 * Returns CSS ID of mem_cgroup at success. 0 at failure. (0 is invalid ID)
486 */ 450 */
487unsigned short lookup_swap_cgroup(swp_entry_t ent) 451unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
488{ 452{
489 int type = swp_type(ent); 453 return lookup_swap_cgroup(ent, NULL)->id;
490 unsigned long offset = swp_offset(ent);
491 unsigned long idx = offset / SC_PER_PAGE;
492 unsigned long pos = offset & SC_POS_MASK;
493 struct swap_cgroup_ctrl *ctrl;
494 struct page *mappage;
495 struct swap_cgroup *sc;
496 unsigned short ret;
497
498 ctrl = &swap_cgroup_ctrl[type];
499 mappage = ctrl->map[idx];
500 sc = page_address(mappage);
501 sc += pos;
502 ret = sc->id;
503 return ret;
504} 454}
505 455
506int swap_cgroup_swapon(int type, unsigned long max_pages) 456int swap_cgroup_swapon(int type, unsigned long max_pages)
diff --git a/mm/rmap.c b/mm/rmap.c
index a2e5ce1fa081..c8454e06b6c8 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -773,7 +773,7 @@ out:
773} 773}
774 774
775static int page_referenced_anon(struct page *page, 775static int page_referenced_anon(struct page *page,
776 struct mem_cgroup *mem_cont, 776 struct mem_cgroup *memcg,
777 unsigned long *vm_flags) 777 unsigned long *vm_flags)
778{ 778{
779 unsigned int mapcount; 779 unsigned int mapcount;
@@ -796,7 +796,7 @@ static int page_referenced_anon(struct page *page,
796 * counting on behalf of references from different 796 * counting on behalf of references from different
797 * cgroups 797 * cgroups
798 */ 798 */
799 if (mem_cont && !mm_match_cgroup(vma->vm_mm, mem_cont)) 799 if (memcg && !mm_match_cgroup(vma->vm_mm, memcg))
800 continue; 800 continue;
801 referenced += page_referenced_one(page, vma, address, 801 referenced += page_referenced_one(page, vma, address,
802 &mapcount, vm_flags); 802 &mapcount, vm_flags);
@@ -811,7 +811,7 @@ static int page_referenced_anon(struct page *page,
811/** 811/**
812 * page_referenced_file - referenced check for object-based rmap 812 * page_referenced_file - referenced check for object-based rmap
813 * @page: the page we're checking references on. 813 * @page: the page we're checking references on.
814 * @mem_cont: target memory controller 814 * @memcg: target memory control group
815 * @vm_flags: collect encountered vma->vm_flags who actually referenced the page 815 * @vm_flags: collect encountered vma->vm_flags who actually referenced the page
816 * 816 *
817 * For an object-based mapped page, find all the places it is mapped and 817 * For an object-based mapped page, find all the places it is mapped and
@@ -822,7 +822,7 @@ static int page_referenced_anon(struct page *page,
822 * This function is only called from page_referenced for object-based pages. 822 * This function is only called from page_referenced for object-based pages.
823 */ 823 */
824static int page_referenced_file(struct page *page, 824static int page_referenced_file(struct page *page,
825 struct mem_cgroup *mem_cont, 825 struct mem_cgroup *memcg,
826 unsigned long *vm_flags) 826 unsigned long *vm_flags)
827{ 827{
828 unsigned int mapcount; 828 unsigned int mapcount;
@@ -864,7 +864,7 @@ static int page_referenced_file(struct page *page,
864 * counting on behalf of references from different 864 * counting on behalf of references from different
865 * cgroups 865 * cgroups
866 */ 866 */
867 if (mem_cont && !mm_match_cgroup(vma->vm_mm, mem_cont)) 867 if (memcg && !mm_match_cgroup(vma->vm_mm, memcg))
868 continue; 868 continue;
869 referenced += page_referenced_one(page, vma, address, 869 referenced += page_referenced_one(page, vma, address,
870 &mapcount, vm_flags); 870 &mapcount, vm_flags);
@@ -880,7 +880,7 @@ static int page_referenced_file(struct page *page,
880 * page_referenced - test if the page was referenced 880 * page_referenced - test if the page was referenced
881 * @page: the page to test 881 * @page: the page to test
882 * @is_locked: caller holds lock on the page 882 * @is_locked: caller holds lock on the page
883 * @mem_cont: target memory controller 883 * @memcg: target memory cgroup
884 * @vm_flags: collect encountered vma->vm_flags who actually referenced the page 884 * @vm_flags: collect encountered vma->vm_flags who actually referenced the page
885 * 885 *
886 * Quick test_and_clear_referenced for all mappings to a page, 886 * Quick test_and_clear_referenced for all mappings to a page,
@@ -888,7 +888,7 @@ static int page_referenced_file(struct page *page,
888 */ 888 */
889int page_referenced(struct page *page, 889int page_referenced(struct page *page,
890 int is_locked, 890 int is_locked,
891 struct mem_cgroup *mem_cont, 891 struct mem_cgroup *memcg,
892 unsigned long *vm_flags) 892 unsigned long *vm_flags)
893{ 893{
894 int referenced = 0; 894 int referenced = 0;
@@ -904,13 +904,13 @@ int page_referenced(struct page *page,
904 } 904 }
905 } 905 }
906 if (unlikely(PageKsm(page))) 906 if (unlikely(PageKsm(page)))
907 referenced += page_referenced_ksm(page, mem_cont, 907 referenced += page_referenced_ksm(page, memcg,
908 vm_flags); 908 vm_flags);
909 else if (PageAnon(page)) 909 else if (PageAnon(page))
910 referenced += page_referenced_anon(page, mem_cont, 910 referenced += page_referenced_anon(page, memcg,
911 vm_flags); 911 vm_flags);
912 else if (page->mapping) 912 else if (page->mapping)
913 referenced += page_referenced_file(page, mem_cont, 913 referenced += page_referenced_file(page, memcg,
914 vm_flags); 914 vm_flags);
915 if (we_locked) 915 if (we_locked)
916 unlock_page(page); 916 unlock_page(page);
diff --git a/mm/slub.c b/mm/slub.c
index 5d37b5e44140..4907563ef7ff 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -366,7 +366,8 @@ static inline bool __cmpxchg_double_slab(struct kmem_cache *s, struct page *page
366 const char *n) 366 const char *n)
367{ 367{
368 VM_BUG_ON(!irqs_disabled()); 368 VM_BUG_ON(!irqs_disabled());
369#ifdef CONFIG_CMPXCHG_DOUBLE 369#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
370 defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
370 if (s->flags & __CMPXCHG_DOUBLE) { 371 if (s->flags & __CMPXCHG_DOUBLE) {
371 if (cmpxchg_double(&page->freelist, &page->counters, 372 if (cmpxchg_double(&page->freelist, &page->counters,
372 freelist_old, counters_old, 373 freelist_old, counters_old,
@@ -400,7 +401,8 @@ static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
400 void *freelist_new, unsigned long counters_new, 401 void *freelist_new, unsigned long counters_new,
401 const char *n) 402 const char *n)
402{ 403{
403#ifdef CONFIG_CMPXCHG_DOUBLE 404#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
405 defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
404 if (s->flags & __CMPXCHG_DOUBLE) { 406 if (s->flags & __CMPXCHG_DOUBLE) {
405 if (cmpxchg_double(&page->freelist, &page->counters, 407 if (cmpxchg_double(&page->freelist, &page->counters,
406 freelist_old, counters_old, 408 freelist_old, counters_old,
@@ -3014,7 +3016,8 @@ static int kmem_cache_open(struct kmem_cache *s,
3014 } 3016 }
3015 } 3017 }
3016 3018
3017#ifdef CONFIG_CMPXCHG_DOUBLE 3019#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
3020 defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
3018 if (system_has_cmpxchg_double() && (s->flags & SLAB_DEBUG_FLAGS) == 0) 3021 if (system_has_cmpxchg_double() && (s->flags & SLAB_DEBUG_FLAGS) == 0)
3019 /* Enable fast mode */ 3022 /* Enable fast mode */
3020 s->flags |= __CMPXCHG_DOUBLE; 3023 s->flags |= __CMPXCHG_DOUBLE;
diff --git a/mm/swap.c b/mm/swap.c
index 67a09a633a09..b0f529b38979 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/export.h> 24#include <linux/export.h>
25#include <linux/mm_inline.h> 25#include <linux/mm_inline.h>
26#include <linux/buffer_head.h> /* for try_to_release_page() */
27#include <linux/percpu_counter.h> 26#include <linux/percpu_counter.h>
28#include <linux/percpu.h> 27#include <linux/percpu.h>
29#include <linux/cpu.h> 28#include <linux/cpu.h>
@@ -54,7 +53,7 @@ static void __page_cache_release(struct page *page)
54 spin_lock_irqsave(&zone->lru_lock, flags); 53 spin_lock_irqsave(&zone->lru_lock, flags);
55 VM_BUG_ON(!PageLRU(page)); 54 VM_BUG_ON(!PageLRU(page));
56 __ClearPageLRU(page); 55 __ClearPageLRU(page);
57 del_page_from_lru(zone, page); 56 del_page_from_lru_list(zone, page, page_off_lru(page));
58 spin_unlock_irqrestore(&zone->lru_lock, flags); 57 spin_unlock_irqrestore(&zone->lru_lock, flags);
59 } 58 }
60} 59}
@@ -232,12 +231,14 @@ static void pagevec_lru_move_fn(struct pagevec *pvec,
232static void pagevec_move_tail_fn(struct page *page, void *arg) 231static void pagevec_move_tail_fn(struct page *page, void *arg)
233{ 232{
234 int *pgmoved = arg; 233 int *pgmoved = arg;
235 struct zone *zone = page_zone(page);
236 234
237 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) { 235 if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
238 enum lru_list lru = page_lru_base_type(page); 236 enum lru_list lru = page_lru_base_type(page);
239 list_move_tail(&page->lru, &zone->lru[lru].list); 237 struct lruvec *lruvec;
240 mem_cgroup_rotate_reclaimable_page(page); 238
239 lruvec = mem_cgroup_lru_move_lists(page_zone(page),
240 page, lru, lru);
241 list_move_tail(&page->lru, &lruvec->lists[lru]);
241 (*pgmoved)++; 242 (*pgmoved)++;
242 } 243 }
243} 244}
@@ -368,7 +369,6 @@ void mark_page_accessed(struct page *page)
368 SetPageReferenced(page); 369 SetPageReferenced(page);
369 } 370 }
370} 371}
371
372EXPORT_SYMBOL(mark_page_accessed); 372EXPORT_SYMBOL(mark_page_accessed);
373 373
374void __lru_cache_add(struct page *page, enum lru_list lru) 374void __lru_cache_add(struct page *page, enum lru_list lru)
@@ -377,7 +377,7 @@ void __lru_cache_add(struct page *page, enum lru_list lru)
377 377
378 page_cache_get(page); 378 page_cache_get(page);
379 if (!pagevec_add(pvec, page)) 379 if (!pagevec_add(pvec, page))
380 ____pagevec_lru_add(pvec, lru); 380 __pagevec_lru_add(pvec, lru);
381 put_cpu_var(lru_add_pvecs); 381 put_cpu_var(lru_add_pvecs);
382} 382}
383EXPORT_SYMBOL(__lru_cache_add); 383EXPORT_SYMBOL(__lru_cache_add);
@@ -476,12 +476,13 @@ static void lru_deactivate_fn(struct page *page, void *arg)
476 */ 476 */
477 SetPageReclaim(page); 477 SetPageReclaim(page);
478 } else { 478 } else {
479 struct lruvec *lruvec;
479 /* 480 /*
480 * The page's writeback ends up during pagevec 481 * The page's writeback ends up during pagevec
481 * We moves tha page into tail of inactive. 482 * We moves tha page into tail of inactive.
482 */ 483 */
483 list_move_tail(&page->lru, &zone->lru[lru].list); 484 lruvec = mem_cgroup_lru_move_lists(zone, page, lru, lru);
484 mem_cgroup_rotate_reclaimable_page(page); 485 list_move_tail(&page->lru, &lruvec->lists[lru]);
485 __count_vm_event(PGROTATED); 486 __count_vm_event(PGROTATED);
486 } 487 }
487 488
@@ -504,7 +505,7 @@ static void drain_cpu_pagevecs(int cpu)
504 for_each_lru(lru) { 505 for_each_lru(lru) {
505 pvec = &pvecs[lru - LRU_BASE]; 506 pvec = &pvecs[lru - LRU_BASE];
506 if (pagevec_count(pvec)) 507 if (pagevec_count(pvec))
507 ____pagevec_lru_add(pvec, lru); 508 __pagevec_lru_add(pvec, lru);
508 } 509 }
509 510
510 pvec = &per_cpu(lru_rotate_pvecs, cpu); 511 pvec = &per_cpu(lru_rotate_pvecs, cpu);
@@ -616,7 +617,7 @@ void release_pages(struct page **pages, int nr, int cold)
616 } 617 }
617 VM_BUG_ON(!PageLRU(page)); 618 VM_BUG_ON(!PageLRU(page));
618 __ClearPageLRU(page); 619 __ClearPageLRU(page);
619 del_page_from_lru(zone, page); 620 del_page_from_lru_list(zone, page, page_off_lru(page));
620 } 621 }
621 622
622 list_add(&page->lru, &pages_to_free); 623 list_add(&page->lru, &pages_to_free);
@@ -644,9 +645,9 @@ void __pagevec_release(struct pagevec *pvec)
644 release_pages(pvec->pages, pagevec_count(pvec), pvec->cold); 645 release_pages(pvec->pages, pagevec_count(pvec), pvec->cold);
645 pagevec_reinit(pvec); 646 pagevec_reinit(pvec);
646} 647}
647
648EXPORT_SYMBOL(__pagevec_release); 648EXPORT_SYMBOL(__pagevec_release);
649 649
650#ifdef CONFIG_TRANSPARENT_HUGEPAGE
650/* used by __split_huge_page_refcount() */ 651/* used by __split_huge_page_refcount() */
651void lru_add_page_tail(struct zone* zone, 652void lru_add_page_tail(struct zone* zone,
652 struct page *page, struct page *page_tail) 653 struct page *page, struct page *page_tail)
@@ -654,7 +655,6 @@ void lru_add_page_tail(struct zone* zone,
654 int active; 655 int active;
655 enum lru_list lru; 656 enum lru_list lru;
656 const int file = 0; 657 const int file = 0;
657 struct list_head *head;
658 658
659 VM_BUG_ON(!PageHead(page)); 659 VM_BUG_ON(!PageHead(page));
660 VM_BUG_ON(PageCompound(page_tail)); 660 VM_BUG_ON(PageCompound(page_tail));
@@ -673,18 +673,30 @@ void lru_add_page_tail(struct zone* zone,
673 lru = LRU_INACTIVE_ANON; 673 lru = LRU_INACTIVE_ANON;
674 } 674 }
675 update_page_reclaim_stat(zone, page_tail, file, active); 675 update_page_reclaim_stat(zone, page_tail, file, active);
676 if (likely(PageLRU(page)))
677 head = page->lru.prev;
678 else
679 head = &zone->lru[lru].list;
680 __add_page_to_lru_list(zone, page_tail, lru, head);
681 } else { 676 } else {
682 SetPageUnevictable(page_tail); 677 SetPageUnevictable(page_tail);
683 add_page_to_lru_list(zone, page_tail, LRU_UNEVICTABLE); 678 lru = LRU_UNEVICTABLE;
679 }
680
681 if (likely(PageLRU(page)))
682 list_add_tail(&page_tail->lru, &page->lru);
683 else {
684 struct list_head *list_head;
685 /*
686 * Head page has not yet been counted, as an hpage,
687 * so we must account for each subpage individually.
688 *
689 * Use the standard add function to put page_tail on the list,
690 * but then correct its position so they all end up in order.
691 */
692 add_page_to_lru_list(zone, page_tail, lru);
693 list_head = page_tail->lru.prev;
694 list_move_tail(&page_tail->lru, list_head);
684 } 695 }
685} 696}
697#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
686 698
687static void ____pagevec_lru_add_fn(struct page *page, void *arg) 699static void __pagevec_lru_add_fn(struct page *page, void *arg)
688{ 700{
689 enum lru_list lru = (enum lru_list)arg; 701 enum lru_list lru = (enum lru_list)arg;
690 struct zone *zone = page_zone(page); 702 struct zone *zone = page_zone(page);
@@ -706,32 +718,13 @@ static void ____pagevec_lru_add_fn(struct page *page, void *arg)
706 * Add the passed pages to the LRU, then drop the caller's refcount 718 * Add the passed pages to the LRU, then drop the caller's refcount
707 * on them. Reinitialises the caller's pagevec. 719 * on them. Reinitialises the caller's pagevec.
708 */ 720 */
709void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru) 721void __pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
710{ 722{
711 VM_BUG_ON(is_unevictable_lru(lru)); 723 VM_BUG_ON(is_unevictable_lru(lru));
712 724
713 pagevec_lru_move_fn(pvec, ____pagevec_lru_add_fn, (void *)lru); 725 pagevec_lru_move_fn(pvec, __pagevec_lru_add_fn, (void *)lru);
714}
715
716EXPORT_SYMBOL(____pagevec_lru_add);
717
718/*
719 * Try to drop buffers from the pages in a pagevec
720 */
721void pagevec_strip(struct pagevec *pvec)
722{
723 int i;
724
725 for (i = 0; i < pagevec_count(pvec); i++) {
726 struct page *page = pvec->pages[i];
727
728 if (page_has_private(page) && trylock_page(page)) {
729 if (page_has_private(page))
730 try_to_release_page(page, 0);
731 unlock_page(page);
732 }
733 }
734} 726}
727EXPORT_SYMBOL(__pagevec_lru_add);
735 728
736/** 729/**
737 * pagevec_lookup - gang pagecache lookup 730 * pagevec_lookup - gang pagecache lookup
@@ -755,7 +748,6 @@ unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
755 pvec->nr = find_get_pages(mapping, start, nr_pages, pvec->pages); 748 pvec->nr = find_get_pages(mapping, start, nr_pages, pvec->pages);
756 return pagevec_count(pvec); 749 return pagevec_count(pvec);
757} 750}
758
759EXPORT_SYMBOL(pagevec_lookup); 751EXPORT_SYMBOL(pagevec_lookup);
760 752
761unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping, 753unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
@@ -765,7 +757,6 @@ unsigned pagevec_lookup_tag(struct pagevec *pvec, struct address_space *mapping,
765 nr_pages, pvec->pages); 757 nr_pages, pvec->pages);
766 return pagevec_count(pvec); 758 return pagevec_count(pvec);
767} 759}
768
769EXPORT_SYMBOL(pagevec_lookup_tag); 760EXPORT_SYMBOL(pagevec_lookup_tag);
770 761
771/* 762/*
diff --git a/mm/swap_state.c b/mm/swap_state.c
index ea6b32d61873..470038a91873 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -300,6 +300,16 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
300 new_page = alloc_page_vma(gfp_mask, vma, addr); 300 new_page = alloc_page_vma(gfp_mask, vma, addr);
301 if (!new_page) 301 if (!new_page)
302 break; /* Out of memory */ 302 break; /* Out of memory */
303 /*
304 * The memcg-specific accounting when moving
305 * pages around the LRU lists relies on the
306 * page's owner (memcg) to be valid. Usually,
307 * pages are assigned to a new owner before
308 * being put on the LRU list, but since this
309 * is not the case here, the stale owner from
310 * a previous allocation cycle must be reset.
311 */
312 mem_cgroup_reset_owner(new_page);
303 } 313 }
304 314
305 /* 315 /*
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 9520592d4231..d999f090dfda 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -847,12 +847,13 @@ unsigned int count_swap_pages(int type, int free)
847static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, 847static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
848 unsigned long addr, swp_entry_t entry, struct page *page) 848 unsigned long addr, swp_entry_t entry, struct page *page)
849{ 849{
850 struct mem_cgroup *ptr; 850 struct mem_cgroup *memcg;
851 spinlock_t *ptl; 851 spinlock_t *ptl;
852 pte_t *pte; 852 pte_t *pte;
853 int ret = 1; 853 int ret = 1;
854 854
855 if (mem_cgroup_try_charge_swapin(vma->vm_mm, page, GFP_KERNEL, &ptr)) { 855 if (mem_cgroup_try_charge_swapin(vma->vm_mm, page,
856 GFP_KERNEL, &memcg)) {
856 ret = -ENOMEM; 857 ret = -ENOMEM;
857 goto out_nolock; 858 goto out_nolock;
858 } 859 }
@@ -860,7 +861,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
860 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); 861 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
861 if (unlikely(!pte_same(*pte, swp_entry_to_pte(entry)))) { 862 if (unlikely(!pte_same(*pte, swp_entry_to_pte(entry)))) {
862 if (ret > 0) 863 if (ret > 0)
863 mem_cgroup_cancel_charge_swapin(ptr); 864 mem_cgroup_cancel_charge_swapin(memcg);
864 ret = 0; 865 ret = 0;
865 goto out; 866 goto out;
866 } 867 }
@@ -871,7 +872,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
871 set_pte_at(vma->vm_mm, addr, pte, 872 set_pte_at(vma->vm_mm, addr, pte,
872 pte_mkold(mk_pte(page, vma->vm_page_prot))); 873 pte_mkold(mk_pte(page, vma->vm_page_prot)));
873 page_add_anon_rmap(page, vma, addr); 874 page_add_anon_rmap(page, vma, addr);
874 mem_cgroup_commit_charge_swapin(page, ptr); 875 mem_cgroup_commit_charge_swapin(page, memcg);
875 swap_free(entry); 876 swap_free(entry);
876 /* 877 /*
877 * Move the page to the active list so it is not 878 * Move the page to the active list so it is not
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 877ca046f43d..86ce9a526c17 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2378,7 +2378,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
2378 vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL); 2378 vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
2379 vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL); 2379 vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
2380 if (!vas || !vms) 2380 if (!vas || !vms)
2381 goto err_free; 2381 goto err_free2;
2382 2382
2383 for (area = 0; area < nr_vms; area++) { 2383 for (area = 0; area < nr_vms; area++) {
2384 vas[area] = kzalloc(sizeof(struct vmap_area), GFP_KERNEL); 2384 vas[area] = kzalloc(sizeof(struct vmap_area), GFP_KERNEL);
@@ -2476,11 +2476,10 @@ found:
2476 2476
2477err_free: 2477err_free:
2478 for (area = 0; area < nr_vms; area++) { 2478 for (area = 0; area < nr_vms; area++) {
2479 if (vas) 2479 kfree(vas[area]);
2480 kfree(vas[area]); 2480 kfree(vms[area]);
2481 if (vms)
2482 kfree(vms[area]);
2483 } 2481 }
2482err_free2:
2484 kfree(vas); 2483 kfree(vas);
2485 kfree(vms); 2484 kfree(vms);
2486 return NULL; 2485 return NULL;
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 26f4a8a4e0c7..2880396f7953 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -103,8 +103,11 @@ struct scan_control {
103 */ 103 */
104 reclaim_mode_t reclaim_mode; 104 reclaim_mode_t reclaim_mode;
105 105
106 /* Which cgroup do we reclaim from */ 106 /*
107 struct mem_cgroup *mem_cgroup; 107 * The memory cgroup that hit its limit and as a result is the
108 * primary target of this reclaim invocation.
109 */
110 struct mem_cgroup *target_mem_cgroup;
108 111
109 /* 112 /*
110 * Nodemask of nodes allowed by the caller. If NULL, all nodes 113 * Nodemask of nodes allowed by the caller. If NULL, all nodes
@@ -113,6 +116,11 @@ struct scan_control {
113 nodemask_t *nodemask; 116 nodemask_t *nodemask;
114}; 117};
115 118
119struct mem_cgroup_zone {
120 struct mem_cgroup *mem_cgroup;
121 struct zone *zone;
122};
123
116#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru)) 124#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
117 125
118#ifdef ARCH_HAS_PREFETCH 126#ifdef ARCH_HAS_PREFETCH
@@ -153,28 +161,45 @@ static LIST_HEAD(shrinker_list);
153static DECLARE_RWSEM(shrinker_rwsem); 161static DECLARE_RWSEM(shrinker_rwsem);
154 162
155#ifdef CONFIG_CGROUP_MEM_RES_CTLR 163#ifdef CONFIG_CGROUP_MEM_RES_CTLR
156#define scanning_global_lru(sc) (!(sc)->mem_cgroup) 164static bool global_reclaim(struct scan_control *sc)
165{
166 return !sc->target_mem_cgroup;
167}
168
169static bool scanning_global_lru(struct mem_cgroup_zone *mz)
170{
171 return !mz->mem_cgroup;
172}
157#else 173#else
158#define scanning_global_lru(sc) (1) 174static bool global_reclaim(struct scan_control *sc)
175{
176 return true;
177}
178
179static bool scanning_global_lru(struct mem_cgroup_zone *mz)
180{
181 return true;
182}
159#endif 183#endif
160 184
161static struct zone_reclaim_stat *get_reclaim_stat(struct zone *zone, 185static struct zone_reclaim_stat *get_reclaim_stat(struct mem_cgroup_zone *mz)
162 struct scan_control *sc)
163{ 186{
164 if (!scanning_global_lru(sc)) 187 if (!scanning_global_lru(mz))
165 return mem_cgroup_get_reclaim_stat(sc->mem_cgroup, zone); 188 return mem_cgroup_get_reclaim_stat(mz->mem_cgroup, mz->zone);
166 189
167 return &zone->reclaim_stat; 190 return &mz->zone->reclaim_stat;
168} 191}
169 192
170static unsigned long zone_nr_lru_pages(struct zone *zone, 193static unsigned long zone_nr_lru_pages(struct mem_cgroup_zone *mz,
171 struct scan_control *sc, enum lru_list lru) 194 enum lru_list lru)
172{ 195{
173 if (!scanning_global_lru(sc)) 196 if (!scanning_global_lru(mz))
174 return mem_cgroup_zone_nr_lru_pages(sc->mem_cgroup, 197 return mem_cgroup_zone_nr_lru_pages(mz->mem_cgroup,
175 zone_to_nid(zone), zone_idx(zone), BIT(lru)); 198 zone_to_nid(mz->zone),
199 zone_idx(mz->zone),
200 BIT(lru));
176 201
177 return zone_page_state(zone, NR_LRU_BASE + lru); 202 return zone_page_state(mz->zone, NR_LRU_BASE + lru);
178} 203}
179 204
180 205
@@ -677,12 +702,13 @@ enum page_references {
677}; 702};
678 703
679static enum page_references page_check_references(struct page *page, 704static enum page_references page_check_references(struct page *page,
705 struct mem_cgroup_zone *mz,
680 struct scan_control *sc) 706 struct scan_control *sc)
681{ 707{
682 int referenced_ptes, referenced_page; 708 int referenced_ptes, referenced_page;
683 unsigned long vm_flags; 709 unsigned long vm_flags;
684 710
685 referenced_ptes = page_referenced(page, 1, sc->mem_cgroup, &vm_flags); 711 referenced_ptes = page_referenced(page, 1, mz->mem_cgroup, &vm_flags);
686 referenced_page = TestClearPageReferenced(page); 712 referenced_page = TestClearPageReferenced(page);
687 713
688 /* Lumpy reclaim - ignore references */ 714 /* Lumpy reclaim - ignore references */
@@ -738,7 +764,7 @@ static enum page_references page_check_references(struct page *page,
738 * shrink_page_list() returns the number of reclaimed pages 764 * shrink_page_list() returns the number of reclaimed pages
739 */ 765 */
740static unsigned long shrink_page_list(struct list_head *page_list, 766static unsigned long shrink_page_list(struct list_head *page_list,
741 struct zone *zone, 767 struct mem_cgroup_zone *mz,
742 struct scan_control *sc, 768 struct scan_control *sc,
743 int priority, 769 int priority,
744 unsigned long *ret_nr_dirty, 770 unsigned long *ret_nr_dirty,
@@ -769,7 +795,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
769 goto keep; 795 goto keep;
770 796
771 VM_BUG_ON(PageActive(page)); 797 VM_BUG_ON(PageActive(page));
772 VM_BUG_ON(page_zone(page) != zone); 798 VM_BUG_ON(page_zone(page) != mz->zone);
773 799
774 sc->nr_scanned++; 800 sc->nr_scanned++;
775 801
@@ -803,7 +829,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
803 } 829 }
804 } 830 }
805 831
806 references = page_check_references(page, sc); 832 references = page_check_references(page, mz, sc);
807 switch (references) { 833 switch (references) {
808 case PAGEREF_ACTIVATE: 834 case PAGEREF_ACTIVATE:
809 goto activate_locked; 835 goto activate_locked;
@@ -994,8 +1020,8 @@ keep_lumpy:
994 * back off and wait for congestion to clear because further reclaim 1020 * back off and wait for congestion to clear because further reclaim
995 * will encounter the same problem 1021 * will encounter the same problem
996 */ 1022 */
997 if (nr_dirty && nr_dirty == nr_congested && scanning_global_lru(sc)) 1023 if (nr_dirty && nr_dirty == nr_congested && global_reclaim(sc))
998 zone_set_flag(zone, ZONE_CONGESTED); 1024 zone_set_flag(mz->zone, ZONE_CONGESTED);
999 1025
1000 free_hot_cold_page_list(&free_pages, 1); 1026 free_hot_cold_page_list(&free_pages, 1);
1001 1027
@@ -1049,8 +1075,39 @@ int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file)
1049 1075
1050 ret = -EBUSY; 1076 ret = -EBUSY;
1051 1077
1052 if ((mode & ISOLATE_CLEAN) && (PageDirty(page) || PageWriteback(page))) 1078 /*
1053 return ret; 1079 * To minimise LRU disruption, the caller can indicate that it only
1080 * wants to isolate pages it will be able to operate on without
1081 * blocking - clean pages for the most part.
1082 *
1083 * ISOLATE_CLEAN means that only clean pages should be isolated. This
1084 * is used by reclaim when it is cannot write to backing storage
1085 *
1086 * ISOLATE_ASYNC_MIGRATE is used to indicate that it only wants to pages
1087 * that it is possible to migrate without blocking
1088 */
1089 if (mode & (ISOLATE_CLEAN|ISOLATE_ASYNC_MIGRATE)) {
1090 /* All the caller can do on PageWriteback is block */
1091 if (PageWriteback(page))
1092 return ret;
1093
1094 if (PageDirty(page)) {
1095 struct address_space *mapping;
1096
1097 /* ISOLATE_CLEAN means only clean pages */
1098 if (mode & ISOLATE_CLEAN)
1099 return ret;
1100
1101 /*
1102 * Only pages without mappings or that have a
1103 * ->migratepage callback are possible to migrate
1104 * without blocking
1105 */
1106 mapping = page_mapping(page);
1107 if (mapping && !mapping->a_ops->migratepage)
1108 return ret;
1109 }
1110 }
1054 1111
1055 if ((mode & ISOLATE_UNMAPPED) && page_mapped(page)) 1112 if ((mode & ISOLATE_UNMAPPED) && page_mapped(page))
1056 return ret; 1113 return ret;
@@ -1079,25 +1136,36 @@ int __isolate_lru_page(struct page *page, isolate_mode_t mode, int file)
1079 * Appropriate locks must be held before calling this function. 1136 * Appropriate locks must be held before calling this function.
1080 * 1137 *
1081 * @nr_to_scan: The number of pages to look through on the list. 1138 * @nr_to_scan: The number of pages to look through on the list.
1082 * @src: The LRU list to pull pages off. 1139 * @mz: The mem_cgroup_zone to pull pages from.
1083 * @dst: The temp list to put pages on to. 1140 * @dst: The temp list to put pages on to.
1084 * @scanned: The number of pages that were scanned. 1141 * @nr_scanned: The number of pages that were scanned.
1085 * @order: The caller's attempted allocation order 1142 * @order: The caller's attempted allocation order
1086 * @mode: One of the LRU isolation modes 1143 * @mode: One of the LRU isolation modes
1144 * @active: True [1] if isolating active pages
1087 * @file: True [1] if isolating file [!anon] pages 1145 * @file: True [1] if isolating file [!anon] pages
1088 * 1146 *
1089 * returns how many pages were moved onto *@dst. 1147 * returns how many pages were moved onto *@dst.
1090 */ 1148 */
1091static unsigned long isolate_lru_pages(unsigned long nr_to_scan, 1149static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1092 struct list_head *src, struct list_head *dst, 1150 struct mem_cgroup_zone *mz, struct list_head *dst,
1093 unsigned long *scanned, int order, isolate_mode_t mode, 1151 unsigned long *nr_scanned, int order, isolate_mode_t mode,
1094 int file) 1152 int active, int file)
1095{ 1153{
1154 struct lruvec *lruvec;
1155 struct list_head *src;
1096 unsigned long nr_taken = 0; 1156 unsigned long nr_taken = 0;
1097 unsigned long nr_lumpy_taken = 0; 1157 unsigned long nr_lumpy_taken = 0;
1098 unsigned long nr_lumpy_dirty = 0; 1158 unsigned long nr_lumpy_dirty = 0;
1099 unsigned long nr_lumpy_failed = 0; 1159 unsigned long nr_lumpy_failed = 0;
1100 unsigned long scan; 1160 unsigned long scan;
1161 int lru = LRU_BASE;
1162
1163 lruvec = mem_cgroup_zone_lruvec(mz->zone, mz->mem_cgroup);
1164 if (active)
1165 lru += LRU_ACTIVE;
1166 if (file)
1167 lru += LRU_FILE;
1168 src = &lruvec->lists[lru];
1101 1169
1102 for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) { 1170 for (scan = 0; scan < nr_to_scan && !list_empty(src); scan++) {
1103 struct page *page; 1171 struct page *page;
@@ -1113,15 +1181,14 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1113 1181
1114 switch (__isolate_lru_page(page, mode, file)) { 1182 switch (__isolate_lru_page(page, mode, file)) {
1115 case 0: 1183 case 0:
1184 mem_cgroup_lru_del(page);
1116 list_move(&page->lru, dst); 1185 list_move(&page->lru, dst);
1117 mem_cgroup_del_lru(page);
1118 nr_taken += hpage_nr_pages(page); 1186 nr_taken += hpage_nr_pages(page);
1119 break; 1187 break;
1120 1188
1121 case -EBUSY: 1189 case -EBUSY:
1122 /* else it is being freed elsewhere */ 1190 /* else it is being freed elsewhere */
1123 list_move(&page->lru, src); 1191 list_move(&page->lru, src);
1124 mem_cgroup_rotate_lru_list(page, page_lru(page));
1125 continue; 1192 continue;
1126 1193
1127 default: 1194 default:
@@ -1171,13 +1238,17 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1171 break; 1238 break;
1172 1239
1173 if (__isolate_lru_page(cursor_page, mode, file) == 0) { 1240 if (__isolate_lru_page(cursor_page, mode, file) == 0) {
1241 unsigned int isolated_pages;
1242
1243 mem_cgroup_lru_del(cursor_page);
1174 list_move(&cursor_page->lru, dst); 1244 list_move(&cursor_page->lru, dst);
1175 mem_cgroup_del_lru(cursor_page); 1245 isolated_pages = hpage_nr_pages(cursor_page);
1176 nr_taken += hpage_nr_pages(cursor_page); 1246 nr_taken += isolated_pages;
1177 nr_lumpy_taken++; 1247 nr_lumpy_taken += isolated_pages;
1178 if (PageDirty(cursor_page)) 1248 if (PageDirty(cursor_page))
1179 nr_lumpy_dirty++; 1249 nr_lumpy_dirty += isolated_pages;
1180 scan++; 1250 scan++;
1251 pfn += isolated_pages - 1;
1181 } else { 1252 } else {
1182 /* 1253 /*
1183 * Check if the page is freed already. 1254 * Check if the page is freed already.
@@ -1203,57 +1274,16 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan,
1203 nr_lumpy_failed++; 1274 nr_lumpy_failed++;
1204 } 1275 }
1205 1276
1206 *scanned = scan; 1277 *nr_scanned = scan;
1207 1278
1208 trace_mm_vmscan_lru_isolate(order, 1279 trace_mm_vmscan_lru_isolate(order,
1209 nr_to_scan, scan, 1280 nr_to_scan, scan,
1210 nr_taken, 1281 nr_taken,
1211 nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed, 1282 nr_lumpy_taken, nr_lumpy_dirty, nr_lumpy_failed,
1212 mode); 1283 mode, file);
1213 return nr_taken; 1284 return nr_taken;
1214} 1285}
1215 1286
1216static unsigned long isolate_pages_global(unsigned long nr,
1217 struct list_head *dst,
1218 unsigned long *scanned, int order,
1219 isolate_mode_t mode,
1220 struct zone *z, int active, int file)
1221{
1222 int lru = LRU_BASE;
1223 if (active)
1224 lru += LRU_ACTIVE;
1225 if (file)
1226 lru += LRU_FILE;
1227 return isolate_lru_pages(nr, &z->lru[lru].list, dst, scanned, order,
1228 mode, file);
1229}
1230
1231/*
1232 * clear_active_flags() is a helper for shrink_active_list(), clearing
1233 * any active bits from the pages in the list.
1234 */
1235static unsigned long clear_active_flags(struct list_head *page_list,
1236 unsigned int *count)
1237{
1238 int nr_active = 0;
1239 int lru;
1240 struct page *page;
1241
1242 list_for_each_entry(page, page_list, lru) {
1243 int numpages = hpage_nr_pages(page);
1244 lru = page_lru_base_type(page);
1245 if (PageActive(page)) {
1246 lru += LRU_ACTIVE;
1247 ClearPageActive(page);
1248 nr_active += numpages;
1249 }
1250 if (count)
1251 count[lru] += numpages;
1252 }
1253
1254 return nr_active;
1255}
1256
1257/** 1287/**
1258 * isolate_lru_page - tries to isolate a page from its LRU list 1288 * isolate_lru_page - tries to isolate a page from its LRU list
1259 * @page: page to isolate from its LRU list 1289 * @page: page to isolate from its LRU list
@@ -1313,7 +1343,7 @@ static int too_many_isolated(struct zone *zone, int file,
1313 if (current_is_kswapd()) 1343 if (current_is_kswapd())
1314 return 0; 1344 return 0;
1315 1345
1316 if (!scanning_global_lru(sc)) 1346 if (!global_reclaim(sc))
1317 return 0; 1347 return 0;
1318 1348
1319 if (file) { 1349 if (file) {
@@ -1327,27 +1357,21 @@ static int too_many_isolated(struct zone *zone, int file,
1327 return isolated > inactive; 1357 return isolated > inactive;
1328} 1358}
1329 1359
1330/*
1331 * TODO: Try merging with migrations version of putback_lru_pages
1332 */
1333static noinline_for_stack void 1360static noinline_for_stack void
1334putback_lru_pages(struct zone *zone, struct scan_control *sc, 1361putback_inactive_pages(struct mem_cgroup_zone *mz,
1335 unsigned long nr_anon, unsigned long nr_file, 1362 struct list_head *page_list)
1336 struct list_head *page_list)
1337{ 1363{
1338 struct page *page; 1364 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(mz);
1339 struct pagevec pvec; 1365 struct zone *zone = mz->zone;
1340 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); 1366 LIST_HEAD(pages_to_free);
1341
1342 pagevec_init(&pvec, 1);
1343 1367
1344 /* 1368 /*
1345 * Put back any unfreeable pages. 1369 * Put back any unfreeable pages.
1346 */ 1370 */
1347 spin_lock(&zone->lru_lock);
1348 while (!list_empty(page_list)) { 1371 while (!list_empty(page_list)) {
1372 struct page *page = lru_to_page(page_list);
1349 int lru; 1373 int lru;
1350 page = lru_to_page(page_list); 1374
1351 VM_BUG_ON(PageLRU(page)); 1375 VM_BUG_ON(PageLRU(page));
1352 list_del(&page->lru); 1376 list_del(&page->lru);
1353 if (unlikely(!page_evictable(page, NULL))) { 1377 if (unlikely(!page_evictable(page, NULL))) {
@@ -1364,30 +1388,53 @@ putback_lru_pages(struct zone *zone, struct scan_control *sc,
1364 int numpages = hpage_nr_pages(page); 1388 int numpages = hpage_nr_pages(page);
1365 reclaim_stat->recent_rotated[file] += numpages; 1389 reclaim_stat->recent_rotated[file] += numpages;
1366 } 1390 }
1367 if (!pagevec_add(&pvec, page)) { 1391 if (put_page_testzero(page)) {
1368 spin_unlock_irq(&zone->lru_lock); 1392 __ClearPageLRU(page);
1369 __pagevec_release(&pvec); 1393 __ClearPageActive(page);
1370 spin_lock_irq(&zone->lru_lock); 1394 del_page_from_lru_list(zone, page, lru);
1395
1396 if (unlikely(PageCompound(page))) {
1397 spin_unlock_irq(&zone->lru_lock);
1398 (*get_compound_page_dtor(page))(page);
1399 spin_lock_irq(&zone->lru_lock);
1400 } else
1401 list_add(&page->lru, &pages_to_free);
1371 } 1402 }
1372 } 1403 }
1373 __mod_zone_page_state(zone, NR_ISOLATED_ANON, -nr_anon);
1374 __mod_zone_page_state(zone, NR_ISOLATED_FILE, -nr_file);
1375 1404
1376 spin_unlock_irq(&zone->lru_lock); 1405 /*
1377 pagevec_release(&pvec); 1406 * To save our caller's stack, now use input list for pages to free.
1407 */
1408 list_splice(&pages_to_free, page_list);
1378} 1409}
1379 1410
1380static noinline_for_stack void update_isolated_counts(struct zone *zone, 1411static noinline_for_stack void
1381 struct scan_control *sc, 1412update_isolated_counts(struct mem_cgroup_zone *mz,
1382 unsigned long *nr_anon, 1413 struct list_head *page_list,
1383 unsigned long *nr_file, 1414 unsigned long *nr_anon,
1384 struct list_head *isolated_list) 1415 unsigned long *nr_file)
1385{ 1416{
1386 unsigned long nr_active; 1417 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(mz);
1418 struct zone *zone = mz->zone;
1387 unsigned int count[NR_LRU_LISTS] = { 0, }; 1419 unsigned int count[NR_LRU_LISTS] = { 0, };
1388 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); 1420 unsigned long nr_active = 0;
1421 struct page *page;
1422 int lru;
1423
1424 /*
1425 * Count pages and clear active flags
1426 */
1427 list_for_each_entry(page, page_list, lru) {
1428 int numpages = hpage_nr_pages(page);
1429 lru = page_lru_base_type(page);
1430 if (PageActive(page)) {
1431 lru += LRU_ACTIVE;
1432 ClearPageActive(page);
1433 nr_active += numpages;
1434 }
1435 count[lru] += numpages;
1436 }
1389 1437
1390 nr_active = clear_active_flags(isolated_list, count);
1391 __count_vm_events(PGDEACTIVATE, nr_active); 1438 __count_vm_events(PGDEACTIVATE, nr_active);
1392 1439
1393 __mod_zone_page_state(zone, NR_ACTIVE_FILE, 1440 __mod_zone_page_state(zone, NR_ACTIVE_FILE,
@@ -1401,8 +1448,6 @@ static noinline_for_stack void update_isolated_counts(struct zone *zone,
1401 1448
1402 *nr_anon = count[LRU_ACTIVE_ANON] + count[LRU_INACTIVE_ANON]; 1449 *nr_anon = count[LRU_ACTIVE_ANON] + count[LRU_INACTIVE_ANON];
1403 *nr_file = count[LRU_ACTIVE_FILE] + count[LRU_INACTIVE_FILE]; 1450 *nr_file = count[LRU_ACTIVE_FILE] + count[LRU_INACTIVE_FILE];
1404 __mod_zone_page_state(zone, NR_ISOLATED_ANON, *nr_anon);
1405 __mod_zone_page_state(zone, NR_ISOLATED_FILE, *nr_file);
1406 1451
1407 reclaim_stat->recent_scanned[0] += *nr_anon; 1452 reclaim_stat->recent_scanned[0] += *nr_anon;
1408 reclaim_stat->recent_scanned[1] += *nr_file; 1453 reclaim_stat->recent_scanned[1] += *nr_file;
@@ -1454,8 +1499,8 @@ static inline bool should_reclaim_stall(unsigned long nr_taken,
1454 * of reclaimed pages 1499 * of reclaimed pages
1455 */ 1500 */
1456static noinline_for_stack unsigned long 1501static noinline_for_stack unsigned long
1457shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone, 1502shrink_inactive_list(unsigned long nr_to_scan, struct mem_cgroup_zone *mz,
1458 struct scan_control *sc, int priority, int file) 1503 struct scan_control *sc, int priority, int file)
1459{ 1504{
1460 LIST_HEAD(page_list); 1505 LIST_HEAD(page_list);
1461 unsigned long nr_scanned; 1506 unsigned long nr_scanned;
@@ -1466,6 +1511,7 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
1466 unsigned long nr_dirty = 0; 1511 unsigned long nr_dirty = 0;
1467 unsigned long nr_writeback = 0; 1512 unsigned long nr_writeback = 0;
1468 isolate_mode_t reclaim_mode = ISOLATE_INACTIVE; 1513 isolate_mode_t reclaim_mode = ISOLATE_INACTIVE;
1514 struct zone *zone = mz->zone;
1469 1515
1470 while (unlikely(too_many_isolated(zone, file, sc))) { 1516 while (unlikely(too_many_isolated(zone, file, sc))) {
1471 congestion_wait(BLK_RW_ASYNC, HZ/10); 1517 congestion_wait(BLK_RW_ASYNC, HZ/10);
@@ -1488,9 +1534,10 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
1488 1534
1489 spin_lock_irq(&zone->lru_lock); 1535 spin_lock_irq(&zone->lru_lock);
1490 1536
1491 if (scanning_global_lru(sc)) { 1537 nr_taken = isolate_lru_pages(nr_to_scan, mz, &page_list,
1492 nr_taken = isolate_pages_global(nr_to_scan, &page_list, 1538 &nr_scanned, sc->order,
1493 &nr_scanned, sc->order, reclaim_mode, zone, 0, file); 1539 reclaim_mode, 0, file);
1540 if (global_reclaim(sc)) {
1494 zone->pages_scanned += nr_scanned; 1541 zone->pages_scanned += nr_scanned;
1495 if (current_is_kswapd()) 1542 if (current_is_kswapd())
1496 __count_zone_vm_events(PGSCAN_KSWAPD, zone, 1543 __count_zone_vm_events(PGSCAN_KSWAPD, zone,
@@ -1498,14 +1545,6 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
1498 else 1545 else
1499 __count_zone_vm_events(PGSCAN_DIRECT, zone, 1546 __count_zone_vm_events(PGSCAN_DIRECT, zone,
1500 nr_scanned); 1547 nr_scanned);
1501 } else {
1502 nr_taken = mem_cgroup_isolate_pages(nr_to_scan, &page_list,
1503 &nr_scanned, sc->order, reclaim_mode, zone,
1504 sc->mem_cgroup, 0, file);
1505 /*
1506 * mem_cgroup_isolate_pages() keeps track of
1507 * scanned pages on its own.
1508 */
1509 } 1548 }
1510 1549
1511 if (nr_taken == 0) { 1550 if (nr_taken == 0) {
@@ -1513,26 +1552,37 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
1513 return 0; 1552 return 0;
1514 } 1553 }
1515 1554
1516 update_isolated_counts(zone, sc, &nr_anon, &nr_file, &page_list); 1555 update_isolated_counts(mz, &page_list, &nr_anon, &nr_file);
1556
1557 __mod_zone_page_state(zone, NR_ISOLATED_ANON, nr_anon);
1558 __mod_zone_page_state(zone, NR_ISOLATED_FILE, nr_file);
1517 1559
1518 spin_unlock_irq(&zone->lru_lock); 1560 spin_unlock_irq(&zone->lru_lock);
1519 1561
1520 nr_reclaimed = shrink_page_list(&page_list, zone, sc, priority, 1562 nr_reclaimed = shrink_page_list(&page_list, mz, sc, priority,
1521 &nr_dirty, &nr_writeback); 1563 &nr_dirty, &nr_writeback);
1522 1564
1523 /* Check if we should syncronously wait for writeback */ 1565 /* Check if we should syncronously wait for writeback */
1524 if (should_reclaim_stall(nr_taken, nr_reclaimed, priority, sc)) { 1566 if (should_reclaim_stall(nr_taken, nr_reclaimed, priority, sc)) {
1525 set_reclaim_mode(priority, sc, true); 1567 set_reclaim_mode(priority, sc, true);
1526 nr_reclaimed += shrink_page_list(&page_list, zone, sc, 1568 nr_reclaimed += shrink_page_list(&page_list, mz, sc,
1527 priority, &nr_dirty, &nr_writeback); 1569 priority, &nr_dirty, &nr_writeback);
1528 } 1570 }
1529 1571
1530 local_irq_disable(); 1572 spin_lock_irq(&zone->lru_lock);
1573
1531 if (current_is_kswapd()) 1574 if (current_is_kswapd())
1532 __count_vm_events(KSWAPD_STEAL, nr_reclaimed); 1575 __count_vm_events(KSWAPD_STEAL, nr_reclaimed);
1533 __count_zone_vm_events(PGSTEAL, zone, nr_reclaimed); 1576 __count_zone_vm_events(PGSTEAL, zone, nr_reclaimed);
1534 1577
1535 putback_lru_pages(zone, sc, nr_anon, nr_file, &page_list); 1578 putback_inactive_pages(mz, &page_list);
1579
1580 __mod_zone_page_state(zone, NR_ISOLATED_ANON, -nr_anon);
1581 __mod_zone_page_state(zone, NR_ISOLATED_FILE, -nr_file);
1582
1583 spin_unlock_irq(&zone->lru_lock);
1584
1585 free_hot_cold_page_list(&page_list, 1);
1536 1586
1537 /* 1587 /*
1538 * If reclaim is isolating dirty pages under writeback, it implies 1588 * If reclaim is isolating dirty pages under writeback, it implies
@@ -1588,30 +1638,47 @@ shrink_inactive_list(unsigned long nr_to_scan, struct zone *zone,
1588 1638
1589static void move_active_pages_to_lru(struct zone *zone, 1639static void move_active_pages_to_lru(struct zone *zone,
1590 struct list_head *list, 1640 struct list_head *list,
1641 struct list_head *pages_to_free,
1591 enum lru_list lru) 1642 enum lru_list lru)
1592{ 1643{
1593 unsigned long pgmoved = 0; 1644 unsigned long pgmoved = 0;
1594 struct pagevec pvec;
1595 struct page *page; 1645 struct page *page;
1596 1646
1597 pagevec_init(&pvec, 1); 1647 if (buffer_heads_over_limit) {
1648 spin_unlock_irq(&zone->lru_lock);
1649 list_for_each_entry(page, list, lru) {
1650 if (page_has_private(page) && trylock_page(page)) {
1651 if (page_has_private(page))
1652 try_to_release_page(page, 0);
1653 unlock_page(page);
1654 }
1655 }
1656 spin_lock_irq(&zone->lru_lock);
1657 }
1598 1658
1599 while (!list_empty(list)) { 1659 while (!list_empty(list)) {
1660 struct lruvec *lruvec;
1661
1600 page = lru_to_page(list); 1662 page = lru_to_page(list);
1601 1663
1602 VM_BUG_ON(PageLRU(page)); 1664 VM_BUG_ON(PageLRU(page));
1603 SetPageLRU(page); 1665 SetPageLRU(page);
1604 1666
1605 list_move(&page->lru, &zone->lru[lru].list); 1667 lruvec = mem_cgroup_lru_add_list(zone, page, lru);
1606 mem_cgroup_add_lru_list(page, lru); 1668 list_move(&page->lru, &lruvec->lists[lru]);
1607 pgmoved += hpage_nr_pages(page); 1669 pgmoved += hpage_nr_pages(page);
1608 1670
1609 if (!pagevec_add(&pvec, page) || list_empty(list)) { 1671 if (put_page_testzero(page)) {
1610 spin_unlock_irq(&zone->lru_lock); 1672 __ClearPageLRU(page);
1611 if (buffer_heads_over_limit) 1673 __ClearPageActive(page);
1612 pagevec_strip(&pvec); 1674 del_page_from_lru_list(zone, page, lru);
1613 __pagevec_release(&pvec); 1675
1614 spin_lock_irq(&zone->lru_lock); 1676 if (unlikely(PageCompound(page))) {
1677 spin_unlock_irq(&zone->lru_lock);
1678 (*get_compound_page_dtor(page))(page);
1679 spin_lock_irq(&zone->lru_lock);
1680 } else
1681 list_add(&page->lru, pages_to_free);
1615 } 1682 }
1616 } 1683 }
1617 __mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved); 1684 __mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
@@ -1619,19 +1686,22 @@ static void move_active_pages_to_lru(struct zone *zone,
1619 __count_vm_events(PGDEACTIVATE, pgmoved); 1686 __count_vm_events(PGDEACTIVATE, pgmoved);
1620} 1687}
1621 1688
1622static void shrink_active_list(unsigned long nr_pages, struct zone *zone, 1689static void shrink_active_list(unsigned long nr_to_scan,
1623 struct scan_control *sc, int priority, int file) 1690 struct mem_cgroup_zone *mz,
1691 struct scan_control *sc,
1692 int priority, int file)
1624{ 1693{
1625 unsigned long nr_taken; 1694 unsigned long nr_taken;
1626 unsigned long pgscanned; 1695 unsigned long nr_scanned;
1627 unsigned long vm_flags; 1696 unsigned long vm_flags;
1628 LIST_HEAD(l_hold); /* The pages which were snipped off */ 1697 LIST_HEAD(l_hold); /* The pages which were snipped off */
1629 LIST_HEAD(l_active); 1698 LIST_HEAD(l_active);
1630 LIST_HEAD(l_inactive); 1699 LIST_HEAD(l_inactive);
1631 struct page *page; 1700 struct page *page;
1632 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); 1701 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(mz);
1633 unsigned long nr_rotated = 0; 1702 unsigned long nr_rotated = 0;
1634 isolate_mode_t reclaim_mode = ISOLATE_ACTIVE; 1703 isolate_mode_t reclaim_mode = ISOLATE_ACTIVE;
1704 struct zone *zone = mz->zone;
1635 1705
1636 lru_add_drain(); 1706 lru_add_drain();
1637 1707
@@ -1641,26 +1711,16 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
1641 reclaim_mode |= ISOLATE_CLEAN; 1711 reclaim_mode |= ISOLATE_CLEAN;
1642 1712
1643 spin_lock_irq(&zone->lru_lock); 1713 spin_lock_irq(&zone->lru_lock);
1644 if (scanning_global_lru(sc)) { 1714
1645 nr_taken = isolate_pages_global(nr_pages, &l_hold, 1715 nr_taken = isolate_lru_pages(nr_to_scan, mz, &l_hold,
1646 &pgscanned, sc->order, 1716 &nr_scanned, sc->order,
1647 reclaim_mode, zone, 1717 reclaim_mode, 1, file);
1648 1, file); 1718 if (global_reclaim(sc))
1649 zone->pages_scanned += pgscanned; 1719 zone->pages_scanned += nr_scanned;
1650 } else {
1651 nr_taken = mem_cgroup_isolate_pages(nr_pages, &l_hold,
1652 &pgscanned, sc->order,
1653 reclaim_mode, zone,
1654 sc->mem_cgroup, 1, file);
1655 /*
1656 * mem_cgroup_isolate_pages() keeps track of
1657 * scanned pages on its own.
1658 */
1659 }
1660 1720
1661 reclaim_stat->recent_scanned[file] += nr_taken; 1721 reclaim_stat->recent_scanned[file] += nr_taken;
1662 1722
1663 __count_zone_vm_events(PGREFILL, zone, pgscanned); 1723 __count_zone_vm_events(PGREFILL, zone, nr_scanned);
1664 if (file) 1724 if (file)
1665 __mod_zone_page_state(zone, NR_ACTIVE_FILE, -nr_taken); 1725 __mod_zone_page_state(zone, NR_ACTIVE_FILE, -nr_taken);
1666 else 1726 else
@@ -1678,7 +1738,7 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
1678 continue; 1738 continue;
1679 } 1739 }
1680 1740
1681 if (page_referenced(page, 0, sc->mem_cgroup, &vm_flags)) { 1741 if (page_referenced(page, 0, mz->mem_cgroup, &vm_flags)) {
1682 nr_rotated += hpage_nr_pages(page); 1742 nr_rotated += hpage_nr_pages(page);
1683 /* 1743 /*
1684 * Identify referenced, file-backed active pages and 1744 * Identify referenced, file-backed active pages and
@@ -1711,12 +1771,14 @@ static void shrink_active_list(unsigned long nr_pages, struct zone *zone,
1711 */ 1771 */
1712 reclaim_stat->recent_rotated[file] += nr_rotated; 1772 reclaim_stat->recent_rotated[file] += nr_rotated;
1713 1773
1714 move_active_pages_to_lru(zone, &l_active, 1774 move_active_pages_to_lru(zone, &l_active, &l_hold,
1715 LRU_ACTIVE + file * LRU_FILE); 1775 LRU_ACTIVE + file * LRU_FILE);
1716 move_active_pages_to_lru(zone, &l_inactive, 1776 move_active_pages_to_lru(zone, &l_inactive, &l_hold,
1717 LRU_BASE + file * LRU_FILE); 1777 LRU_BASE + file * LRU_FILE);
1718 __mod_zone_page_state(zone, NR_ISOLATED_ANON + file, -nr_taken); 1778 __mod_zone_page_state(zone, NR_ISOLATED_ANON + file, -nr_taken);
1719 spin_unlock_irq(&zone->lru_lock); 1779 spin_unlock_irq(&zone->lru_lock);
1780
1781 free_hot_cold_page_list(&l_hold, 1);
1720} 1782}
1721 1783
1722#ifdef CONFIG_SWAP 1784#ifdef CONFIG_SWAP
@@ -1741,10 +1803,8 @@ static int inactive_anon_is_low_global(struct zone *zone)
1741 * Returns true if the zone does not have enough inactive anon pages, 1803 * Returns true if the zone does not have enough inactive anon pages,
1742 * meaning some active anon pages need to be deactivated. 1804 * meaning some active anon pages need to be deactivated.
1743 */ 1805 */
1744static int inactive_anon_is_low(struct zone *zone, struct scan_control *sc) 1806static int inactive_anon_is_low(struct mem_cgroup_zone *mz)
1745{ 1807{
1746 int low;
1747
1748 /* 1808 /*
1749 * If we don't have swap space, anonymous page deactivation 1809 * If we don't have swap space, anonymous page deactivation
1750 * is pointless. 1810 * is pointless.
@@ -1752,15 +1812,14 @@ static int inactive_anon_is_low(struct zone *zone, struct scan_control *sc)
1752 if (!total_swap_pages) 1812 if (!total_swap_pages)
1753 return 0; 1813 return 0;
1754 1814
1755 if (scanning_global_lru(sc)) 1815 if (!scanning_global_lru(mz))
1756 low = inactive_anon_is_low_global(zone); 1816 return mem_cgroup_inactive_anon_is_low(mz->mem_cgroup,
1757 else 1817 mz->zone);
1758 low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup, zone); 1818
1759 return low; 1819 return inactive_anon_is_low_global(mz->zone);
1760} 1820}
1761#else 1821#else
1762static inline int inactive_anon_is_low(struct zone *zone, 1822static inline int inactive_anon_is_low(struct mem_cgroup_zone *mz)
1763 struct scan_control *sc)
1764{ 1823{
1765 return 0; 1824 return 0;
1766} 1825}
@@ -1778,8 +1837,7 @@ static int inactive_file_is_low_global(struct zone *zone)
1778 1837
1779/** 1838/**
1780 * inactive_file_is_low - check if file pages need to be deactivated 1839 * inactive_file_is_low - check if file pages need to be deactivated
1781 * @zone: zone to check 1840 * @mz: memory cgroup and zone to check
1782 * @sc: scan control of this context
1783 * 1841 *
1784 * When the system is doing streaming IO, memory pressure here 1842 * When the system is doing streaming IO, memory pressure here
1785 * ensures that active file pages get deactivated, until more 1843 * ensures that active file pages get deactivated, until more
@@ -1791,45 +1849,44 @@ static int inactive_file_is_low_global(struct zone *zone)
1791 * This uses a different ratio than the anonymous pages, because 1849 * This uses a different ratio than the anonymous pages, because
1792 * the page cache uses a use-once replacement algorithm. 1850 * the page cache uses a use-once replacement algorithm.
1793 */ 1851 */
1794static int inactive_file_is_low(struct zone *zone, struct scan_control *sc) 1852static int inactive_file_is_low(struct mem_cgroup_zone *mz)
1795{ 1853{
1796 int low; 1854 if (!scanning_global_lru(mz))
1855 return mem_cgroup_inactive_file_is_low(mz->mem_cgroup,
1856 mz->zone);
1797 1857
1798 if (scanning_global_lru(sc)) 1858 return inactive_file_is_low_global(mz->zone);
1799 low = inactive_file_is_low_global(zone);
1800 else
1801 low = mem_cgroup_inactive_file_is_low(sc->mem_cgroup, zone);
1802 return low;
1803} 1859}
1804 1860
1805static int inactive_list_is_low(struct zone *zone, struct scan_control *sc, 1861static int inactive_list_is_low(struct mem_cgroup_zone *mz, int file)
1806 int file)
1807{ 1862{
1808 if (file) 1863 if (file)
1809 return inactive_file_is_low(zone, sc); 1864 return inactive_file_is_low(mz);
1810 else 1865 else
1811 return inactive_anon_is_low(zone, sc); 1866 return inactive_anon_is_low(mz);
1812} 1867}
1813 1868
1814static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, 1869static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
1815 struct zone *zone, struct scan_control *sc, int priority) 1870 struct mem_cgroup_zone *mz,
1871 struct scan_control *sc, int priority)
1816{ 1872{
1817 int file = is_file_lru(lru); 1873 int file = is_file_lru(lru);
1818 1874
1819 if (is_active_lru(lru)) { 1875 if (is_active_lru(lru)) {
1820 if (inactive_list_is_low(zone, sc, file)) 1876 if (inactive_list_is_low(mz, file))
1821 shrink_active_list(nr_to_scan, zone, sc, priority, file); 1877 shrink_active_list(nr_to_scan, mz, sc, priority, file);
1822 return 0; 1878 return 0;
1823 } 1879 }
1824 1880
1825 return shrink_inactive_list(nr_to_scan, zone, sc, priority, file); 1881 return shrink_inactive_list(nr_to_scan, mz, sc, priority, file);
1826} 1882}
1827 1883
1828static int vmscan_swappiness(struct scan_control *sc) 1884static int vmscan_swappiness(struct mem_cgroup_zone *mz,
1885 struct scan_control *sc)
1829{ 1886{
1830 if (scanning_global_lru(sc)) 1887 if (global_reclaim(sc))
1831 return vm_swappiness; 1888 return vm_swappiness;
1832 return mem_cgroup_swappiness(sc->mem_cgroup); 1889 return mem_cgroup_swappiness(mz->mem_cgroup);
1833} 1890}
1834 1891
1835/* 1892/*
@@ -1840,15 +1897,15 @@ static int vmscan_swappiness(struct scan_control *sc)
1840 * 1897 *
1841 * nr[0] = anon pages to scan; nr[1] = file pages to scan 1898 * nr[0] = anon pages to scan; nr[1] = file pages to scan
1842 */ 1899 */
1843static void get_scan_count(struct zone *zone, struct scan_control *sc, 1900static void get_scan_count(struct mem_cgroup_zone *mz, struct scan_control *sc,
1844 unsigned long *nr, int priority) 1901 unsigned long *nr, int priority)
1845{ 1902{
1846 unsigned long anon, file, free; 1903 unsigned long anon, file, free;
1847 unsigned long anon_prio, file_prio; 1904 unsigned long anon_prio, file_prio;
1848 unsigned long ap, fp; 1905 unsigned long ap, fp;
1849 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc); 1906 struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(mz);
1850 u64 fraction[2], denominator; 1907 u64 fraction[2], denominator;
1851 enum lru_list l; 1908 enum lru_list lru;
1852 int noswap = 0; 1909 int noswap = 0;
1853 bool force_scan = false; 1910 bool force_scan = false;
1854 1911
@@ -1862,9 +1919,9 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
1862 * latencies, so it's better to scan a minimum amount there as 1919 * latencies, so it's better to scan a minimum amount there as
1863 * well. 1920 * well.
1864 */ 1921 */
1865 if (scanning_global_lru(sc) && current_is_kswapd()) 1922 if (current_is_kswapd() && mz->zone->all_unreclaimable)
1866 force_scan = true; 1923 force_scan = true;
1867 if (!scanning_global_lru(sc)) 1924 if (!global_reclaim(sc))
1868 force_scan = true; 1925 force_scan = true;
1869 1926
1870 /* If we have no swap space, do not bother scanning anon pages. */ 1927 /* If we have no swap space, do not bother scanning anon pages. */
@@ -1876,16 +1933,16 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
1876 goto out; 1933 goto out;
1877 } 1934 }
1878 1935
1879 anon = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) + 1936 anon = zone_nr_lru_pages(mz, LRU_ACTIVE_ANON) +
1880 zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON); 1937 zone_nr_lru_pages(mz, LRU_INACTIVE_ANON);
1881 file = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_FILE) + 1938 file = zone_nr_lru_pages(mz, LRU_ACTIVE_FILE) +
1882 zone_nr_lru_pages(zone, sc, LRU_INACTIVE_FILE); 1939 zone_nr_lru_pages(mz, LRU_INACTIVE_FILE);
1883 1940
1884 if (scanning_global_lru(sc)) { 1941 if (global_reclaim(sc)) {
1885 free = zone_page_state(zone, NR_FREE_PAGES); 1942 free = zone_page_state(mz->zone, NR_FREE_PAGES);
1886 /* If we have very few page cache pages, 1943 /* If we have very few page cache pages,
1887 force-scan anon pages. */ 1944 force-scan anon pages. */
1888 if (unlikely(file + free <= high_wmark_pages(zone))) { 1945 if (unlikely(file + free <= high_wmark_pages(mz->zone))) {
1889 fraction[0] = 1; 1946 fraction[0] = 1;
1890 fraction[1] = 0; 1947 fraction[1] = 0;
1891 denominator = 1; 1948 denominator = 1;
@@ -1897,8 +1954,8 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
1897 * With swappiness at 100, anonymous and file have the same priority. 1954 * With swappiness at 100, anonymous and file have the same priority.
1898 * This scanning priority is essentially the inverse of IO cost. 1955 * This scanning priority is essentially the inverse of IO cost.
1899 */ 1956 */
1900 anon_prio = vmscan_swappiness(sc); 1957 anon_prio = vmscan_swappiness(mz, sc);
1901 file_prio = 200 - vmscan_swappiness(sc); 1958 file_prio = 200 - vmscan_swappiness(mz, sc);
1902 1959
1903 /* 1960 /*
1904 * OK, so we have swap space and a fair amount of page cache 1961 * OK, so we have swap space and a fair amount of page cache
@@ -1911,7 +1968,7 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
1911 * 1968 *
1912 * anon in [0], file in [1] 1969 * anon in [0], file in [1]
1913 */ 1970 */
1914 spin_lock_irq(&zone->lru_lock); 1971 spin_lock_irq(&mz->zone->lru_lock);
1915 if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) { 1972 if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) {
1916 reclaim_stat->recent_scanned[0] /= 2; 1973 reclaim_stat->recent_scanned[0] /= 2;
1917 reclaim_stat->recent_rotated[0] /= 2; 1974 reclaim_stat->recent_rotated[0] /= 2;
@@ -1932,24 +1989,24 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
1932 1989
1933 fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1); 1990 fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
1934 fp /= reclaim_stat->recent_rotated[1] + 1; 1991 fp /= reclaim_stat->recent_rotated[1] + 1;
1935 spin_unlock_irq(&zone->lru_lock); 1992 spin_unlock_irq(&mz->zone->lru_lock);
1936 1993
1937 fraction[0] = ap; 1994 fraction[0] = ap;
1938 fraction[1] = fp; 1995 fraction[1] = fp;
1939 denominator = ap + fp + 1; 1996 denominator = ap + fp + 1;
1940out: 1997out:
1941 for_each_evictable_lru(l) { 1998 for_each_evictable_lru(lru) {
1942 int file = is_file_lru(l); 1999 int file = is_file_lru(lru);
1943 unsigned long scan; 2000 unsigned long scan;
1944 2001
1945 scan = zone_nr_lru_pages(zone, sc, l); 2002 scan = zone_nr_lru_pages(mz, lru);
1946 if (priority || noswap) { 2003 if (priority || noswap) {
1947 scan >>= priority; 2004 scan >>= priority;
1948 if (!scan && force_scan) 2005 if (!scan && force_scan)
1949 scan = SWAP_CLUSTER_MAX; 2006 scan = SWAP_CLUSTER_MAX;
1950 scan = div64_u64(scan * fraction[file], denominator); 2007 scan = div64_u64(scan * fraction[file], denominator);
1951 } 2008 }
1952 nr[l] = scan; 2009 nr[lru] = scan;
1953 } 2010 }
1954} 2011}
1955 2012
@@ -1960,7 +2017,7 @@ out:
1960 * back to the allocator and call try_to_compact_zone(), we ensure that 2017 * back to the allocator and call try_to_compact_zone(), we ensure that
1961 * there are enough free pages for it to be likely successful 2018 * there are enough free pages for it to be likely successful
1962 */ 2019 */
1963static inline bool should_continue_reclaim(struct zone *zone, 2020static inline bool should_continue_reclaim(struct mem_cgroup_zone *mz,
1964 unsigned long nr_reclaimed, 2021 unsigned long nr_reclaimed,
1965 unsigned long nr_scanned, 2022 unsigned long nr_scanned,
1966 struct scan_control *sc) 2023 struct scan_control *sc)
@@ -2000,15 +2057,15 @@ static inline bool should_continue_reclaim(struct zone *zone,
2000 * inactive lists are large enough, continue reclaiming 2057 * inactive lists are large enough, continue reclaiming
2001 */ 2058 */
2002 pages_for_compaction = (2UL << sc->order); 2059 pages_for_compaction = (2UL << sc->order);
2003 inactive_lru_pages = zone_nr_lru_pages(zone, sc, LRU_INACTIVE_FILE); 2060 inactive_lru_pages = zone_nr_lru_pages(mz, LRU_INACTIVE_FILE);
2004 if (nr_swap_pages > 0) 2061 if (nr_swap_pages > 0)
2005 inactive_lru_pages += zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON); 2062 inactive_lru_pages += zone_nr_lru_pages(mz, LRU_INACTIVE_ANON);
2006 if (sc->nr_reclaimed < pages_for_compaction && 2063 if (sc->nr_reclaimed < pages_for_compaction &&
2007 inactive_lru_pages > pages_for_compaction) 2064 inactive_lru_pages > pages_for_compaction)
2008 return true; 2065 return true;
2009 2066
2010 /* If compaction would go ahead or the allocation would succeed, stop */ 2067 /* If compaction would go ahead or the allocation would succeed, stop */
2011 switch (compaction_suitable(zone, sc->order)) { 2068 switch (compaction_suitable(mz->zone, sc->order)) {
2012 case COMPACT_PARTIAL: 2069 case COMPACT_PARTIAL:
2013 case COMPACT_CONTINUE: 2070 case COMPACT_CONTINUE:
2014 return false; 2071 return false;
@@ -2020,12 +2077,12 @@ static inline bool should_continue_reclaim(struct zone *zone,
2020/* 2077/*
2021 * This is a basic per-zone page freer. Used by both kswapd and direct reclaim. 2078 * This is a basic per-zone page freer. Used by both kswapd and direct reclaim.
2022 */ 2079 */
2023static void shrink_zone(int priority, struct zone *zone, 2080static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz,
2024 struct scan_control *sc) 2081 struct scan_control *sc)
2025{ 2082{
2026 unsigned long nr[NR_LRU_LISTS]; 2083 unsigned long nr[NR_LRU_LISTS];
2027 unsigned long nr_to_scan; 2084 unsigned long nr_to_scan;
2028 enum lru_list l; 2085 enum lru_list lru;
2029 unsigned long nr_reclaimed, nr_scanned; 2086 unsigned long nr_reclaimed, nr_scanned;
2030 unsigned long nr_to_reclaim = sc->nr_to_reclaim; 2087 unsigned long nr_to_reclaim = sc->nr_to_reclaim;
2031 struct blk_plug plug; 2088 struct blk_plug plug;
@@ -2033,19 +2090,19 @@ static void shrink_zone(int priority, struct zone *zone,
2033restart: 2090restart:
2034 nr_reclaimed = 0; 2091 nr_reclaimed = 0;
2035 nr_scanned = sc->nr_scanned; 2092 nr_scanned = sc->nr_scanned;
2036 get_scan_count(zone, sc, nr, priority); 2093 get_scan_count(mz, sc, nr, priority);
2037 2094
2038 blk_start_plug(&plug); 2095 blk_start_plug(&plug);
2039 while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] || 2096 while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
2040 nr[LRU_INACTIVE_FILE]) { 2097 nr[LRU_INACTIVE_FILE]) {
2041 for_each_evictable_lru(l) { 2098 for_each_evictable_lru(lru) {
2042 if (nr[l]) { 2099 if (nr[lru]) {
2043 nr_to_scan = min_t(unsigned long, 2100 nr_to_scan = min_t(unsigned long,
2044 nr[l], SWAP_CLUSTER_MAX); 2101 nr[lru], SWAP_CLUSTER_MAX);
2045 nr[l] -= nr_to_scan; 2102 nr[lru] -= nr_to_scan;
2046 2103
2047 nr_reclaimed += shrink_list(l, nr_to_scan, 2104 nr_reclaimed += shrink_list(lru, nr_to_scan,
2048 zone, sc, priority); 2105 mz, sc, priority);
2049 } 2106 }
2050 } 2107 }
2051 /* 2108 /*
@@ -2066,17 +2123,89 @@ restart:
2066 * Even if we did not try to evict anon pages at all, we want to 2123 * Even if we did not try to evict anon pages at all, we want to
2067 * rebalance the anon lru active/inactive ratio. 2124 * rebalance the anon lru active/inactive ratio.
2068 */ 2125 */
2069 if (inactive_anon_is_low(zone, sc)) 2126 if (inactive_anon_is_low(mz))
2070 shrink_active_list(SWAP_CLUSTER_MAX, zone, sc, priority, 0); 2127 shrink_active_list(SWAP_CLUSTER_MAX, mz, sc, priority, 0);
2071 2128
2072 /* reclaim/compaction might need reclaim to continue */ 2129 /* reclaim/compaction might need reclaim to continue */
2073 if (should_continue_reclaim(zone, nr_reclaimed, 2130 if (should_continue_reclaim(mz, nr_reclaimed,
2074 sc->nr_scanned - nr_scanned, sc)) 2131 sc->nr_scanned - nr_scanned, sc))
2075 goto restart; 2132 goto restart;
2076 2133
2077 throttle_vm_writeout(sc->gfp_mask); 2134 throttle_vm_writeout(sc->gfp_mask);
2078} 2135}
2079 2136
2137static void shrink_zone(int priority, struct zone *zone,
2138 struct scan_control *sc)
2139{
2140 struct mem_cgroup *root = sc->target_mem_cgroup;
2141 struct mem_cgroup_reclaim_cookie reclaim = {
2142 .zone = zone,
2143 .priority = priority,
2144 };
2145 struct mem_cgroup *memcg;
2146
2147 memcg = mem_cgroup_iter(root, NULL, &reclaim);
2148 do {
2149 struct mem_cgroup_zone mz = {
2150 .mem_cgroup = memcg,
2151 .zone = zone,
2152 };
2153
2154 shrink_mem_cgroup_zone(priority, &mz, sc);
2155 /*
2156 * Limit reclaim has historically picked one memcg and
2157 * scanned it with decreasing priority levels until
2158 * nr_to_reclaim had been reclaimed. This priority
2159 * cycle is thus over after a single memcg.
2160 *
2161 * Direct reclaim and kswapd, on the other hand, have
2162 * to scan all memory cgroups to fulfill the overall
2163 * scan target for the zone.
2164 */
2165 if (!global_reclaim(sc)) {
2166 mem_cgroup_iter_break(root, memcg);
2167 break;
2168 }
2169 memcg = mem_cgroup_iter(root, memcg, &reclaim);
2170 } while (memcg);
2171}
2172
2173/* Returns true if compaction should go ahead for a high-order request */
2174static inline bool compaction_ready(struct zone *zone, struct scan_control *sc)
2175{
2176 unsigned long balance_gap, watermark;
2177 bool watermark_ok;
2178
2179 /* Do not consider compaction for orders reclaim is meant to satisfy */
2180 if (sc->order <= PAGE_ALLOC_COSTLY_ORDER)
2181 return false;
2182
2183 /*
2184 * Compaction takes time to run and there are potentially other
2185 * callers using the pages just freed. Continue reclaiming until
2186 * there is a buffer of free pages available to give compaction
2187 * a reasonable chance of completing and allocating the page
2188 */
2189 balance_gap = min(low_wmark_pages(zone),
2190 (zone->present_pages + KSWAPD_ZONE_BALANCE_GAP_RATIO-1) /
2191 KSWAPD_ZONE_BALANCE_GAP_RATIO);
2192 watermark = high_wmark_pages(zone) + balance_gap + (2UL << sc->order);
2193 watermark_ok = zone_watermark_ok_safe(zone, 0, watermark, 0, 0);
2194
2195 /*
2196 * If compaction is deferred, reclaim up to a point where
2197 * compaction will have a chance of success when re-enabled
2198 */
2199 if (compaction_deferred(zone))
2200 return watermark_ok;
2201
2202 /* If compaction is not ready to start, keep reclaiming */
2203 if (!compaction_suitable(zone, sc->order))
2204 return false;
2205
2206 return watermark_ok;
2207}
2208
2080/* 2209/*
2081 * This is the direct reclaim path, for page-allocating processes. We only 2210 * This is the direct reclaim path, for page-allocating processes. We only
2082 * try to reclaim pages from zones which will satisfy the caller's allocation 2211 * try to reclaim pages from zones which will satisfy the caller's allocation
@@ -2094,8 +2223,9 @@ restart:
2094 * scan then give up on it. 2223 * scan then give up on it.
2095 * 2224 *
2096 * This function returns true if a zone is being reclaimed for a costly 2225 * This function returns true if a zone is being reclaimed for a costly
2097 * high-order allocation and compaction is either ready to begin or deferred. 2226 * high-order allocation and compaction is ready to begin. This indicates to
2098 * This indicates to the caller that it should retry the allocation or fail. 2227 * the caller that it should consider retrying the allocation instead of
2228 * further reclaim.
2099 */ 2229 */
2100static bool shrink_zones(int priority, struct zonelist *zonelist, 2230static bool shrink_zones(int priority, struct zonelist *zonelist,
2101 struct scan_control *sc) 2231 struct scan_control *sc)
@@ -2104,7 +2234,7 @@ static bool shrink_zones(int priority, struct zonelist *zonelist,
2104 struct zone *zone; 2234 struct zone *zone;
2105 unsigned long nr_soft_reclaimed; 2235 unsigned long nr_soft_reclaimed;
2106 unsigned long nr_soft_scanned; 2236 unsigned long nr_soft_scanned;
2107 bool should_abort_reclaim = false; 2237 bool aborted_reclaim = false;
2108 2238
2109 for_each_zone_zonelist_nodemask(zone, z, zonelist, 2239 for_each_zone_zonelist_nodemask(zone, z, zonelist,
2110 gfp_zone(sc->gfp_mask), sc->nodemask) { 2240 gfp_zone(sc->gfp_mask), sc->nodemask) {
@@ -2114,7 +2244,7 @@ static bool shrink_zones(int priority, struct zonelist *zonelist,
2114 * Take care memory controller reclaiming has small influence 2244 * Take care memory controller reclaiming has small influence
2115 * to global LRU. 2245 * to global LRU.
2116 */ 2246 */
2117 if (scanning_global_lru(sc)) { 2247 if (global_reclaim(sc)) {
2118 if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL)) 2248 if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
2119 continue; 2249 continue;
2120 if (zone->all_unreclaimable && priority != DEF_PRIORITY) 2250 if (zone->all_unreclaimable && priority != DEF_PRIORITY)
@@ -2129,10 +2259,8 @@ static bool shrink_zones(int priority, struct zonelist *zonelist,
2129 * noticable problem, like transparent huge page 2259 * noticable problem, like transparent huge page
2130 * allocations. 2260 * allocations.
2131 */ 2261 */
2132 if (sc->order > PAGE_ALLOC_COSTLY_ORDER && 2262 if (compaction_ready(zone, sc)) {
2133 (compaction_suitable(zone, sc->order) || 2263 aborted_reclaim = true;
2134 compaction_deferred(zone))) {
2135 should_abort_reclaim = true;
2136 continue; 2264 continue;
2137 } 2265 }
2138 } 2266 }
@@ -2154,7 +2282,7 @@ static bool shrink_zones(int priority, struct zonelist *zonelist,
2154 shrink_zone(priority, zone, sc); 2282 shrink_zone(priority, zone, sc);
2155 } 2283 }
2156 2284
2157 return should_abort_reclaim; 2285 return aborted_reclaim;
2158} 2286}
2159 2287
2160static bool zone_reclaimable(struct zone *zone) 2288static bool zone_reclaimable(struct zone *zone)
@@ -2208,25 +2336,25 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
2208 struct zoneref *z; 2336 struct zoneref *z;
2209 struct zone *zone; 2337 struct zone *zone;
2210 unsigned long writeback_threshold; 2338 unsigned long writeback_threshold;
2339 bool aborted_reclaim;
2211 2340
2212 get_mems_allowed(); 2341 get_mems_allowed();
2213 delayacct_freepages_start(); 2342 delayacct_freepages_start();
2214 2343
2215 if (scanning_global_lru(sc)) 2344 if (global_reclaim(sc))
2216 count_vm_event(ALLOCSTALL); 2345 count_vm_event(ALLOCSTALL);
2217 2346
2218 for (priority = DEF_PRIORITY; priority >= 0; priority--) { 2347 for (priority = DEF_PRIORITY; priority >= 0; priority--) {
2219 sc->nr_scanned = 0; 2348 sc->nr_scanned = 0;
2220 if (!priority) 2349 if (!priority)
2221 disable_swap_token(sc->mem_cgroup); 2350 disable_swap_token(sc->target_mem_cgroup);
2222 if (shrink_zones(priority, zonelist, sc)) 2351 aborted_reclaim = shrink_zones(priority, zonelist, sc);
2223 break;
2224 2352
2225 /* 2353 /*
2226 * Don't shrink slabs when reclaiming memory from 2354 * Don't shrink slabs when reclaiming memory from
2227 * over limit cgroups 2355 * over limit cgroups
2228 */ 2356 */
2229 if (scanning_global_lru(sc)) { 2357 if (global_reclaim(sc)) {
2230 unsigned long lru_pages = 0; 2358 unsigned long lru_pages = 0;
2231 for_each_zone_zonelist(zone, z, zonelist, 2359 for_each_zone_zonelist(zone, z, zonelist,
2232 gfp_zone(sc->gfp_mask)) { 2360 gfp_zone(sc->gfp_mask)) {
@@ -2287,8 +2415,12 @@ out:
2287 if (oom_killer_disabled) 2415 if (oom_killer_disabled)
2288 return 0; 2416 return 0;
2289 2417
2418 /* Aborted reclaim to try compaction? don't OOM, then */
2419 if (aborted_reclaim)
2420 return 1;
2421
2290 /* top priority shrink_zones still had more to do? don't OOM, then */ 2422 /* top priority shrink_zones still had more to do? don't OOM, then */
2291 if (scanning_global_lru(sc) && !all_unreclaimable(zonelist, sc)) 2423 if (global_reclaim(sc) && !all_unreclaimable(zonelist, sc))
2292 return 1; 2424 return 1;
2293 2425
2294 return 0; 2426 return 0;
@@ -2305,7 +2437,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
2305 .may_unmap = 1, 2437 .may_unmap = 1,
2306 .may_swap = 1, 2438 .may_swap = 1,
2307 .order = order, 2439 .order = order,
2308 .mem_cgroup = NULL, 2440 .target_mem_cgroup = NULL,
2309 .nodemask = nodemask, 2441 .nodemask = nodemask,
2310 }; 2442 };
2311 struct shrink_control shrink = { 2443 struct shrink_control shrink = {
@@ -2325,7 +2457,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
2325 2457
2326#ifdef CONFIG_CGROUP_MEM_RES_CTLR 2458#ifdef CONFIG_CGROUP_MEM_RES_CTLR
2327 2459
2328unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, 2460unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *memcg,
2329 gfp_t gfp_mask, bool noswap, 2461 gfp_t gfp_mask, bool noswap,
2330 struct zone *zone, 2462 struct zone *zone,
2331 unsigned long *nr_scanned) 2463 unsigned long *nr_scanned)
@@ -2337,7 +2469,11 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
2337 .may_unmap = 1, 2469 .may_unmap = 1,
2338 .may_swap = !noswap, 2470 .may_swap = !noswap,
2339 .order = 0, 2471 .order = 0,
2340 .mem_cgroup = mem, 2472 .target_mem_cgroup = memcg,
2473 };
2474 struct mem_cgroup_zone mz = {
2475 .mem_cgroup = memcg,
2476 .zone = zone,
2341 }; 2477 };
2342 2478
2343 sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | 2479 sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
@@ -2354,7 +2490,7 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
2354 * will pick up pages from other mem cgroup's as well. We hack 2490 * will pick up pages from other mem cgroup's as well. We hack
2355 * the priority and make it zero. 2491 * the priority and make it zero.
2356 */ 2492 */
2357 shrink_zone(0, zone, &sc); 2493 shrink_mem_cgroup_zone(0, &mz, &sc);
2358 2494
2359 trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed); 2495 trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed);
2360 2496
@@ -2362,7 +2498,7 @@ unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem,
2362 return sc.nr_reclaimed; 2498 return sc.nr_reclaimed;
2363} 2499}
2364 2500
2365unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont, 2501unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
2366 gfp_t gfp_mask, 2502 gfp_t gfp_mask,
2367 bool noswap) 2503 bool noswap)
2368{ 2504{
@@ -2375,7 +2511,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
2375 .may_swap = !noswap, 2511 .may_swap = !noswap,
2376 .nr_to_reclaim = SWAP_CLUSTER_MAX, 2512 .nr_to_reclaim = SWAP_CLUSTER_MAX,
2377 .order = 0, 2513 .order = 0,
2378 .mem_cgroup = mem_cont, 2514 .target_mem_cgroup = memcg,
2379 .nodemask = NULL, /* we don't care the placement */ 2515 .nodemask = NULL, /* we don't care the placement */
2380 .gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | 2516 .gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) |
2381 (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK), 2517 (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK),
@@ -2389,7 +2525,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
2389 * take care of from where we get pages. So the node where we start the 2525 * take care of from where we get pages. So the node where we start the
2390 * scan does not need to be the current node. 2526 * scan does not need to be the current node.
2391 */ 2527 */
2392 nid = mem_cgroup_select_victim_node(mem_cont); 2528 nid = mem_cgroup_select_victim_node(memcg);
2393 2529
2394 zonelist = NODE_DATA(nid)->node_zonelists; 2530 zonelist = NODE_DATA(nid)->node_zonelists;
2395 2531
@@ -2405,6 +2541,29 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem_cont,
2405} 2541}
2406#endif 2542#endif
2407 2543
2544static void age_active_anon(struct zone *zone, struct scan_control *sc,
2545 int priority)
2546{
2547 struct mem_cgroup *memcg;
2548
2549 if (!total_swap_pages)
2550 return;
2551
2552 memcg = mem_cgroup_iter(NULL, NULL, NULL);
2553 do {
2554 struct mem_cgroup_zone mz = {
2555 .mem_cgroup = memcg,
2556 .zone = zone,
2557 };
2558
2559 if (inactive_anon_is_low(&mz))
2560 shrink_active_list(SWAP_CLUSTER_MAX, &mz,
2561 sc, priority, 0);
2562
2563 memcg = mem_cgroup_iter(NULL, memcg, NULL);
2564 } while (memcg);
2565}
2566
2408/* 2567/*
2409 * pgdat_balanced is used when checking if a node is balanced for high-order 2568 * pgdat_balanced is used when checking if a node is balanced for high-order
2410 * allocations. Only zones that meet watermarks and are in a zone allowed 2569 * allocations. Only zones that meet watermarks and are in a zone allowed
@@ -2525,7 +2684,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
2525 */ 2684 */
2526 .nr_to_reclaim = ULONG_MAX, 2685 .nr_to_reclaim = ULONG_MAX,
2527 .order = order, 2686 .order = order,
2528 .mem_cgroup = NULL, 2687 .target_mem_cgroup = NULL,
2529 }; 2688 };
2530 struct shrink_control shrink = { 2689 struct shrink_control shrink = {
2531 .gfp_mask = sc.gfp_mask, 2690 .gfp_mask = sc.gfp_mask,
@@ -2564,9 +2723,7 @@ loop_again:
2564 * Do some background aging of the anon list, to give 2723 * Do some background aging of the anon list, to give
2565 * pages a chance to be referenced before reclaiming. 2724 * pages a chance to be referenced before reclaiming.
2566 */ 2725 */
2567 if (inactive_anon_is_low(zone, &sc)) 2726 age_active_anon(zone, &sc, priority);
2568 shrink_active_list(SWAP_CLUSTER_MAX, zone,
2569 &sc, priority, 0);
2570 2727
2571 if (!zone_watermark_ok_safe(zone, order, 2728 if (!zone_watermark_ok_safe(zone, order,
2572 high_wmark_pages(zone), 0, 0)) { 2729 high_wmark_pages(zone), 0, 0)) {
@@ -3355,16 +3512,18 @@ int page_evictable(struct page *page, struct vm_area_struct *vma)
3355 */ 3512 */
3356static void check_move_unevictable_page(struct page *page, struct zone *zone) 3513static void check_move_unevictable_page(struct page *page, struct zone *zone)
3357{ 3514{
3358 VM_BUG_ON(PageActive(page)); 3515 struct lruvec *lruvec;
3359 3516
3517 VM_BUG_ON(PageActive(page));
3360retry: 3518retry:
3361 ClearPageUnevictable(page); 3519 ClearPageUnevictable(page);
3362 if (page_evictable(page, NULL)) { 3520 if (page_evictable(page, NULL)) {
3363 enum lru_list l = page_lru_base_type(page); 3521 enum lru_list l = page_lru_base_type(page);
3364 3522
3365 __dec_zone_state(zone, NR_UNEVICTABLE); 3523 __dec_zone_state(zone, NR_UNEVICTABLE);
3366 list_move(&page->lru, &zone->lru[l].list); 3524 lruvec = mem_cgroup_lru_move_lists(zone, page,
3367 mem_cgroup_move_lists(page, LRU_UNEVICTABLE, l); 3525 LRU_UNEVICTABLE, l);
3526 list_move(&page->lru, &lruvec->lists[l]);
3368 __inc_zone_state(zone, NR_INACTIVE_ANON + l); 3527 __inc_zone_state(zone, NR_INACTIVE_ANON + l);
3369 __count_vm_event(UNEVICTABLE_PGRESCUED); 3528 __count_vm_event(UNEVICTABLE_PGRESCUED);
3370 } else { 3529 } else {
@@ -3372,8 +3531,9 @@ retry:
3372 * rotate unevictable list 3531 * rotate unevictable list
3373 */ 3532 */
3374 SetPageUnevictable(page); 3533 SetPageUnevictable(page);
3375 list_move(&page->lru, &zone->lru[LRU_UNEVICTABLE].list); 3534 lruvec = mem_cgroup_lru_move_lists(zone, page, LRU_UNEVICTABLE,
3376 mem_cgroup_rotate_lru_list(page, LRU_UNEVICTABLE); 3535 LRU_UNEVICTABLE);
3536 list_move(&page->lru, &lruvec->lists[LRU_UNEVICTABLE]);
3377 if (page_evictable(page, NULL)) 3537 if (page_evictable(page, NULL))
3378 goto retry; 3538 goto retry;
3379 } 3539 }
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 8fd603b1665e..f600557a7659 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -295,7 +295,7 @@ void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
295} 295}
296EXPORT_SYMBOL(__dec_zone_page_state); 296EXPORT_SYMBOL(__dec_zone_page_state);
297 297
298#ifdef CONFIG_CMPXCHG_LOCAL 298#ifdef CONFIG_HAVE_CMPXCHG_LOCAL
299/* 299/*
300 * If we have cmpxchg_local support then we do not need to incur the overhead 300 * If we have cmpxchg_local support then we do not need to incur the overhead
301 * that comes with local_irq_save/restore if we use this_cpu_cmpxchg. 301 * that comes with local_irq_save/restore if we use this_cpu_cmpxchg.
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index cdcfcabb34ab..ef92864ac625 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -156,17 +156,17 @@ static int bt_sock_create(struct net *net, struct socket *sock, int proto,
156 156
157void bt_sock_link(struct bt_sock_list *l, struct sock *sk) 157void bt_sock_link(struct bt_sock_list *l, struct sock *sk)
158{ 158{
159 write_lock_bh(&l->lock); 159 write_lock(&l->lock);
160 sk_add_node(sk, &l->head); 160 sk_add_node(sk, &l->head);
161 write_unlock_bh(&l->lock); 161 write_unlock(&l->lock);
162} 162}
163EXPORT_SYMBOL(bt_sock_link); 163EXPORT_SYMBOL(bt_sock_link);
164 164
165void bt_sock_unlink(struct bt_sock_list *l, struct sock *sk) 165void bt_sock_unlink(struct bt_sock_list *l, struct sock *sk)
166{ 166{
167 write_lock_bh(&l->lock); 167 write_lock(&l->lock);
168 sk_del_node_init(sk); 168 sk_del_node_init(sk);
169 write_unlock_bh(&l->lock); 169 write_unlock(&l->lock);
170} 170}
171EXPORT_SYMBOL(bt_sock_unlink); 171EXPORT_SYMBOL(bt_sock_unlink);
172 172
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 4221bd256bdd..001307f81057 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -711,7 +711,14 @@ static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
711 if (rp->status) 711 if (rp->status)
712 return; 712 return;
713 713
714 memcpy(hdev->extfeatures, rp->features, 8); 714 switch (rp->page) {
715 case 0:
716 memcpy(hdev->features, rp->features, 8);
717 break;
718 case 1:
719 memcpy(hdev->host_features, rp->features, 8);
720 break;
721 }
715 722
716 hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status); 723 hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status);
717} 724}
@@ -1047,9 +1054,7 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
1047 case LE_SCANNING_DISABLED: 1054 case LE_SCANNING_DISABLED:
1048 clear_bit(HCI_LE_SCAN, &hdev->dev_flags); 1055 clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
1049 1056
1050 cancel_delayed_work_sync(&hdev->adv_work); 1057 schedule_delayed_work(&hdev->adv_work, ADV_CLEAR_TIMEOUT);
1051 queue_delayed_work(hdev->workqueue, &hdev->adv_work,
1052 jiffies + ADV_CLEAR_TIMEOUT);
1053 break; 1058 break;
1054 1059
1055 default: 1060 default:
@@ -2266,20 +2271,19 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
2266 struct hci_ev_num_comp_pkts *ev = (void *) skb->data; 2271 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
2267 int i; 2272 int i;
2268 2273
2269 skb_pull(skb, sizeof(*ev));
2270
2271 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2272
2273 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) { 2274 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
2274 BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode); 2275 BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode);
2275 return; 2276 return;
2276 } 2277 }
2277 2278
2278 if (skb->len < ev->num_hndl * 4) { 2279 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
2280 ev->num_hndl * sizeof(struct hci_comp_pkts_info)) {
2279 BT_DBG("%s bad parameters", hdev->name); 2281 BT_DBG("%s bad parameters", hdev->name);
2280 return; 2282 return;
2281 } 2283 }
2282 2284
2285 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2286
2283 for (i = 0; i < ev->num_hndl; i++) { 2287 for (i = 0; i < ev->num_hndl; i++) {
2284 struct hci_comp_pkts_info *info = &ev->handles[i]; 2288 struct hci_comp_pkts_info *info = &ev->handles[i];
2285 struct hci_conn *conn; 2289 struct hci_conn *conn;
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 6d94616af312..0dcc96266779 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -767,7 +767,6 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
767 /* Detach sockets from device */ 767 /* Detach sockets from device */
768 read_lock(&hci_sk_list.lock); 768 read_lock(&hci_sk_list.lock);
769 sk_for_each(sk, node, &hci_sk_list.head) { 769 sk_for_each(sk, node, &hci_sk_list.head) {
770 local_bh_disable();
771 bh_lock_sock_nested(sk); 770 bh_lock_sock_nested(sk);
772 if (hci_pi(sk)->hdev == hdev) { 771 if (hci_pi(sk)->hdev == hdev) {
773 hci_pi(sk)->hdev = NULL; 772 hci_pi(sk)->hdev = NULL;
@@ -778,7 +777,6 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
778 hci_dev_put(hdev); 777 hci_dev_put(hdev);
779 } 778 }
780 bh_unlock_sock(sk); 779 bh_unlock_sock(sk);
781 local_bh_enable();
782 } 780 }
783 read_unlock(&hci_sk_list.lock); 781 read_unlock(&hci_sk_list.lock);
784 } 782 }
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index aa78d8c4b93b..faf0b11ac1d3 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -165,7 +165,7 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
165{ 165{
166 int err; 166 int err;
167 167
168 write_lock_bh(&chan_list_lock); 168 write_lock(&chan_list_lock);
169 169
170 if (psm && __l2cap_global_chan_by_addr(psm, src)) { 170 if (psm && __l2cap_global_chan_by_addr(psm, src)) {
171 err = -EADDRINUSE; 171 err = -EADDRINUSE;
@@ -190,17 +190,17 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
190 } 190 }
191 191
192done: 192done:
193 write_unlock_bh(&chan_list_lock); 193 write_unlock(&chan_list_lock);
194 return err; 194 return err;
195} 195}
196 196
197int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid) 197int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid)
198{ 198{
199 write_lock_bh(&chan_list_lock); 199 write_lock(&chan_list_lock);
200 200
201 chan->scid = scid; 201 chan->scid = scid;
202 202
203 write_unlock_bh(&chan_list_lock); 203 write_unlock(&chan_list_lock);
204 204
205 return 0; 205 return 0;
206} 206}
@@ -289,9 +289,9 @@ struct l2cap_chan *l2cap_chan_create(struct sock *sk)
289 289
290 chan->sk = sk; 290 chan->sk = sk;
291 291
292 write_lock_bh(&chan_list_lock); 292 write_lock(&chan_list_lock);
293 list_add(&chan->global_l, &chan_list); 293 list_add(&chan->global_l, &chan_list);
294 write_unlock_bh(&chan_list_lock); 294 write_unlock(&chan_list_lock);
295 295
296 INIT_DELAYED_WORK(&chan->chan_timer, l2cap_chan_timeout); 296 INIT_DELAYED_WORK(&chan->chan_timer, l2cap_chan_timeout);
297 297
@@ -306,9 +306,9 @@ struct l2cap_chan *l2cap_chan_create(struct sock *sk)
306 306
307void l2cap_chan_destroy(struct l2cap_chan *chan) 307void l2cap_chan_destroy(struct l2cap_chan *chan)
308{ 308{
309 write_lock_bh(&chan_list_lock); 309 write_lock(&chan_list_lock);
310 list_del(&chan->global_l); 310 list_del(&chan->global_l);
311 write_unlock_bh(&chan_list_lock); 311 write_unlock(&chan_list_lock);
312 312
313 l2cap_chan_put(chan); 313 l2cap_chan_put(chan);
314} 314}
@@ -543,14 +543,14 @@ static u8 l2cap_get_ident(struct l2cap_conn *conn)
543 * 200 - 254 are used by utilities like l2ping, etc. 543 * 200 - 254 are used by utilities like l2ping, etc.
544 */ 544 */
545 545
546 spin_lock_bh(&conn->lock); 546 spin_lock(&conn->lock);
547 547
548 if (++conn->tx_ident > 128) 548 if (++conn->tx_ident > 128)
549 conn->tx_ident = 1; 549 conn->tx_ident = 1;
550 550
551 id = conn->tx_ident; 551 id = conn->tx_ident;
552 552
553 spin_unlock_bh(&conn->lock); 553 spin_unlock(&conn->lock);
554 554
555 return id; 555 return id;
556} 556}
@@ -1190,7 +1190,7 @@ inline int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdad
1190 } 1190 }
1191 1191
1192 /* Set destination address and psm */ 1192 /* Set destination address and psm */
1193 bacpy(&bt_sk(sk)->dst, src); 1193 bacpy(&bt_sk(sk)->dst, dst);
1194 chan->psm = psm; 1194 chan->psm = psm;
1195 chan->dcid = cid; 1195 chan->dcid = cid;
1196 1196
@@ -4702,7 +4702,7 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
4702{ 4702{
4703 struct l2cap_chan *c; 4703 struct l2cap_chan *c;
4704 4704
4705 read_lock_bh(&chan_list_lock); 4705 read_lock(&chan_list_lock);
4706 4706
4707 list_for_each_entry(c, &chan_list, global_l) { 4707 list_for_each_entry(c, &chan_list, global_l) {
4708 struct sock *sk = c->sk; 4708 struct sock *sk = c->sk;
@@ -4715,7 +4715,7 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
4715 c->sec_level, c->mode); 4715 c->sec_level, c->mode);
4716} 4716}
4717 4717
4718 read_unlock_bh(&chan_list_lock); 4718 read_unlock(&chan_list_lock);
4719 4719
4720 return 0; 4720 return 0;
4721} 4721}
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 9ca5616166f7..c61d967012b2 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -587,6 +587,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
587 if (smp_conn_security(conn, sec.level)) 587 if (smp_conn_security(conn, sec.level))
588 break; 588 break;
589 sk->sk_state = BT_CONFIG; 589 sk->sk_state = BT_CONFIG;
590 chan->state = BT_CONFIG;
590 591
591 /* or for ACL link, under defer_setup time */ 592 /* or for ACL link, under defer_setup time */
592 } else if (sk->sk_state == BT_CONNECT2 && 593 } else if (sk->sk_state == BT_CONNECT2 &&
@@ -731,6 +732,7 @@ static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct ms
731 732
732 if (sk->sk_state == BT_CONNECT2 && bt_sk(sk)->defer_setup) { 733 if (sk->sk_state == BT_CONNECT2 && bt_sk(sk)->defer_setup) {
733 sk->sk_state = BT_CONFIG; 734 sk->sk_state = BT_CONFIG;
735 pi->chan->state = BT_CONFIG;
734 736
735 __l2cap_connect_rsp_defer(pi->chan); 737 __l2cap_connect_rsp_defer(pi->chan);
736 release_sock(sk); 738 release_sock(sk);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 2540944d871f..bc8e59dda78e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -291,7 +291,7 @@ static u32 get_current_settings(struct hci_dev *hdev)
291 if (!(hdev->features[4] & LMP_NO_BREDR)) 291 if (!(hdev->features[4] & LMP_NO_BREDR))
292 settings |= MGMT_SETTING_BREDR; 292 settings |= MGMT_SETTING_BREDR;
293 293
294 if (hdev->extfeatures[0] & LMP_HOST_LE) 294 if (hdev->host_features[0] & LMP_HOST_LE)
295 settings |= MGMT_SETTING_LE; 295 settings |= MGMT_SETTING_LE;
296 296
297 if (test_bit(HCI_AUTH, &hdev->flags)) 297 if (test_bit(HCI_AUTH, &hdev->flags))
@@ -2756,7 +2756,7 @@ int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status)
2756 if (!cmd) 2756 if (!cmd)
2757 return -ENOENT; 2757 return -ENOENT;
2758 2758
2759 err = cmd_status(cmd->sk, hdev->id, cmd->opcode, status); 2759 err = cmd_status(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status));
2760 mgmt_pending_remove(cmd); 2760 mgmt_pending_remove(cmd);
2761 2761
2762 return err; 2762 return err;
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index aea2bdd1510f..f066678faeee 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -370,7 +370,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
370 goto done; 370 goto done;
371 } 371 }
372 372
373 write_lock_bh(&rfcomm_sk_list.lock); 373 write_lock(&rfcomm_sk_list.lock);
374 374
375 if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) { 375 if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) {
376 err = -EADDRINUSE; 376 err = -EADDRINUSE;
@@ -381,7 +381,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
381 sk->sk_state = BT_BOUND; 381 sk->sk_state = BT_BOUND;
382 } 382 }
383 383
384 write_unlock_bh(&rfcomm_sk_list.lock); 384 write_unlock(&rfcomm_sk_list.lock);
385 385
386done: 386done:
387 release_sock(sk); 387 release_sock(sk);
@@ -455,7 +455,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
455 455
456 err = -EINVAL; 456 err = -EINVAL;
457 457
458 write_lock_bh(&rfcomm_sk_list.lock); 458 write_lock(&rfcomm_sk_list.lock);
459 459
460 for (channel = 1; channel < 31; channel++) 460 for (channel = 1; channel < 31; channel++)
461 if (!__rfcomm_get_sock_by_addr(channel, src)) { 461 if (!__rfcomm_get_sock_by_addr(channel, src)) {
@@ -464,7 +464,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
464 break; 464 break;
465 } 465 }
466 466
467 write_unlock_bh(&rfcomm_sk_list.lock); 467 write_unlock(&rfcomm_sk_list.lock);
468 468
469 if (err < 0) 469 if (err < 0)
470 goto done; 470 goto done;
@@ -982,7 +982,7 @@ static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
982 struct sock *sk; 982 struct sock *sk;
983 struct hlist_node *node; 983 struct hlist_node *node;
984 984
985 read_lock_bh(&rfcomm_sk_list.lock); 985 read_lock(&rfcomm_sk_list.lock);
986 986
987 sk_for_each(sk, node, &rfcomm_sk_list.head) { 987 sk_for_each(sk, node, &rfcomm_sk_list.head) {
988 seq_printf(f, "%s %s %d %d\n", 988 seq_printf(f, "%s %s %d %d\n",
@@ -991,7 +991,7 @@ static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
991 sk->sk_state, rfcomm_pi(sk)->channel); 991 sk->sk_state, rfcomm_pi(sk)->channel);
992 } 992 }
993 993
994 read_unlock_bh(&rfcomm_sk_list.lock); 994 read_unlock(&rfcomm_sk_list.lock);
995 995
996 return 0; 996 return 0;
997} 997}
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index fa8f4de53b99..a2d4f5122a6a 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -76,7 +76,7 @@ struct rfcomm_dev {
76}; 76};
77 77
78static LIST_HEAD(rfcomm_dev_list); 78static LIST_HEAD(rfcomm_dev_list);
79static DEFINE_RWLOCK(rfcomm_dev_lock); 79static DEFINE_SPINLOCK(rfcomm_dev_lock);
80 80
81static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb); 81static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb);
82static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err); 82static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);
@@ -146,7 +146,7 @@ static inline struct rfcomm_dev *rfcomm_dev_get(int id)
146{ 146{
147 struct rfcomm_dev *dev; 147 struct rfcomm_dev *dev;
148 148
149 read_lock(&rfcomm_dev_lock); 149 spin_lock(&rfcomm_dev_lock);
150 150
151 dev = __rfcomm_dev_get(id); 151 dev = __rfcomm_dev_get(id);
152 152
@@ -157,7 +157,7 @@ static inline struct rfcomm_dev *rfcomm_dev_get(int id)
157 rfcomm_dev_hold(dev); 157 rfcomm_dev_hold(dev);
158 } 158 }
159 159
160 read_unlock(&rfcomm_dev_lock); 160 spin_unlock(&rfcomm_dev_lock);
161 161
162 return dev; 162 return dev;
163} 163}
@@ -205,7 +205,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
205 if (!dev) 205 if (!dev)
206 return -ENOMEM; 206 return -ENOMEM;
207 207
208 write_lock_bh(&rfcomm_dev_lock); 208 spin_lock(&rfcomm_dev_lock);
209 209
210 if (req->dev_id < 0) { 210 if (req->dev_id < 0) {
211 dev->id = 0; 211 dev->id = 0;
@@ -290,7 +290,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
290 __module_get(THIS_MODULE); 290 __module_get(THIS_MODULE);
291 291
292out: 292out:
293 write_unlock_bh(&rfcomm_dev_lock); 293 spin_unlock(&rfcomm_dev_lock);
294 294
295 if (err < 0) 295 if (err < 0)
296 goto free; 296 goto free;
@@ -327,9 +327,9 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
327 if (atomic_read(&dev->opened) > 0) 327 if (atomic_read(&dev->opened) > 0)
328 return; 328 return;
329 329
330 write_lock_bh(&rfcomm_dev_lock); 330 spin_lock(&rfcomm_dev_lock);
331 list_del_init(&dev->list); 331 list_del_init(&dev->list);
332 write_unlock_bh(&rfcomm_dev_lock); 332 spin_unlock(&rfcomm_dev_lock);
333 333
334 rfcomm_dev_put(dev); 334 rfcomm_dev_put(dev);
335} 335}
@@ -473,7 +473,7 @@ static int rfcomm_get_dev_list(void __user *arg)
473 473
474 di = dl->dev_info; 474 di = dl->dev_info;
475 475
476 read_lock_bh(&rfcomm_dev_lock); 476 spin_lock(&rfcomm_dev_lock);
477 477
478 list_for_each_entry(dev, &rfcomm_dev_list, list) { 478 list_for_each_entry(dev, &rfcomm_dev_list, list) {
479 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) 479 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))
@@ -488,7 +488,7 @@ static int rfcomm_get_dev_list(void __user *arg)
488 break; 488 break;
489 } 489 }
490 490
491 read_unlock_bh(&rfcomm_dev_lock); 491 spin_unlock(&rfcomm_dev_lock);
492 492
493 dl->dev_num = n; 493 dl->dev_num = n;
494 size = sizeof(*dl) + n * sizeof(*di); 494 size = sizeof(*dl) + n * sizeof(*di);
@@ -766,9 +766,9 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
766 rfcomm_dlc_unlock(dev->dlc); 766 rfcomm_dlc_unlock(dev->dlc);
767 767
768 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) { 768 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {
769 write_lock_bh(&rfcomm_dev_lock); 769 spin_lock(&rfcomm_dev_lock);
770 list_del_init(&dev->list); 770 list_del_init(&dev->list);
771 write_unlock_bh(&rfcomm_dev_lock); 771 spin_unlock(&rfcomm_dev_lock);
772 772
773 rfcomm_dev_put(dev); 773 rfcomm_dev_put(dev);
774 } 774 }
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 5dc2f2126fac..8bf26d1bc5c1 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -482,7 +482,7 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
482 goto done; 482 goto done;
483 } 483 }
484 484
485 write_lock_bh(&sco_sk_list.lock); 485 write_lock(&sco_sk_list.lock);
486 486
487 if (bacmp(src, BDADDR_ANY) && __sco_get_sock_by_addr(src)) { 487 if (bacmp(src, BDADDR_ANY) && __sco_get_sock_by_addr(src)) {
488 err = -EADDRINUSE; 488 err = -EADDRINUSE;
@@ -492,7 +492,7 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
492 sk->sk_state = BT_BOUND; 492 sk->sk_state = BT_BOUND;
493 } 493 }
494 494
495 write_unlock_bh(&sco_sk_list.lock); 495 write_unlock(&sco_sk_list.lock);
496 496
497done: 497done:
498 release_sock(sk); 498 release_sock(sk);
@@ -965,14 +965,14 @@ static int sco_debugfs_show(struct seq_file *f, void *p)
965 struct sock *sk; 965 struct sock *sk;
966 struct hlist_node *node; 966 struct hlist_node *node;
967 967
968 read_lock_bh(&sco_sk_list.lock); 968 read_lock(&sco_sk_list.lock);
969 969
970 sk_for_each(sk, node, &sco_sk_list.head) { 970 sk_for_each(sk, node, &sco_sk_list.head) {
971 seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src), 971 seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src),
972 batostr(&bt_sk(sk)->dst), sk->sk_state); 972 batostr(&bt_sk(sk)->dst), sk->sk_state);
973 } 973 }
974 974
975 read_unlock_bh(&sco_sk_list.lock); 975 read_unlock(&sco_sk_list.lock);
976 976
977 return 0; 977 return 0;
978} 978}
diff --git a/net/ceph/crush/mapper.c b/net/ceph/crush/mapper.c
index 3a94eae7abe9..b79747c4b645 100644
--- a/net/ceph/crush/mapper.c
+++ b/net/ceph/crush/mapper.c
@@ -510,10 +510,15 @@ int crush_do_rule(struct crush_map *map,
510 switch (rule->steps[step].op) { 510 switch (rule->steps[step].op) {
511 case CRUSH_RULE_TAKE: 511 case CRUSH_RULE_TAKE:
512 w[0] = rule->steps[step].arg1; 512 w[0] = rule->steps[step].arg1;
513 if (force_pos >= 0) { 513
514 BUG_ON(force_context[force_pos] != w[0]); 514 /* find position in force_context/hierarchy */
515 while (force_pos >= 0 &&
516 force_context[force_pos] != w[0])
515 force_pos--; 517 force_pos--;
516 } 518 /* and move past it */
519 if (force_pos >= 0)
520 force_pos--;
521
517 wsize = 1; 522 wsize = 1;
518 break; 523 break;
519 524
diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c
index 85f3bc0a7062..b780cb7947dd 100644
--- a/net/ceph/crypto.c
+++ b/net/ceph/crypto.c
@@ -15,10 +15,9 @@ int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
15 const struct ceph_crypto_key *src) 15 const struct ceph_crypto_key *src)
16{ 16{
17 memcpy(dst, src, sizeof(struct ceph_crypto_key)); 17 memcpy(dst, src, sizeof(struct ceph_crypto_key));
18 dst->key = kmalloc(src->len, GFP_NOFS); 18 dst->key = kmemdup(src->key, src->len, GFP_NOFS);
19 if (!dst->key) 19 if (!dst->key)
20 return -ENOMEM; 20 return -ENOMEM;
21 memcpy(dst->key, src->key, src->len);
22 return 0; 21 return 0;
23} 22}
24 23
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index f4f3f58f5234..5e254055c910 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -29,8 +29,8 @@ static void __register_request(struct ceph_osd_client *osdc,
29 struct ceph_osd_request *req); 29 struct ceph_osd_request *req);
30static void __unregister_linger_request(struct ceph_osd_client *osdc, 30static void __unregister_linger_request(struct ceph_osd_client *osdc,
31 struct ceph_osd_request *req); 31 struct ceph_osd_request *req);
32static int __send_request(struct ceph_osd_client *osdc, 32static void __send_request(struct ceph_osd_client *osdc,
33 struct ceph_osd_request *req); 33 struct ceph_osd_request *req);
34 34
35static int op_needs_trail(int op) 35static int op_needs_trail(int op)
36{ 36{
@@ -1022,8 +1022,8 @@ out:
1022/* 1022/*
1023 * caller should hold map_sem (for read) and request_mutex 1023 * caller should hold map_sem (for read) and request_mutex
1024 */ 1024 */
1025static int __send_request(struct ceph_osd_client *osdc, 1025static void __send_request(struct ceph_osd_client *osdc,
1026 struct ceph_osd_request *req) 1026 struct ceph_osd_request *req)
1027{ 1027{
1028 struct ceph_osd_request_head *reqhead; 1028 struct ceph_osd_request_head *reqhead;
1029 1029
@@ -1041,7 +1041,6 @@ static int __send_request(struct ceph_osd_client *osdc,
1041 ceph_msg_get(req->r_request); /* send consumes a ref */ 1041 ceph_msg_get(req->r_request); /* send consumes a ref */
1042 ceph_con_send(&req->r_osd->o_con, req->r_request); 1042 ceph_con_send(&req->r_osd->o_con, req->r_request);
1043 req->r_sent = req->r_osd->o_incarnation; 1043 req->r_sent = req->r_osd->o_incarnation;
1044 return 0;
1045} 1044}
1046 1045
1047/* 1046/*
@@ -1726,17 +1725,9 @@ int ceph_osdc_start_request(struct ceph_osd_client *osdc,
1726 dout("send_request %p no up osds in pg\n", req); 1725 dout("send_request %p no up osds in pg\n", req);
1727 ceph_monc_request_next_osdmap(&osdc->client->monc); 1726 ceph_monc_request_next_osdmap(&osdc->client->monc);
1728 } else { 1727 } else {
1729 rc = __send_request(osdc, req); 1728 __send_request(osdc, req);
1730 if (rc) {
1731 if (nofail) {
1732 dout("osdc_start_request failed send, "
1733 " will retry %lld\n", req->r_tid);
1734 rc = 0;
1735 } else {
1736 __unregister_request(osdc, req);
1737 }
1738 }
1739 } 1729 }
1730 rc = 0;
1740 } 1731 }
1741 1732
1742out_unlock: 1733out_unlock:
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index abf4393a77b3..f3dbd4f596a4 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1177,9 +1177,9 @@ static ssize_t store_xps_map(struct netdev_queue *queue,
1177 nonempty = 1; 1177 nonempty = 1;
1178 } 1178 }
1179 1179
1180 if (nonempty) 1180 if (nonempty) {
1181 RCU_INIT_POINTER(dev->xps_maps, new_dev_maps); 1181 rcu_assign_pointer(dev->xps_maps, new_dev_maps);
1182 else { 1182 } else {
1183 kfree(new_dev_maps); 1183 kfree(new_dev_maps);
1184 RCU_INIT_POINTER(dev->xps_maps, NULL); 1184 RCU_INIT_POINTER(dev->xps_maps, NULL);
1185 } 1185 }
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 0d38808a2305..556b08298669 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -765,7 +765,7 @@ int __netpoll_setup(struct netpoll *np)
765 } 765 }
766 766
767 /* last thing to do is link it to the net device structure */ 767 /* last thing to do is link it to the net device structure */
768 RCU_INIT_POINTER(ndev->npinfo, npinfo); 768 rcu_assign_pointer(ndev->npinfo, npinfo);
769 769
770 return 0; 770 return 0;
771 771
diff --git a/net/dccp/diag.c b/net/dccp/diag.c
index 8f1625753377..028fc43aacbd 100644
--- a/net/dccp/diag.c
+++ b/net/dccp/diag.c
@@ -49,13 +49,13 @@ static void dccp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
49} 49}
50 50
51static void dccp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 51static void dccp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
52 struct inet_diag_req *r, struct nlattr *bc) 52 struct inet_diag_req_v2 *r, struct nlattr *bc)
53{ 53{
54 inet_diag_dump_icsk(&dccp_hashinfo, skb, cb, r, bc); 54 inet_diag_dump_icsk(&dccp_hashinfo, skb, cb, r, bc);
55} 55}
56 56
57static int dccp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, 57static int dccp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
58 struct inet_diag_req *req) 58 struct inet_diag_req_v2 *req)
59{ 59{
60 return inet_diag_dump_one_icsk(&dccp_hashinfo, in_skb, nlh, req); 60 return inet_diag_dump_one_icsk(&dccp_hashinfo, in_skb, nlh, req);
61} 61}
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 2ab16e12520c..74d321a60e7b 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -388,7 +388,7 @@ static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
388 } 388 }
389 389
390 ifa->ifa_next = dn_db->ifa_list; 390 ifa->ifa_next = dn_db->ifa_list;
391 RCU_INIT_POINTER(dn_db->ifa_list, ifa); 391 rcu_assign_pointer(dn_db->ifa_list, ifa);
392 392
393 dn_ifaddr_notify(RTM_NEWADDR, ifa); 393 dn_ifaddr_notify(RTM_NEWADDR, ifa);
394 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa); 394 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa);
@@ -1093,7 +1093,7 @@ static struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1093 1093
1094 memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms)); 1094 memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
1095 1095
1096 RCU_INIT_POINTER(dev->dn_ptr, dn_db); 1096 rcu_assign_pointer(dev->dn_ptr, dn_db);
1097 dn_db->dev = dev; 1097 dn_db->dev = dev;
1098 init_timer(&dn_db->timer); 1098 init_timer(&dn_db->timer);
1099 1099
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 65f01dc47565..e41c40f48cfe 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -258,7 +258,7 @@ static struct in_device *inetdev_init(struct net_device *dev)
258 ip_mc_up(in_dev); 258 ip_mc_up(in_dev);
259 259
260 /* we can receive as soon as ip_ptr is set -- do this last */ 260 /* we can receive as soon as ip_ptr is set -- do this last */
261 RCU_INIT_POINTER(dev->ip_ptr, in_dev); 261 rcu_assign_pointer(dev->ip_ptr, in_dev);
262out: 262out:
263 return in_dev; 263 return in_dev;
264out_kfree: 264out_kfree:
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index d04b13ae18fe..2b555a5521e0 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -205,7 +205,7 @@ static inline struct tnode *node_parent_rcu(const struct rt_trie_node *node)
205 return (struct tnode *)(parent & ~NODE_TYPE_MASK); 205 return (struct tnode *)(parent & ~NODE_TYPE_MASK);
206} 206}
207 207
208/* Same as RCU_INIT_POINTER 208/* Same as rcu_assign_pointer
209 * but that macro() assumes that value is a pointer. 209 * but that macro() assumes that value is a pointer.
210 */ 210 */
211static inline void node_set_parent(struct rt_trie_node *node, struct tnode *ptr) 211static inline void node_set_parent(struct rt_trie_node *node, struct tnode *ptr)
@@ -529,7 +529,7 @@ static void tnode_put_child_reorg(struct tnode *tn, int i, struct rt_trie_node *
529 if (n) 529 if (n)
530 node_set_parent(n, tn); 530 node_set_parent(n, tn);
531 531
532 RCU_INIT_POINTER(tn->child[i], n); 532 rcu_assign_pointer(tn->child[i], n);
533} 533}
534 534
535#define MAX_WORK 10 535#define MAX_WORK 10
@@ -1015,7 +1015,7 @@ static void trie_rebalance(struct trie *t, struct tnode *tn)
1015 1015
1016 tp = node_parent((struct rt_trie_node *) tn); 1016 tp = node_parent((struct rt_trie_node *) tn);
1017 if (!tp) 1017 if (!tp)
1018 RCU_INIT_POINTER(t->trie, (struct rt_trie_node *)tn); 1018 rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn);
1019 1019
1020 tnode_free_flush(); 1020 tnode_free_flush();
1021 if (!tp) 1021 if (!tp)
@@ -1027,7 +1027,7 @@ static void trie_rebalance(struct trie *t, struct tnode *tn)
1027 if (IS_TNODE(tn)) 1027 if (IS_TNODE(tn))
1028 tn = (struct tnode *)resize(t, (struct tnode *)tn); 1028 tn = (struct tnode *)resize(t, (struct tnode *)tn);
1029 1029
1030 RCU_INIT_POINTER(t->trie, (struct rt_trie_node *)tn); 1030 rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn);
1031 tnode_free_flush(); 1031 tnode_free_flush();
1032} 1032}
1033 1033
@@ -1164,7 +1164,7 @@ static struct list_head *fib_insert_node(struct trie *t, u32 key, int plen)
1164 put_child(t, (struct tnode *)tp, cindex, 1164 put_child(t, (struct tnode *)tp, cindex,
1165 (struct rt_trie_node *)tn); 1165 (struct rt_trie_node *)tn);
1166 } else { 1166 } else {
1167 RCU_INIT_POINTER(t->trie, (struct rt_trie_node *)tn); 1167 rcu_assign_pointer(t->trie, (struct rt_trie_node *)tn);
1168 tp = tn; 1168 tp = tn;
1169 } 1169 }
1170 } 1170 }
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 5104bc0bbdbe..450e5d21ed2a 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1249,7 +1249,7 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr)
1249 1249
1250 im->next_rcu = in_dev->mc_list; 1250 im->next_rcu = in_dev->mc_list;
1251 in_dev->mc_count++; 1251 in_dev->mc_count++;
1252 RCU_INIT_POINTER(in_dev->mc_list, im); 1252 rcu_assign_pointer(in_dev->mc_list, im);
1253 1253
1254#ifdef CONFIG_IP_MULTICAST 1254#ifdef CONFIG_IP_MULTICAST
1255 igmpv3_del_delrec(in_dev, im->multiaddr); 1255 igmpv3_del_delrec(in_dev, im->multiaddr);
@@ -1821,7 +1821,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1821 iml->next_rcu = inet->mc_list; 1821 iml->next_rcu = inet->mc_list;
1822 iml->sflist = NULL; 1822 iml->sflist = NULL;
1823 iml->sfmode = MCAST_EXCLUDE; 1823 iml->sfmode = MCAST_EXCLUDE;
1824 RCU_INIT_POINTER(inet->mc_list, iml); 1824 rcu_assign_pointer(inet->mc_list, iml);
1825 ip_mc_inc_group(in_dev, addr); 1825 ip_mc_inc_group(in_dev, addr);
1826 err = 0; 1826 err = 0;
1827done: 1827done:
@@ -2008,7 +2008,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
2008 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc); 2008 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc);
2009 kfree_rcu(psl, rcu); 2009 kfree_rcu(psl, rcu);
2010 } 2010 }
2011 RCU_INIT_POINTER(pmc->sflist, newpsl); 2011 rcu_assign_pointer(pmc->sflist, newpsl);
2012 psl = newpsl; 2012 psl = newpsl;
2013 } 2013 }
2014 rv = 1; /* > 0 for insert logic below if sl_count is 0 */ 2014 rv = 1; /* > 0 for insert logic below if sl_count is 0 */
@@ -2111,7 +2111,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
2111 } else 2111 } else
2112 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, 2112 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode,
2113 0, NULL, 0); 2113 0, NULL, 0);
2114 RCU_INIT_POINTER(pmc->sflist, newpsl); 2114 rcu_assign_pointer(pmc->sflist, newpsl);
2115 pmc->sfmode = msf->imsf_fmode; 2115 pmc->sfmode = msf->imsf_fmode;
2116 err = 0; 2116 err = 0;
2117done: 2117done:
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 2240a8e8c44d..fcf281819cd4 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -71,7 +71,7 @@ static inline void inet_diag_unlock_handler(
71} 71}
72 72
73int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, 73int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
74 struct sk_buff *skb, struct inet_diag_req *req, 74 struct sk_buff *skb, struct inet_diag_req_v2 *req,
75 u32 pid, u32 seq, u16 nlmsg_flags, 75 u32 pid, u32 seq, u16 nlmsg_flags,
76 const struct nlmsghdr *unlh) 76 const struct nlmsghdr *unlh)
77{ 77{
@@ -193,7 +193,7 @@ nlmsg_failure:
193EXPORT_SYMBOL_GPL(inet_sk_diag_fill); 193EXPORT_SYMBOL_GPL(inet_sk_diag_fill);
194 194
195static int inet_csk_diag_fill(struct sock *sk, 195static int inet_csk_diag_fill(struct sock *sk,
196 struct sk_buff *skb, struct inet_diag_req *req, 196 struct sk_buff *skb, struct inet_diag_req_v2 *req,
197 u32 pid, u32 seq, u16 nlmsg_flags, 197 u32 pid, u32 seq, u16 nlmsg_flags,
198 const struct nlmsghdr *unlh) 198 const struct nlmsghdr *unlh)
199{ 199{
@@ -202,7 +202,7 @@ static int inet_csk_diag_fill(struct sock *sk,
202} 202}
203 203
204static int inet_twsk_diag_fill(struct inet_timewait_sock *tw, 204static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
205 struct sk_buff *skb, struct inet_diag_req *req, 205 struct sk_buff *skb, struct inet_diag_req_v2 *req,
206 u32 pid, u32 seq, u16 nlmsg_flags, 206 u32 pid, u32 seq, u16 nlmsg_flags,
207 const struct nlmsghdr *unlh) 207 const struct nlmsghdr *unlh)
208{ 208{
@@ -253,7 +253,7 @@ nlmsg_failure:
253} 253}
254 254
255static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, 255static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
256 struct inet_diag_req *r, u32 pid, u32 seq, u16 nlmsg_flags, 256 struct inet_diag_req_v2 *r, u32 pid, u32 seq, u16 nlmsg_flags,
257 const struct nlmsghdr *unlh) 257 const struct nlmsghdr *unlh)
258{ 258{
259 if (sk->sk_state == TCP_TIME_WAIT) 259 if (sk->sk_state == TCP_TIME_WAIT)
@@ -264,7 +264,7 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
264} 264}
265 265
266int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_skb, 266int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_skb,
267 const struct nlmsghdr *nlh, struct inet_diag_req *req) 267 const struct nlmsghdr *nlh, struct inet_diag_req_v2 *req)
268{ 268{
269 int err; 269 int err;
270 struct sock *sk; 270 struct sock *sk;
@@ -333,7 +333,7 @@ EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk);
333 333
334static int inet_diag_get_exact(struct sk_buff *in_skb, 334static int inet_diag_get_exact(struct sk_buff *in_skb,
335 const struct nlmsghdr *nlh, 335 const struct nlmsghdr *nlh,
336 struct inet_diag_req *req) 336 struct inet_diag_req_v2 *req)
337{ 337{
338 const struct inet_diag_handler *handler; 338 const struct inet_diag_handler *handler;
339 int err; 339 int err;
@@ -540,7 +540,7 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
540static int inet_csk_diag_dump(struct sock *sk, 540static int inet_csk_diag_dump(struct sock *sk,
541 struct sk_buff *skb, 541 struct sk_buff *skb,
542 struct netlink_callback *cb, 542 struct netlink_callback *cb,
543 struct inet_diag_req *r, 543 struct inet_diag_req_v2 *r,
544 const struct nlattr *bc) 544 const struct nlattr *bc)
545{ 545{
546 if (!inet_diag_bc_sk(bc, sk)) 546 if (!inet_diag_bc_sk(bc, sk))
@@ -554,7 +554,7 @@ static int inet_csk_diag_dump(struct sock *sk,
554static int inet_twsk_diag_dump(struct inet_timewait_sock *tw, 554static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
555 struct sk_buff *skb, 555 struct sk_buff *skb,
556 struct netlink_callback *cb, 556 struct netlink_callback *cb,
557 struct inet_diag_req *r, 557 struct inet_diag_req_v2 *r,
558 const struct nlattr *bc) 558 const struct nlattr *bc)
559{ 559{
560 if (bc != NULL) { 560 if (bc != NULL) {
@@ -639,7 +639,7 @@ nlmsg_failure:
639 639
640static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk, 640static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
641 struct netlink_callback *cb, 641 struct netlink_callback *cb,
642 struct inet_diag_req *r, 642 struct inet_diag_req_v2 *r,
643 const struct nlattr *bc) 643 const struct nlattr *bc)
644{ 644{
645 struct inet_diag_entry entry; 645 struct inet_diag_entry entry;
@@ -721,7 +721,7 @@ out:
721} 721}
722 722
723void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb, 723void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb,
724 struct netlink_callback *cb, struct inet_diag_req *r, struct nlattr *bc) 724 struct netlink_callback *cb, struct inet_diag_req_v2 *r, struct nlattr *bc)
725{ 725{
726 int i, num; 726 int i, num;
727 int s_i, s_num; 727 int s_i, s_num;
@@ -872,7 +872,7 @@ out:
872EXPORT_SYMBOL_GPL(inet_diag_dump_icsk); 872EXPORT_SYMBOL_GPL(inet_diag_dump_icsk);
873 873
874static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 874static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
875 struct inet_diag_req *r, struct nlattr *bc) 875 struct inet_diag_req_v2 *r, struct nlattr *bc)
876{ 876{
877 const struct inet_diag_handler *handler; 877 const struct inet_diag_handler *handler;
878 878
@@ -887,12 +887,12 @@ static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
887static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) 887static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
888{ 888{
889 struct nlattr *bc = NULL; 889 struct nlattr *bc = NULL;
890 int hdrlen = sizeof(struct inet_diag_req); 890 int hdrlen = sizeof(struct inet_diag_req_v2);
891 891
892 if (nlmsg_attrlen(cb->nlh, hdrlen)) 892 if (nlmsg_attrlen(cb->nlh, hdrlen))
893 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE); 893 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
894 894
895 return __inet_diag_dump(skb, cb, (struct inet_diag_req *)NLMSG_DATA(cb->nlh), bc); 895 return __inet_diag_dump(skb, cb, (struct inet_diag_req_v2 *)NLMSG_DATA(cb->nlh), bc);
896} 896}
897 897
898static inline int inet_diag_type2proto(int type) 898static inline int inet_diag_type2proto(int type)
@@ -909,10 +909,10 @@ static inline int inet_diag_type2proto(int type)
909 909
910static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb) 910static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
911{ 911{
912 struct inet_diag_req_compat *rc = NLMSG_DATA(cb->nlh); 912 struct inet_diag_req *rc = NLMSG_DATA(cb->nlh);
913 struct inet_diag_req req; 913 struct inet_diag_req_v2 req;
914 struct nlattr *bc = NULL; 914 struct nlattr *bc = NULL;
915 int hdrlen = sizeof(struct inet_diag_req_compat); 915 int hdrlen = sizeof(struct inet_diag_req);
916 916
917 req.sdiag_family = AF_UNSPEC; /* compatibility */ 917 req.sdiag_family = AF_UNSPEC; /* compatibility */
918 req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type); 918 req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
@@ -929,8 +929,8 @@ static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *c
929static int inet_diag_get_exact_compat(struct sk_buff *in_skb, 929static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
930 const struct nlmsghdr *nlh) 930 const struct nlmsghdr *nlh)
931{ 931{
932 struct inet_diag_req_compat *rc = NLMSG_DATA(nlh); 932 struct inet_diag_req *rc = NLMSG_DATA(nlh);
933 struct inet_diag_req req; 933 struct inet_diag_req_v2 req;
934 934
935 req.sdiag_family = rc->idiag_family; 935 req.sdiag_family = rc->idiag_family;
936 req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type); 936 req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type);
@@ -943,7 +943,7 @@ static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
943 943
944static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) 944static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
945{ 945{
946 int hdrlen = sizeof(struct inet_diag_req_compat); 946 int hdrlen = sizeof(struct inet_diag_req);
947 947
948 if (nlh->nlmsg_type >= INET_DIAG_GETSOCK_MAX || 948 if (nlh->nlmsg_type >= INET_DIAG_GETSOCK_MAX ||
949 nlmsg_len(nlh) < hdrlen) 949 nlmsg_len(nlh) < hdrlen)
@@ -970,7 +970,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
970 970
971static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) 971static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
972{ 972{
973 int hdrlen = sizeof(struct inet_diag_req); 973 int hdrlen = sizeof(struct inet_diag_req_v2);
974 974
975 if (nlmsg_len(h) < hdrlen) 975 if (nlmsg_len(h) < hdrlen)
976 return -EINVAL; 976 return -EINVAL;
@@ -990,7 +990,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
990 inet_diag_dump, NULL, 0); 990 inet_diag_dump, NULL, 0);
991 } 991 }
992 992
993 return inet_diag_get_exact(skb, h, (struct inet_diag_req *)NLMSG_DATA(h)); 993 return inet_diag_get_exact(skb, h, (struct inet_diag_req_v2 *)NLMSG_DATA(h));
994} 994}
995 995
996static struct sock_diag_handler inet_diag_handler = { 996static struct sock_diag_handler inet_diag_handler = {
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 413ed1ba7a5a..22a199315309 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -231,7 +231,7 @@ static void ipip_tunnel_unlink(struct ipip_net *ipn, struct ip_tunnel *t)
231 (iter = rtnl_dereference(*tp)) != NULL; 231 (iter = rtnl_dereference(*tp)) != NULL;
232 tp = &iter->next) { 232 tp = &iter->next) {
233 if (t == iter) { 233 if (t == iter) {
234 RCU_INIT_POINTER(*tp, t->next); 234 rcu_assign_pointer(*tp, t->next);
235 break; 235 break;
236 } 236 }
237 } 237 }
@@ -241,8 +241,8 @@ static void ipip_tunnel_link(struct ipip_net *ipn, struct ip_tunnel *t)
241{ 241{
242 struct ip_tunnel __rcu **tp = ipip_bucket(ipn, t); 242 struct ip_tunnel __rcu **tp = ipip_bucket(ipn, t);
243 243
244 RCU_INIT_POINTER(t->next, rtnl_dereference(*tp)); 244 rcu_assign_pointer(t->next, rtnl_dereference(*tp));
245 RCU_INIT_POINTER(*tp, t); 245 rcu_assign_pointer(*tp, t);
246} 246}
247 247
248static struct ip_tunnel * ipip_tunnel_locate(struct net *net, 248static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
@@ -792,7 +792,7 @@ static int __net_init ipip_fb_tunnel_init(struct net_device *dev)
792 return -ENOMEM; 792 return -ENOMEM;
793 793
794 dev_hold(dev); 794 dev_hold(dev);
795 RCU_INIT_POINTER(ipn->tunnels_wc[0], tunnel); 795 rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
796 return 0; 796 return 0;
797} 797}
798 798
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 8e54490ee3f4..7bc2db6db8d4 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1225,7 +1225,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
1225 1225
1226 ret = ip_ra_control(sk, 1, mrtsock_destruct); 1226 ret = ip_ra_control(sk, 1, mrtsock_destruct);
1227 if (ret == 0) { 1227 if (ret == 0) {
1228 RCU_INIT_POINTER(mrt->mroute_sk, sk); 1228 rcu_assign_pointer(mrt->mroute_sk, sk);
1229 IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; 1229 IPV4_DEVCONF_ALL(net, MC_FORWARDING)++;
1230 } 1230 }
1231 rtnl_unlock(); 1231 rtnl_unlock();
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index 8cd357a8be79..ed3f2ad42e0f 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -35,13 +35,13 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
35} 35}
36 36
37static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 37static void tcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
38 struct inet_diag_req *r, struct nlattr *bc) 38 struct inet_diag_req_v2 *r, struct nlattr *bc)
39{ 39{
40 inet_diag_dump_icsk(&tcp_hashinfo, skb, cb, r, bc); 40 inet_diag_dump_icsk(&tcp_hashinfo, skb, cb, r, bc);
41} 41}
42 42
43static int tcp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, 43static int tcp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
44 struct inet_diag_req *req) 44 struct inet_diag_req_v2 *req)
45{ 45{
46 return inet_diag_dump_one_icsk(&tcp_hashinfo, in_skb, nlh, req); 46 return inet_diag_dump_one_icsk(&tcp_hashinfo, in_skb, nlh, req);
47} 47}
diff --git a/net/ipv4/tcp_memcontrol.c b/net/ipv4/tcp_memcontrol.c
index 7fed04f875c1..49978788a9dc 100644
--- a/net/ipv4/tcp_memcontrol.c
+++ b/net/ipv4/tcp_memcontrol.c
@@ -108,7 +108,7 @@ void tcp_destroy_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss)
108 tcp = tcp_from_cgproto(cg_proto); 108 tcp = tcp_from_cgproto(cg_proto);
109 percpu_counter_destroy(&tcp->tcp_sockets_allocated); 109 percpu_counter_destroy(&tcp->tcp_sockets_allocated);
110 110
111 val = res_counter_read_u64(&tcp->tcp_memory_allocated, RES_USAGE); 111 val = res_counter_read_u64(&tcp->tcp_memory_allocated, RES_LIMIT);
112 112
113 if (val != RESOURCE_MAX) 113 if (val != RESOURCE_MAX)
114 jump_label_dec(&memcg_socket_limit_enabled); 114 jump_label_dec(&memcg_socket_limit_enabled);
diff --git a/net/ipv4/udp_diag.c b/net/ipv4/udp_diag.c
index 69f8a7ca63dd..e5e18cb8a586 100644
--- a/net/ipv4/udp_diag.c
+++ b/net/ipv4/udp_diag.c
@@ -19,7 +19,7 @@
19#include <linux/sock_diag.h> 19#include <linux/sock_diag.h>
20 20
21static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, 21static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
22 struct netlink_callback *cb, struct inet_diag_req *req, 22 struct netlink_callback *cb, struct inet_diag_req_v2 *req,
23 struct nlattr *bc) 23 struct nlattr *bc)
24{ 24{
25 if (!inet_diag_bc_sk(bc, sk)) 25 if (!inet_diag_bc_sk(bc, sk))
@@ -30,7 +30,7 @@ static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
30} 30}
31 31
32static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb, 32static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb,
33 const struct nlmsghdr *nlh, struct inet_diag_req *req) 33 const struct nlmsghdr *nlh, struct inet_diag_req_v2 *req)
34{ 34{
35 int err = -EINVAL; 35 int err = -EINVAL;
36 struct sock *sk; 36 struct sock *sk;
@@ -88,7 +88,7 @@ out_nosk:
88} 88}
89 89
90static void udp_dump(struct udp_table *table, struct sk_buff *skb, struct netlink_callback *cb, 90static void udp_dump(struct udp_table *table, struct sk_buff *skb, struct netlink_callback *cb,
91 struct inet_diag_req *r, struct nlattr *bc) 91 struct inet_diag_req_v2 *r, struct nlattr *bc)
92{ 92{
93 int num, s_num, slot, s_slot; 93 int num, s_num, slot, s_slot;
94 94
@@ -136,13 +136,13 @@ done:
136} 136}
137 137
138static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 138static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
139 struct inet_diag_req *r, struct nlattr *bc) 139 struct inet_diag_req_v2 *r, struct nlattr *bc)
140{ 140{
141 udp_dump(&udp_table, skb, cb, r, bc); 141 udp_dump(&udp_table, skb, cb, r, bc);
142} 142}
143 143
144static int udp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, 144static int udp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
145 struct inet_diag_req *req) 145 struct inet_diag_req_v2 *req)
146{ 146{
147 return udp_dump_one(&udp_table, in_skb, nlh, req); 147 return udp_dump_one(&udp_table, in_skb, nlh, req);
148} 148}
@@ -154,13 +154,13 @@ static const struct inet_diag_handler udp_diag_handler = {
154}; 154};
155 155
156static void udplite_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 156static void udplite_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
157 struct inet_diag_req *r, struct nlattr *bc) 157 struct inet_diag_req_v2 *r, struct nlattr *bc)
158{ 158{
159 udp_dump(&udplite_table, skb, cb, r, bc); 159 udp_dump(&udplite_table, skb, cb, r, bc);
160} 160}
161 161
162static int udplite_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh, 162static int udplite_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
163 struct inet_diag_req *req) 163 struct inet_diag_req_v2 *req)
164{ 164{
165 return udp_dump_one(&udplite_table, in_skb, nlh, req); 165 return udp_dump_one(&udplite_table, in_skb, nlh, req);
166} 166}
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 0ba0866230c9..a225d5ee3c2f 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -429,7 +429,7 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
429 ndev->tstamp = jiffies; 429 ndev->tstamp = jiffies;
430 addrconf_sysctl_register(ndev); 430 addrconf_sysctl_register(ndev);
431 /* protected by rtnl_lock */ 431 /* protected by rtnl_lock */
432 RCU_INIT_POINTER(dev->ip6_ptr, ndev); 432 rcu_assign_pointer(dev->ip6_ptr, ndev);
433 433
434 /* Join all-node multicast group */ 434 /* Join all-node multicast group */
435 ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes); 435 ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes);
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index e1f7761815f3..aa21da6a09cd 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -218,8 +218,8 @@ ip6_tnl_link(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
218{ 218{
219 struct ip6_tnl __rcu **tp = ip6_tnl_bucket(ip6n, &t->parms); 219 struct ip6_tnl __rcu **tp = ip6_tnl_bucket(ip6n, &t->parms);
220 220
221 RCU_INIT_POINTER(t->next , rtnl_dereference(*tp)); 221 rcu_assign_pointer(t->next , rtnl_dereference(*tp));
222 RCU_INIT_POINTER(*tp, t); 222 rcu_assign_pointer(*tp, t);
223} 223}
224 224
225/** 225/**
@@ -237,7 +237,7 @@ ip6_tnl_unlink(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
237 (iter = rtnl_dereference(*tp)) != NULL; 237 (iter = rtnl_dereference(*tp)) != NULL;
238 tp = &iter->next) { 238 tp = &iter->next) {
239 if (t == iter) { 239 if (t == iter) {
240 RCU_INIT_POINTER(*tp, t->next); 240 rcu_assign_pointer(*tp, t->next);
241 break; 241 break;
242 } 242 }
243 } 243 }
@@ -1450,7 +1450,7 @@ static int __net_init ip6_fb_tnl_dev_init(struct net_device *dev)
1450 1450
1451 t->parms.proto = IPPROTO_IPV6; 1451 t->parms.proto = IPPROTO_IPV6;
1452 dev_hold(dev); 1452 dev_hold(dev);
1453 RCU_INIT_POINTER(ip6n->tnls_wc[0], t); 1453 rcu_assign_pointer(ip6n->tnls_wc[0], t);
1454 return 0; 1454 return 0;
1455} 1455}
1456 1456
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index a4894f4f1944..d02f7e4dd611 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -131,7 +131,7 @@ static mh_filter_t __rcu *mh_filter __read_mostly;
131 131
132int rawv6_mh_filter_register(mh_filter_t filter) 132int rawv6_mh_filter_register(mh_filter_t filter)
133{ 133{
134 RCU_INIT_POINTER(mh_filter, filter); 134 rcu_assign_pointer(mh_filter, filter);
135 return 0; 135 return 0;
136} 136}
137EXPORT_SYMBOL(rawv6_mh_filter_register); 137EXPORT_SYMBOL(rawv6_mh_filter_register);
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 3b6dac956bb0..133768e52912 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -182,7 +182,7 @@ static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t)
182 (iter = rtnl_dereference(*tp)) != NULL; 182 (iter = rtnl_dereference(*tp)) != NULL;
183 tp = &iter->next) { 183 tp = &iter->next) {
184 if (t == iter) { 184 if (t == iter) {
185 RCU_INIT_POINTER(*tp, t->next); 185 rcu_assign_pointer(*tp, t->next);
186 break; 186 break;
187 } 187 }
188 } 188 }
@@ -192,8 +192,8 @@ static void ipip6_tunnel_link(struct sit_net *sitn, struct ip_tunnel *t)
192{ 192{
193 struct ip_tunnel __rcu **tp = ipip6_bucket(sitn, t); 193 struct ip_tunnel __rcu **tp = ipip6_bucket(sitn, t);
194 194
195 RCU_INIT_POINTER(t->next, rtnl_dereference(*tp)); 195 rcu_assign_pointer(t->next, rtnl_dereference(*tp));
196 RCU_INIT_POINTER(*tp, t); 196 rcu_assign_pointer(*tp, t);
197} 197}
198 198
199static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) 199static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn)
@@ -393,7 +393,7 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
393 p->addr = a->addr; 393 p->addr = a->addr;
394 p->flags = a->flags; 394 p->flags = a->flags;
395 t->prl_count++; 395 t->prl_count++;
396 RCU_INIT_POINTER(t->prl, p); 396 rcu_assign_pointer(t->prl, p);
397out: 397out:
398 return err; 398 return err;
399} 399}
@@ -1177,7 +1177,7 @@ static int __net_init ipip6_fb_tunnel_init(struct net_device *dev)
1177 if (!dev->tstats) 1177 if (!dev->tstats)
1178 return -ENOMEM; 1178 return -ENOMEM;
1179 dev_hold(dev); 1179 dev_hold(dev);
1180 RCU_INIT_POINTER(sitn->tunnels_wc[0], tunnel); 1180 rcu_assign_pointer(sitn->tunnels_wc[0], tunnel);
1181 return 0; 1181 return 0;
1182} 1182}
1183 1183
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index 96debba2c407..1068f668ac4e 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -332,7 +332,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
332 status = WLAN_STATUS_SUCCESS; 332 status = WLAN_STATUS_SUCCESS;
333 333
334 /* activate it for RX */ 334 /* activate it for RX */
335 RCU_INIT_POINTER(sta->ampdu_mlme.tid_rx[tid], tid_agg_rx); 335 rcu_assign_pointer(sta->ampdu_mlme.tid_rx[tid], tid_agg_rx);
336 336
337 if (timeout) 337 if (timeout)
338 mod_timer(&tid_agg_rx->session_timer, TU_TO_EXP_TIME(timeout)); 338 mod_timer(&tid_agg_rx->session_timer, TU_TO_EXP_TIME(timeout));
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 850bb96bd680..e60df48fa4d4 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -616,7 +616,7 @@ static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
616 616
617 sdata->vif.bss_conf.dtim_period = new->dtim_period; 617 sdata->vif.bss_conf.dtim_period = new->dtim_period;
618 618
619 RCU_INIT_POINTER(sdata->u.ap.beacon, new); 619 rcu_assign_pointer(sdata->u.ap.beacon, new);
620 620
621 synchronize_rcu(); 621 synchronize_rcu();
622 622
@@ -1033,7 +1033,7 @@ static int ieee80211_change_station(struct wiphy *wiphy,
1033 return -EBUSY; 1033 return -EBUSY;
1034 } 1034 }
1035 1035
1036 RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta); 1036 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1037 } 1037 }
1038 1038
1039 sta->sdata = vlansdata; 1039 sta->sdata = vlansdata;
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index f8a32bf98216..b3d76b756cd5 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -207,7 +207,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
207 *pos++ = 0; /* U-APSD no in use */ 207 *pos++ = 0; /* U-APSD no in use */
208 } 208 }
209 209
210 RCU_INIT_POINTER(ifibss->presp, skb); 210 rcu_assign_pointer(ifibss->presp, skb);
211 211
212 sdata->vif.bss_conf.beacon_int = beacon_int; 212 sdata->vif.bss_conf.beacon_int = beacon_int;
213 sdata->vif.bss_conf.basic_rates = basic_rates; 213 sdata->vif.bss_conf.basic_rates = basic_rates;
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index b197136aea2c..3c428d4839c7 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -73,7 +73,7 @@ static int sta_info_hash_del(struct ieee80211_local *local,
73 if (!s) 73 if (!s)
74 return -ENOENT; 74 return -ENOENT;
75 if (s == sta) { 75 if (s == sta) {
76 RCU_INIT_POINTER(local->sta_hash[STA_HASH(sta->sta.addr)], 76 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)],
77 s->hnext); 77 s->hnext);
78 return 0; 78 return 0;
79 } 79 }
@@ -83,7 +83,7 @@ static int sta_info_hash_del(struct ieee80211_local *local,
83 s = rcu_dereference_protected(s->hnext, 83 s = rcu_dereference_protected(s->hnext,
84 lockdep_is_held(&local->sta_mtx)); 84 lockdep_is_held(&local->sta_mtx));
85 if (rcu_access_pointer(s->hnext)) { 85 if (rcu_access_pointer(s->hnext)) {
86 RCU_INIT_POINTER(s->hnext, sta->hnext); 86 rcu_assign_pointer(s->hnext, sta->hnext);
87 return 0; 87 return 0;
88 } 88 }
89 89
@@ -226,7 +226,7 @@ static void sta_info_hash_add(struct ieee80211_local *local,
226{ 226{
227 lockdep_assert_held(&local->sta_mtx); 227 lockdep_assert_held(&local->sta_mtx);
228 sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; 228 sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
229 RCU_INIT_POINTER(local->sta_hash[STA_HASH(sta->sta.addr)], sta); 229 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
230} 230}
231 231
232static void sta_unblock(struct work_struct *wk) 232static void sta_unblock(struct work_struct *wk)
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 93aab0715e8a..422b79851ec5 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -106,7 +106,7 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
106 if (status->flag & RX_FLAG_MMIC_ERROR) 106 if (status->flag & RX_FLAG_MMIC_ERROR)
107 goto mic_fail; 107 goto mic_fail;
108 108
109 if (!(status->flag & RX_FLAG_IV_STRIPPED)) 109 if (!(status->flag & RX_FLAG_IV_STRIPPED) && rx->key)
110 goto update_iv; 110 goto update_iv;
111 111
112 return RX_CONTINUE; 112 return RX_CONTINUE;
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index e875f8902db3..76613f5a55c0 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -777,7 +777,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
777 if (exp->helper) { 777 if (exp->helper) {
778 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC); 778 help = nf_ct_helper_ext_add(ct, GFP_ATOMIC);
779 if (help) 779 if (help)
780 RCU_INIT_POINTER(help->helper, exp->helper); 780 rcu_assign_pointer(help->helper, exp->helper);
781 } 781 }
782 782
783#ifdef CONFIG_NF_CONNTRACK_MARK 783#ifdef CONFIG_NF_CONNTRACK_MARK
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index b62c4148b921..14af6329bdda 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -91,7 +91,7 @@ int nf_conntrack_register_notifier(struct net *net,
91 ret = -EBUSY; 91 ret = -EBUSY;
92 goto out_unlock; 92 goto out_unlock;
93 } 93 }
94 RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb, new); 94 rcu_assign_pointer(net->ct.nf_conntrack_event_cb, new);
95 mutex_unlock(&nf_ct_ecache_mutex); 95 mutex_unlock(&nf_ct_ecache_mutex);
96 return ret; 96 return ret;
97 97
@@ -128,7 +128,7 @@ int nf_ct_expect_register_notifier(struct net *net,
128 ret = -EBUSY; 128 ret = -EBUSY;
129 goto out_unlock; 129 goto out_unlock;
130 } 130 }
131 RCU_INIT_POINTER(net->ct.nf_expect_event_cb, new); 131 rcu_assign_pointer(net->ct.nf_expect_event_cb, new);
132 mutex_unlock(&nf_ct_ecache_mutex); 132 mutex_unlock(&nf_ct_ecache_mutex);
133 return ret; 133 return ret;
134 134
diff --git a/net/netfilter/nf_conntrack_extend.c b/net/netfilter/nf_conntrack_extend.c
index 4605c947dcc4..641ff5f96718 100644
--- a/net/netfilter/nf_conntrack_extend.c
+++ b/net/netfilter/nf_conntrack_extend.c
@@ -169,7 +169,7 @@ int nf_ct_extend_register(struct nf_ct_ext_type *type)
169 before updating alloc_size */ 169 before updating alloc_size */
170 type->alloc_size = ALIGN(sizeof(struct nf_ct_ext), type->align) 170 type->alloc_size = ALIGN(sizeof(struct nf_ct_ext), type->align)
171 + type->len; 171 + type->len;
172 RCU_INIT_POINTER(nf_ct_ext_types[type->id], type); 172 rcu_assign_pointer(nf_ct_ext_types[type->id], type);
173 update_alloc_size(type); 173 update_alloc_size(type);
174out: 174out:
175 mutex_unlock(&nf_ct_ext_type_mutex); 175 mutex_unlock(&nf_ct_ext_type_mutex);
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index c9e0de08aa87..299fec91f741 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -157,7 +157,7 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
157 memset(&help->help, 0, sizeof(help->help)); 157 memset(&help->help, 0, sizeof(help->help));
158 } 158 }
159 159
160 RCU_INIT_POINTER(help->helper, helper); 160 rcu_assign_pointer(help->helper, helper);
161out: 161out:
162 return ret; 162 return ret;
163} 163}
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index e07dc3ae930e..2a4834b83332 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1172,7 +1172,7 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
1172 return -EOPNOTSUPP; 1172 return -EOPNOTSUPP;
1173 } 1173 }
1174 1174
1175 RCU_INIT_POINTER(help->helper, helper); 1175 rcu_assign_pointer(help->helper, helper);
1176 1176
1177 return 0; 1177 return 0;
1178} 1178}
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index ce0c406f58a8..957374a234d4 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -55,7 +55,7 @@ int nf_log_register(u_int8_t pf, struct nf_logger *logger)
55 llog = rcu_dereference_protected(nf_loggers[pf], 55 llog = rcu_dereference_protected(nf_loggers[pf],
56 lockdep_is_held(&nf_log_mutex)); 56 lockdep_is_held(&nf_log_mutex));
57 if (llog == NULL) 57 if (llog == NULL)
58 RCU_INIT_POINTER(nf_loggers[pf], logger); 58 rcu_assign_pointer(nf_loggers[pf], logger);
59 } 59 }
60 60
61 mutex_unlock(&nf_log_mutex); 61 mutex_unlock(&nf_log_mutex);
@@ -92,7 +92,7 @@ int nf_log_bind_pf(u_int8_t pf, const struct nf_logger *logger)
92 mutex_unlock(&nf_log_mutex); 92 mutex_unlock(&nf_log_mutex);
93 return -ENOENT; 93 return -ENOENT;
94 } 94 }
95 RCU_INIT_POINTER(nf_loggers[pf], logger); 95 rcu_assign_pointer(nf_loggers[pf], logger);
96 mutex_unlock(&nf_log_mutex); 96 mutex_unlock(&nf_log_mutex);
97 return 0; 97 return 0;
98} 98}
@@ -250,7 +250,7 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
250 mutex_unlock(&nf_log_mutex); 250 mutex_unlock(&nf_log_mutex);
251 return -ENOENT; 251 return -ENOENT;
252 } 252 }
253 RCU_INIT_POINTER(nf_loggers[tindex], logger); 253 rcu_assign_pointer(nf_loggers[tindex], logger);
254 mutex_unlock(&nf_log_mutex); 254 mutex_unlock(&nf_log_mutex);
255 } else { 255 } else {
256 mutex_lock(&nf_log_mutex); 256 mutex_lock(&nf_log_mutex);
diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
index 99ffd2885088..b3a7db678b8d 100644
--- a/net/netfilter/nf_queue.c
+++ b/net/netfilter/nf_queue.c
@@ -40,7 +40,7 @@ int nf_register_queue_handler(u_int8_t pf, const struct nf_queue_handler *qh)
40 else if (old) 40 else if (old)
41 ret = -EBUSY; 41 ret = -EBUSY;
42 else { 42 else {
43 RCU_INIT_POINTER(queue_handler[pf], qh); 43 rcu_assign_pointer(queue_handler[pf], qh);
44 ret = 0; 44 ret = 0;
45 } 45 }
46 mutex_unlock(&queue_handler_mutex); 46 mutex_unlock(&queue_handler_mutex);
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index c879c1a2370e..b4f8d849480c 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -59,7 +59,7 @@ int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n)
59 nfnl_unlock(); 59 nfnl_unlock();
60 return -EBUSY; 60 return -EBUSY;
61 } 61 }
62 RCU_INIT_POINTER(subsys_table[n->subsys_id], n); 62 rcu_assign_pointer(subsys_table[n->subsys_id], n);
63 nfnl_unlock(); 63 nfnl_unlock();
64 64
65 return 0; 65 return 0;
@@ -210,7 +210,7 @@ static int __net_init nfnetlink_net_init(struct net *net)
210 if (!nfnl) 210 if (!nfnl)
211 return -ENOMEM; 211 return -ENOMEM;
212 net->nfnl_stash = nfnl; 212 net->nfnl_stash = nfnl;
213 RCU_INIT_POINTER(net->nfnl, nfnl); 213 rcu_assign_pointer(net->nfnl, nfnl);
214 return 0; 214 return 0;
215} 215}
216 216
diff --git a/net/netlabel/netlabel_domainhash.c b/net/netlabel/netlabel_domainhash.c
index 38204112b9f4..d8d424337550 100644
--- a/net/netlabel/netlabel_domainhash.c
+++ b/net/netlabel/netlabel_domainhash.c
@@ -282,7 +282,7 @@ int __init netlbl_domhsh_init(u32 size)
282 INIT_LIST_HEAD(&hsh_tbl->tbl[iter]); 282 INIT_LIST_HEAD(&hsh_tbl->tbl[iter]);
283 283
284 spin_lock(&netlbl_domhsh_lock); 284 spin_lock(&netlbl_domhsh_lock);
285 RCU_INIT_POINTER(netlbl_domhsh, hsh_tbl); 285 rcu_assign_pointer(netlbl_domhsh, hsh_tbl);
286 spin_unlock(&netlbl_domhsh_lock); 286 spin_unlock(&netlbl_domhsh_lock);
287 287
288 return 0; 288 return 0;
@@ -330,7 +330,7 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry,
330 &rcu_dereference(netlbl_domhsh)->tbl[bkt]); 330 &rcu_dereference(netlbl_domhsh)->tbl[bkt]);
331 } else { 331 } else {
332 INIT_LIST_HEAD(&entry->list); 332 INIT_LIST_HEAD(&entry->list);
333 RCU_INIT_POINTER(netlbl_domhsh_def, entry); 333 rcu_assign_pointer(netlbl_domhsh_def, entry);
334 } 334 }
335 335
336 if (entry->type == NETLBL_NLTYPE_ADDRSELECT) { 336 if (entry->type == NETLBL_NLTYPE_ADDRSELECT) {
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index 4b5fa0fe78fd..e7ff694f1049 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -354,7 +354,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex)
354 INIT_LIST_HEAD(&iface->list); 354 INIT_LIST_HEAD(&iface->list);
355 if (netlbl_unlhsh_rcu_deref(netlbl_unlhsh_def) != NULL) 355 if (netlbl_unlhsh_rcu_deref(netlbl_unlhsh_def) != NULL)
356 goto add_iface_failure; 356 goto add_iface_failure;
357 RCU_INIT_POINTER(netlbl_unlhsh_def, iface); 357 rcu_assign_pointer(netlbl_unlhsh_def, iface);
358 } 358 }
359 spin_unlock(&netlbl_unlhsh_lock); 359 spin_unlock(&netlbl_unlhsh_lock);
360 360
@@ -1447,11 +1447,9 @@ int __init netlbl_unlabel_init(u32 size)
1447 for (iter = 0; iter < hsh_tbl->size; iter++) 1447 for (iter = 0; iter < hsh_tbl->size; iter++)
1448 INIT_LIST_HEAD(&hsh_tbl->tbl[iter]); 1448 INIT_LIST_HEAD(&hsh_tbl->tbl[iter]);
1449 1449
1450 rcu_read_lock();
1451 spin_lock(&netlbl_unlhsh_lock); 1450 spin_lock(&netlbl_unlhsh_lock);
1452 RCU_INIT_POINTER(netlbl_unlhsh, hsh_tbl); 1451 rcu_assign_pointer(netlbl_unlhsh, hsh_tbl);
1453 spin_unlock(&netlbl_unlhsh_lock); 1452 spin_unlock(&netlbl_unlhsh_lock);
1454 rcu_read_unlock();
1455 1453
1456 register_netdevice_notifier(&netlbl_unlhsh_netdev_notifier); 1454 register_netdevice_notifier(&netlbl_unlhsh_netdev_notifier);
1457 1455
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index bf10ea8fbbf9..d65f699fbf34 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -480,7 +480,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
480 if (proto_tab[protocol]) 480 if (proto_tab[protocol])
481 err = -EBUSY; 481 err = -EBUSY;
482 else 482 else
483 RCU_INIT_POINTER(proto_tab[protocol], pp); 483 rcu_assign_pointer(proto_tab[protocol], pp);
484 mutex_unlock(&proto_tab_lock); 484 mutex_unlock(&proto_tab_lock);
485 485
486 return err; 486 return err;
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index c5827614376b..9b9a85ecc4c7 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -390,7 +390,7 @@ int phonet_route_add(struct net_device *dev, u8 daddr)
390 daddr = daddr >> 2; 390 daddr = daddr >> 2;
391 mutex_lock(&routes->lock); 391 mutex_lock(&routes->lock);
392 if (routes->table[daddr] == NULL) { 392 if (routes->table[daddr] == NULL) {
393 RCU_INIT_POINTER(routes->table[daddr], dev); 393 rcu_assign_pointer(routes->table[daddr], dev);
394 dev_hold(dev); 394 dev_hold(dev);
395 err = 0; 395 err = 0;
396 } 396 }
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 3f8d0b1603b9..4c7eff30dfa9 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -680,7 +680,7 @@ int pn_sock_bind_res(struct sock *sk, u8 res)
680 mutex_lock(&resource_mutex); 680 mutex_lock(&resource_mutex);
681 if (pnres.sk[res] == NULL) { 681 if (pnres.sk[res] == NULL) {
682 sock_hold(sk); 682 sock_hold(sk);
683 RCU_INIT_POINTER(pnres.sk[res], sk); 683 rcu_assign_pointer(pnres.sk[res], sk);
684 ret = 0; 684 ret = 0;
685 } 685 }
686 mutex_unlock(&resource_mutex); 686 mutex_unlock(&resource_mutex);
diff --git a/net/rds/iw_rdma.c b/net/rds/iw_rdma.c
index 4e1de171866c..a817705ce2d0 100644
--- a/net/rds/iw_rdma.c
+++ b/net/rds/iw_rdma.c
@@ -477,17 +477,6 @@ void rds_iw_sync_mr(void *trans_private, int direction)
477 } 477 }
478} 478}
479 479
480static inline unsigned int rds_iw_flush_goal(struct rds_iw_mr_pool *pool, int free_all)
481{
482 unsigned int item_count;
483
484 item_count = atomic_read(&pool->item_count);
485 if (free_all)
486 return item_count;
487
488 return 0;
489}
490
491/* 480/*
492 * Flush our pool of MRs. 481 * Flush our pool of MRs.
493 * At a minimum, all currently unused MRs are unmapped. 482 * At a minimum, all currently unused MRs are unmapped.
@@ -500,7 +489,7 @@ static int rds_iw_flush_mr_pool(struct rds_iw_mr_pool *pool, int free_all)
500 LIST_HEAD(unmap_list); 489 LIST_HEAD(unmap_list);
501 LIST_HEAD(kill_list); 490 LIST_HEAD(kill_list);
502 unsigned long flags; 491 unsigned long flags;
503 unsigned int nfreed = 0, ncleaned = 0, unpinned = 0, free_goal; 492 unsigned int nfreed = 0, ncleaned = 0, unpinned = 0;
504 int ret = 0; 493 int ret = 0;
505 494
506 rds_iw_stats_inc(s_iw_rdma_mr_pool_flush); 495 rds_iw_stats_inc(s_iw_rdma_mr_pool_flush);
@@ -514,8 +503,6 @@ static int rds_iw_flush_mr_pool(struct rds_iw_mr_pool *pool, int free_all)
514 list_splice_init(&pool->clean_list, &kill_list); 503 list_splice_init(&pool->clean_list, &kill_list);
515 spin_unlock_irqrestore(&pool->list_lock, flags); 504 spin_unlock_irqrestore(&pool->list_lock, flags);
516 505
517 free_goal = rds_iw_flush_goal(pool, free_all);
518
519 /* Batched invalidate of dirty MRs. 506 /* Batched invalidate of dirty MRs.
520 * For FMR based MRs, the mappings on the unmap list are 507 * For FMR based MRs, the mappings on the unmap list are
521 * actually members of an ibmr (ibmr->mapping). They either 508 * actually members of an ibmr (ibmr->mapping). They either
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 0a7964009e8c..67494aef9acf 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -24,6 +24,7 @@
24#include <net/netlink.h> 24#include <net/netlink.h>
25#include <net/pkt_sched.h> 25#include <net/pkt_sched.h>
26#include <net/flow_keys.h> 26#include <net/flow_keys.h>
27#include <net/red.h>
27 28
28 29
29/* Stochastic Fairness Queuing algorithm. 30/* Stochastic Fairness Queuing algorithm.
@@ -108,24 +109,30 @@ struct sfq_slot {
108 struct sfq_head dep; /* anchor in dep[] chains */ 109 struct sfq_head dep; /* anchor in dep[] chains */
109 unsigned short hash; /* hash value (index in ht[]) */ 110 unsigned short hash; /* hash value (index in ht[]) */
110 short allot; /* credit for this slot */ 111 short allot; /* credit for this slot */
112
113 unsigned int backlog;
114 struct red_vars vars;
111}; 115};
112 116
113struct sfq_sched_data { 117struct sfq_sched_data {
114/* frequently used fields */ 118/* frequently used fields */
115 int limit; /* limit of total number of packets in this qdisc */ 119 int limit; /* limit of total number of packets in this qdisc */
116 unsigned int divisor; /* number of slots in hash table */ 120 unsigned int divisor; /* number of slots in hash table */
117 unsigned int maxflows; /* number of flows in flows array */ 121 u8 headdrop;
118 int headdrop; 122 u8 maxdepth; /* limit of packets per flow */
119 int maxdepth; /* limit of packets per flow */
120 123
121 u32 perturbation; 124 u32 perturbation;
122 struct tcf_proto *filter_list; 125 u8 cur_depth; /* depth of longest slot */
123 sfq_index cur_depth; /* depth of longest slot */ 126 u8 flags;
124 unsigned short scaled_quantum; /* SFQ_ALLOT_SIZE(quantum) */ 127 unsigned short scaled_quantum; /* SFQ_ALLOT_SIZE(quantum) */
125 struct sfq_slot *tail; /* current slot in round */ 128 struct tcf_proto *filter_list;
126 sfq_index *ht; /* Hash table ('divisor' slots) */ 129 sfq_index *ht; /* Hash table ('divisor' slots) */
127 struct sfq_slot *slots; /* Flows table ('maxflows' entries) */ 130 struct sfq_slot *slots; /* Flows table ('maxflows' entries) */
128 131
132 struct red_parms *red_parms;
133 struct tc_sfqred_stats stats;
134 struct sfq_slot *tail; /* current slot in round */
135
129 struct sfq_head dep[SFQ_MAX_DEPTH + 1]; 136 struct sfq_head dep[SFQ_MAX_DEPTH + 1];
130 /* Linked lists of slots, indexed by depth 137 /* Linked lists of slots, indexed by depth
131 * dep[0] : list of unused flows 138 * dep[0] : list of unused flows
@@ -133,6 +140,7 @@ struct sfq_sched_data {
133 * dep[X] : list of flows with X packets 140 * dep[X] : list of flows with X packets
134 */ 141 */
135 142
143 unsigned int maxflows; /* number of flows in flows array */
136 int perturb_period; 144 int perturb_period;
137 unsigned int quantum; /* Allotment per round: MUST BE >= MTU */ 145 unsigned int quantum; /* Allotment per round: MUST BE >= MTU */
138 struct timer_list perturb_timer; 146 struct timer_list perturb_timer;
@@ -321,6 +329,7 @@ static unsigned int sfq_drop(struct Qdisc *sch)
321drop: 329drop:
322 skb = q->headdrop ? slot_dequeue_head(slot) : slot_dequeue_tail(slot); 330 skb = q->headdrop ? slot_dequeue_head(slot) : slot_dequeue_tail(slot);
323 len = qdisc_pkt_len(skb); 331 len = qdisc_pkt_len(skb);
332 slot->backlog -= len;
324 sfq_dec(q, x); 333 sfq_dec(q, x);
325 kfree_skb(skb); 334 kfree_skb(skb);
326 sch->q.qlen--; 335 sch->q.qlen--;
@@ -341,6 +350,23 @@ drop:
341 return 0; 350 return 0;
342} 351}
343 352
353/* Is ECN parameter configured */
354static int sfq_prob_mark(const struct sfq_sched_data *q)
355{
356 return q->flags & TC_RED_ECN;
357}
358
359/* Should packets over max threshold just be marked */
360static int sfq_hard_mark(const struct sfq_sched_data *q)
361{
362 return (q->flags & (TC_RED_ECN | TC_RED_HARDDROP)) == TC_RED_ECN;
363}
364
365static int sfq_headdrop(const struct sfq_sched_data *q)
366{
367 return q->headdrop;
368}
369
344static int 370static int
345sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch) 371sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
346{ 372{
@@ -349,6 +375,8 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
349 sfq_index x, qlen; 375 sfq_index x, qlen;
350 struct sfq_slot *slot; 376 struct sfq_slot *slot;
351 int uninitialized_var(ret); 377 int uninitialized_var(ret);
378 struct sk_buff *head;
379 int delta;
352 380
353 hash = sfq_classify(skb, sch, &ret); 381 hash = sfq_classify(skb, sch, &ret);
354 if (hash == 0) { 382 if (hash == 0) {
@@ -368,24 +396,75 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
368 q->ht[hash] = x; 396 q->ht[hash] = x;
369 slot = &q->slots[x]; 397 slot = &q->slots[x];
370 slot->hash = hash; 398 slot->hash = hash;
399 slot->backlog = 0; /* should already be 0 anyway... */
400 red_set_vars(&slot->vars);
401 goto enqueue;
371 } 402 }
403 if (q->red_parms) {
404 slot->vars.qavg = red_calc_qavg_no_idle_time(q->red_parms,
405 &slot->vars,
406 slot->backlog);
407 switch (red_action(q->red_parms,
408 &slot->vars,
409 slot->vars.qavg)) {
410 case RED_DONT_MARK:
411 break;
372 412
373 if (slot->qlen >= q->maxdepth) { 413 case RED_PROB_MARK:
374 struct sk_buff *head; 414 sch->qstats.overlimits++;
415 if (sfq_prob_mark(q)) {
416 /* We know we have at least one packet in queue */
417 if (sfq_headdrop(q) &&
418 INET_ECN_set_ce(slot->skblist_next)) {
419 q->stats.prob_mark_head++;
420 break;
421 }
422 if (INET_ECN_set_ce(skb)) {
423 q->stats.prob_mark++;
424 break;
425 }
426 }
427 q->stats.prob_drop++;
428 goto congestion_drop;
429
430 case RED_HARD_MARK:
431 sch->qstats.overlimits++;
432 if (sfq_hard_mark(q)) {
433 /* We know we have at least one packet in queue */
434 if (sfq_headdrop(q) &&
435 INET_ECN_set_ce(slot->skblist_next)) {
436 q->stats.forced_mark_head++;
437 break;
438 }
439 if (INET_ECN_set_ce(skb)) {
440 q->stats.forced_mark++;
441 break;
442 }
443 }
444 q->stats.forced_drop++;
445 goto congestion_drop;
446 }
447 }
375 448
376 if (!q->headdrop) 449 if (slot->qlen >= q->maxdepth) {
450congestion_drop:
451 if (!sfq_headdrop(q))
377 return qdisc_drop(skb, sch); 452 return qdisc_drop(skb, sch);
378 453
454 /* We know we have at least one packet in queue */
379 head = slot_dequeue_head(slot); 455 head = slot_dequeue_head(slot);
380 sch->qstats.backlog -= qdisc_pkt_len(head); 456 delta = qdisc_pkt_len(head) - qdisc_pkt_len(skb);
457 sch->qstats.backlog -= delta;
458 slot->backlog -= delta;
381 qdisc_drop(head, sch); 459 qdisc_drop(head, sch);
382 460
383 sch->qstats.backlog += qdisc_pkt_len(skb);
384 slot_queue_add(slot, skb); 461 slot_queue_add(slot, skb);
385 return NET_XMIT_CN; 462 return NET_XMIT_CN;
386 } 463 }
387 464
465enqueue:
388 sch->qstats.backlog += qdisc_pkt_len(skb); 466 sch->qstats.backlog += qdisc_pkt_len(skb);
467 slot->backlog += qdisc_pkt_len(skb);
389 slot_queue_add(slot, skb); 468 slot_queue_add(slot, skb);
390 sfq_inc(q, x); 469 sfq_inc(q, x);
391 if (slot->qlen == 1) { /* The flow is new */ 470 if (slot->qlen == 1) { /* The flow is new */
@@ -396,6 +475,7 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
396 slot->next = q->tail->next; 475 slot->next = q->tail->next;
397 q->tail->next = x; 476 q->tail->next = x;
398 } 477 }
478 /* We could use a bigger initial quantum for new flows */
399 slot->allot = q->scaled_quantum; 479 slot->allot = q->scaled_quantum;
400 } 480 }
401 if (++sch->q.qlen <= q->limit) 481 if (++sch->q.qlen <= q->limit)
@@ -439,7 +519,7 @@ next_slot:
439 qdisc_bstats_update(sch, skb); 519 qdisc_bstats_update(sch, skb);
440 sch->q.qlen--; 520 sch->q.qlen--;
441 sch->qstats.backlog -= qdisc_pkt_len(skb); 521 sch->qstats.backlog -= qdisc_pkt_len(skb);
442 522 slot->backlog -= qdisc_pkt_len(skb);
443 /* Is the slot empty? */ 523 /* Is the slot empty? */
444 if (slot->qlen == 0) { 524 if (slot->qlen == 0) {
445 q->ht[slot->hash] = SFQ_EMPTY_SLOT; 525 q->ht[slot->hash] = SFQ_EMPTY_SLOT;
@@ -490,6 +570,8 @@ static void sfq_rehash(struct Qdisc *sch)
490 sfq_dec(q, i); 570 sfq_dec(q, i);
491 __skb_queue_tail(&list, skb); 571 __skb_queue_tail(&list, skb);
492 } 572 }
573 slot->backlog = 0;
574 red_set_vars(&slot->vars);
493 q->ht[slot->hash] = SFQ_EMPTY_SLOT; 575 q->ht[slot->hash] = SFQ_EMPTY_SLOT;
494 } 576 }
495 q->tail = NULL; 577 q->tail = NULL;
@@ -514,6 +596,11 @@ drop: sch->qstats.backlog -= qdisc_pkt_len(skb);
514 if (slot->qlen >= q->maxdepth) 596 if (slot->qlen >= q->maxdepth)
515 goto drop; 597 goto drop;
516 slot_queue_add(slot, skb); 598 slot_queue_add(slot, skb);
599 if (q->red_parms)
600 slot->vars.qavg = red_calc_qavg(q->red_parms,
601 &slot->vars,
602 slot->backlog);
603 slot->backlog += qdisc_pkt_len(skb);
517 sfq_inc(q, x); 604 sfq_inc(q, x);
518 if (slot->qlen == 1) { /* The flow is new */ 605 if (slot->qlen == 1) { /* The flow is new */
519 if (q->tail == NULL) { /* It is the first flow */ 606 if (q->tail == NULL) { /* It is the first flow */
@@ -552,6 +639,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
552 struct tc_sfq_qopt *ctl = nla_data(opt); 639 struct tc_sfq_qopt *ctl = nla_data(opt);
553 struct tc_sfq_qopt_v1 *ctl_v1 = NULL; 640 struct tc_sfq_qopt_v1 *ctl_v1 = NULL;
554 unsigned int qlen; 641 unsigned int qlen;
642 struct red_parms *p = NULL;
555 643
556 if (opt->nla_len < nla_attr_size(sizeof(*ctl))) 644 if (opt->nla_len < nla_attr_size(sizeof(*ctl)))
557 return -EINVAL; 645 return -EINVAL;
@@ -560,7 +648,11 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
560 if (ctl->divisor && 648 if (ctl->divisor &&
561 (!is_power_of_2(ctl->divisor) || ctl->divisor > 65536)) 649 (!is_power_of_2(ctl->divisor) || ctl->divisor > 65536))
562 return -EINVAL; 650 return -EINVAL;
563 651 if (ctl_v1 && ctl_v1->qth_min) {
652 p = kmalloc(sizeof(*p), GFP_KERNEL);
653 if (!p)
654 return -ENOMEM;
655 }
564 sch_tree_lock(sch); 656 sch_tree_lock(sch);
565 if (ctl->quantum) { 657 if (ctl->quantum) {
566 q->quantum = ctl->quantum; 658 q->quantum = ctl->quantum;
@@ -576,6 +668,16 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
576 if (ctl_v1) { 668 if (ctl_v1) {
577 if (ctl_v1->depth) 669 if (ctl_v1->depth)
578 q->maxdepth = min_t(u32, ctl_v1->depth, SFQ_MAX_DEPTH); 670 q->maxdepth = min_t(u32, ctl_v1->depth, SFQ_MAX_DEPTH);
671 if (p) {
672 swap(q->red_parms, p);
673 red_set_parms(q->red_parms,
674 ctl_v1->qth_min, ctl_v1->qth_max,
675 ctl_v1->Wlog,
676 ctl_v1->Plog, ctl_v1->Scell_log,
677 NULL,
678 ctl_v1->max_P);
679 }
680 q->flags = ctl_v1->flags;
579 q->headdrop = ctl_v1->headdrop; 681 q->headdrop = ctl_v1->headdrop;
580 } 682 }
581 if (ctl->limit) { 683 if (ctl->limit) {
@@ -594,6 +696,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
594 q->perturbation = net_random(); 696 q->perturbation = net_random();
595 } 697 }
596 sch_tree_unlock(sch); 698 sch_tree_unlock(sch);
699 kfree(p);
597 return 0; 700 return 0;
598} 701}
599 702
@@ -625,6 +728,7 @@ static void sfq_destroy(struct Qdisc *sch)
625 del_timer_sync(&q->perturb_timer); 728 del_timer_sync(&q->perturb_timer);
626 sfq_free(q->ht); 729 sfq_free(q->ht);
627 sfq_free(q->slots); 730 sfq_free(q->slots);
731 kfree(q->red_parms);
628} 732}
629 733
630static int sfq_init(struct Qdisc *sch, struct nlattr *opt) 734static int sfq_init(struct Qdisc *sch, struct nlattr *opt)
@@ -683,6 +787,7 @@ static int sfq_dump(struct Qdisc *sch, struct sk_buff *skb)
683 struct sfq_sched_data *q = qdisc_priv(sch); 787 struct sfq_sched_data *q = qdisc_priv(sch);
684 unsigned char *b = skb_tail_pointer(skb); 788 unsigned char *b = skb_tail_pointer(skb);
685 struct tc_sfq_qopt_v1 opt; 789 struct tc_sfq_qopt_v1 opt;
790 struct red_parms *p = q->red_parms;
686 791
687 memset(&opt, 0, sizeof(opt)); 792 memset(&opt, 0, sizeof(opt));
688 opt.v0.quantum = q->quantum; 793 opt.v0.quantum = q->quantum;
@@ -693,6 +798,17 @@ static int sfq_dump(struct Qdisc *sch, struct sk_buff *skb)
693 opt.depth = q->maxdepth; 798 opt.depth = q->maxdepth;
694 opt.headdrop = q->headdrop; 799 opt.headdrop = q->headdrop;
695 800
801 if (p) {
802 opt.qth_min = p->qth_min >> p->Wlog;
803 opt.qth_max = p->qth_max >> p->Wlog;
804 opt.Wlog = p->Wlog;
805 opt.Plog = p->Plog;
806 opt.Scell_log = p->Scell_log;
807 opt.max_P = p->max_P;
808 }
809 memcpy(&opt.stats, &q->stats, sizeof(opt.stats));
810 opt.flags = q->flags;
811
696 NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt); 812 NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
697 813
698 return skb->len; 814 return skb->len;
@@ -747,15 +863,13 @@ static int sfq_dump_class_stats(struct Qdisc *sch, unsigned long cl,
747 sfq_index idx = q->ht[cl - 1]; 863 sfq_index idx = q->ht[cl - 1];
748 struct gnet_stats_queue qs = { 0 }; 864 struct gnet_stats_queue qs = { 0 };
749 struct tc_sfq_xstats xstats = { 0 }; 865 struct tc_sfq_xstats xstats = { 0 };
750 struct sk_buff *skb;
751 866
752 if (idx != SFQ_EMPTY_SLOT) { 867 if (idx != SFQ_EMPTY_SLOT) {
753 const struct sfq_slot *slot = &q->slots[idx]; 868 const struct sfq_slot *slot = &q->slots[idx];
754 869
755 xstats.allot = slot->allot << SFQ_ALLOT_SHIFT; 870 xstats.allot = slot->allot << SFQ_ALLOT_SHIFT;
756 qs.qlen = slot->qlen; 871 qs.qlen = slot->qlen;
757 slot_queue_walk(slot, skb) 872 qs.backlog = slot->backlog;
758 qs.backlog += qdisc_pkt_len(skb);
759 } 873 }
760 if (gnet_stats_copy_queue(d, &qs) < 0) 874 if (gnet_stats_copy_queue(d, &qs) < 0)
761 return -1; 875 return -1;
diff --git a/net/socket.c b/net/socket.c
index e56162cd65b0..28a96af484b4 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2492,7 +2492,7 @@ int sock_register(const struct net_proto_family *ops)
2492 lockdep_is_held(&net_family_lock))) 2492 lockdep_is_held(&net_family_lock)))
2493 err = -EEXIST; 2493 err = -EEXIST;
2494 else { 2494 else {
2495 RCU_INIT_POINTER(net_families[ops->family], ops); 2495 rcu_assign_pointer(net_families[ops->family], ops);
2496 err = 0; 2496 err = 0;
2497 } 2497 }
2498 spin_unlock(&net_family_lock); 2498 spin_unlock(&net_family_lock);
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 28d72d298735..affa631ac1ab 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -122,7 +122,7 @@ gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
122 if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags)) 122 if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags))
123 return; 123 return;
124 gss_get_ctx(ctx); 124 gss_get_ctx(ctx);
125 RCU_INIT_POINTER(gss_cred->gc_ctx, ctx); 125 rcu_assign_pointer(gss_cred->gc_ctx, ctx);
126 set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 126 set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
127 smp_mb__before_clear_bit(); 127 smp_mb__before_clear_bit();
128 clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags); 128 clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags);
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 03b56bc3b659..465df9ae1046 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -1641,6 +1641,7 @@ int cache_register_net(struct cache_detail *cd, struct net *net)
1641 sunrpc_destroy_cache_detail(cd); 1641 sunrpc_destroy_cache_detail(cd);
1642 return ret; 1642 return ret;
1643} 1643}
1644EXPORT_SYMBOL_GPL(cache_register_net);
1644 1645
1645int cache_register(struct cache_detail *cd) 1646int cache_register(struct cache_detail *cd)
1646{ 1647{
@@ -1653,6 +1654,7 @@ void cache_unregister_net(struct cache_detail *cd, struct net *net)
1653 remove_cache_proc_entries(cd, net); 1654 remove_cache_proc_entries(cd, net);
1654 sunrpc_destroy_cache_detail(cd); 1655 sunrpc_destroy_cache_detail(cd);
1655} 1656}
1657EXPORT_SYMBOL_GPL(cache_unregister_net);
1656 1658
1657void cache_unregister(struct cache_detail *cd) 1659void cache_unregister(struct cache_detail *cd)
1658{ 1660{
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 9d01d46b05f3..e4aabc02368b 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -167,6 +167,7 @@ svc_pool_map_alloc_arrays(struct svc_pool_map *m, unsigned int maxpools)
167 167
168fail_free: 168fail_free:
169 kfree(m->to_pool); 169 kfree(m->to_pool);
170 m->to_pool = NULL;
170fail: 171fail:
171 return -ENOMEM; 172 return -ENOMEM;
172} 173}
@@ -285,9 +286,10 @@ svc_pool_map_put(void)
285 mutex_lock(&svc_pool_map_mutex); 286 mutex_lock(&svc_pool_map_mutex);
286 287
287 if (!--m->count) { 288 if (!--m->count) {
288 m->mode = SVC_POOL_DEFAULT;
289 kfree(m->to_pool); 289 kfree(m->to_pool);
290 m->to_pool = NULL;
290 kfree(m->pool_to); 291 kfree(m->pool_to);
292 m->pool_to = NULL;
291 m->npools = 0; 293 m->npools = 0;
292 } 294 }
293 295
@@ -527,17 +529,20 @@ svc_destroy(struct svc_serv *serv)
527 printk("svc_destroy: no threads for serv=%p!\n", serv); 529 printk("svc_destroy: no threads for serv=%p!\n", serv);
528 530
529 del_timer_sync(&serv->sv_temptimer); 531 del_timer_sync(&serv->sv_temptimer);
530 532 /*
531 svc_close_all(&serv->sv_tempsocks); 533 * The set of xprts (contained in the sv_tempsocks and
534 * sv_permsocks lists) is now constant, since it is modified
535 * only by accepting new sockets (done by service threads in
536 * svc_recv) or aging old ones (done by sv_temptimer), or
537 * configuration changes (excluded by whatever locking the
538 * caller is using--nfsd_mutex in the case of nfsd). So it's
539 * safe to traverse those lists and shut everything down:
540 */
541 svc_close_all(serv);
532 542
533 if (serv->sv_shutdown) 543 if (serv->sv_shutdown)
534 serv->sv_shutdown(serv); 544 serv->sv_shutdown(serv);
535 545
536 svc_close_all(&serv->sv_permsocks);
537
538 BUG_ON(!list_empty(&serv->sv_permsocks));
539 BUG_ON(!list_empty(&serv->sv_tempsocks));
540
541 cache_clean_deferred(serv); 546 cache_clean_deferred(serv);
542 547
543 if (svc_serv_is_pooled(serv)) 548 if (svc_serv_is_pooled(serv))
@@ -683,8 +688,8 @@ found_pool:
683 * Create or destroy enough new threads to make the number 688 * Create or destroy enough new threads to make the number
684 * of threads the given number. If `pool' is non-NULL, applies 689 * of threads the given number. If `pool' is non-NULL, applies
685 * only to threads in that pool, otherwise round-robins between 690 * only to threads in that pool, otherwise round-robins between
686 * all pools. Must be called with a svc_get() reference and 691 * all pools. Caller must ensure that mutual exclusion between this and
687 * the BKL or another lock to protect access to svc_serv fields. 692 * server startup or shutdown.
688 * 693 *
689 * Destroying threads relies on the service threads filling in 694 * Destroying threads relies on the service threads filling in
690 * rqstp->rq_task, which only the nfs ones do. Assumes the serv 695 * rqstp->rq_task, which only the nfs ones do. Assumes the serv
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 38649cfa4e81..74cb0d8e9ca1 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -22,6 +22,7 @@ static struct svc_deferred_req *svc_deferred_dequeue(struct svc_xprt *xprt);
22static int svc_deferred_recv(struct svc_rqst *rqstp); 22static int svc_deferred_recv(struct svc_rqst *rqstp);
23static struct cache_deferred_req *svc_defer(struct cache_req *req); 23static struct cache_deferred_req *svc_defer(struct cache_req *req);
24static void svc_age_temp_xprts(unsigned long closure); 24static void svc_age_temp_xprts(unsigned long closure);
25static void svc_delete_xprt(struct svc_xprt *xprt);
25 26
26/* apparently the "standard" is that clients close 27/* apparently the "standard" is that clients close
27 * idle connections after 5 minutes, servers after 28 * idle connections after 5 minutes, servers after
@@ -147,8 +148,8 @@ EXPORT_SYMBOL_GPL(svc_xprt_put);
147 * Called by transport drivers to initialize the transport independent 148 * Called by transport drivers to initialize the transport independent
148 * portion of the transport instance. 149 * portion of the transport instance.
149 */ 150 */
150void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt, 151void svc_xprt_init(struct net *net, struct svc_xprt_class *xcl,
151 struct svc_serv *serv) 152 struct svc_xprt *xprt, struct svc_serv *serv)
152{ 153{
153 memset(xprt, 0, sizeof(*xprt)); 154 memset(xprt, 0, sizeof(*xprt));
154 xprt->xpt_class = xcl; 155 xprt->xpt_class = xcl;
@@ -163,7 +164,7 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt,
163 spin_lock_init(&xprt->xpt_lock); 164 spin_lock_init(&xprt->xpt_lock);
164 set_bit(XPT_BUSY, &xprt->xpt_flags); 165 set_bit(XPT_BUSY, &xprt->xpt_flags);
165 rpc_init_wait_queue(&xprt->xpt_bc_pending, "xpt_bc_pending"); 166 rpc_init_wait_queue(&xprt->xpt_bc_pending, "xpt_bc_pending");
166 xprt->xpt_net = get_net(&init_net); 167 xprt->xpt_net = get_net(net);
167} 168}
168EXPORT_SYMBOL_GPL(svc_xprt_init); 169EXPORT_SYMBOL_GPL(svc_xprt_init);
169 170
@@ -878,7 +879,7 @@ static void call_xpt_users(struct svc_xprt *xprt)
878/* 879/*
879 * Remove a dead transport 880 * Remove a dead transport
880 */ 881 */
881void svc_delete_xprt(struct svc_xprt *xprt) 882static void svc_delete_xprt(struct svc_xprt *xprt)
882{ 883{
883 struct svc_serv *serv = xprt->xpt_server; 884 struct svc_serv *serv = xprt->xpt_server;
884 struct svc_deferred_req *dr; 885 struct svc_deferred_req *dr;
@@ -893,14 +894,7 @@ void svc_delete_xprt(struct svc_xprt *xprt)
893 spin_lock_bh(&serv->sv_lock); 894 spin_lock_bh(&serv->sv_lock);
894 if (!test_and_set_bit(XPT_DETACHED, &xprt->xpt_flags)) 895 if (!test_and_set_bit(XPT_DETACHED, &xprt->xpt_flags))
895 list_del_init(&xprt->xpt_list); 896 list_del_init(&xprt->xpt_list);
896 /* 897 BUG_ON(!list_empty(&xprt->xpt_ready));
897 * The only time we're called while xpt_ready is still on a list
898 * is while the list itself is about to be destroyed (in
899 * svc_destroy). BUT svc_xprt_enqueue could still be attempting
900 * to add new entries to the sp_sockets list, so we can't leave
901 * a freed xprt on it.
902 */
903 list_del_init(&xprt->xpt_ready);
904 if (test_bit(XPT_TEMP, &xprt->xpt_flags)) 898 if (test_bit(XPT_TEMP, &xprt->xpt_flags))
905 serv->sv_tmpcnt--; 899 serv->sv_tmpcnt--;
906 spin_unlock_bh(&serv->sv_lock); 900 spin_unlock_bh(&serv->sv_lock);
@@ -928,22 +922,48 @@ void svc_close_xprt(struct svc_xprt *xprt)
928} 922}
929EXPORT_SYMBOL_GPL(svc_close_xprt); 923EXPORT_SYMBOL_GPL(svc_close_xprt);
930 924
931void svc_close_all(struct list_head *xprt_list) 925static void svc_close_list(struct list_head *xprt_list)
926{
927 struct svc_xprt *xprt;
928
929 list_for_each_entry(xprt, xprt_list, xpt_list) {
930 set_bit(XPT_CLOSE, &xprt->xpt_flags);
931 set_bit(XPT_BUSY, &xprt->xpt_flags);
932 }
933}
934
935void svc_close_all(struct svc_serv *serv)
932{ 936{
937 struct svc_pool *pool;
933 struct svc_xprt *xprt; 938 struct svc_xprt *xprt;
934 struct svc_xprt *tmp; 939 struct svc_xprt *tmp;
940 int i;
941
942 svc_close_list(&serv->sv_tempsocks);
943 svc_close_list(&serv->sv_permsocks);
935 944
945 for (i = 0; i < serv->sv_nrpools; i++) {
946 pool = &serv->sv_pools[i];
947
948 spin_lock_bh(&pool->sp_lock);
949 while (!list_empty(&pool->sp_sockets)) {
950 xprt = list_first_entry(&pool->sp_sockets, struct svc_xprt, xpt_ready);
951 list_del_init(&xprt->xpt_ready);
952 }
953 spin_unlock_bh(&pool->sp_lock);
954 }
936 /* 955 /*
937 * The server is shutting down, and no more threads are running. 956 * At this point the sp_sockets lists will stay empty, since
938 * svc_xprt_enqueue() might still be running, but at worst it 957 * svc_enqueue will not add new entries without taking the
939 * will re-add the xprt to sp_sockets, which will soon get 958 * sp_lock and checking XPT_BUSY.
940 * freed. So we don't bother with any more locking, and don't
941 * leave the close to the (nonexistent) server threads:
942 */ 959 */
943 list_for_each_entry_safe(xprt, tmp, xprt_list, xpt_list) { 960 list_for_each_entry_safe(xprt, tmp, &serv->sv_tempsocks, xpt_list)
944 set_bit(XPT_CLOSE, &xprt->xpt_flags);
945 svc_delete_xprt(xprt); 961 svc_delete_xprt(xprt);
946 } 962 list_for_each_entry_safe(xprt, tmp, &serv->sv_permsocks, xpt_list)
963 svc_delete_xprt(xprt);
964
965 BUG_ON(!list_empty(&serv->sv_permsocks));
966 BUG_ON(!list_empty(&serv->sv_tempsocks));
947} 967}
948 968
949/* 969/*
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 4653286fcc9e..464570906f80 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -739,7 +739,8 @@ static void svc_udp_init(struct svc_sock *svsk, struct svc_serv *serv)
739{ 739{
740 int err, level, optname, one = 1; 740 int err, level, optname, one = 1;
741 741
742 svc_xprt_init(&svc_udp_class, &svsk->sk_xprt, serv); 742 svc_xprt_init(sock_net(svsk->sk_sock->sk), &svc_udp_class,
743 &svsk->sk_xprt, serv);
743 clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); 744 clear_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
744 svsk->sk_sk->sk_data_ready = svc_udp_data_ready; 745 svsk->sk_sk->sk_data_ready = svc_udp_data_ready;
745 svsk->sk_sk->sk_write_space = svc_write_space; 746 svsk->sk_sk->sk_write_space = svc_write_space;
@@ -1343,7 +1344,8 @@ static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)
1343{ 1344{
1344 struct sock *sk = svsk->sk_sk; 1345 struct sock *sk = svsk->sk_sk;
1345 1346
1346 svc_xprt_init(&svc_tcp_class, &svsk->sk_xprt, serv); 1347 svc_xprt_init(sock_net(svsk->sk_sock->sk), &svc_tcp_class,
1348 &svsk->sk_xprt, serv);
1347 set_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); 1349 set_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
1348 if (sk->sk_state == TCP_LISTEN) { 1350 if (sk->sk_state == TCP_LISTEN) {
1349 dprintk("setting up TCP socket for listening\n"); 1351 dprintk("setting up TCP socket for listening\n");
@@ -1659,7 +1661,7 @@ static struct svc_xprt *svc_bc_create_socket(struct svc_serv *serv,
1659 return ERR_PTR(-ENOMEM); 1661 return ERR_PTR(-ENOMEM);
1660 1662
1661 xprt = &svsk->sk_xprt; 1663 xprt = &svsk->sk_xprt;
1662 svc_xprt_init(&svc_tcp_bc_class, xprt, serv); 1664 svc_xprt_init(net, &svc_tcp_bc_class, xprt, serv);
1663 1665
1664 serv->sv_bc_xprt = xprt; 1666 serv->sv_bc_xprt = xprt;
1665 1667
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
index ba1296d88de0..894cb42db91d 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
@@ -453,7 +453,7 @@ static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv,
453 453
454 if (!cma_xprt) 454 if (!cma_xprt)
455 return NULL; 455 return NULL;
456 svc_xprt_init(&svc_rdma_class, &cma_xprt->sc_xprt, serv); 456 svc_xprt_init(&init_net, &svc_rdma_class, &cma_xprt->sc_xprt, serv);
457 INIT_LIST_HEAD(&cma_xprt->sc_accept_q); 457 INIT_LIST_HEAD(&cma_xprt->sc_accept_q);
458 INIT_LIST_HEAD(&cma_xprt->sc_dto_q); 458 INIT_LIST_HEAD(&cma_xprt->sc_dto_q);
459 INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q); 459 INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index b3d3cf8931cb..afeea32e04ad 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2250,6 +2250,7 @@ static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
2250}; 2250};
2251 2251
2252static int parse_station_flags(struct genl_info *info, 2252static int parse_station_flags(struct genl_info *info,
2253 enum nl80211_iftype iftype,
2253 struct station_parameters *params) 2254 struct station_parameters *params)
2254{ 2255{
2255 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 2256 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
@@ -2283,8 +2284,33 @@ static int parse_station_flags(struct genl_info *info,
2283 nla, sta_flags_policy)) 2284 nla, sta_flags_policy))
2284 return -EINVAL; 2285 return -EINVAL;
2285 2286
2286 params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; 2287 /*
2287 params->sta_flags_mask &= ~1; 2288 * Only allow certain flags for interface types so that
2289 * other attributes are silently ignored. Remember that
2290 * this is backward compatibility code with old userspace
2291 * and shouldn't be hit in other cases anyway.
2292 */
2293 switch (iftype) {
2294 case NL80211_IFTYPE_AP:
2295 case NL80211_IFTYPE_AP_VLAN:
2296 case NL80211_IFTYPE_P2P_GO:
2297 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2298 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2299 BIT(NL80211_STA_FLAG_WME) |
2300 BIT(NL80211_STA_FLAG_MFP);
2301 break;
2302 case NL80211_IFTYPE_P2P_CLIENT:
2303 case NL80211_IFTYPE_STATION:
2304 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2305 BIT(NL80211_STA_FLAG_TDLS_PEER);
2306 break;
2307 case NL80211_IFTYPE_MESH_POINT:
2308 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2309 BIT(NL80211_STA_FLAG_MFP) |
2310 BIT(NL80211_STA_FLAG_AUTHORIZED);
2311 default:
2312 return -EINVAL;
2313 }
2288 2314
2289 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) 2315 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
2290 if (flags[flag]) 2316 if (flags[flag])
@@ -2585,7 +2611,7 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
2585 if (!rdev->ops->change_station) 2611 if (!rdev->ops->change_station)
2586 return -EOPNOTSUPP; 2612 return -EOPNOTSUPP;
2587 2613
2588 if (parse_station_flags(info, &params)) 2614 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
2589 return -EINVAL; 2615 return -EINVAL;
2590 2616
2591 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 2617 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
@@ -2731,7 +2757,7 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
2731 if (!rdev->ops->add_station) 2757 if (!rdev->ops->add_station)
2732 return -EOPNOTSUPP; 2758 return -EOPNOTSUPP;
2733 2759
2734 if (parse_station_flags(info, &params)) 2760 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
2735 return -EINVAL; 2761 return -EINVAL;
2736 2762
2737 switch (dev->ieee80211_ptr->iftype) { 2763 switch (dev->ieee80211_ptr->iftype) {
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index e0d747a2e803..637f11a1e4df 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -2927,7 +2927,7 @@ static int __net_init xfrm_user_net_init(struct net *net)
2927 if (nlsk == NULL) 2927 if (nlsk == NULL)
2928 return -ENOMEM; 2928 return -ENOMEM;
2929 net->xfrm.nlsk_stash = nlsk; /* Don't set to NULL */ 2929 net->xfrm.nlsk_stash = nlsk; /* Don't set to NULL */
2930 RCU_INIT_POINTER(net->xfrm.nlsk, nlsk); 2930 rcu_assign_pointer(net->xfrm.nlsk, nlsk);
2931 return 0; 2931 return 0;
2932} 2932}
2933 2933
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index e8c969577768..c0e14b3f2306 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -823,6 +823,16 @@ static int do_spi_entry(const char *filename, struct spi_device_id *id,
823} 823}
824ADD_TO_DEVTABLE("spi", struct spi_device_id, do_spi_entry); 824ADD_TO_DEVTABLE("spi", struct spi_device_id, do_spi_entry);
825 825
826/* Looks like: mcp:S */
827static int do_mcp_entry(const char *filename, struct mcp_device_id *id,
828 char *alias)
829{
830 sprintf(alias, MCP_MODULE_PREFIX "%s", id->name);
831
832 return 1;
833}
834ADD_TO_DEVTABLE("mcp", struct mcp_device_id, do_mcp_entry);
835
826static const struct dmifield { 836static const struct dmifield {
827 const char *prefix; 837 const char *prefix;
828 int field; 838 int field;
diff --git a/tools/nfsd/inject_fault.sh b/tools/nfsd/inject_fault.sh
new file mode 100755
index 000000000000..06a399ac8b2f
--- /dev/null
+++ b/tools/nfsd/inject_fault.sh
@@ -0,0 +1,49 @@
1#!/bin/bash
2#
3# Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
4#
5# Script for easier NFSD fault injection
6
7# Check that debugfs has been mounted
8DEBUGFS=`cat /proc/mounts | grep debugfs`
9if [ "$DEBUGFS" == "" ]; then
10 echo "debugfs does not appear to be mounted!"
11 echo "Please mount debugfs and try again"
12 exit 1
13fi
14
15# Check that the fault injection directory exists
16DEBUGDIR=`echo $DEBUGFS | awk '{print $2}'`/nfsd
17if [ ! -d "$DEBUGDIR" ]; then
18 echo "$DEBUGDIR does not exist"
19 echo "Check that your .config selects CONFIG_NFSD_FAULT_INJECTION"
20 exit 1
21fi
22
23function help()
24{
25 echo "Usage $0 injection_type [count]"
26 echo ""
27 echo "Injection types are:"
28 ls $DEBUGDIR
29 exit 1
30}
31
32if [ $# == 0 ]; then
33 help
34elif [ ! -f $DEBUGDIR/$1 ]; then
35 help
36elif [ $# != 2 ]; then
37 COUNT=0
38else
39 COUNT=$2
40fi
41
42BEFORE=`mktemp`
43AFTER=`mktemp`
44dmesg > $BEFORE
45echo $COUNT > $DEBUGDIR/$1
46dmesg > $AFTER
47# Capture lines that only exist in the $AFTER file
48diff $BEFORE $AFTER | grep ">"
49rm -f $BEFORE $AFTER
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
new file mode 100644
index 000000000000..4ec84018cc13
--- /dev/null
+++ b/tools/testing/selftests/Makefile
@@ -0,0 +1,11 @@
1TARGETS = breakpoints
2
3all:
4 for TARGET in $(TARGETS); do \
5 make -C $$TARGET; \
6 done;
7
8clean:
9 for TARGET in $(TARGETS); do \
10 make -C $$TARGET clean; \
11 done;
diff --git a/tools/testing/selftests/breakpoints/Makefile b/tools/testing/selftests/breakpoints/Makefile
new file mode 100644
index 000000000000..f362722cdce7
--- /dev/null
+++ b/tools/testing/selftests/breakpoints/Makefile
@@ -0,0 +1,20 @@
1# Taken from perf makefile
2uname_M := $(shell uname -m 2>/dev/null || echo not)
3ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
4ifeq ($(ARCH),i386)
5 ARCH := x86
6endif
7ifeq ($(ARCH),x86_64)
8 ARCH := x86
9endif
10
11
12all:
13ifeq ($(ARCH),x86)
14 gcc breakpoint_test.c -o run_test
15else
16 echo "Not an x86 target, can't build breakpoints selftests"
17endif
18
19clean:
20 rm -fr run_test
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tools/testing/selftests/breakpoints/breakpoint_test.c
new file mode 100644
index 000000000000..a0743f3b2b57
--- /dev/null
+++ b/tools/testing/selftests/breakpoints/breakpoint_test.c
@@ -0,0 +1,394 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc., Frederic Weisbecker <fweisbec@redhat.com>
3 *
4 * Licensed under the terms of the GNU GPL License version 2
5 *
6 * Selftests for breakpoints (and more generally the do_debug() path) in x86.
7 */
8
9
10#include <sys/ptrace.h>
11#include <unistd.h>
12#include <stddef.h>
13#include <sys/user.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <signal.h>
17#include <sys/types.h>
18#include <sys/wait.h>
19
20
21/* Breakpoint access modes */
22enum {
23 BP_X = 1,
24 BP_RW = 2,
25 BP_W = 4,
26};
27
28static pid_t child_pid;
29
30/*
31 * Ensures the child and parent are always "talking" about
32 * the same test sequence. (ie: that we haven't forgotten
33 * to call check_trapped() somewhere).
34 */
35static int nr_tests;
36
37static void set_breakpoint_addr(void *addr, int n)
38{
39 int ret;
40
41 ret = ptrace(PTRACE_POKEUSER, child_pid,
42 offsetof(struct user, u_debugreg[n]), addr);
43 if (ret) {
44 perror("Can't set breakpoint addr\n");
45 exit(-1);
46 }
47}
48
49static void toggle_breakpoint(int n, int type, int len,
50 int local, int global, int set)
51{
52 int ret;
53
54 int xtype, xlen;
55 unsigned long vdr7, dr7;
56
57 switch (type) {
58 case BP_X:
59 xtype = 0;
60 break;
61 case BP_W:
62 xtype = 1;
63 break;
64 case BP_RW:
65 xtype = 3;
66 break;
67 }
68
69 switch (len) {
70 case 1:
71 xlen = 0;
72 break;
73 case 2:
74 xlen = 4;
75 break;
76 case 4:
77 xlen = 0xc;
78 break;
79 case 8:
80 xlen = 8;
81 break;
82 }
83
84 dr7 = ptrace(PTRACE_PEEKUSER, child_pid,
85 offsetof(struct user, u_debugreg[7]), 0);
86
87 vdr7 = (xlen | xtype) << 16;
88 vdr7 <<= 4 * n;
89
90 if (local) {
91 vdr7 |= 1 << (2 * n);
92 vdr7 |= 1 << 8;
93 }
94 if (global) {
95 vdr7 |= 2 << (2 * n);
96 vdr7 |= 1 << 9;
97 }
98
99 if (set)
100 dr7 |= vdr7;
101 else
102 dr7 &= ~vdr7;
103
104 ret = ptrace(PTRACE_POKEUSER, child_pid,
105 offsetof(struct user, u_debugreg[7]), dr7);
106 if (ret) {
107 perror("Can't set dr7");
108 exit(-1);
109 }
110}
111
112/* Dummy variables to test read/write accesses */
113static unsigned long long dummy_var[4];
114
115/* Dummy functions to test execution accesses */
116static void dummy_func(void) { }
117static void dummy_func1(void) { }
118static void dummy_func2(void) { }
119static void dummy_func3(void) { }
120
121static void (*dummy_funcs[])(void) = {
122 dummy_func,
123 dummy_func1,
124 dummy_func2,
125 dummy_func3,
126};
127
128static int trapped;
129
130static void check_trapped(void)
131{
132 /*
133 * If we haven't trapped, wake up the parent
134 * so that it notices the failure.
135 */
136 if (!trapped)
137 kill(getpid(), SIGUSR1);
138 trapped = 0;
139
140 nr_tests++;
141}
142
143static void write_var(int len)
144{
145 char *pcval; short *psval; int *pival; long long *plval;
146 int i;
147
148 for (i = 0; i < 4; i++) {
149 switch (len) {
150 case 1:
151 pcval = (char *)&dummy_var[i];
152 *pcval = 0xff;
153 break;
154 case 2:
155 psval = (short *)&dummy_var[i];
156 *psval = 0xffff;
157 break;
158 case 4:
159 pival = (int *)&dummy_var[i];
160 *pival = 0xffffffff;
161 break;
162 case 8:
163 plval = (long long *)&dummy_var[i];
164 *plval = 0xffffffffffffffffLL;
165 break;
166 }
167 check_trapped();
168 }
169}
170
171static void read_var(int len)
172{
173 char cval; short sval; int ival; long long lval;
174 int i;
175
176 for (i = 0; i < 4; i++) {
177 switch (len) {
178 case 1:
179 cval = *(char *)&dummy_var[i];
180 break;
181 case 2:
182 sval = *(short *)&dummy_var[i];
183 break;
184 case 4:
185 ival = *(int *)&dummy_var[i];
186 break;
187 case 8:
188 lval = *(long long *)&dummy_var[i];
189 break;
190 }
191 check_trapped();
192 }
193}
194
195/*
196 * Do the r/w/x accesses to trigger the breakpoints. And run
197 * the usual traps.
198 */
199static void trigger_tests(void)
200{
201 int len, local, global, i;
202 char val;
203 int ret;
204
205 ret = ptrace(PTRACE_TRACEME, 0, NULL, 0);
206 if (ret) {
207 perror("Can't be traced?\n");
208 return;
209 }
210
211 /* Wake up father so that it sets up the first test */
212 kill(getpid(), SIGUSR1);
213
214 /* Test instruction breakpoints */
215 for (local = 0; local < 2; local++) {
216 for (global = 0; global < 2; global++) {
217 if (!local && !global)
218 continue;
219
220 for (i = 0; i < 4; i++) {
221 dummy_funcs[i]();
222 check_trapped();
223 }
224 }
225 }
226
227 /* Test write watchpoints */
228 for (len = 1; len <= sizeof(long); len <<= 1) {
229 for (local = 0; local < 2; local++) {
230 for (global = 0; global < 2; global++) {
231 if (!local && !global)
232 continue;
233 write_var(len);
234 }
235 }
236 }
237
238 /* Test read/write watchpoints (on read accesses) */
239 for (len = 1; len <= sizeof(long); len <<= 1) {
240 for (local = 0; local < 2; local++) {
241 for (global = 0; global < 2; global++) {
242 if (!local && !global)
243 continue;
244 read_var(len);
245 }
246 }
247 }
248
249 /* Icebp trap */
250 asm(".byte 0xf1\n");
251 check_trapped();
252
253 /* Int 3 trap */
254 asm("int $3\n");
255 check_trapped();
256
257 kill(getpid(), SIGUSR1);
258}
259
260static void check_success(const char *msg)
261{
262 const char *msg2;
263 int child_nr_tests;
264 int status;
265
266 /* Wait for the child to SIGTRAP */
267 wait(&status);
268
269 msg2 = "Failed";
270
271 if (WSTOPSIG(status) == SIGTRAP) {
272 child_nr_tests = ptrace(PTRACE_PEEKDATA, child_pid,
273 &nr_tests, 0);
274 if (child_nr_tests == nr_tests)
275 msg2 = "Ok";
276 if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) {
277 perror("Can't poke\n");
278 exit(-1);
279 }
280 }
281
282 nr_tests++;
283
284 printf("%s [%s]\n", msg, msg2);
285}
286
287static void launch_instruction_breakpoints(char *buf, int local, int global)
288{
289 int i;
290
291 for (i = 0; i < 4; i++) {
292 set_breakpoint_addr(dummy_funcs[i], i);
293 toggle_breakpoint(i, BP_X, 1, local, global, 1);
294 ptrace(PTRACE_CONT, child_pid, NULL, 0);
295 sprintf(buf, "Test breakpoint %d with local: %d global: %d",
296 i, local, global);
297 check_success(buf);
298 toggle_breakpoint(i, BP_X, 1, local, global, 0);
299 }
300}
301
302static void launch_watchpoints(char *buf, int mode, int len,
303 int local, int global)
304{
305 const char *mode_str;
306 int i;
307
308 if (mode == BP_W)
309 mode_str = "write";
310 else
311 mode_str = "read";
312
313 for (i = 0; i < 4; i++) {
314 set_breakpoint_addr(&dummy_var[i], i);
315 toggle_breakpoint(i, mode, len, local, global, 1);
316 ptrace(PTRACE_CONT, child_pid, NULL, 0);
317 sprintf(buf, "Test %s watchpoint %d with len: %d local: "
318 "%d global: %d", mode_str, i, len, local, global);
319 check_success(buf);
320 toggle_breakpoint(i, mode, len, local, global, 0);
321 }
322}
323
324/* Set the breakpoints and check the child successfully trigger them */
325static void launch_tests(void)
326{
327 char buf[1024];
328 int len, local, global, i;
329
330 /* Instruction breakpoints */
331 for (local = 0; local < 2; local++) {
332 for (global = 0; global < 2; global++) {
333 if (!local && !global)
334 continue;
335 launch_instruction_breakpoints(buf, local, global);
336 }
337 }
338
339 /* Write watchpoint */
340 for (len = 1; len <= sizeof(long); len <<= 1) {
341 for (local = 0; local < 2; local++) {
342 for (global = 0; global < 2; global++) {
343 if (!local && !global)
344 continue;
345 launch_watchpoints(buf, BP_W, len,
346 local, global);
347 }
348 }
349 }
350
351 /* Read-Write watchpoint */
352 for (len = 1; len <= sizeof(long); len <<= 1) {
353 for (local = 0; local < 2; local++) {
354 for (global = 0; global < 2; global++) {
355 if (!local && !global)
356 continue;
357 launch_watchpoints(buf, BP_RW, len,
358 local, global);
359 }
360 }
361 }
362
363 /* Icebp traps */
364 ptrace(PTRACE_CONT, child_pid, NULL, 0);
365 check_success("Test icebp");
366
367 /* Int 3 traps */
368 ptrace(PTRACE_CONT, child_pid, NULL, 0);
369 check_success("Test int 3 trap");
370
371 ptrace(PTRACE_CONT, child_pid, NULL, 0);
372}
373
374int main(int argc, char **argv)
375{
376 pid_t pid;
377 int ret;
378
379 pid = fork();
380 if (!pid) {
381 trigger_tests();
382 return 0;
383 }
384
385 child_pid = pid;
386
387 wait(NULL);
388
389 launch_tests();
390
391 wait(NULL);
392
393 return 0;
394}
diff --git a/tools/testing/selftests/run_tests b/tools/testing/selftests/run_tests
new file mode 100644
index 000000000000..320718a4e6bf
--- /dev/null
+++ b/tools/testing/selftests/run_tests
@@ -0,0 +1,8 @@
1#!/bin/bash
2
3TARGETS=breakpoints
4
5for TARGET in $TARGETS
6do
7 $TARGET/run_test
8done